TextEditorPane dirty flag not resetting to clean

Post a reply

Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review
   

Expand view Topic review: TextEditorPane dirty flag not resetting to clean

Re: TextEditorPane dirty flag not resetting to clean

Post by robert » Sun Dec 29, 2013 4:02 pm

Thanks sugref2! I'll take a look.

TextEditorPane dirty flag not resetting to clean

Post by 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();
}
}

Top

cron