mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 22:29:18 +01:00
X set bg/fg color of text editing area
X add option for running with external editor X sets text area to not editable, changes color X gets new text on each run.. calls handleOpen2 or whatever X disables save.. save as ? X organizing directories, save to other directories blows up X for now, disallow the / or : characters X there was a bug that required a noop() b/c of jikes or 1.3 problems X is problem w/ beautify that it has no menu event handler? X write event handler, and make sure it doesn't work for external ed
This commit is contained in:
@@ -33,9 +33,10 @@ public class PdeEditor extends Panel {
|
||||
String openingPath;
|
||||
String openingName;
|
||||
|
||||
static final int RUN = 5; // for history
|
||||
static final int SAVE = 6;
|
||||
static final int AUTO = 7;
|
||||
static final int RUN = 5; // for history
|
||||
static final int SAVE = 6;
|
||||
static final int AUTOSAVE = 7;
|
||||
static final int BEAUTIFY = 8;
|
||||
|
||||
PdeEditorButtons buttons;
|
||||
PdeEditorHeader header;
|
||||
@@ -46,6 +47,7 @@ public class PdeEditor extends Panel {
|
||||
#else
|
||||
JEditTextArea textarea;
|
||||
#endif
|
||||
boolean externalEditor;
|
||||
|
||||
// currently opened program
|
||||
String userName; // user currently logged in
|
||||
@@ -116,6 +118,10 @@ public class PdeEditor extends Panel {
|
||||
textarea.setFont(PdeBase.getFont("editor.program.font",
|
||||
new Font("Monospaced",
|
||||
Font.PLAIN, 12)));
|
||||
textarea.setForeground(PdeBase.getColor("editor.program.fgcolor",
|
||||
Color.black));
|
||||
textarea.setBackground(PdeBase.getColor("editor.program.bgcolor",
|
||||
Color.white));
|
||||
textarea.addMouseMotionListener(new MouseMotionAdapter() {
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
frame.setCursor(Frame.CROSSHAIR_CURSOR);
|
||||
@@ -249,6 +255,9 @@ public class PdeEditor extends Panel {
|
||||
skNew();
|
||||
}
|
||||
|
||||
boolean ee = new Boolean(skprops.getProperty("editor.external", "false")).booleanValue();
|
||||
setExternalEditor(ee);
|
||||
|
||||
} catch (Exception e) {
|
||||
// this exception doesn't matter, it's just the normal course of things
|
||||
// the app reaches here when no sketch.properties file exists
|
||||
@@ -261,7 +270,6 @@ public class PdeEditor extends Panel {
|
||||
// doesn't exist, not available, make my own
|
||||
skNew();
|
||||
}
|
||||
|
||||
//rebuildSketchbookMenu(PdeBase.sketchbookMenu);
|
||||
}
|
||||
|
||||
@@ -269,10 +277,17 @@ public class PdeEditor extends Panel {
|
||||
// mode is RUN, SAVE or AUTO
|
||||
public void makeHistory(String program, int mode) {
|
||||
if (!base.recordingHistory) return;
|
||||
|
||||
//if (historyLast.equals(program) && !externalEditor) return;
|
||||
if (historyLast.equals(program)) return;
|
||||
|
||||
String modeStr = (mode == RUN) ? "run" : ((mode == SAVE) ? "save" : "autosave");
|
||||
String modeStr = null;
|
||||
switch (mode) {
|
||||
case RUN: modeStr = "run"; break;
|
||||
case SAVE: modeStr = "save"; break;
|
||||
case AUTOSAVE: modeStr = "autosave"; break;
|
||||
case BEAUTIFY: modeStr = "beautify"; break;
|
||||
}
|
||||
//String modeStr = (mode == RUN) ? "run" : ((mode == SAVE) ? "save" : "autosave");
|
||||
|
||||
try {
|
||||
//PrintWriter historyWriter = new PrintWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(historyFile.getPath(), true))));
|
||||
@@ -356,7 +371,7 @@ public class PdeEditor extends Panel {
|
||||
selection.substring(selection.indexOf("-") + 2);
|
||||
|
||||
// make history for the current guy
|
||||
makeHistory(textarea.getText(), AUTO);
|
||||
makeHistory(textarea.getText(), AUTOSAVE);
|
||||
// mark editor text as having been edited
|
||||
|
||||
try {
|
||||
@@ -413,6 +428,13 @@ public class PdeEditor extends Panel {
|
||||
//System.out.println("RUNNING");
|
||||
buttons.run();
|
||||
|
||||
if (externalEditor) {
|
||||
// history gets screwed by the open..
|
||||
String historySaved = historyLast;
|
||||
handleOpen(sketchName, sketchFile, sketchDir);
|
||||
historyLast = historySaved;
|
||||
}
|
||||
|
||||
presenting = present;
|
||||
|
||||
try {
|
||||
@@ -1314,6 +1336,8 @@ public class PdeEditor extends Panel {
|
||||
skprops.put("sketch.directory", sketchDir.getCanonicalPath());
|
||||
skprops.put("user.name", userName);
|
||||
|
||||
skprops.put("editor.external", externalEditor ? "true" : "false");
|
||||
|
||||
skprops.save(output, "auto-generated by pde, please don't touch");
|
||||
|
||||
} catch (IOException e) {
|
||||
@@ -1327,6 +1351,8 @@ public class PdeEditor extends Panel {
|
||||
|
||||
public void doBeautify() {
|
||||
String prog = textarea.getText();
|
||||
makeHistory(prog, BEAUTIFY);
|
||||
|
||||
//if ((prog.charAt(0) == '#') || (prog.charAt(0) == ';')) {
|
||||
//message("Only DBN code can be made beautiful.");
|
||||
//buttons.clear();
|
||||
@@ -1368,7 +1394,7 @@ public class PdeEditor extends Panel {
|
||||
gotBlankLine = true;
|
||||
}
|
||||
} else {
|
||||
System.out.println(level);
|
||||
//System.out.println(level);
|
||||
int idx = -1;
|
||||
String myline = line.substring(0);
|
||||
while (myline.lastIndexOf('}') != idx) {
|
||||
@@ -1376,7 +1402,8 @@ public class PdeEditor extends Panel {
|
||||
myline = myline.substring(idx+1);
|
||||
level--;
|
||||
}
|
||||
for (int i = 0; i < level*2; i++) {
|
||||
//for (int i = 0; i < level*2; i++) {
|
||||
for (int i = 0; i < level; i++) {
|
||||
buffer.append(' ');
|
||||
}
|
||||
buffer.append(line);
|
||||
@@ -1395,10 +1422,31 @@ public class PdeEditor extends Panel {
|
||||
}
|
||||
}
|
||||
textarea.setText(buffer.toString());
|
||||
setSketchModified(true);
|
||||
buttons.clear();
|
||||
}
|
||||
|
||||
|
||||
public void setExternalEditor(boolean external) {
|
||||
this.externalEditor = external;
|
||||
//System.out.println("setting ee to " + externalEditor);
|
||||
|
||||
textarea.setEditable(!external);
|
||||
base.externalEditorItem.setState(external);
|
||||
base.saveMenuItem.setEnabled(!external);
|
||||
base.saveAsMenuItem.setEnabled(!external);
|
||||
base.beautifyMenuItem.setEnabled(!external);
|
||||
|
||||
if (external) {
|
||||
textarea.setBackground(PdeBase.getColor("editor.program.bgcolor.external", new Color(204, 204, 204)));
|
||||
|
||||
} else {
|
||||
textarea.setBackground(PdeBase.getColor("editor.program.bgcolor",
|
||||
Color.white));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void terminate() { // part of PdeEnvironment
|
||||
//runner.stop();
|
||||
|
||||
Reference in New Issue
Block a user