Skip to content

Commit cbcc41e

Browse files
ricardojlrufinoFederico Fissore
authored and
Federico Fissore
committed
preferences for syntax highlighting theme
1 parent 79539e6 commit cbcc41e

File tree

6 files changed

+190
-14
lines changed

6 files changed

+190
-14
lines changed

app/src/processing/app/Editor.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ public void windowDeactivated(WindowEvent e) {
262262
lineStatus = new EditorLineStatus(textarea);
263263
consolePanel.add(lineStatus, BorderLayout.SOUTH);
264264

265-
//scrollPane = new RTextScrollPane(textarea);
266-
265+
// RTextScrollPane
267266
scrollPane = new RTextScrollPane(textarea, true);
268267
scrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
269-
scrollPane.setIconRowHeaderEnabled(true);
268+
scrollPane.setLineNumbersEnabled(Preferences.getBoolean("editor.linenumbers"));
269+
scrollPane.setIconRowHeaderEnabled(false);
270270

271271
Gutter gutter = scrollPane.getGutter();
272272
gutter.setBookmarkingEnabled(false);
@@ -459,7 +459,7 @@ protected void applyPreferences() {
459459
saveMenuItem.setEnabled(!external);
460460
saveAsMenuItem.setEnabled(!external);
461461

462-
textarea.setMarginLineEnabled(PreferencesData.getBoolean("editor.linenumbers"));
462+
scrollPane.setLineNumbersEnabled(PreferencesData.getBoolean("editor.linenumbers"));
463463

464464
if (external) {
465465
// disable line highlight and turn off the caret when disabling
@@ -488,6 +488,8 @@ protected void applyPreferences() {
488488
//sketchbook.rebuildMenus();
489489
// For 0126, moved into Base, which will notify all editors.
490490
//base.rebuildMenusAsync();
491+
492+
textarea.setTheme(Preferences.get("editor.syntax_theme"));
491493
}
492494

493495

@@ -923,6 +925,7 @@ protected SketchTextArea createTextArea(){
923925
SketchTextArea textArea = new SketchTextArea();
924926
textArea.requestFocusInWindow();
925927
textArea.setMarkOccurrences(true);
928+
textArea.setMarginLineEnabled(false);
926929
textArea.setCodeFoldingEnabled(PreferencesData.getBoolean("editor.codefolding"));
927930
textArea.setAntiAliasingEnabled(PreferencesData.getBoolean("editor.antialias"));
928931
// textArea.setClearWhitespaceLinesEnabled(false);

app/src/processing/app/Preferences.java

+22
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public String toString() {
230230
JCheckBox autoAssociateBox;
231231
JComboBox comboLanguage;
232232
JComboBox comboWarnings;
233+
JComboBox comboSyntaxThemes;
233234
JCheckBox saveVerifyUploadBox;
234235
JTextField proxyHTTPServer;
235236
JTextField proxyHTTPPort;
@@ -357,7 +358,27 @@ public void actionPerformed(ActionEvent e) {
357358
fontSizeField.setText(String.valueOf(editorFont.getSize()));
358359
top += d.height + GUI_BETWEEN;
359360

361+
// Syntax Coloring [ ]
360362

363+
box = Box.createHorizontalBox();
364+
label = new JLabel(_("Syntax Coloring: "));
365+
box.add(label);
366+
String[] syntaxThemes = new String[]{"default","dark"};
367+
comboSyntaxThemes = new JComboBox(syntaxThemes);
368+
String currentTheme = PreferencesData.get("editor.syntax_theme", "default");
369+
for (String item : syntaxThemes) {
370+
if (currentTheme.equals(item)) {
371+
comboSyntaxThemes.setSelectedItem(item);
372+
}
373+
}
374+
box.add(comboSyntaxThemes);
375+
pane.add(box);
376+
d = box.getPreferredSize();
377+
box.setForeground(Color.gray);
378+
box.setBounds(left, top, d.width, d.height);
379+
right = Math.max(right, left + d.width);
380+
top += d.height + GUI_BETWEEN;
381+
361382
// Show verbose output during: [ ] compilation [ ] upload
362383

363384
box = Box.createHorizontalBox();
@@ -746,6 +767,7 @@ protected void applyFrame() {
746767
PreferencesData.set("sketchbook.path", newPath);
747768
}
748769

770+
PreferencesData.set("editor.syntax_theme", comboSyntaxThemes.getSelectedItem().toString());
749771
PreferencesData.setBoolean("editor.external", externalEditorBox.isSelected());
750772
PreferencesData.setBoolean("update.check", checkUpdatesBox.isSelected());
751773
PreferencesData.setBoolean("editor.save_on_verify", saveVerifyUploadBox.isSelected());

app/src/processing/app/syntax/SketchTextArea.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
import javax.swing.undo.UndoManager;
2222

2323
import org.fife.ui.rsyntaxtextarea.*;
24+
import org.fife.ui.rsyntaxtextarea.Theme;
2425
import org.fife.ui.rsyntaxtextarea.Token;
2526
import org.fife.ui.rsyntaxtextarea.focusabletip.FocusableTip;
2627
import org.fife.ui.rtextarea.RUndoManager;
2728

28-
import processing.app.Base;
29-
import processing.app.BaseNoGui;
30-
import processing.app.EditorLineStatus;
31-
import processing.app.EditorListener;
29+
import processing.app.*;
3230

3331
/**
3432
* Arduino Sketch code editor based on RSyntaxTextArea (http://fifesoft.com/rsyntaxtextarea)
@@ -57,9 +55,18 @@ public SketchTextArea() {
5755

5856

5957
protected void installFeatures(){
58+
setTheme(PreferencesData.get("editor.syntax_theme", "default"));
59+
60+
setLinkGenerator(new DocLinkGenerator());
61+
62+
fixControlTab();
63+
installTokenMaker();
64+
}
65+
66+
public void setTheme(String name){
6067
FileInputStream defaultXmlInputStream = null;
6168
try {
62-
defaultXmlInputStream = new FileInputStream(new File(BaseNoGui.getContentFile("lib"), "theme/syntax/default.xml"));
69+
defaultXmlInputStream = new FileInputStream(new File(BaseNoGui.getContentFile("lib"), "theme/syntax/"+name+".xml"));
6370
Theme theme = Theme.load(defaultXmlInputStream);
6471
theme.apply(this);
6572
} catch (IOException e) {
@@ -73,11 +80,6 @@ protected void installFeatures(){
7380
}
7481
}
7582
}
76-
77-
setLinkGenerator(new DocLinkGenerator());
78-
79-
fixControlTab();
80-
installTokenMaker();
8183
}
8284

8385
// Removing the default focus traversal keys

build/shared/lib/preferences.txt

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ editor.window.height.min = 290
8686
# tested to be 515 on Windows XP, this leaves some room
8787
#editor.window.height.min.windows = 530
8888

89+
# Syntax coloring ( on lib/theme/syntax )
90+
editor.syntax_theme = default
8991

9092
# font size for editor
9193
editor.font=Monospaced,plain,12
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE RSyntaxTheme SYSTEM "theme.dtd">
3+
4+
<!--
5+
Dark theme based off of Notepad++'s Obsidian theme.
6+
See theme.dtd and org.fife.ui.rsyntaxtextarea.Theme for more information.
7+
-->
8+
<RSyntaxTheme version="1.0">
9+
10+
<!-- Omitting baseFont will use a system-appropriate monospaced. -->
11+
<!--<baseFont family="..." size="13"/>-->
12+
13+
<!-- General editor colors. -->
14+
<background color="293134"/>
15+
<caret color="c1cbc2"/>
16+
<selection useFG="false" bg="404E51" roundedEdges="false"/>
17+
<currentLineHighlight color="2F393C" fade="false"/>
18+
<marginLine fg="394448"/>
19+
<markAllHighlight color="6b8189"/> <!-- TODO: Fix me -->
20+
<markOccurrencesHighlight color="5b7179" border="false"/>
21+
<matchedBracket fg="6A8088" bg="6b8189" highlightBoth="false" animate="true"/>
22+
<hyperlinks fg="a082bd"/>
23+
<secondaryLanguages>
24+
<language index="1" bg="333344"/>
25+
<language index="2" bg="223322"/>
26+
<language index="3" bg="332222"/>
27+
</secondaryLanguages>
28+
29+
<!-- Gutter styling. -->
30+
<gutterBorder color="81969A"/>
31+
<lineNumbers fg="81969A"/>
32+
<foldIndicator fg="6A8088" iconBg="2f383c"/>
33+
<iconRowHeader activeLineRange="3399ff"/>
34+
35+
<!-- Syntax tokens. -->
36+
<tokenStyles>
37+
<style token="IDENTIFIER" fg="E0E2E4"/>
38+
<style token="RESERVED_WORD" fg="93C763" bold="true"/>
39+
<style token="RESERVED_WORD_2" fg="93C763" bold="true"/>
40+
<style token="ANNOTATION" fg="E8E2B7"/>
41+
<style token="COMMENT_DOCUMENTATION" fg="6C788C"/>
42+
<style token="COMMENT_EOL" fg="66747B"/>
43+
<style token="COMMENT_MULTILINE" fg="66747B"/>
44+
<style token="COMMENT_KEYWORD" fg="ae9fbf"/>
45+
<style token="COMMENT_MARKUP" fg="ae9fbf"/>
46+
<style token="FUNCTION" fg="E0E2E4"/>
47+
<style token="DATA_TYPE" fg="678CB1" bold="true"/>
48+
<style token="LITERAL_BOOLEAN" fg="93C763" bold="true"/>
49+
<style token="LITERAL_NUMBER_DECIMAL_INT" fg="FFCD22"/>
50+
<style token="LITERAL_NUMBER_FLOAT" fg="FFCD22"/>
51+
<style token="LITERAL_NUMBER_HEXADECIMAL" fg="FFCD22"/>
52+
<style token="LITERAL_STRING_DOUBLE_QUOTE" fg="EC7600"/>
53+
<style token="LITERAL_CHAR" fg="EC7600"/>
54+
<style token="LITERAL_BACKQUOTE" fg="EC7600"/>
55+
<style token="MARKUP_TAG_DELIMITER" fg="678CB1"/>
56+
<style token="MARKUP_TAG_NAME" fg="ABBFD3" bold="true"/>
57+
<style token="MARKUP_TAG_ATTRIBUTE" fg="B3B689"/>
58+
<style token="MARKUP_TAG_ATTRIBUTE_VALUE" fg="e1e2cf"/>
59+
<style token="MARKUP_COMMENT" fg="66747B"/>
60+
<style token="MARKUP_DTD" fg="A082BD"/>
61+
<style token="MARKUP_PROCESSING_INSTRUCTION" fg="A082BD"/>
62+
<style token="MARKUP_CDATA" fg="d5e6f0"/>
63+
<style token="MARKUP_CDATA_DELIMITER" fg="ae9fbf"/>
64+
<style token="MARKUP_ENTITY_REFERENCE" fg="678CB1"/>
65+
<style token="OPERATOR" fg="E8E2B7"/>
66+
<style token="PREPROCESSOR" fg="A082BD"/>
67+
<style token="REGEX" fg="d39745"/>
68+
<style token="SEPARATOR" fg="E8E2B7"/>
69+
<style token="VARIABLE" fg="ae9fbf" bold="true"/>
70+
<style token="WHITESPACE" fg="E0E2E4"/>
71+
72+
<style token="ERROR_IDENTIFIER" fg="E0E2E4" bg="04790e"/>
73+
<style token="ERROR_NUMBER_FORMAT" fg="E0E2E4" bg="04790e"/>
74+
<style token="ERROR_STRING_DOUBLE" fg="E0E2E4" bg="04790e"/>
75+
<style token="ERROR_CHAR" fg="E0E2E4" bg="04790e"/>
76+
</tokenStyles>
77+
78+
</RSyntaxTheme>
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE RSyntaxTheme SYSTEM "theme.dtd">
3+
4+
<!--
5+
RSyntaxTextArea's default theme.
6+
See theme.dtd and org.fife.ui.rsyntaxtextarea.Theme for more information.
7+
-->
8+
<RSyntaxTheme version="1.0">
9+
10+
<!-- Omitting baseFont will use a system-appropriate monospaced. -->
11+
<!--<baseFont family="..." size="13"/>-->
12+
13+
<!-- General editor colors. -->
14+
<background color="ffffff"/>
15+
<caret color="424242"/>
16+
<selection fg="ffffff" bg="4a90d9" />
17+
<currentLineHighlight color="ffffaa" fade="false"/>
18+
<marginLine fg="b0b4b9"/>
19+
<markAllHighlight color="ffc800"/>
20+
<markOccurrencesHighlight color="d4d4d4" border="false"/>
21+
<matchedBracket fg="000080" bg="eaeaff" highlightBoth="false" animate="true"/>
22+
<hyperlinks fg="0000ff"/>
23+
<secondaryLanguages>
24+
<language index="1" bg="fff0cc"/>
25+
<language index="2" bg="dafeda"/>
26+
<language index="3" bg="ffe0f0"/>
27+
</secondaryLanguages>
28+
29+
<!-- Gutter styling. -->
30+
<gutterBorder color="dddddd"/>
31+
<lineNumbers fg="787878"/>
32+
<foldIndicator fg="808080" iconBg="ffffff"/>
33+
<iconRowHeader activeLineRange="3399ff"/>
34+
35+
<!-- Syntax tokens. -->
36+
<tokenStyles>
37+
<style token="IDENTIFIER" fg="000000"/>
38+
<style token="DATA_TYPE" fg="008080" bold="true"/>
39+
<style token="FUNCTION" fg="cc6600"/>
40+
<style token="VARIABLE" fg="cc6600" bold="true"/>
41+
<style token="RESERVED_WORD" fg="024f8b" bold="true"/>
42+
<style token="RESERVED_WORD_2" fg="008080" bold="false"/>
43+
<style token="PREPROCESSOR" fg="024f8b" bold="false"/>
44+
45+
<style token="ANNOTATION" fg="808080"/>
46+
<style token="COMMENT_DOCUMENTATION" fg="7e7e7e"/>
47+
<style token="COMMENT_EOL" fg="7e7e7e"/>
48+
<style token="COMMENT_MULTILINE" fg="7e7e7e"/>
49+
<style token="COMMENT_KEYWORD" fg="7F9FBF" bold="true"/>
50+
<style token="COMMENT_MARKUP" fg="7f7f9f"/>
51+
<style token="LITERAL_BOOLEAN" fg="ff0000" bold="false"/>
52+
<style token="LITERAL_NUMBER_DECIMAL_INT" fg="ff0000"/>
53+
<style token="LITERAL_NUMBER_FLOAT" fg="ff0000"/>
54+
<style token="LITERAL_NUMBER_HEXADECIMAL" fg="ff0000"/>
55+
<style token="LITERAL_STRING_DOUBLE_QUOTE" fg="006699"/>
56+
<style token="LITERAL_CHAR" fg="DC009C"/>
57+
<style token="LITERAL_BACKQUOTE" fg="DC009C"/>
58+
59+
<style token="OPERATOR" fg="804040"/>
60+
<style token="REGEX" fg="008040"/>
61+
<style token="SEPARATOR" fg="000000" />
62+
<style token="WHITESPACE" fg="000000"/>
63+
<style token="ERROR_IDENTIFIER" fg="000000" />
64+
<style token="ERROR_NUMBER_FORMAT" fg="000000" />
65+
<style token="ERROR_STRING_DOUBLE" fg="000000" />
66+
<style token="ERROR_CHAR" fg="000000" />
67+
</tokenStyles>
68+
69+
</RSyntaxTheme>

0 commit comments

Comments
 (0)