Implementing an Undo routine
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Implementing an Undo routine
I have a facility that enables users to delete fields from my main stack, using the list in a palette:
on deleteKey
` get the value of the selectedLine
` cut field it of card 1 of stack "organiser 4"
` send mouseup to button "List Fields" of card 1 of stack "organiser 4" -- updates the field list palette
end deleteKey
Now I'd like to add an undo routine that enables them to reinstate the field if they change their mind. Something along the lines of:
on undo
-- paste the recently cut field back into stack "organiser 4"
-- (update the list palette) send mouseup to button "List Fields" of card 1 of stack "organiser 4"
end undo
How do I modify the Rev menus so that choosing Edit:Undo, or typing Cmd-Z, will run this routine?
Thanks for your help,
Eric
on deleteKey
` get the value of the selectedLine
` cut field it of card 1 of stack "organiser 4"
` send mouseup to button "List Fields" of card 1 of stack "organiser 4" -- updates the field list palette
end deleteKey
Now I'd like to add an undo routine that enables them to reinstate the field if they change their mind. Something along the lines of:
on undo
-- paste the recently cut field back into stack "organiser 4"
-- (update the list palette) send mouseup to button "List Fields" of card 1 of stack "organiser 4"
end undo
How do I modify the Rev menus so that choosing Edit:Undo, or typing Cmd-Z, will run this routine?
Thanks for your help,
Eric
Re: Implementing an Undo routine
Eric,
There is no reliable way to do this. If it hasn't been reported yet, report it as a bug to the QA center. It happens to me every day, that I accidentally delete an object and can't undo. It happens, because the property inspector appears to have focus, while in fact the stack window has focus. If I press the backspace button to delete the name of an object in the property inspector, the entire object is often deleted
Mark
There is no reliable way to do this. If it hasn't been reported yet, report it as a bug to the QA center. It happens to me every day, that I accidentally delete an object and can't undo. It happens, because the property inspector appears to have focus, while in fact the stack window has focus. If I press the backspace button to delete the name of an object in the property inspector, the entire object is often deleted

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Implementing an Undo routine
Thanks, Mark.
That's a bit remiss, don't you think?
It seems I CAN intercept the undoKey *- which, surely, is always Cmd-Z (or Ctrl+Z on Windows);
and it seems I can even intercept a message (undoChanged) when the action to be undone updates to some new action.
So why wouldn't Rev developers want me to intercept the menu item Edit:Undo?
Please explain, oh Rev team. Why not give out a message when the Undo menu command has been called?
Any particular reason? Or is this a simple oversight which you now intend to address?
_______________________________________________________________
*Here's my undo routine, anyway.
That's a bit remiss, don't you think?
It seems I CAN intercept the undoKey *- which, surely, is always Cmd-Z (or Ctrl+Z on Windows);
and it seems I can even intercept a message (undoChanged) when the action to be undone updates to some new action.
So why wouldn't Rev developers want me to intercept the menu item Edit:Undo?
Please explain, oh Rev team. Why not give out a message when the Undo menu command has been called?
Any particular reason? Or is this a simple oversight which you now intend to address?
_______________________________________________________________
*Here's my undo routine, anyway.
Code: Select all
global FieldJustDeleted
on deleteKey
get the value of the selectedLine
cut field it of card 1 of stack "organiser 4"
send mouseup to button "List Fields" of card 1 of stack "organiser 4" -- updates the field list palette
end deleteKey
on UndoCmd -- (IF THE REV TEAM WOULD ONLY ALLOW IT)
if FieldJustDeleted is in the clipboardData["objects"] then
if the name of this stack is not "Organiser 4" then go to stack "Organiser 4"
paste
end if
send mouseup to button "List Fields" of card 1 of stack "organiser 4"
end UndoCmd
on undoKey -- NB THIS KEY ONLY CALLED WHEN NOT IN DEVELOPMENT ENVIRONMENT
undoCmd
end undoKey
on commandKeyDown theKey -- WITHIN DEVELOPMENT ENVIRONMENT, HOLD DOWN SHIFT KEY AND TYPE CMD-SHIFT-Z
if theKey is "Z" then
undoCmd
else pass commandKeyDown
end commandKeyDown
Last edited by Eric on Tue Jul 27, 2010 11:08 pm, edited 2 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Implementing an Undo routine
Testing here my card gets a commandKeyDown message when I type Cmd-Z in the Rev 4.0 IDE.Eric wrote:So why wouldn't Rev developers want me to intercept the menu item Edit:Undo?
Please explain, oh Rev team. Why not release a message when the Undo menu command is called?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Implementing an Undo routine
Hi Eric,
You have posted an interesting script, but I wouldn't want to use it because you mess around with the clipboard. Sometimes, I keep valuable data in the clipboard and I would be rather upset if the undo command deleted the data in the clipboard.
I understood that you wanted to undo the deletion of fields in the IDE. Everything related to undo is unreliable in the IDE. However, you're free to write a script to undo changes in a standalone and it should be possible to do this reliably in a standalone.
Best,
Mark
You have posted an interesting script, but I wouldn't want to use it because you mess around with the clipboard. Sometimes, I keep valuable data in the clipboard and I would be rather upset if the undo command deleted the data in the clipboard.
I understood that you wanted to undo the deletion of fields in the IDE. Everything related to undo is unreliable in the IDE. However, you're free to write a script to undo changes in a standalone and it should be possible to do this reliably in a standalone.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Implementing an Undo routine
Well, I peek at the clipboard data - but I don't "mess around" with it beyond that. By convention, when you paste from the clipboard, the clipboard data remains unchanged so you might even paste again (a second, third or fourth copy - even if the original instruction had only been to "cut").
But you're right. I posted hastily, without fully implementing my alternative to pasting when the clipboard data may already have changed.
In this version, if the name of the deleted field (global FieldJustDeleted) is not found in the clipboard objects list, then it doesn't paste but instead reverts to the last version saved. I believe reverting still leaves your clipboard data intact?
But you're right. I posted hastily, without fully implementing my alternative to pasting when the clipboard data may already have changed.
In this version, if the name of the deleted field (global FieldJustDeleted) is not found in the clipboard objects list, then it doesn't paste but instead reverts to the last version saved. I believe reverting still leaves your clipboard data intact?
Code: Select all
global FieldJustDeleted
on deleteKey
get the value of the selectedLine
put it into FieldJustDeleted
save stack "organiser 4"
cut field it of card 1 of stack "organiser 4"
send mouseup to button "List Fields" of card 1 of stack "organiser 4" -- updates the field list palette
end deleteKey
on UndoCmd -- (IF THE REV TEAM WOULD ONLY ALLOW IT)
if FieldJustDeleted is empty then pass UndoCmd
if the name of this stack is not "Organiser 4" then go to stack "Organiser 4"
if FieldJustDeleted is in the clipboardData["objects"] then
paste
else revert
put empty into FieldJustDeleted
send mouseup to button "List Fields" of card 1 of stack "organiser 4" -- updates the field list palette
end UndoCmd
on undoKey -- NB THIS KEY ONLY CALLED WHEN NOT IN DEVELOPMENT ENVIRONMENT
undoCmd
end undoKey
--on commandKeyDown theKey -- WITHIN DEVELOPMENT ENVIRONMENT, HOLD DOWN SHIFT KEY AND TYPE CMD-SHIFT-Z
-- if theKey is "Z" then
-- undoCmd
-- else pass commandKeyDown
--end commandKeyDown
Re: Implementing an Undo routine
By storing some info (properties) about the deleted field, you could later restore it with a new field using that info.
Best wishes,
Curry Kenworthy
LiveCode Development, Training & Consulting
http://livecodeconsulting.com/
WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/
Curry Kenworthy
LiveCode Development, Training & Consulting
http://livecodeconsulting.com/
WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/
Re: Implementing an Undo routine
Good idea.
But, however the routine were implemented, I would still prefer for it to be called when the user selects Edit:Undo from the menus.
Surely selecting any menu item ought to trigger a system message that one could intercept?
Alternatively, does anyone know how I could modify the Edit Menu and replace Undo with a custom command, say: "Edit:Undo Field Delete"?
But, however the routine were implemented, I would still prefer for it to be called when the user selects Edit:Undo from the menus.
Surely selecting any menu item ought to trigger a system message that one could intercept?
Alternatively, does anyone know how I could modify the Edit Menu and replace Undo with a custom command, say: "Edit:Undo Field Delete"?
Re: Implementing an Undo routine
You probably already know this, but just in case: You can make all your own menus for a stack/app and do whatever you want with them.
Or is your goal to modify the IDE?
Or is your goal to modify the IDE?
Best wishes,
Curry Kenworthy
LiveCode Development, Training & Consulting
http://livecodeconsulting.com/
WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/
Curry Kenworthy
LiveCode Development, Training & Consulting
http://livecodeconsulting.com/
WordLib: Conquer MS Word & OpenOffice
SpreadLib: "Excel-lent" spreadsheet import/export
http://livecodeaddons.com/