Skip to content

Commit 11d2190

Browse files
author
Federico Fissore
committed
Restoring keyword.txt loading and parsing. Added token type identifiers and related style in theme.txt
1 parent 136f9ab commit 11d2190

File tree

12 files changed

+483
-427
lines changed

12 files changed

+483
-427
lines changed

app/src/processing/app/Base.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import processing.app.macosx.ThinkDifferent;
5252
import processing.app.packages.LibraryList;
5353
import processing.app.packages.UserLibrary;
54+
import processing.app.syntax.PdeKeywords;
5455
import processing.app.tools.MenuScroller;
5556
import processing.app.tools.ZipDeflater;
5657

@@ -115,6 +116,8 @@ public boolean apply(UserLibrary library) {
115116
// actually used are determined by the preferences, which are shared)
116117
private List<JMenu> boardsCustomMenus;
117118

119+
private final PdeKeywords pdeKeywords;
120+
118121
static public void main(String args[]) throws Exception {
119122
System.setProperty("awt.useSystemAAFontSettings", "on");
120123
System.setProperty("swing.aatext", "true");
@@ -342,6 +345,9 @@ public Base(String[] args) throws Exception {
342345
// them.
343346
Preferences.save();
344347

348+
this.pdeKeywords = new PdeKeywords();
349+
this.pdeKeywords.reload();
350+
345351
if (parser.isInstallBoard()) {
346352
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
347353
ContributionInstaller installer = new ContributionInstaller(indexer) {
@@ -2746,4 +2752,8 @@ public Editor getActiveEditor() {
27462752
public List<Editor> getEditors() {
27472753
return new LinkedList<Editor>(editors);
27482754
}
2755+
2756+
public PdeKeywords getPdeKeywords() {
2757+
return pdeKeywords;
2758+
}
27492759
}

app/src/processing/app/Editor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ protected String findClassInZipFile(String base, File file) {
929929

930930

931931
protected SketchTextArea createTextArea() throws IOException {
932-
SketchTextArea textArea = new SketchTextArea();
932+
SketchTextArea textArea = new SketchTextArea(base.getPdeKeywords());
933933
textArea.requestFocusInWindow();
934934
textArea.setMarkOccurrences(true);
935935
textArea.setMarginLineEnabled(false);
@@ -1728,7 +1728,7 @@ protected void setCode(final SketchCodeDocument codeDoc) {
17281728
RSyntaxDocument document = (RSyntaxDocument) codeDoc.getDocument();
17291729

17301730
if (document == null) { // this document not yet inited
1731-
document = new RSyntaxDocument(RSyntaxDocument.SYNTAX_STYLE_CPLUSPLUS);
1731+
document = new RSyntaxDocument(new ArduinoTokenMakerFactory(base.getPdeKeywords()), RSyntaxDocument.SYNTAX_STYLE_CPLUSPLUS);
17321732
document.putProperty(PlainDocument.tabSizeAttribute, Preferences.getInteger("editor.tabs.size"));
17331733

17341734
// insert the program text into the document object
@@ -1925,7 +1925,7 @@ protected String getCurrentKeyword() {
19251925
protected void handleFindReference() {
19261926
String text = getCurrentKeyword();
19271927

1928-
String referenceFile = PdeKeywords.getReference(text);
1928+
String referenceFile = base.getPdeKeywords().getReference(text);
19291929
if (referenceFile == null) {
19301930
statusNotice(I18n.format(_("No reference available for \"{0}\""), text));
19311931
} else {
@@ -2861,7 +2861,7 @@ public void actionPerformed(ActionEvent e) {
28612861

28622862
@Override
28632863
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
2864-
String referenceFile = PdeKeywords.getReference(getCurrentKeyword());
2864+
String referenceFile = base.getPdeKeywords().getReference(getCurrentKeyword());
28652865
referenceItem.setEnabled(referenceFile != null);
28662866

28672867
int offset = textarea.getCaretPosition();

app/src/processing/app/Theme.java

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,41 @@
2121

2222
package processing.app;
2323

24-
import static processing.app.I18n._;
25-
26-
import java.awt.Color;
27-
import java.awt.Font;
28-
import java.awt.SystemColor;
29-
30-
import javax.swing.text.StyleContext;
31-
3224
import processing.app.helpers.OSUtils;
3325
import processing.app.helpers.PreferencesHelper;
3426
import processing.app.helpers.PreferencesMap;
3527

28+
import javax.swing.text.StyleContext;
29+
import java.awt.*;
30+
import java.awt.font.TextAttribute;
31+
import java.util.HashMap;
32+
import java.util.Hashtable;
33+
import java.util.Map;
34+
35+
import static processing.app.I18n._;
36+
3637
/**
3738
* Storage class for theme settings. This was separated from the Preferences
3839
* class for 1.0 so that the coloring wouldn't conflict with previous releases
3940
* and to make way for future ability to customize.
4041
*/
4142
public class Theme {
4243

43-
/** Copy of the defaults in case the user mangles a preference. */
44+
/**
45+
* Copy of the defaults in case the user mangles a preference.
46+
*/
4447
static PreferencesMap defaults;
45-
/** Table of attributes/values for the theme. */
48+
/**
49+
* Table of attributes/values for the theme.
50+
*/
4651
static PreferencesMap table = new PreferencesMap();
4752

4853
static protected void init() {
4954
try {
5055
table.load(Base.getLibStream("theme/theme.txt"));
5156
} catch (Exception te) {
5257
Base.showError(null, _("Could not read color theme settings.\n" +
53-
"You'll need to reinstall Arduino."), te);
58+
"You'll need to reinstall Arduino."), te);
5459
}
5560

5661
// other things that have to be set explicitly for the defaults
@@ -105,8 +110,8 @@ static public Font getFont(String attr) {
105110
}
106111
return font;
107112
}
108-
109-
/**
113+
114+
/**
110115
* Returns the default font for text areas.
111116
*
112117
* @return The default font.
@@ -128,8 +133,7 @@ public static final Font getDefaultFont() {
128133
font = sc.getFont("Monospaced", Font.PLAIN, 13);
129134
}
130135
}
131-
}
132-
else {
136+
} else {
133137
// Consolas added in Vista, used by VS2010+.
134138
font = sc.getFont("Consolas", Font.PLAIN, 13);
135139
if (!"Consolas".equals(font.getFamily())) {
@@ -139,6 +143,30 @@ public static final Font getDefaultFont() {
139143

140144
//System.out.println(font.getFamily() + ", " + font.getName());
141145
return font;
146+
}
147+
148+
public static Map<String, Object> getStyledFont(String what, Font font) {
149+
String split[] = get("editor." + what + ".style").split(",");
150+
151+
Color color = PreferencesHelper.parseColor(split[0]);
142152

153+
String style = split[1];
154+
boolean bold = style.contains("bold");
155+
boolean italic = style.contains("italic");
156+
boolean underlined = style.contains("underlined");
157+
158+
Font styledFont = new Font(font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize());
159+
if (underlined) {
160+
Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
161+
attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
162+
styledFont = styledFont.deriveFont(attr);
163+
}
164+
165+
Map<String, Object> result = new HashMap<String, Object>();
166+
result.put("color", color);
167+
result.put("font", styledFont);
168+
169+
return result;
143170
}
171+
144172
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package processing.app.syntax;
2+
3+
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
4+
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
5+
import org.fife.ui.rsyntaxtextarea.TokenMaker;
6+
7+
public class ArduinoTokenMakerFactory extends AbstractTokenMakerFactory {
8+
9+
private final PdeKeywords pdeKeywords;
10+
11+
public ArduinoTokenMakerFactory(PdeKeywords pdeKeywords) {
12+
this.pdeKeywords = pdeKeywords;
13+
}
14+
15+
@Override
16+
protected TokenMaker getTokenMakerImpl(String key) {
17+
return new SketchTokenMaker(pdeKeywords);
18+
}
19+
20+
@Override
21+
protected void initTokenMakerMap() {
22+
putMapping(RSyntaxDocument.SYNTAX_STYLE_CPLUSPLUS, SketchTokenMaker.class.getName());
23+
}
24+
25+
}

0 commit comments

Comments
 (0)