Skip to content

Allow per-platform keywords.txt #3847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class Base {
private List<JMenu> boardsCustomMenus;
private List<JMenuItem> programmerMenus;

private final PdeKeywords pdeKeywords;
private PdeKeywords pdeKeywords;
private final List<JMenuItem> recentSketchesMenuItems;

static public void main(String args[]) throws Exception {
Expand Down Expand Up @@ -1250,9 +1250,25 @@ public void rebuildExamplesMenu(JMenu menu) {
}
}

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();
Expand Down
10 changes: 10 additions & 0 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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;
Expand Down Expand Up @@ -1060,6 +1061,15 @@ public void caretUpdate(CaretEvent e) {
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);
Expand Down
6 changes: 6 additions & 0 deletions app/src/processing/app/syntax/PdeKeywords.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -84,6 +85,11 @@ public 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()) {
Expand Down
7 changes: 6 additions & 1 deletion app/src/processing/app/syntax/SketchTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down