fixes for undo mess, setting new document obj for each tab

This commit is contained in:
benfry
2005-05-10 00:29:05 +00:00
parent 739aab7819
commit 217adeba17
6 changed files with 232 additions and 120 deletions
+68 -1
View File
@@ -183,7 +183,7 @@ public class Editor extends JFrame
textarea = new JEditTextArea(new PdeTextAreaDefaults());
textarea.setRightClickPopup(new TextAreaPopup());
textarea.setTokenMarker(new PdeKeywords());
//textarea.setTokenMarker(new PdeKeywords());
textarea.setHorizontalOffset(6);
// assemble console panel, consisting of status area and the console itself
@@ -231,6 +231,7 @@ public class Editor extends JFrame
listener = new EditorListener(this, textarea);
pain.add(box);
/*
// set the undo stuff for this feller
Document document = textarea.getDocument();
//document.addUndoableEditListener(new PdeUndoableEditListener());
@@ -244,6 +245,7 @@ public class Editor extends JFrame
}
}
});
*/
}
@@ -949,6 +951,7 @@ public class Editor extends JFrame
/**
* Called by Sketch when the tab is changed or a new set of files are opened.
*/
/*
public void setText(String currentProgram,
int selectionStart, int selectionEnd,
UndoManager currentUndo) {
@@ -966,6 +969,70 @@ public class Editor extends JFrame
undoAction.updateUndoState();
redoAction.updateRedoState();
}
*/
/*
public void setDocument(SyntaxDocument document,
int selectionStart, int selectionStop,
int scrollPosition, UndoManager undo) {
textarea.setDocument(document, selectionStart, selectionStop,
scrollPosition);
textarea.requestFocus(); // get the caret blinking
this.undo = undo;
undoAction.updateUndoState();
redoAction.updateRedoState();
}
*/
/**
* Switch between tabs, this swaps out the Document object
* that's currently being manipulated.
*/
public void setCode(SketchCode code) {
if (code.document == null) { // this document not yet inited
code.document = new SyntaxDocument();
// turn on syntax highlighting
code.document.setTokenMarker(new PdeKeywords());
// insert the program text into the document object
try {
code.document.insertString(0, code.program, null);
} catch (BadLocationException bl) {
bl.printStackTrace();
}
// set up this guy's own undo manager
code.undo = new UndoManager();
// connect the undo listener to the editor
code.document.addUndoableEditListener(new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent e) {
if (undo != null) {
undo.addEdit(e.getEdit());
undoAction.updateUndoState();
redoAction.updateRedoState();
}
}
});
}
// update the document object that's in use
textarea.setDocument(code.document,
code.selectionStart, code.selectionStop,
code.scrollPosition);
textarea.requestFocus(); // get the caret blinking
this.undo = code.undo;
undoAction.updateUndoState();
redoAction.updateRedoState();
}
public void handleRun(boolean present) {
+7 -1
View File
@@ -1083,16 +1083,22 @@ public class Sketch {
}
current = code[which];
editor.setCode(current);
//editor.setDocument(current.document,
// current.selectionStart, current.selectionStop,
// current.scrollPosition, current.undo);
// set to the text for this file
// 'true' means to wipe out the undo buffer
// (so they don't undo back to the other file.. whups!)
/*
editor.setText(current.program,
current.selectionStart, current.selectionStop,
current.undo);
*/
// set stored caret and scroll positions
editor.textarea.setScrollPosition(current.scrollPosition);
//editor.textarea.setScrollPosition(current.scrollPosition);
//editor.textarea.select(current.selectionStart, current.selectionStop);
//editor.textarea.setSelectionStart(current.selectionStart);
//editor.textarea.setSelectionEnd(current.selectionStop);
+6 -1
View File
@@ -23,8 +23,10 @@
*/
package processing.app;
import processing.app.syntax.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.undo.*;
@@ -41,8 +43,11 @@ public class SketchCode {
/** Text of the program text for this tab */
public String program;
/** Document object for this tab */
public SyntaxDocument document;
/** Undo Manager for this tab, each tab keeps track of their own */
public UndoManager undo = new UndoManager();
public UndoManager undo; // = new UndoManager();
// saved positions from last time this tab was used
public int selectionStart;
+129 -108
View File
@@ -607,10 +607,10 @@ public class JEditTextArea extends JComponent
}
/**
* Converts an x co-ordinate to an offset within a line.
* @param line The line
* @param x The x co-ordinate
*/
* Converts an x co-ordinate to an offset within a line.
* @param line The line
* @param x The x co-ordinate
*/
public int xToOffset(int line, int x)
{
TokenMarker tokenMarker = getTokenMarker();
@@ -716,10 +716,10 @@ public class JEditTextArea extends JComponent
}
/**
* Converts a point to an offset, from the start of the text.
* @param x The x co-ordinate of the point
* @param y The y co-ordinate of the point
*/
* Converts a point to an offset, from the start of the text.
* @param x The x co-ordinate of the point
* @param y The y co-ordinate of the point
*/
public int xyToOffset(int x, int y)
{
int line = yToLine(y);
@@ -728,83 +728,104 @@ public class JEditTextArea extends JComponent
}
/**
* Returns the document this text area is editing.
*/
* Returns the document this text area is editing.
*/
public final SyntaxDocument getDocument()
{
return document;
}
/**
* Sets the document this text area is editing.
* @param document The document
*/
public void setDocument(SyntaxDocument document)
{
if(this.document == document)
* Sets the document this text area is editing.
* @param document The document
*/
public void setDocument(SyntaxDocument document) {
if (this.document == document)
return;
if(this.document != null)
if (this.document != null)
this.document.removeDocumentListener(documentHandler);
this.document = document;
document.addDocumentListener(documentHandler);
select(0,0);
select(0, 0);
updateScrollBars();
painter.repaint();
}
/**
* Returns the document's token marker. Equivalent to calling
* <code>getDocument().getTokenMarker()</code>.
*/
* Set document with a twist, includes the old caret
* and scroll positions, added for p5. [fry]
*/
public void setDocument(SyntaxDocument document,
int start, int stop, int scroll) {
if (this.document == document)
return;
if (this.document != null)
this.document.removeDocumentListener(documentHandler);
this.document = document;
document.addDocumentListener(documentHandler);
select(start, stop);
updateScrollBars();
setScrollPosition(scroll);
painter.repaint();
}
/**
* Returns the document's token marker. Equivalent to calling
* <code>getDocument().getTokenMarker()</code>.
*/
public final TokenMarker getTokenMarker()
{
return document.getTokenMarker();
}
/**
* Sets the document's token marker. Equivalent to caling
* <code>getDocument().setTokenMarker()</code>.
* @param tokenMarker The token marker
*/
* Sets the document's token marker. Equivalent to caling
* <code>getDocument().setTokenMarker()</code>.
* @param tokenMarker The token marker
*/
public final void setTokenMarker(TokenMarker tokenMarker)
{
document.setTokenMarker(tokenMarker);
}
/**
* Returns the length of the document. Equivalent to calling
* <code>getDocument().getLength()</code>.
*/
* Returns the length of the document. Equivalent to calling
* <code>getDocument().getLength()</code>.
*/
public final int getDocumentLength()
{
return document.getLength();
}
/**
* Returns the number of lines in the document.
*/
* Returns the number of lines in the document.
*/
public final int getLineCount()
{
return document.getDefaultRootElement().getElementCount();
}
/**
* Returns the line containing the specified offset.
* @param offset The offset
*/
* Returns the line containing the specified offset.
* @param offset The offset
*/
public final int getLineOfOffset(int offset)
{
return document.getDefaultRootElement().getElementIndex(offset);
}
/**
* Returns the start offset of the specified line.
* @param line The line
* @return The start offset of the specified line, or -1 if the line is
* invalid
*/
* Returns the start offset of the specified line.
* @param line The line
* @return The start offset of the specified line, or -1 if the line is
* invalid
*/
public int getLineStartOffset(int line)
{
Element lineElement = document.getDefaultRootElement()
@@ -816,11 +837,11 @@ public class JEditTextArea extends JComponent
}
/**
* Returns the end offset of the specified line.
* @param line The line
* @return The end offset of the specified line, or -1 if the line is
* invalid.
*/
* Returns the end offset of the specified line.
* @param line The line
* @return The end offset of the specified line, or -1 if the line is
* invalid.
*/
public int getLineEndOffset(int line)
{
Element lineElement = document.getDefaultRootElement()
@@ -832,9 +853,9 @@ public class JEditTextArea extends JComponent
}
/**
* Returns the length of the specified line.
* @param line The line
*/
* Returns the length of the specified line.
* @param line The line
*/
public int getLineLength(int line)
{
Element lineElement = document.getDefaultRootElement()
@@ -847,8 +868,8 @@ public class JEditTextArea extends JComponent
}
/**
* Returns the entire text of this text area.
*/
* Returns the entire text of this text area.
*/
public String getText()
{
try
@@ -884,11 +905,11 @@ public class JEditTextArea extends JComponent
}
/**
* Returns the specified substring of the document.
* @param start The start offset
* @param len The length of the substring
* @return The substring, or null if the offsets are invalid
*/
* Returns the specified substring of the document.
* @param start The start offset
* @param len The length of the substring
* @return The substring, or null if the offsets are invalid
*/
public final String getText(int start, int len)
{
try
@@ -1201,8 +1222,8 @@ public class JEditTextArea extends JComponent
/**
* Returns the selected text, or null if no selection is active.
*/
* Returns the selected text, or null if no selection is active.
*/
public final String getSelectedText()
{
if(selectionStart == selectionEnd)
@@ -1354,35 +1375,35 @@ public class JEditTextArea extends JComponent
}
/**
* Returns true if this text area is editable, false otherwise.
*/
* Returns true if this text area is editable, false otherwise.
*/
public final boolean isEditable()
{
return editable;
}
/**
* Sets if this component is editable.
* @param editable True if this text area should be editable,
* false otherwise
*/
* Sets if this component is editable.
* @param editable True if this text area should be editable,
* false otherwise
*/
public final void setEditable(boolean editable)
{
this.editable = editable;
}
/**
* Returns the right click popup menu.
*/
* Returns the right click popup menu.
*/
public final JPopupMenu getRightClickPopup()
{
return popup;
}
/**
* Sets the right click popup menu.
* @param popup The popup
*/
* Sets the right click popup menu.
* @param popup The popup
*/
//public final void setRightClickPopup(EditPopupMenu popup)
public final void setRightClickPopup(JPopupMenu popup)
{
@@ -1400,22 +1421,22 @@ public class JEditTextArea extends JComponent
}
/**
* Sets the `magic' caret position. This can be used to preserve
* the column position when moving up and down lines.
* @param magicCaret The magic caret position
*/
* Sets the `magic' caret position. This can be used to preserve
* the column position when moving up and down lines.
* @param magicCaret The magic caret position
*/
public final void setMagicCaretPosition(int magicCaret)
{
this.magicCaret = magicCaret;
}
/**
* Similar to <code>setSelectedText()</code>, but overstrikes the
* appropriate number of characters if overwrite mode is enabled.
* @param str The string
* @see #setSelectedText(String)
* @see #isOverwriteEnabled()
*/
* Similar to <code>setSelectedText()</code>, but overstrikes the
* appropriate number of characters if overwrite mode is enabled.
* @param str The string
* @see #setSelectedText(String)
* @see #isOverwriteEnabled()
*/
public void overwriteSetSelectedText(String str)
{
// Don't overstrike if there is a selection
@@ -1453,18 +1474,18 @@ public class JEditTextArea extends JComponent
}
/**
* Returns true if overwrite mode is enabled, false otherwise.
*/
* Returns true if overwrite mode is enabled, false otherwise.
*/
public final boolean isOverwriteEnabled()
{
return overwrite;
}
/**
* Sets if overwrite mode should be enabled.
* @param overwrite True if overwrite mode should be enabled,
* false otherwise.
*/
* Sets if overwrite mode should be enabled.
* @param overwrite True if overwrite mode should be enabled,
* false otherwise.
*/
public final void setOverwriteEnabled(boolean overwrite)
{
this.overwrite = overwrite;
@@ -1472,18 +1493,18 @@ public class JEditTextArea extends JComponent
}
/**
* Returns true if the selection is rectangular, false otherwise.
*/
* Returns true if the selection is rectangular, false otherwise.
*/
public final boolean isSelectionRectangular()
{
return rectSelect;
}
/**
* Sets if the selection should be rectangular.
* @param overwrite True if the selection should be rectangular,
* false otherwise.
*/
* Sets if the selection should be rectangular.
* @param overwrite True if the selection should be rectangular,
* false otherwise.
*/
public final void setSelectionRectangular(boolean rectSelect)
{
this.rectSelect = rectSelect;
@@ -1491,45 +1512,45 @@ public class JEditTextArea extends JComponent
}
/**
* Returns the position of the highlighted bracket (the bracket
* matching the one before the caret)
*/
* Returns the position of the highlighted bracket (the bracket
* matching the one before the caret)
*/
public final int getBracketPosition()
{
return bracketPosition;
}
/**
* Returns the line of the highlighted bracket (the bracket
* matching the one before the caret)
*/
* Returns the line of the highlighted bracket (the bracket
* matching the one before the caret)
*/
public final int getBracketLine()
{
return bracketLine;
}
/**
* Adds a caret change listener to this text area.
* @param listener The listener
*/
* Adds a caret change listener to this text area.
* @param listener The listener
*/
public final void addCaretListener(CaretListener listener)
{
eventListenerList.add(CaretListener.class,listener);
}
/**
* Removes a caret change listener from this text area.
* @param listener The listener
*/
* Removes a caret change listener from this text area.
* @param listener The listener
*/
public final void removeCaretListener(CaretListener listener)
{
eventListenerList.remove(CaretListener.class,listener);
}
/**
* Deletes the selected text from the text area and places it
* into the clipboard.
*/
* Deletes the selected text from the text area and places it
* into the clipboard.
*/
public void cut()
{
if(editable)
@@ -1540,8 +1561,8 @@ public class JEditTextArea extends JComponent
}
/**
* Places the selected text into the clipboard.
*/
* Places the selected text into the clipboard.
*/
public void copy()
{
if(selectionStart != selectionEnd)
@@ -1589,9 +1610,9 @@ public class JEditTextArea extends JComponent
}
/**
* Called by the AWT when this component is removed from it's parent.
* This stops clears the currently focused component.
*/
* Called by the AWT when this component is removed from it's parent.
* This stops clears the currently focused component.
*/
public void removeNotify()
{
super.removeNotify();
+2
View File
@@ -448,6 +448,8 @@ _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs
PGraphicsGL
_ updatePixels() seems to be having trouble
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Contribution_3DOpenGL;action=display;num=1115630361;start=0
_ gl smoothing.. how to disable polygon but keep line enabled
_ or at least make a note of this?
_ leave smooth off, get the gl object, then enable line smooth
+20 -9
View File
@@ -1,9 +1,9 @@
0090 pde
X working on strange undo problems, allowing a new Document for each tab
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
_ runtime exceptions have stopped coming through (on pc only?)
_ test with florian example for the exception stuff
_ that they don't show up in the error bar
@@ -18,14 +18,17 @@ _ make simple tool for casey to rebuild all the examples at once
_ just make it easier to go to the next sketch
_ need to rebuild with this release because of 1.3/1.4 issues
_ auto-run the javadoc in dist.sh
_ doctor a copy of the css file to use p5 defaults
_ and re-copy the css in after generating the doc each time
bugzilla
_ get these two todo lists into their bugzilla categories
_ setup bugzilla and enter all the bugs
discuss with casey
_ auto-run the javadoc in dist.sh
_ doctor a copy of the css file to use p5 defaults
_ and re-copy the css in after generating the doc each time
_ redraw() should be related for loop and noLoop
_ redraw() can't be called inside draw(), but loop/noLoop can
_ documentation on tabs: .java files, inner classes, etc
_ additional tabs are added to the main code
_ as a result, static variables can't be used
@@ -210,6 +213,8 @@ _ switch to newer revision of jedit?
_ is enormous horizontal scroller issue fixed properly
_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1083787569
_ mouse wheel broken in the text editor? (windows jdk 1.5?)
_ don't draw the nasty couple of pixels in the margin
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Suggestions;action=display;num=1115597365;start=0
undo problems
_ Ctrl-Z will undo, but not scroll to where the undo happens.
@@ -222,6 +227,17 @@ _ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Suggestions;action=
PDE / Find & Replace
_ only enable "find next" in menu after a find has happened
_ several tweaks
_ allowing to find & replace over multiple tabs
- placing "replace" next to "find" ... (hitting "replace all" by accident)
- have a button "replace & find next"
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Suggestions;action=display;num=1115645270;start=0
_ fix find/replace focus issue on osx
_ give that field focus explicitly, rather than just for typing
_ right now, typing works, but no caret, no blue highlight
_ and on second find run, should instead select all the find string
_ so that typing will replace it directly
_ all around very ugly, fix it up
PDE / Editor Buttons
@@ -580,11 +596,6 @@ _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs
PLATFORMS / Mac OS X
_ fix find/replace focus issue on osx
_ give that field focus explicitly, rather than just for typing
_ right now, typing works, but no caret, no blue highlight
_ and on second find run, should instead select all the find string
_ so that typing will replace it directly
_ set nice background for disk image on macosx
_ test more to see if runtime exceptions are coming through
_ track down error in PdeCompiler for message parsing