TextEditorPane dirty flag not resetting to clean

Questions on using RSyntaxTextArea should go here.

Moderator: robert

TextEditorPane dirty flag not resetting to clean

Postby sugref2 » Wed Dec 18, 2013 2:37 pm

The dirty flag on TextEditorPane is not being reset to false when all edits are undone.
(I am assuming that all edits are Undoable and that any non-Undoable edit is handled specially by the particular application)

There are a number of approaches to a fix

[list=]allowing RUndoManager to be subclassed in RTextArea
exposing UndoManager in RTextArea as in UndoManager getUndoManager()
providing canUndo(), canUndo() in RTextArea[/list]

The following snippets might help; it is from a subclass of TextEditorPane that gets over the problem

java code:

public void undoLastAction() {
super.undoLastAction();
final UndoManager undoManager = getUndoManagerHACK();
if (undoManager != null)
if (undoManager.canUndo())
setDirtyHACK(true);
else
setDirtyHACK(false);
}

UndoManager getUndoManagerHACK() {
final AbstractDocument doc = (AbstractDocument) getDocument();
final UndoableEditListener[] undoMgrArray = doc
.getListeners(UndoableEditListener.class);
if (undoMgrArray == null || undoMgrArray.length == 0)
return null;
return (UndoManager) undoMgrArray[0];
}

void setDirtyHACK(boolean dirty) {
try {
final Class<?> claz = Class.forName(TextEditorPane.class.getName());
final java.lang.reflect.Method m = claz.getDeclaredMethod("setDirty",
Boolean.TYPE);
m.setAccessible(true);
m.invoke(this, dirty);
}
catch (final Throwable e) {
e.printStackTrace();
}
}
sugref2
 

Re: TextEditorPane dirty flag not resetting to clean

Postby robert » Sun Dec 29, 2013 4:02 pm

Thanks sugref2! I'll take a look.
User avatar
robert
 
Posts: 794
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron