Skip to content

Commit 09e36bd

Browse files
author
Federico Fissore
committed
Restoring keyword.txt loading and parsing. Added token type identifiers and related style in theme.txt
1 parent bb74e06 commit 09e36bd

File tree

12 files changed

+474
-410
lines changed

12 files changed

+474
-410
lines changed

app/src/processing/app/Base.java

+10
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import processing.app.macosx.ThinkDifferent;
5454
import processing.app.packages.LibraryList;
5555
import processing.app.packages.UserLibrary;
56+
import processing.app.syntax.PdeKeywords;
5657
import processing.app.tools.MenuScroller;
5758
import processing.app.tools.ZipDeflater;
5859

@@ -118,6 +119,8 @@ public boolean apply(UserLibrary library) {
118119
private List<JMenu> boardsCustomMenus;
119120
private volatile Action openBoardsManager;
120121

122+
private final PdeKeywords pdeKeywords;
123+
121124
static public void main(String args[]) throws Exception {
122125
System.setProperty("awt.useSystemAAFontSettings", "on");
123126
System.setProperty("swing.aatext", "true");
@@ -345,6 +348,9 @@ public Base(String[] args) throws Exception {
345348
// them.
346349
PreferencesData.save();
347350

351+
this.pdeKeywords = new PdeKeywords();
352+
this.pdeKeywords.reload();
353+
348354
if (parser.isInstallBoard()) {
349355
ContributionsIndexer indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
350356
ContributionInstaller installer = new ContributionInstaller(indexer) {
@@ -2771,4 +2777,8 @@ public List<Editor> getEditors() {
27712777
public Action getOpenBoardsManager() {
27722778
return openBoardsManager;
27732779
}
2780+
2781+
public PdeKeywords getPdeKeywords() {
2782+
return pdeKeywords;
2783+
}
27742784
}

app/src/processing/app/Editor.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ protected String findClassInZipFile(String base, File file) {
925925

926926

927927
protected SketchTextArea createTextArea() throws IOException {
928-
SketchTextArea textArea = new SketchTextArea();
928+
SketchTextArea textArea = new SketchTextArea(base.getPdeKeywords());
929929
textArea.requestFocusInWindow();
930930
textArea.setMarkOccurrences(true);
931931
textArea.setMarginLineEnabled(false);
@@ -1716,7 +1716,7 @@ protected void setCode(final SketchCodeDocument codeDoc) {
17161716
RSyntaxDocument document = (RSyntaxDocument) codeDoc.getDocument();
17171717

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

17221722
// insert the program text into the document object
@@ -1912,7 +1912,7 @@ protected String getCurrentKeyword() {
19121912
protected void handleFindReference() {
19131913
String text = getCurrentKeyword();
19141914

1915-
String referenceFile = PdeKeywords.getReference(text);
1915+
String referenceFile = base.getPdeKeywords().getReference(text);
19161916
if (referenceFile == null) {
19171917
statusNotice(I18n.format(_("No reference available for \"{0}\""), text));
19181918
} else {
@@ -2848,7 +2848,7 @@ public void actionPerformed(ActionEvent e) {
28482848

28492849
@Override
28502850
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
2851-
String referenceFile = PdeKeywords.getReference(getCurrentKeyword());
2851+
String referenceFile = base.getPdeKeywords().getReference(getCurrentKeyword());
28522852
referenceItem.setEnabled(referenceFile != null);
28532853

28542854
int offset = textarea.getCaretPosition();

app/src/processing/app/Theme.java

+44-16
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,42 @@
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-
import java.io.File;
30-
31-
import javax.swing.text.StyleContext;
32-
3324
import processing.app.helpers.OSUtils;
3425
import processing.app.helpers.PreferencesHelper;
3526
import processing.app.helpers.PreferencesMap;
3627

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

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

4954
static protected void init() {
5055
try {
5156
table.load(new File(BaseNoGui.getContentFile("lib"), "theme/theme.txt"));
5257
} catch (Exception te) {
5358
Base.showError(null, _("Could not read color theme settings.\n" +
54-
"You'll need to reinstall Arduino."), te);
59+
"You'll need to reinstall Arduino."), te);
5560
}
5661

5762
// other things that have to be set explicitly for the defaults
@@ -106,8 +111,8 @@ static public Font getFont(String attr) {
106111
}
107112
return font;
108113
}
109-
110-
/**
114+
115+
/**
111116
* Returns the default font for text areas.
112117
*
113118
* @return The default font.
@@ -129,8 +134,7 @@ public static final Font getDefaultFont() {
129134
font = sc.getFont("Monospaced", Font.PLAIN, 13);
130135
}
131136
}
132-
}
133-
else {
137+
} else {
134138
// Consolas added in Vista, used by VS2010+.
135139
font = sc.getFont("Consolas", Font.PLAIN, 13);
136140
if (!"Consolas".equals(font.getFamily())) {
@@ -140,6 +144,30 @@ public static final Font getDefaultFont() {
140144

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

154+
String style = split[1];
155+
boolean bold = style.contains("bold");
156+
boolean italic = style.contains("italic");
157+
boolean underlined = style.contains("underlined");
158+
159+
Font styledFont = new Font(font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize());
160+
if (underlined) {
161+
Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
162+
attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
163+
styledFont = styledFont.deriveFont(attr);
164+
}
165+
166+
Map<String, Object> result = new HashMap<String, Object>();
167+
result.put("color", color);
168+
result.put("font", styledFont);
169+
170+
return result;
144171
}
172+
145173
}
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)