Undo / Redo

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Undo / Redo

Postby KalemKutu » Sun Oct 18, 2009 7:36 am

Hi together,

I am using a JMenu, where I implement a JMenuItem "Undo" and "Redo".
But in RSyntaxTextArea there is also "Undo" and "Redo".
So now I have 2 places with undo / redo functions.

If I use only either of them, everything is ok.
If I mix them up, for example
- I write someting in RSyntaxTextArea
- I undo with RSyntaxTextArea
- I continue writing
- I undo via JMenuItem

=> Than I got an error!

I think the reason is, that I use in JMenuItem "import javax.swing.undo.UndoManager;"

So how can I use the undo / redo functions of RSyntaxTextArea?
Can anyone give me an example?

Thanks
Kalem
KalemKutu
 

Re: Undo / Redo

Postby robert » Mon Oct 19, 2009 3:07 am

Hi Kalem,

You'll want to use the standard editing Actions (cut, copy, paste, delete, undo, and redo) that are built into RSyntaxTextArea. These Actions will stay enabled as appropriate to the currently active text area and its selection, as well as automagically be localized into several languages!

The main method you'll want to use is the getAction() method in the RTextArea class (the base class of RSyntaxTextArea):

Code: Select all
public RecordableTextAction getAction(int action)


The "action" parameter for this method can be any of the following values, also defined in the RTextArea class:

Code: Select all
RTextArea.CUT_ACTION
RTextArea.COPY_ACTION
RTextArea.PASTE_ACTION
RTextArea.DELETE_ACTION
RTextArea.UNDO_ACTION
RTextArea.REDO_ACTION
RTextArea.SELECT_ALL_ACTION


This example shows how you could create the standard "edit menu" found in text editor applications:

Code: Select all
JMenu menu = new JMenu("Edit");
menu.add(new JMenuItem(textArea.getAction(RTextArea.UNDO_ACTION)));
menu.add(new JMenuItem(textArea.getAction(RTextArea.REDO_ACTION)));
menu.addSeparator();
menu.add(new JMenuItem(textArea.getAction(RTextArea.CUT_ACTION)));
menu.add(new JMenuItem(textArea.getAction(RTextArea.COPY_ACTION)));
menu.add(new JMenuItem(textArea.getAction(RTextArea.PASTE_ACTION)));
menu.add(new JMenuItem(textArea.getAction(RTextArea.DELETE_ACTION)));
menu.addSeparator();
menu.add(new JMenuItem(textArea.getAction(RTextArea.SELECT_ALL_ACTION)));


For more information, check out the javadoc for RSyntaxTextArea for the complete API. Specifically, check out the RTextArea and RSyntaxTextArea classes.

Let me know if you have any questions!

Robert
User avatar
robert
 
Posts: 774
Joined: Sat May 10, 2008 5:16 pm

Re: Undo / Redo

Postby KalemKutu » Thu Dec 31, 2009 9:15 am

Hi Robert,

I am using the methods
- RSyntaxTextArea.undoLastAction()
- RSyntaxTextArea.redoLastAction()

They are inherited from RTextArea.

It works, thanks!

Kalem
KalemKutu
 

Re: Undo / Redo

Postby robert » Sat Jan 02, 2010 3:12 am

So, just to be sure, I assume because you said

It works, thanks!


that you got things working? If not, I'll need more details!
User avatar
robert
 
Posts: 774
Joined: Sat May 10, 2008 5:16 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 5 guests

cron