mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
new text editor coming along nicely
This commit is contained in:
103
app/PdeBase.java
103
app/PdeBase.java
@@ -20,7 +20,7 @@ public class PdeBase extends Frame implements ActionListener {
|
||||
|
||||
protected UndoAction undoAction;
|
||||
protected RedoAction redoAction;
|
||||
protected UndoManager undo = new UndoManager();
|
||||
static public UndoManager undo = new UndoManager(); // editor needs this guy
|
||||
|
||||
// indicator that this is the first time this feller has used p5
|
||||
static boolean firstTime;
|
||||
@@ -44,6 +44,7 @@ public class PdeBase extends Frame implements ActionListener {
|
||||
};
|
||||
|
||||
Menu serialMenu;
|
||||
MenuItem undoItem, redoItem;
|
||||
MenuItem saveMenuItem;
|
||||
MenuItem saveAsMenuItem;
|
||||
MenuItem beautifyMenuItem;
|
||||
@@ -251,7 +252,75 @@ public class PdeBase extends Frame implements ActionListener {
|
||||
menu.addActionListener(this);
|
||||
menubar.add(menu);
|
||||
|
||||
menu = new Menu("Edit");
|
||||
|
||||
undoItem = new MenuItem("Undo", new MenuShortcut('Z'));
|
||||
undoItem.addActionListener(undoAction = new UndoAction());
|
||||
menu.add(undoItem);
|
||||
|
||||
redoItem = new MenuItem("Redo", new MenuShortcut('Y'));
|
||||
redoItem.addActionListener(redoAction = new RedoAction());
|
||||
menu.add(redoItem);
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
item = new MenuItem("Cut", new MenuShortcut('X'));
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editor.textarea.cut();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
|
||||
item = new MenuItem("Copy", new MenuShortcut('C'));
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editor.textarea.copy();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
|
||||
item = new MenuItem("Paste", new MenuShortcut('V'));
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editor.textarea.paste();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
item = new MenuItem("Select All", new MenuShortcut('A'));
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
editor.textarea.selectAll();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
|
||||
/*
|
||||
item = new MenuItem("Cut", new MenuShortcut('X'));
|
||||
//Action act = getActionByName(DefaultEditorKit.cutAction);
|
||||
//System.out.println("act is " + act);
|
||||
item.addActionListener(getActionByName(DefaultEditorKit.cutAction));
|
||||
menu.add(item);
|
||||
item = new MenuItem("Copy", new MenuShortcut('C'));
|
||||
item.addActionListener(getActionByName(DefaultEditorKit.copyAction));
|
||||
menu.add(item);
|
||||
item = new MenuItem("Paste", new MenuShortcut('V'));
|
||||
item.addActionListener(getActionByName(DefaultEditorKit.pasteAction));
|
||||
menu.add(item);
|
||||
menu.addSeparator();
|
||||
item = new MenuItem("Select All", new MenuShortcut('A'));
|
||||
item.addActionListener(getActionByName(DefaultEditorKit.selectAllAction));
|
||||
menu.add(item);
|
||||
*/
|
||||
|
||||
menubar.add(menu);
|
||||
|
||||
/*
|
||||
PdeEditorTextPane version
|
||||
|
||||
createActionTable(editor.textarea);
|
||||
menu = new Menu("Edit");
|
||||
//undoAction = new UndoAction();
|
||||
@@ -282,9 +351,12 @@ public class PdeBase extends Frame implements ActionListener {
|
||||
menubar.add(menu);
|
||||
|
||||
// i hear a cs prof or a first year student screaming somewhere
|
||||
Document document = editor.textarea.document;
|
||||
//Document document = editor.textarea.document;
|
||||
Document document = editor.textarea.getDocument();
|
||||
document.addUndoableEditListener(new MyUndoableEditListener());
|
||||
*/
|
||||
Document document = editor.textarea.getDocument();
|
||||
document.addUndoableEditListener(new MyUndoableEditListener());
|
||||
|
||||
menu = new Menu("Sketch");
|
||||
menu.add(new MenuItem("Run", new MenuShortcut('R')));
|
||||
@@ -339,26 +411,8 @@ public class PdeBase extends Frame implements ActionListener {
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
Dimension screen = tk.getScreenSize();
|
||||
|
||||
// THESE CAN BE REMOVED TO SOME EXTENT
|
||||
/*
|
||||
int frameX = getInteger("window.x", (screen.width - width) / 2);
|
||||
int frameY = getInteger("window.y", (screen.height - height) / 2);
|
||||
|
||||
frame.setBounds(frameX, frameY,
|
||||
width + insets.left + insets.right,
|
||||
height + insets.top + insets.bottom);
|
||||
*/
|
||||
|
||||
//frame.reshape(50, 50, width + insets.left + insets.right,
|
||||
// height + insets.top + insets.bottom);
|
||||
|
||||
// i don't like this being here, but..
|
||||
//((PdeEditor)environment).graphics.frame = frame;
|
||||
//((PdeEditor)environment).frame = frame
|
||||
frame.pack(); // maybe this should be before the setBounds call
|
||||
|
||||
//System.out.println(frame.getMinimumSize() + " " + frame.getSize());
|
||||
|
||||
editor.frame = frame; // no longer really used
|
||||
editor.init();
|
||||
rebuildSketchbookMenu(sketchbookMenu);
|
||||
@@ -367,6 +421,9 @@ public class PdeBase extends Frame implements ActionListener {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
PdeEditorTextPane
|
||||
|
||||
Hashtable actions;
|
||||
|
||||
//The following two methods allow us to find an
|
||||
@@ -385,7 +442,7 @@ public class PdeBase extends Frame implements ActionListener {
|
||||
//System.out.println(name + " " + actions);
|
||||
return (Action)(actions.get(name));
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
//This one listens for edits that can be undone.
|
||||
protected class MyUndoableEditListener implements UndoableEditListener {
|
||||
@@ -420,9 +477,11 @@ public class PdeBase extends Frame implements ActionListener {
|
||||
protected void updateUndoState() {
|
||||
if (undo.canUndo()) {
|
||||
this.setEnabled(true);
|
||||
undoItem.setEnabled(true);
|
||||
putValue(Action.NAME, undo.getUndoPresentationName());
|
||||
} else {
|
||||
this.setEnabled(false);
|
||||
undoItem.setEnabled(false);
|
||||
putValue(Action.NAME, "Undo");
|
||||
}
|
||||
}
|
||||
@@ -449,9 +508,11 @@ public class PdeBase extends Frame implements ActionListener {
|
||||
protected void updateRedoState() {
|
||||
if (undo.canRedo()) {
|
||||
this.setEnabled(true);
|
||||
redoItem.setEnabled(true);
|
||||
putValue(Action.NAME, undo.getRedoPresentationName());
|
||||
} else {
|
||||
this.setEnabled(false);
|
||||
redoItem.setEnabled(false);
|
||||
putValue(Action.NAME, "Redo");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,8 +201,9 @@ public class PdeEditor extends Panel {
|
||||
|
||||
// hopefully these are no longer needed w/ swing
|
||||
// (that was wishful thinking, they still are, until we switch to jedit)
|
||||
PdeEditorListener listener = new PdeEditorListener(this);
|
||||
textarea.addKeyListener(listener);
|
||||
PdeEditorListener listener = new PdeEditorListener(this, textarea);
|
||||
textarea.pdeEditorListener = listener;
|
||||
//textarea.addKeyListener(listener);
|
||||
//textarea.addFocusListener(listener);
|
||||
|
||||
/*
|
||||
@@ -451,6 +452,17 @@ public class PdeEditor extends Panel {
|
||||
}
|
||||
|
||||
|
||||
protected void changeText(String what, boolean emptyUndo) {
|
||||
textarea.setText(what);
|
||||
|
||||
// TODO need to wipe out the undo state here
|
||||
if (emptyUndo) PdeBase.undo.discardAllEdits();
|
||||
|
||||
textarea.select(0, 0); // move to the beginning of the document
|
||||
textarea.requestFocus(); // get the caret blinking
|
||||
}
|
||||
|
||||
|
||||
// mode is RUN, SAVE or AUTO
|
||||
public void makeHistory(String program, int mode) {
|
||||
if (!base.recordingHistory) return;
|
||||
@@ -574,7 +586,6 @@ public class PdeEditor extends Panel {
|
||||
}
|
||||
if (found) {
|
||||
// read lines until the next separator
|
||||
//textarea.editorSetText("");
|
||||
line = reader.readLine(); // ignored
|
||||
//String sep = System.getProperty("line.separator");
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
@@ -586,8 +597,7 @@ public class PdeEditor extends Panel {
|
||||
//System.out.println("'" + line + "'");
|
||||
}
|
||||
//textarea.editorSetText(buffer.toString());
|
||||
textarea.setText(buffer.toString());
|
||||
textarea.select(0, 0);
|
||||
changeText(buffer.toString(), true);
|
||||
historyLast = textarea.getText();
|
||||
setSketchModified(false);
|
||||
|
||||
@@ -990,8 +1000,7 @@ afterwards, some of these steps need a cleanup function
|
||||
program = buffer.toString();
|
||||
//System.out.print(program);
|
||||
//textarea.editorSetText(program);
|
||||
textarea.setText(program);
|
||||
textarea.select(0, 0);
|
||||
changeText(program, true);
|
||||
|
||||
//System.out.print(textarea.getText());
|
||||
|
||||
@@ -1028,8 +1037,9 @@ afterwards, some of these steps need a cleanup function
|
||||
} else {
|
||||
//System.out.println("new guy, so setting empty");
|
||||
// style info only gets set if there's text
|
||||
textarea.setText("");
|
||||
textarea.select(0, 0);
|
||||
//textarea.setText("");
|
||||
//textarea.select(0, 0);
|
||||
changeText("", true);
|
||||
//textarea.editorSetText(" ");
|
||||
// now set to now text. yay hack!
|
||||
//textarea.editorSetText(""); // this doesn't work. oh well
|
||||
@@ -1200,7 +1210,8 @@ afterwards, some of these steps need a cleanup function
|
||||
|
||||
// update with the new junk and save that as the new code
|
||||
//textarea.editorSetText(textareaContents);
|
||||
textarea.setText(textareaContents);
|
||||
//textarea.setText(textareaContents);
|
||||
changeText(textareaContents, true);
|
||||
textarea.setCaretPosition(textareaPosition);
|
||||
doSave();
|
||||
}
|
||||
@@ -1705,8 +1716,9 @@ afterwards, some of these steps need a cleanup function
|
||||
}
|
||||
}
|
||||
//textarea.editorSetText(buffer.toString());
|
||||
textarea.setText(buffer.toString());
|
||||
textarea.select(0, 0);
|
||||
//textarea.setText(buffer.toString());
|
||||
//textarea.select(0, 0);
|
||||
changeText(buffer.toString(), false);
|
||||
setSketchModified(true);
|
||||
buttons.clear();
|
||||
}
|
||||
@@ -1722,12 +1734,17 @@ afterwards, some of these steps need a cleanup function
|
||||
base.saveAsMenuItem.setEnabled(!external);
|
||||
base.beautifyMenuItem.setEnabled(!external);
|
||||
|
||||
// disable line highlight and turn off the caret when disabling
|
||||
TextAreaPainter painter = textarea.getPainter();
|
||||
if (external) {
|
||||
textarea.setBackground(PdeBase.getColor("editor.program.bgcolor.external", new Color(204, 204, 204)));
|
||||
painter.setBackground(PdeBase.getColor("editor.program.bgcolor.external", new Color(204, 204, 204)));
|
||||
painter.lineHighlight = false;
|
||||
textarea.setCaretVisible(false);
|
||||
|
||||
} else {
|
||||
textarea.setBackground(PdeBase.getColor("editor.program.bgcolor",
|
||||
Color.white));
|
||||
painter.setBackground(PdeBase.getColor("editor.program.bgcolor", Color.white));
|
||||
painter.lineHighlight = PdeBase.getBoolean("editor.program.linehighlight.enabled", true);
|
||||
textarea.setCaretVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
37
todo.txt
37
todo.txt
@@ -35,33 +35,44 @@ java.lang.NullPointerException
|
||||
at com.apple.buckyball.app.LaunchRunner.callMain(LaunchRunner.java:44)
|
||||
at com.apple.buckyball.app.CarbonLibApp.main(CarbonLibApp.java:76)
|
||||
|
||||
_ recursive sketch add that works properly and ignores crap
|
||||
|
||||
_ jedit text area
|
||||
_ get settings from PdeBase
|
||||
_ need to take care of auto-indent etc
|
||||
_ better defaults for syntax highlighting
|
||||
_ comments should be gray and not italicized
|
||||
_ disable end of line marker by default
|
||||
_ highlight p5 keywords
|
||||
_ setup, draw, loop as one class
|
||||
_ rect, line etc as another
|
||||
_ width, height, pixels as a third
|
||||
_ change bg color for 'use external editor'
|
||||
_ enable wheel mouse
|
||||
_ jump to top of document on load
|
||||
_ change style of ~ at end of document for unused area
|
||||
_ extra linefeeds is getting annoying for folks
|
||||
_ line endings joy
|
||||
_ is setText goobering up on beautify?
|
||||
_ how are line endings working during save?
|
||||
|
||||
X enable/disable undo/redo
|
||||
X don't let undo after setting text
|
||||
X get focus after setText
|
||||
X need to take care of auto-indent etc
|
||||
X is setText goobering up on beautify?
|
||||
X re-implement cut/copy/paste
|
||||
X re-implement undo/redo
|
||||
X get settings from PdeBase
|
||||
X better defaults for syntax highlighting
|
||||
X comments should be gray and not italicized
|
||||
X disable end of line marker by default
|
||||
X highlight p5 keywords
|
||||
X setup, draw, loop as one class
|
||||
X rect, line etc as another
|
||||
X width, height, pixels as a third
|
||||
X jump to top of document on load
|
||||
X change style of ~ at end of document for unused area
|
||||
|
||||
|
||||
MENTION IN DOCS
|
||||
_ describe rundown of constants pulled from pde.properties
|
||||
_ notes on debugging
|
||||
_ look at the code that's created in build/
|
||||
_ run with java -Xint blahblah (turns off jit)
|
||||
_ known issues
|
||||
_ random freezes.. especially under windows
|
||||
_ make a note that size() has to come first [nluken]
|
||||
_ doesn't yet run under java 1.4
|
||||
_ doesn't yet run under java 1.4 on mac
|
||||
_ undo/redo can go to far
|
||||
|
||||
_ p5 faq items: re midi support, msgs w/ adam hoyle in mail folder
|
||||
_ also 'why p5' message from amit pitaru on 12/15/02
|
||||
|
||||
Reference in New Issue
Block a user