mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Allow per-platform keywords.txt
This commit is contained in:
parent
9421e1ceb5
commit
46cfb7f2d4
@ -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 {
|
||||
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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()) {
|
||||
|
@ -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"));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user