Skip to content
Browse files

Fix Issue 311: REPL background color is white only -- cannot use dark…

… theme
  • Loading branch information...
1 parent 741a7cc commit 1e4ed0cfed1c7805f25bc53fb02498b7ca11741e @laurentpetit committed Oct 5, 2012
View
35 ccw.core/src/clj/ccw/repl/view_helpers.clj
@@ -38,34 +38,43 @@
(def ^{:private true} default-log-style (partial set-style-range #(StyleRange.)))
(def ^{:private true} log-styles
- (let [colored-style #(let [s (StyleRange.)]
- (set! (.foreground s) (CCWPlugin/getSystemColor %))
- s)]
- {:err [(partial set-style-range #(colored-style SWT/COLOR_DARK_RED)) nil]
+ (let [colored-style #(let [s (StyleRange.)
+ color-rgb (ccw.editors.clojure.ClojureSourceViewer/getRGBColor (.getCombinedPreferenceStore (CCWPlugin/getDefault)) %)
+ color (CCWPlugin/getColor color-rgb)]
+ (println "color: " color)
+ (when color (set! (.foreground s) color))
+ s)
+ error-rgb-key (ccw.preferences.PreferenceConstants/getTokenPreferenceKey ccw.preferences.PreferenceConstants/replLogError)
+ value-rgb-key (ccw.preferences.PreferenceConstants/getTokenPreferenceKey ccw.preferences.PreferenceConstants/replLogValue)]
+ {:err [(partial set-style-range #(colored-style error-rgb-key)) nil]
:out [default-log-style nil]
- :value [(partial set-style-range #(colored-style SWT/COLOR_DARK_GREEN)) nil]
- :in-expr [default-log-style "ccw.repl.expressionBackground"]}))
+ :value [(partial set-style-range #(colored-style value-rgb-key)) nil]
+ :in-expr [default-log-style :highlight-background]}))
(defn- cursor-at-end
"Puts the cursor at the end of the text in the given widget."
[^StyledText widget]
(.setCaretOffset widget (.getCharCount widget)))
(defn log
- [^StyledText log ^String s type]
+ [^ccw.repl.REPLView repl-view ^StyledText log ^String s type]
(ui-sync
(let [charcnt (.getCharCount log)
- [log-style line-background-color-name] (get log-styles type [default-log-style nil])
+ [log-style highlight-background] (get log-styles type [default-log-style nil])
linecnt (.getLineCount log)]
(.append log s)
(when-not (re-find #"(\n|\r)$" s) (.append log "\n"))
(doto log
cursor-at-end
.showSelection
(.setStyleRange (log-style charcnt (- (.getCharCount log) charcnt))))
- (when line-background-color-name
+ (when highlight-background
(.setLineBackground log (dec linecnt) (- (.getLineCount log) linecnt)
- (-> (CCWPlugin/getDefault) .getColorCache (.get line-background-color-name)))))))
+ (ccw.CCWPlugin/getColor
+ ;; We use RGB color because we cannot take the Color directly since
+ ;; we do not "own" it (it would be disposed when colors are changed
+ ;; from the preferences, not good)
+ (-> repl-view .logPanelEditorColors .fCurrentLineBackgroundColor .getRGB)))))))
(defn eval-failure-msg
[status s]
@@ -83,11 +92,11 @@
(when ns (.setCurrentNamespace repl-view ns))
(doseq [[k v] (dissoc resp :id :ns :status :session)]
(if (log-styles k)
- (log log-component v k)
+ (log repl-view log-component v k)
(CCWPlugin/log (str "Cannot handle REPL response: " k (pr-str resp)))))
(doseq [status status]
(case status
- "interrupted" (log log-component (eval-failure-msg status expr) :err)
+ "interrupted" (log repl-view log-component (eval-failure-msg status expr) :err)
"need-input" (ui-sync (.getStdIn repl-view))
nil))))))
@@ -100,7 +109,7 @@
{:op :eval :code expr :ns (.getCurrentNamespace repl-view)}))
(catch Throwable t
(CCWPlugin/logError (eval-failure-msg nil expr) t)
- (log log-component (eval-failure-msg nil expr) :err))))
+ (log repl-view log-component (eval-failure-msg nil expr) :err))))
(defn configure-repl-view
[repl-view log-panel repl-client session-id]
View
57 ccw.core/src/java/ccw/editors/clojure/ClojureSourceViewer.java
@@ -114,26 +114,24 @@
*/
public Color fSelectionBackgroundColor;
+ /**
+ * The viewer's background color for the selected line
+ */
+ public Color fCurrentLineBackgroundColor;
+
public void unconfigure() {
- if (fForegroundColor != null) {
- fForegroundColor.dispose();
- fForegroundColor= null;
- }
-
- if (fBackgroundColor != null) {
- fBackgroundColor.dispose();
- fBackgroundColor= null;
- }
-
- if (fSelectionForegroundColor != null) {
- fSelectionForegroundColor.dispose();
- fSelectionForegroundColor= null;
- }
-
- if (fSelectionBackgroundColor != null) {
- fSelectionBackgroundColor.dispose();
- fSelectionBackgroundColor= null;
+ fForegroundColor = unconfigure(fForegroundColor);
+ fBackgroundColor = unconfigure(fBackgroundColor= null);
+ fSelectionForegroundColor = unconfigure(fSelectionForegroundColor);
+ fSelectionBackgroundColor = unconfigure(fSelectionBackgroundColor);
+ fCurrentLineBackgroundColor = unconfigure(fCurrentLineBackgroundColor);
+ }
+
+ private Color unconfigure(Color c) {
+ if (c != null) {
+ c.dispose();
}
+ return null;
}
}
@@ -327,23 +325,24 @@ public void configure(SourceViewerConfiguration configuration) {
* @return the created color according to the specification in the preference store
*/
static public Color createColor(IPreferenceStore store, String key, Display display) {
+ RGB rgb = getRGBColor(store, key);
+ return (rgb!= null) ? new Color(display, rgb) : null;
+ }
+
+ static public RGB getRGBColor(IPreferenceStore store, String key) {
RGB rgb = null;
if (store.contains(key)) {
-
if (store.isDefault(key))
rgb = PreferenceConverter.getDefaultColor(store, key);
else
rgb = PreferenceConverter.getColor(store, key);
-
- if (rgb != null)
- return new Color(display, rgb);
}
- return null;
+ return rgb;
}
-
- public void initializeViewerColors() {
+
+ public void initializeViewerColors() {
initializeViewerColors(getTextWidget(), fPreferenceStore, editorColors);
if (fPreferenceStore != null) {
CCWPlugin.registerEditorColors(fPreferenceStore, getTextWidget().getForeground().getRGB());
@@ -395,6 +394,14 @@ public static void initializeViewerColors(StyledText styledText, IPreferenceStor
editorColors.fSelectionBackgroundColor.dispose();
editorColors.fSelectionBackgroundColor= color;
+
+ // ---------- current line background color ----------------------
+ color= createColor(preferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR, styledText.getDisplay());
+
+ if (editorColors.fCurrentLineBackgroundColor != null)
+ editorColors.fCurrentLineBackgroundColor.dispose();
+
+ editorColors.fCurrentLineBackgroundColor= color;
}
}
View
3 ccw.core/src/java/ccw/preferences/Messages.java
@@ -126,6 +126,9 @@
public static String SyntaxColoringPreferencePage_rainbowParenLevel7;
public static String SyntaxColoringPreferencePage_rainbowParenLevel8;
+ public static String SyntaxColoringPreferencePage_replLogValue;
+ public static String SyntaxColoringPreferencePage_replLogError;
+
public static String SyntaxColoringPreferencePage_preview;
public static String ClojureREPLPreferencePage_Description;
View
63 ccw.core/src/java/ccw/preferences/PreferenceConstants.java
@@ -29,32 +29,32 @@
*/
public class PreferenceConstants {
- public static Keyword stringToken = Keyword.intern("string");
- public static Keyword otherLiteralsToken = Keyword.intern("other-literals");
- public static Keyword regexToken = Keyword.intern("regex");
- public static Keyword intToken = Keyword.intern("int");
- public static Keyword floatToken = Keyword.intern("float");
- public static Keyword charToken = Keyword.intern("char");
-// public static Keyword literalSymbolToken = Keyword.intern("literalSymbol");
+ public static final Keyword stringToken = Keyword.intern("string");
+ public static final Keyword otherLiteralsToken = Keyword.intern("other-literals");
+ public static final Keyword regexToken = Keyword.intern("regex");
+ public static final Keyword intToken = Keyword.intern("int");
+ public static final Keyword floatToken = Keyword.intern("float");
+ public static final Keyword charToken = Keyword.intern("char");
+// public static final Keyword literalSymbolToken = Keyword.intern("literalSymbol");
-// public static Keyword symbolToken = Keyword.intern("symbol");
+// public static final Keyword symbolToken = Keyword.intern("symbol");
- public static Keyword FUNCTION_Token = Keyword.intern("FUNCTION");
- public static Keyword callableFUNCTION_Token = Keyword.intern("callableFUNCTION");
- public static Keyword MACRO_Token = Keyword.intern("MACRO");
- public static Keyword callableMACRO_Token = Keyword.intern("callableMACRO");
- public static Keyword SPECIAL_FORM_Token = Keyword.intern("SPECIAL_FORM");
- public static Keyword callableSPECIAL_FORM_Token = Keyword.intern("callableSPECIAL_FORM");
- public static Keyword GLOBAL_VAR_Token = Keyword.intern("GLOBAL_VAR");
- public static Keyword callableGLOBAL_VAR_Token = Keyword.intern("callableGLOBAL_VAR");
- public static Keyword JAVA_CLASS_Token = Keyword.intern("JAVA_CLASS");
- public static Keyword callableJAVA_CLASS_Token = Keyword.intern("callableJAVA_CLASS");
- public static Keyword JAVA_INSTANCE_METHOD_Token = Keyword.intern("JAVA_INSTANCE_METHOD");
- public static Keyword callableJAVA_INSTANCE_METHOD_Token = Keyword.intern("callableJAVA_INSTANCE_METHOD");
- public static Keyword JAVA_STATIC_METHOD_Token = Keyword.intern("JAVA_STATIC_METHOD");
- public static Keyword callableJAVA_STATIC_METHOD_Token = Keyword.intern("callableJAVA_STATIC_METHOD");
- public static Keyword RAW_SYMBOL_Token = Keyword.intern("RAW_SYMBOL");
- public static Keyword callable_RAW_SYMBOL_Token = Keyword.intern("callableRAW_SYMBOL");
+ public static final Keyword FUNCTION_Token = Keyword.intern("FUNCTION");
+ public static final Keyword callableFUNCTION_Token = Keyword.intern("callableFUNCTION");
+ public static final Keyword MACRO_Token = Keyword.intern("MACRO");
+ public static final Keyword callableMACRO_Token = Keyword.intern("callableMACRO");
+ public static final Keyword SPECIAL_FORM_Token = Keyword.intern("SPECIAL_FORM");
+ public static final Keyword callableSPECIAL_FORM_Token = Keyword.intern("callableSPECIAL_FORM");
+ public static final Keyword GLOBAL_VAR_Token = Keyword.intern("GLOBAL_VAR");
+ public static final Keyword callableGLOBAL_VAR_Token = Keyword.intern("callableGLOBAL_VAR");
+ public static final Keyword JAVA_CLASS_Token = Keyword.intern("JAVA_CLASS");
+ public static final Keyword callableJAVA_CLASS_Token = Keyword.intern("callableJAVA_CLASS");
+ public static final Keyword JAVA_INSTANCE_METHOD_Token = Keyword.intern("JAVA_INSTANCE_METHOD");
+ public static final Keyword callableJAVA_INSTANCE_METHOD_Token = Keyword.intern("callableJAVA_INSTANCE_METHOD");
+ public static final Keyword JAVA_STATIC_METHOD_Token = Keyword.intern("JAVA_STATIC_METHOD");
+ public static final Keyword callableJAVA_STATIC_METHOD_Token = Keyword.intern("callableJAVA_STATIC_METHOD");
+ public static final Keyword RAW_SYMBOL_Token = Keyword.intern("RAW_SYMBOL");
+ public static final Keyword callable_RAW_SYMBOL_Token = Keyword.intern("callableRAW_SYMBOL");
public static final Keyword deactivatedRainbowParen = Keyword.intern("deactivated-rainbow-paren");
public static final Keyword rainbowParenLevel1 = Keyword.intern("rainbow-paren-level-1");
@@ -66,11 +66,14 @@
public static final Keyword rainbowParenLevel7 = Keyword.intern("rainbow-paren-level-7");
public static final Keyword rainbowParenLevel8 = Keyword.intern("rainbow-paren-level-8");
- public static Keyword keywordToken = Keyword.intern("keyword");
- public static Keyword commentToken = Keyword.intern("comment");
- public static Keyword whitespaceToken = Keyword.intern("whitespace");
- public static Keyword metaToken = Keyword.intern("meta");
- public static Keyword readerLiteralTag = Keyword.intern("reader-literal");
+ public static final Keyword keywordToken = Keyword.intern("keyword");
+ public static final Keyword commentToken = Keyword.intern("comment");
+ public static final Keyword whitespaceToken = Keyword.intern("whitespace");
+ public static final Keyword metaToken = Keyword.intern("meta");
+ public static final Keyword readerLiteralTag = Keyword.intern("reader-literal");
+
+ public static final Keyword replLogValue = Keyword.intern("repl-log-keyword-value");
+ public static final Keyword replLogError = Keyword.intern("repl-log-error");
/**
* Set of tokens keywords for which syntax color information can be retrieved
@@ -120,6 +123,8 @@
add(rainbowParenLevel6);
add(rainbowParenLevel7);
add(rainbowParenLevel8);
+ add(replLogValue);
+ add(replLogError);
}
});
View
4 ccw.core/src/java/ccw/preferences/PreferenceInitializer.java
@@ -102,7 +102,9 @@ public boolean isItalic() {
new SyntaxColoringDefault(PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.rainbowParenLevel5), true, new RGB(122, 176, 204), false, false),
new SyntaxColoringDefault(PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.rainbowParenLevel6), true, new RGB(122, 122, 204), false, false),
new SyntaxColoringDefault(PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.rainbowParenLevel7), true, new RGB(176, 122, 204), false, false),
- new SyntaxColoringDefault(PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.rainbowParenLevel8), true, new RGB(204, 122, 176), false, false)
+ new SyntaxColoringDefault(PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.rainbowParenLevel8), true, new RGB(204, 122, 176), false, false),
+ new SyntaxColoringDefault(PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.replLogValue), true, new RGB(0, 0x80, 0), false, false),
+ new SyntaxColoringDefault(PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.replLogError), true, new RGB(0x80, 0, 0), false, false),
};
@Override
View
5 ccw.core/src/java/ccw/preferences/SyntaxColoringPreferencePage.java
@@ -263,7 +263,10 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
{ Messages.SyntaxColoringPreferencePage_rainbowParenLevel6, PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.rainbowParenLevel6)},
{ Messages.SyntaxColoringPreferencePage_rainbowParenLevel7, PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.rainbowParenLevel7)},
{ Messages.SyntaxColoringPreferencePage_rainbowParenLevel8, PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.rainbowParenLevel8)},
- };
+
+ { Messages.SyntaxColoringPreferencePage_replLogValue, PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.replLogValue)},
+ { Messages.SyntaxColoringPreferencePage_replLogError, PreferenceConstants.getTokenPreferenceKey(PreferenceConstants.replLogError)},
+};
OverlayPreferenceStore fOverlayStore;
View
2 ccw.core/src/java/ccw/preferences/messages.properties
@@ -61,6 +61,8 @@ SyntaxColoringPreferencePage_rainbowParenLevel6=Rainbow paren nesting level 6
SyntaxColoringPreferencePage_rainbowParenLevel7=Rainbow paren nesting level 7
SyntaxColoringPreferencePage_rainbowParenLevel8=Rainbow paren nesting level 8
+SyntaxColoringPreferencePage_replLogValue=REPL Log - evaluated content
+SyntaxColoringPreferencePage_replLogError=REPL Log - error
SyntaxColoringPreferencePage_preview=Preview:
REPLViewPreferencePage_activate_autoEval_on_Enter=Trailing [Enter] sends valid REPL content
View
8 ccw.core/src/java/ccw/repl/REPLView.java
@@ -156,7 +156,7 @@ private static void releaseSecondaryId (String id) {
// and another range that is editable and has full paredit, code completion, etc.
StyledText logPanel;
/** record for colors used in logPanel */
- final ClojureSourceViewer.EditorColors logPanelEditorColors = new ClojureSourceViewer.EditorColors();
+ public final ClojureSourceViewer.EditorColors logPanelEditorColors = new ClojureSourceViewer.EditorColors();
private ClojureSourceViewer viewer;
public StyledText viewerWidget; // public only to simplify interop with helpers impl'd in Clojure
private ClojureSourceViewerConfiguration viewerConfig;
@@ -208,7 +208,7 @@ private void copyToLog (StyledText s) {
s.setText(boostIndent.matcher(s.getText()).replaceAll(" ").replaceFirst("^\\s+", "=> "));
int start = logPanel.getCharCount();
try {
- log.invoke(logPanel, s.getText(), inputExprLogType);
+ log.invoke(this, logPanel, s.getText(), inputExprLogType);
for (StyleRange sr : s.getStyleRanges()) {
sr.start += start;
logPanel.setStyleRange(sr);
@@ -239,7 +239,7 @@ public void evalExpression (String s) {
public void evalExpression (String s, boolean userInput, boolean logExpression) {
try {
if (s.trim().length() > 0) {
- if (logExpression) log.invoke(logPanel, s, inputExprLogType);
+ if (logExpression) log.invoke(this, logPanel, s, inputExprLogType);
evalExpression.invoke(s, userInput);
}
} catch (Exception e) {
@@ -252,7 +252,7 @@ public void printErrorDetail() {
}
public void sendInterrupt() {
- log.invoke(logPanel, ";; Interrupting...", inputExprLogType);
+ log.invoke(this, logPanel, ";; Interrupting...", inputExprLogType);
evalExpression.invoke(PersistentHashMap.create("op", "interrupt"), false);
}

0 comments on commit 1e4ed0c

Please sign in to comment.
Something went wrong with that request. Please try again.