diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 67e46917d..2ef29d54e 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -117,7 +117,7 @@ public class Base { private List boardsCustomMenus; private List programmerMenus; - private final PdeKeywords pdeKeywords; + private PdeKeywords pdeKeywords; private final List recentSketchesMenuItems; static public void main(String args[]) throws Exception { @@ -1250,9 +1250,25 @@ public class Base { } } + private static String priorPlatformFolder; + public void onBoardOrPortChange() { BaseNoGui.onBoardOrPortChange(); + // reload keywords when package/platform changes + TargetPlatform tp = BaseNoGui.getTargetPlatform(); + if (tp != null) { + String platformFolder = tp.getFolder().getAbsolutePath(); + if (priorPlatformFolder == null || !priorPlatformFolder.equals(platformFolder)) { + pdeKeywords = new PdeKeywords(); + pdeKeywords.reload(); + priorPlatformFolder = platformFolder; + for (Editor editor : editors) { + editor.updateKeywords(pdeKeywords); + } + } + } + // Update editors status bar for (Editor editor : editors) { editor.onBoardOrPortChange(); diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 2f6a41b16..cbe11c8c9 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -40,6 +40,7 @@ import processing.app.forms.PasswordAuthorizationDialog; import processing.app.helpers.OSUtils; import processing.app.helpers.PreferencesMapException; import processing.app.legacy.PApplet; +import processing.app.syntax.PdeKeywords; import processing.app.syntax.ArduinoTokenMakerFactory; import processing.app.syntax.SketchTextArea; import processing.app.tools.DiscourseFormat; @@ -1060,6 +1061,15 @@ public class Editor extends JFrame implements RunnerListener { return textArea; } + public void updateKeywords(PdeKeywords keywords) { + // update GUI for "Find In Reference" + textarea.setKeywords(keywords); + // update document for syntax highlighting + RSyntaxDocument document = (RSyntaxDocument) textarea.getDocument(); + document.setTokenMakerFactory(new ArduinoTokenMakerFactory(keywords)); + document.setSyntaxStyle(RSyntaxDocument.SYNTAX_STYLE_CPLUSPLUS); + } + private JMenuItem createToolMenuItem(String className) { try { Class toolClass = Class.forName(className); diff --git a/app/src/processing/app/syntax/PdeKeywords.java b/app/src/processing/app/syntax/PdeKeywords.java index 2ed2e7325..176e5795e 100644 --- a/app/src/processing/app/syntax/PdeKeywords.java +++ b/app/src/processing/app/syntax/PdeKeywords.java @@ -31,6 +31,7 @@ import org.fife.ui.rsyntaxtextarea.TokenTypes; import processing.app.Base; import processing.app.BaseNoGui; import processing.app.legacy.PApplet; +import processing.app.debug.TargetPlatform; import java.io.BufferedReader; import java.io.File; @@ -84,6 +85,11 @@ public class PdeKeywords { public void reload() { try { parseKeywordsTxt(new File(BaseNoGui.getContentFile("lib"), "keywords.txt")); + TargetPlatform tp = BaseNoGui.getTargetPlatform(); + if (tp != null) { + File platformKeywords = new File(tp.getFolder(), "keywords.txt"); + if (platformKeywords.exists()) parseKeywordsTxt(platformKeywords); + } for (ContributedLibrary lib : Base.getLibraries()) { File keywords = new File(lib.getInstalledFolder(), "keywords.txt"); if (keywords.exists()) { diff --git a/app/src/processing/app/syntax/SketchTextArea.java b/app/src/processing/app/syntax/SketchTextArea.java index c546be878..50d946a06 100644 --- a/app/src/processing/app/syntax/SketchTextArea.java +++ b/app/src/processing/app/syntax/SketchTextArea.java @@ -74,13 +74,18 @@ public class SketchTextArea extends RSyntaxTextArea { private EditorListener editorListener; - private final PdeKeywords pdeKeywords; + private PdeKeywords pdeKeywords; public SketchTextArea(PdeKeywords pdeKeywords) throws IOException { this.pdeKeywords = pdeKeywords; installFeatures(); } + public void setKeywords(PdeKeywords keywords) { + pdeKeywords = keywords; + setLinkGenerator(new DocLinkGenerator(pdeKeywords)); + } + private void installFeatures() throws IOException { setTheme(PreferencesData.get("editor.syntax_theme", "default"));