Remove and later restore UndoManager for RTextArea

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Remove and later restore UndoManager for RTextArea

Postby Dennis » Wed Mar 17, 2010 10:40 am

Hi Robert,

First of all, thank you very much for the time you spend on RSyntaxTextArea. I'm using it on several places in my XULRunner based application. My question is the following:

Imagine two panes, left and right, in the left pane is a tree structure (this represents an XML document) in the right pane is a RSyntaxTextArea embedded as an applet in a XUL document. The user can select nodes in the tree, on selecting a node the text stored with that node must be made editable in the RSyntaxTextArea, on selecting another node the text for that other node is made editable in the RSyntaxTextArea. (The 'text' for each node is stored as a String, not as a file). This all works perfectly.

The problem comes when undo'ing edits, the RTextArea's undoManager has no idea certain edits only relate to 1 node in the tree.
What I wish to do is 'save' all edits before switching tree nodes and restore the edits before showing text for another node. I thought of doing this in several ways

    have 1 RSyntaxTextArea instance per tree node (this will not work since there can be > 100 nodes and several trees)
    have 1 AbstractDocument per tree node and call RTextArea.setDocument() (will this do what I want?)
    force access to "private transient RUndoManager undoManager;" (using reflection?) and create 1 instance of RUndoManager per tree node and switch that on switching selected node in the tree

Can you please advise on how to crack this problem?

Thanks and greetings,
Dennis de Klerk

Btw. I'm a beginner when it comes to Java and Swing
Dennis
 

Re: Remove and later restore UndoManager for RTextArea

Postby Dennis » Wed Mar 17, 2010 10:47 am

Robert,
I forgot to register with this forum. Please reply to this message instead of the previous.
Greetings,
Dennis de Klerk
Dennis
 
Posts: 2
Joined: Wed Mar 17, 2010 10:42 am

Re: Remove and later restore UndoManager for RTextArea

Postby robert » Wed Mar 17, 2010 12:41 pm

Hi Dennis,

I'm betting you want undo history to persist for any particular node, e.g. you can do some edits in the text for one node, switch to a second node, then switch back to the first, and hitting ctrl+z will undo your last edit for that node. Is that right? Because if *not*, and all you care about is edits persisting until they change nodes, you should be able to just call textArea.discardAllEdits() whenever you switch nodes, and it'll clear the undo history.

But assuming you do want them to persist, I suppose the only way to do this currently would be by reflection, like you suggest. Unfortunately, since the undo manager is associated with the editor and not the document, switching out RSyntaxDocuments would simply clear the undo history each time. I see now that a better model might be to associate the undo manager with the Document. I can't recall if there were any specific reasons I made it a member of the editor instead, I'd have to investigate that

Hope this helps. Sorry you have to resort to hacks like reflection for this. Ideas are welcome, of course. I'll look into moving the undo manager into the Document and see what kind of consequences it would have.
User avatar
robert
 
Posts: 801
Joined: Sat May 10, 2008 5:16 pm

Re: Remove and later restore UndoManager for RTextArea

Postby Dennis » Wed Mar 17, 2010 12:52 pm

Hi Robert,

You said:
I'm betting you want undo history to persist for any particular node, e.g. you can do some edits in the text for one node, switch to a second node, then switch back to the first, and hitting ctrl+z will undo your last edit for that node. Is that right?


That's exactly what i'm talking about!
I will try and implement this using reflection, thanks for your fast reply.
Dennis
 
Posts: 2
Joined: Wed Mar 17, 2010 10:42 am


Return to Help

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron