mirror of
https://github.com/processing/processing4.git
synced 2026-02-26 00:35:41 +01:00
change how keywords are loaded
This commit is contained in:
@@ -62,6 +62,13 @@ public class AndroidMode extends JavaMode {
|
||||
public String getTitle() {
|
||||
return "Android";
|
||||
}
|
||||
|
||||
|
||||
public File[] getKeywordFiles() {
|
||||
return new File[] {
|
||||
Base.getContentFile("modes/java/keywords.txt")
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public File[] getExampleCategoryFolders() {
|
||||
|
||||
@@ -21,21 +21,10 @@
|
||||
|
||||
package processing.mode.java;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Editor;
|
||||
import processing.app.EditorState;
|
||||
import processing.app.Library;
|
||||
import processing.app.Mode;
|
||||
import processing.app.RunnerListener;
|
||||
import processing.app.Sketch;
|
||||
import processing.app.SketchException;
|
||||
import processing.app.syntax.PdeKeywords;
|
||||
import processing.core.PApplet;
|
||||
import processing.app.*;
|
||||
import processing.mode.java.runner.Runner;
|
||||
|
||||
|
||||
@@ -53,41 +42,6 @@ public class JavaMode extends Mode {
|
||||
|
||||
public JavaMode(Base base, File folder) {
|
||||
super(base, folder);
|
||||
|
||||
try {
|
||||
loadKeywords();
|
||||
} catch (IOException e) {
|
||||
Base.showError("Problem loading keywords",
|
||||
"Could not load keywords.txt, please re-install Processing.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void loadKeywords() throws IOException {
|
||||
File file = new File(folder, "keywords.txt");
|
||||
BufferedReader reader = PApplet.createReader(file);
|
||||
|
||||
tokenMarker = new PdeKeywords();
|
||||
keywordToReference = new HashMap<String, String>();
|
||||
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] pieces = PApplet.trim(PApplet.split(line, '\t'));
|
||||
if (pieces.length >= 2) {
|
||||
String keyword = pieces[0];
|
||||
String coloring = pieces[1];
|
||||
|
||||
if (coloring.length() > 0) {
|
||||
tokenMarker.addColoring(keyword, coloring);
|
||||
}
|
||||
if (pieces.length == 3) {
|
||||
String htmlFilename = pieces[2];
|
||||
if (htmlFilename.length() > 0) {
|
||||
keywordToReference.put(keyword, htmlFilename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,24 +1,12 @@
|
||||
package processing.mode.javascript;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.Editor;
|
||||
import processing.app.EditorState;
|
||||
import processing.app.Mode;
|
||||
import processing.app.Sketch;
|
||||
import processing.app.SketchException;
|
||||
import processing.app.Library;
|
||||
import processing.core.PApplet;
|
||||
|
||||
import processing.app.syntax.PdeKeywords;
|
||||
import processing.app.syntax.TokenMarker;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.mode.java.JavaMode;
|
||||
|
||||
|
||||
/**
|
||||
* JS Mode for Processing based on Processing.js. Comes with a server as
|
||||
* replacement for the normal runner.
|
||||
@@ -42,18 +30,18 @@ public class JavaScriptMode extends Mode
|
||||
{
|
||||
super(base, folder);
|
||||
|
||||
try {
|
||||
loadKeywords(); // in JavaMode, sets tokenMarker
|
||||
loadAdditionalKeywords(
|
||||
new File(Base.getContentFile("modes/java"), "keywords.txt" ),
|
||||
tokenMarker
|
||||
);
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
Base.showError( "Problem loading keywords",
|
||||
"Could not load keywords.txt, please re-install Processing.", e);
|
||||
}
|
||||
// try {
|
||||
// loadKeywords(); // in JavaMode, sets tokenMarker
|
||||
// loadAdditionalKeywords(
|
||||
// new File(Base.getContentFile("modes/java"), "keywords.txt" ),
|
||||
// tokenMarker
|
||||
// );
|
||||
// }
|
||||
// catch ( IOException e )
|
||||
// {
|
||||
// Base.showError( "Problem loading keywords",
|
||||
// "Could not load keywords.txt, please re-install Processing.", e);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,78 +77,87 @@ public class JavaScriptMode extends Mode
|
||||
return defaultJavaMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads default Java keywords, JS keywords
|
||||
* were already loaded in constructor.
|
||||
*/
|
||||
protected void loadAdditionalKeywords ( File keywords, PdeKeywords tokenMarker ) throws IOException
|
||||
{
|
||||
if ( keywordToReference == null )
|
||||
keywordToReference = new HashMap<String, String>();
|
||||
|
||||
BufferedReader reader = PApplet.createReader( keywords );
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
String[] pieces = PApplet.trim(PApplet.split(line, '\t'));
|
||||
if (pieces.length >= 2)
|
||||
{
|
||||
String keyword = pieces[0];
|
||||
String coloring = pieces[1];
|
||||
if (coloring.length() > 0) {
|
||||
tokenMarker.addColoring(keyword, coloring);
|
||||
}
|
||||
if (pieces.length == 3) {
|
||||
String htmlFilename = pieces[2];
|
||||
if (htmlFilename.length() > 0) {
|
||||
keywordToReference.put(keyword, htmlFilename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * Loads default Java keywords, JS keywords
|
||||
// * were already loaded in constructor.
|
||||
// */
|
||||
// protected void loadAdditionalKeywords ( File keywords, PdeKeywords tokenMarker ) throws IOException
|
||||
// {
|
||||
// if ( keywordToReference == null )
|
||||
// keywordToReference = new HashMap<String, String>();
|
||||
//
|
||||
// BufferedReader reader = PApplet.createReader( keywords );
|
||||
// String line = null;
|
||||
// while ((line = reader.readLine()) != null)
|
||||
// {
|
||||
// String[] pieces = PApplet.trim(PApplet.split(line, '\t'));
|
||||
// if (pieces.length >= 2)
|
||||
// {
|
||||
// String keyword = pieces[0];
|
||||
// String coloring = pieces[1];
|
||||
// if (coloring.length() > 0) {
|
||||
// tokenMarker.addColoring(keyword, coloring);
|
||||
// }
|
||||
// if (pieces.length == 3) {
|
||||
// String htmlFilename = pieces[2];
|
||||
// if (htmlFilename.length() > 0) {
|
||||
// keywordToReference.put(keyword, htmlFilename);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * load the keywords from file, copied from JavaMode.java
|
||||
// */
|
||||
// protected void loadKeywords() throws IOException
|
||||
// {
|
||||
// File file = new File(folder, "keywords.txt");
|
||||
// BufferedReader reader = PApplet.createReader(file);
|
||||
//
|
||||
// tokenMarker = new PdeKeywords();
|
||||
// keywordToReference = new HashMap<String, String>();
|
||||
//
|
||||
// String line = null;
|
||||
// while ((line = reader.readLine()) != null) {
|
||||
// String[] pieces = PApplet.trim(PApplet.split(line, '\t'));
|
||||
// if (pieces.length >= 2) {
|
||||
// String keyword = pieces[0];
|
||||
// String coloring = pieces[1];
|
||||
//
|
||||
// if (coloring.length() > 0) {
|
||||
// tokenMarker.addColoring(keyword, coloring);
|
||||
// }
|
||||
// if (pieces.length == 3) {
|
||||
// String htmlFilename = pieces[2];
|
||||
// if (htmlFilename.length() > 0) {
|
||||
// keywordToReference.put(keyword, htmlFilename);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* load the keywords from file, copied from JavaMode.java
|
||||
*/
|
||||
protected void loadKeywords() throws IOException
|
||||
{
|
||||
File file = new File(folder, "keywords.txt");
|
||||
BufferedReader reader = PApplet.createReader(file);
|
||||
public File[] getKeywordFiles() {
|
||||
return new File[] {
|
||||
Base.getContentFile("modes/java/keywords.txt"),
|
||||
new File(folder, "keywords.txt")
|
||||
};
|
||||
}
|
||||
|
||||
tokenMarker = new PdeKeywords();
|
||||
keywordToReference = new HashMap<String, String>();
|
||||
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] pieces = PApplet.trim(PApplet.split(line, '\t'));
|
||||
if (pieces.length >= 2) {
|
||||
String keyword = pieces[0];
|
||||
String coloring = pieces[1];
|
||||
|
||||
if (coloring.length() > 0) {
|
||||
tokenMarker.addColoring(keyword, coloring);
|
||||
}
|
||||
if (pieces.length == 3) {
|
||||
String htmlFilename = pieces[2];
|
||||
if (htmlFilename.length() > 0) {
|
||||
keywordToReference.put(keyword, htmlFilename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override getTokenMarker in Mode
|
||||
*/
|
||||
public TokenMarker getTokenMarker ()
|
||||
{
|
||||
if ( tokenMarker == null )
|
||||
tokenMarker = new PdeKeywords();
|
||||
return tokenMarker;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Override getTokenMarker in Mode
|
||||
// */
|
||||
// public TokenMarker getTokenMarker ()
|
||||
// {
|
||||
// if ( tokenMarker == null )
|
||||
// tokenMarker = new PdeKeywords();
|
||||
// return tokenMarker;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Return pretty title of this mode for menu listing and such
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user