B4J Question Undo Redo (SOLVED)

ThRuST

Well-Known Member
Licensed User
Longtime User
I tried to implement two buttons with Undo Redo functionality to step backwards and forward in a textarea control.
As well as with the codearea library. By using jAWTRobot library v1.61 and setting focus to the control while performing

Works:
undoredo:
txtAreaDocs.RequestFocus
Main.AWTRobot.RobotSpecialKeyCombo("ctrl_z")

Undo works on my system (Windows 10 running on an Intel i7 CPU, but ctrl_y does not work in jAWTRobot library.
The default manual keys ctrl+z and ctrl+y works as it should in Windows 10. But my "hack" is not a preffered method.
That's why I am reaching out to get help with this, and perhaps Reflector library could be better for such tasks.

So to sum this up I want the users to be able to step back and forth between code using buttons that sets focus on the textarea and gets the job done.
Let me add that I have tried the solution below but that only highlighted where the cursor is from the default ctrl key on Windows 10.

Does not work:

hack:
txtAreaDocs.RequestFocus
Main.AWTRobot.RobotSpecialKeyCombo("ctrl_y")


robot:
txtAreaDocs.RequestFocus
Main.AWTRobot.RobotSpecialKeyPress("ctrl")
Main.AWTRobot.RobotSpecialKeyPress("z")
Main.AWTRobot.RobotSpecialKeyRelease("z")
Main.AWTRobot.RobotSpecialKeyPress("ctrl")

Please confirm how this works on your system and hopefully this can be solved!

Regards,
Roger
 
Last edited:

Sandman

Expert
Licensed User
Longtime User
Why doesn't this work for you?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
@Sandman Interesting. Obviously I missed this one since it came out in 2016 but I'll give it a try.
Roycefer who maintains jAWTRobot library mentioned that the Reflector library could eventually do the trick.
Let me add that his lib is awesome and useful for many things but somehow undo redo have some issues with my approach.
Anyway, thanks for sharing
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Btw here's a screenshot of my documents editor

1654512611349.png


If only undo and redo could work.. sigh :)
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
UndoManager seems very good but I'm having trouble to make it compatible with Code area library.
Probably wrapped by Stevel05. There's no method to refer to Codearea.Text
Hopefully I'll figure it out!!
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
UndoManager works nicely, but so far I have not been able to make it work with code area library.
After an advice I tried this way, however this don't seem like the appropriate way to use undo redo with jAWTRobot library.

undoredo:
txtAreaDocs.RequestFocus
    Main.AWTRobot.RobotDelay(40)
    Main.AWTRobot.RobotSpecialKeyPress("ctrl")
    Main.AWTRobot.RobotDelay(40)
    Main.AWTRobot.RobotSpecialKeyPress("z")
    Main.AWTRobot.RobotDelay(40)
    Main.AWTRobot.RobotSpecialKeyRelease("z")
    Main.AWTRobot.RobotDelay(40)
    Main.AWTRobot.RobotSpecialKeyPress("ctrl")
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Undo manager is the way to go but for the robot solution to work, you would probably have to use the specialkeycombo's with a delay in between.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
I'd like to add that this thread is solved. UndoManager is indeed the way to go.
From my experience jAWTRobot SpecialKeycombo can be an option but only Undo worked in my test (ctrl_z).
Thanks to @Sandman and @stevel05 for the solution. UndoManager also works with CodeArea.
Just make sure the initialization is done in the correct order and it will work.

Edit
Credits to @Erel for the excellent Undo Manager.

:)?
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Hello B4X world!
I made UndoManager work with both the TextArea and the CodeArea view by using two instances and two separate subs. It works very nicely.
A beta version of my project Athena Lite Pro will be released once it's ready for that. For anyone interested welcome to follow my work by going here

Also make sure you enjoy listening to @stevel05 music 'A little light music' and 'Riffraised' by going here
?:)?
 
Upvote 0
Top