Re: Implementing UNDO

2021-05-22 Thread Klaus major-k via use-livecode
Hi Trevor,

> Am 22.05.2021 um 18:49 schrieb Trevor DeVore via use-livecode 
> :
> ...
> Here is a link to the code:
> 
> https://github.com/trevordevore/levure/tree/develop/framework/helpers/undo_manager
> This should be easy enough to add to any app. I just checked the code and
> there are no calls to any functions or commands in the Levure framework
> itself. If you look at the helper.yml file you see this:
> ```
> libraries:
>  - filename: undoManager.livecodescript
> frontscripts:
>  - filename: field_edits_undo.livecodescript
>autoload: false
> ```
> What that means is that you should `start using stack
> "undoManager.livecodescript"` when your app starts up and `put there is a
> stack "field_edits_undo.livecodescript" into tStackIsNoInMemory`. (Note
> that it is left as an exercise to the reader to determine the full path to
> those stacks when being used in your app.) The
> `field_edits_undo.livecodescript` stack just needs to be in memory so that
> `undoManager.livecodescript` can insert it into the front whenever the user
> is editing text in a field.
> 
> -- 
> Trevor DeVore

thanks for the hints, much appreciated!


Best

Klaus
--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-22 Thread Trevor DeVore via use-livecode
On Fri, May 21, 2021 at 3:11 PM Mike Kerner via use-livecode <
use-livecode@lists.runrev.com> wrote:

> fyi, for posterity, here is the link to the wiki for levure's undo manager
> helper
> https://github.com/trevordevore/levure/wiki/helper-undo_manager


Here is a link to the code:

https://github.com/trevordevore/levure/tree/develop/framework/helpers/undo_manager

This should be easy enough to add to any app. I just checked the code and
there are no calls to any functions or commands in the Levure framework
itself. If you look at the helper.yml file you see this:

```
libraries:
  - filename: undoManager.livecodescript
frontscripts:
  - filename: field_edits_undo.livecodescript
autoload: false
```

What that means is that you should `start using stack
"undoManager.livecodescript"` when your app starts up and `put there is a
stack "field_edits_undo.livecodescript" into tStackIsNoInMemory`. (Note
that it is left as an exercise to the reader to determine the full path to
those stacks when being used in your app.) The
`field_edits_undo.livecodescript` stack just needs to be in memory so that
`undoManager.livecodescript` can insert it into the front whenever the user
is editing text in a field.

-- 
Trevor DeVore
ScreenSteps
www.screensteps.com
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Mike Kerner via use-livecode
fyi, for posterity, here is the link to the wiki for levure's undo manager
helper
https://github.com/trevordevore/levure/wiki/helper-undo_manager

On Fri, May 21, 2021 at 2:34 PM David Epstein via use-livecode <
use-livecode@lists.runrev.com> wrote:

> LC’s built in undo does not appear to undo anything done by something I
> have scripted.
> My approach is to use a global array variable “u” to store information
> needed to undo the most recent action.  On each action, an “undoInit” puts
> empty into u, after (if necessary) cleaning up anything u’s values indicate
> is left over from the prior action (e.g., actually deleting an object that
> had been only “pseudo-deleted” (hidden) so as to make the user’s choice of
> deletion undoable).  Then the appropriate new values are loaded into u.
> The main elements I use are
>
> # u["cardID"] = short id of the card where the undoable action was taken
> # u["stackName"] = short name of the stack where the undoable action was
> taken
> # u["changed"], list of objects being changed, each line has:
> propName,objectID
> # u[propName,objectID] holds prior value of that property of that object
> (one key/value for each line of u["changed"]
> # u["removed"], list of objectID,cardID,stackName for objects being
> pseudo-removed
> # u["added"], list of objectID,cardID,stackName for objects being added
> # u["cardsRemoved"], list of cards being pseudo-removed, each line has:
> cardID,cardNumber
> # u["cardsAdded"], list of cards being added, each line has:
> cardID,cardNumber
>
> The “Undo” command makes sure we’re on card id u[“cardID”] of stack
> u[“stackName”}, then checks for non-empty values of
> u[“changed”],u[“removed”],u[“added”],u{“cardsRemoved”], and
> u[“cardsAdded”], and uses values stored in u to restore the prior state of
> things, while reloading u with values reporting the state of things now
> being reversed.
>
> For text, I load u[“changed”] with “htmlText”,, and load
> u[“htmlText”,] with the htmlText of that field before the latest
> editing.
>
> David Epstein
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread David Epstein via use-livecode
LC’s built in undo does not appear to undo anything done by something I have 
scripted.
My approach is to use a global array variable “u” to store information needed 
to undo the most recent action.  On each action, an “undoInit” puts empty into 
u, after (if necessary) cleaning up anything u’s values indicate is left over 
from the prior action (e.g., actually deleting an object that had been only 
“pseudo-deleted” (hidden) so as to make the user’s choice of deletion 
undoable).  Then the appropriate new values are loaded into u.  The main 
elements I use are

# u["cardID"] = short id of the card where the undoable action was taken
# u["stackName"] = short name of the stack where the undoable action was taken
# u["changed"], list of objects being changed, each line has:  propName,objectID
# u[propName,objectID] holds prior value of that property of that object (one 
key/value for each line of u["changed"]
# u["removed"], list of objectID,cardID,stackName for objects being 
pseudo-removed
# u["added"], list of objectID,cardID,stackName for objects being added
# u["cardsRemoved"], list of cards being pseudo-removed, each line has:  
cardID,cardNumber
# u["cardsAdded"], list of cards being added, each line has:  cardID,cardNumber

The “Undo” command makes sure we’re on card id u[“cardID”] of stack 
u[“stackName”}, then checks for non-empty values of 
u[“changed”],u[“removed”],u[“added”],u{“cardsRemoved”], and u[“cardsAdded”], 
and uses values stored in u to restore the prior state of things, while 
reloading u with values reporting the state of things now being reversed.

For text, I load u[“changed”] with “htmlText”,, and load 
u[“htmlText”,] with the htmlText of that field before the latest 
editing.

David Epstein
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Klaus major-k via use-livecode
Hi Jaqueline,

> Am 21.05.2021 um 17:32 schrieb J. Landman Gay via use-livecode 
> :
> 
> If you only need a simple, single-level undo you can use the built-in LC  
> "undo" command. The limitation is that you can't undo/redo repeatedly through 
> more than the last action.

oh, yes, thanks for the reminder!
However it is not yet clear how many levels of UNDO my customer wants to be 
implemented.

> --
> Jacqueline Landman Gay | jac...@hyperactivesw.com
>> Hi friends,
>> 
>> any hints on how to implement some UNDO mechanism into a LC standalone?
>> The stack(s) in question will not only handle TEXT.
>> Thanks for any insight!

Best

Klaus

--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread J. Landman Gay via use-livecode
If you only need a simple, single-level undo you can use the built-in LC  
"undo" command. The limitation is that you can't undo/redo repeatedly 
through more than the last action.


--
Jacqueline Landman Gay | jac...@hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
On May 21, 2021 6:50:43 AM Klaus major-k via use-livecode 
 wrote:



Hi friends,

any hints on how to implement some UNDO mechanism into a LC standalone?
The stack(s) in question will not only handle TEXT.

Thanks for any insight!


Best

Klaus

--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-livecode





___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Klaus major-k via use-livecode
Hi Paul and all,

> Am 21.05.2021 um 17:05 schrieb Paul Dupuis via use-livecode 
> :
> 
> As other have said, the basic mechanism is to have a UNDO LIFO (last in first 
> out) queue or stack (no LC stack for a data structure stack). For each action 
> you want 'undoable" you need a handler (do[action] ) to perform that action 
> that also adds a record (a line) to the queue (a property, global variable, 
> or script variable) that puts enough information in that record to undo the 
> action. You then you have a corresponding undo[action] handler that can take 
> the record from the queue and reverse the action.
> 
> So records on the queue might look like:
> changeFont -- which can be undone by setting the 
>  to 
> resizeImage  
> etc.
> 
> The first item tells you action was done and the subsequent items provide 
> enough information to undo (or do again or redo) the action.

thank you very much for all the hints and examples!
Great inspiration and very encouraging. :-)


Best

Klaus

--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Paul Dupuis via use-livecode
As other have said, the basic mechanism is to have a UNDO LIFO (last in 
first out) queue or stack (no LC stack for a data structure stack). For 
each action you want 'undoable" you need a handler (do[action] ) to 
perform that action that also adds a record (a line) to the queue (a 
property, global variable, or script variable) that puts enough 
information in that record to undo the action. You then you have a 
corresponding undo[action] handler that can take the record from the 
queue and reverse the action.


So records on the queue might look like:

changeFont     -- which can be undone by 
setting the  to 

resizeImage  
etc.

The first item tells you action was done and the subsequent items 
provide enough information to undo (or do again or redo) the action.



On 5/21/2021 10:52 AM, Klaus major-k via use-livecode wrote:

Hi Mark,


Am 21.05.2021 um 16:42 schrieb Mark Wieder via use-livecode 
:
On 5/21/21 6:19 AM, Klaus major-k via use-livecode wrote:

OK, something like this, but for graphics, images etc., too. 8-)
Some general hints will be OK.
Except for TEXT I don't have a clue yet.
Maybe store "the properties of xyz" and re-apply them when the user hits CMD-Z?

I've got an undo library on livecodeshare. It's designed to handle text, but 
the filo stack mechanism would probably work if you store something other than 
text as blobs. Untested, but maybe. My guess is this would use up memory 
rapidly.
...and from experience, don't try to compress/decompress arrays.

thank you, will download and check the stack.


--
Mark Wieder
ahsoftw...@gmail.com

Best

Klaus

--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Klaus major-k via use-livecode
Hi Mark,

> Am 21.05.2021 um 16:42 schrieb Mark Wieder via use-livecode 
> :
> On 5/21/21 6:19 AM, Klaus major-k via use-livecode wrote:
>> OK, something like this, but for graphics, images etc., too. 8-)
>> Some general hints will be OK.
>> Except for TEXT I don't have a clue yet.
>> Maybe store "the properties of xyz" and re-apply them when the user hits 
>> CMD-Z?
> I've got an undo library on livecodeshare. It's designed to handle text, but 
> the filo stack mechanism would probably work if you store something other 
> than text as blobs. Untested, but maybe. My guess is this would use up memory 
> rapidly.
> ...and from experience, don't try to compress/decompress arrays.

thank you, will download and check the stack.

> -- 
> Mark Wieder
> ahsoftw...@gmail.com

Best

Klaus

--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Mark Wieder via use-livecode

On 5/21/21 6:19 AM, Klaus major-k via use-livecode wrote:


OK, something like this, but for graphics, images etc., too. 8-)
Some general hints will be OK.

Except for TEXT I don't have a clue yet.
Maybe store "the properties of xyz" and re-apply them when the user hits CMD-Z?


I've got an undo library on livecodeshare. It's designed to handle text, 
but the filo stack mechanism would probably work if you store something 
other than text as blobs. Untested, but maybe. My guess is this would 
use up memory rapidly.


...and from experience, don't try to compress/decompress arrays.

--
 Mark Wieder
 ahsoftw...@gmail.com

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Klaus major-k via use-livecode
Hi Brian,

> Am 21.05.2021 um 16:25 schrieb Brian Milby via use-livecode 
> :
> 
> For text, the method will depend on the size of the text.  In general, 
> implement an undo stack and a redo stack.  For single line fields it could 
> simply be a list for each.  After each change, add entry to undo list and 
> clear redo list.  When doing undo, move entries to redo list allowing 
> forward/backward movement between changes.
> 
> For longer text, an array based stack could be used.  Either store the full 
> text or use the diff library - method will depend on size of text.

thank you, very helpful!


Best

Klaus
--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Brian Milby via use-livecode
For text, the method will depend on the size of the text.  In general, 
implement an undo stack and a redo stack.  For single line fields it could 
simply be a list for each.  After each change, add entry to undo list and clear 
redo list.  When doing undo, move entries to redo list allowing 
forward/backward movement between changes.

For longer text, an array based stack could be used.  Either store the full 
text or use the diff library - method will depend on size of text.

Sent from my iPhone

> On May 21, 2021, at 9:28 AM, Klaus major-k via use-livecode 
>  wrote:
> 
> Hi Mike,
> 
>> Am 21.05.2021 um 15:23 schrieb Mike Kerner via use-livecode 
>> :
>> 
>> I _think_ that there might also be an undo manager built into levure, if
>> you are interested.
> 
> oh, OK, sounds great, will take a look!
> Thank you!
> 
> 
> Best
> 
> Klaus
> --
> Klaus Major
> https://www.major-k.de
> https://www.major-k.de/bass
> kl...@major-k.de
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Klaus major-k via use-livecode
Hi Mike,

> Am 21.05.2021 um 15:23 schrieb Mike Kerner via use-livecode 
> :
> 
> I _think_ that there might also be an undo manager built into levure, if
> you are interested.

oh, OK, sounds great, will take a look!
Thank you!


Best

Klaus
--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Mike Kerner via use-livecode
I _think_ that there might also be an undo manager built into levure, if
you are interested.

On Fri, May 21, 2021 at 9:20 AM Klaus major-k via use-livecode <
use-livecode@lists.runrev.com> wrote:

> Hi Craig,
>
> > Am 21.05.2021 um 15:12 schrieb Craig Newman via use-livecode <
> use-livecode@lists.runrev.com>:
> >
> > Klaus.
> >
> > What are you doing here on the dark side??
>
> Oh, come on!
>
> > Do you mean something like this, with a field and a button?  in the card
> script:
> >
> > on textChanged
> > set the currentText of this cd to fld 1
> > end textChanged
> >
> > on undoText
> > get the currentText of this cd
> > delete the last word of it
> > set the text of fld 1 to it
> > set the currentText of this cd to it
> > end undoText
> >
> > and in the button:
> > on mouseUp
> >  undoText
> > end mouseUp
>
> OK, something like this, but for graphics, images etc., too. 8-)
> Some general hints will be OK.
>
> Except for TEXT I don't have a clue yet.
> Maybe store "the properties of xyz" and re-apply them when the user hits
> CMD-Z?
>
> > Craig
> >
> >> On May 21, 2021, at 7:48 AM, Klaus major-k via use-livecode <
> use-livecode@lists.runrev.com> wrote:
> >>
> >> Hi friends,
> >>
> >> any hints on how to implement some UNDO mechanism into a LC standalone?
> >> The stack(s) in question will not only handle TEXT...
>
> Best
>
> Klaus
>
> --
> Klaus Major
> https://www.major-k.de
> https://www.major-k.de/bass
> kl...@major-k.de
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Klaus major-k via use-livecode
Hi Craig,

> Am 21.05.2021 um 15:12 schrieb Craig Newman via use-livecode 
> :
> 
> Klaus.
> 
> What are you doing here on the dark side??

Oh, come on!

> Do you mean something like this, with a field and a button?  in the card 
> script:
> 
> on textChanged
> set the currentText of this cd to fld 1
> end textChanged
> 
> on undoText
> get the currentText of this cd
> delete the last word of it
> set the text of fld 1 to it
> set the currentText of this cd to it
> end undoText
> 
> and in the button:
> on mouseUp
>  undoText
> end mouseUp

OK, something like this, but for graphics, images etc., too. 8-)
Some general hints will be OK. 

Except for TEXT I don't have a clue yet.
Maybe store "the properties of xyz" and re-apply them when the user hits CMD-Z?

> Craig
> 
>> On May 21, 2021, at 7:48 AM, Klaus major-k via use-livecode 
>>  wrote:
>> 
>> Hi friends,
>> 
>> any hints on how to implement some UNDO mechanism into a LC standalone? 
>> The stack(s) in question will not only handle TEXT...

Best

Klaus

--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: Implementing UNDO

2021-05-21 Thread Craig Newman via use-livecode
Klaus.

What are you doing here on the dark side??

Do you mean something like this, with a field and a button?  in the card script:

on textChanged

set the currentText of this cd to fld 1

end textChanged


on undoText

get the currentText of this cd

delete the last word of it

set the text of fld 1 to it

set the currentText of this cd to it

end undoText


and in the button:
on mouseUp
  undoText
end mouseUp

Craig

> On May 21, 2021, at 7:48 AM, Klaus major-k via use-livecode 
>  wrote:
> 
> Hi friends,
> 
> any hints on how to implement some UNDO mechanism into a LC standalone? 
> The stack(s) in question will not only handle TEXT.
> 
> Thanks for any insight!
> 
> 
> Best
> 
> Klaus
> 
> --
> Klaus Major
> https://www.major-k.de
> https://www.major-k.de/bass
> kl...@major-k.de
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Implementing UNDO

2021-05-21 Thread Klaus major-k via use-livecode
Hi friends,

any hints on how to implement some UNDO mechanism into a LC standalone? 
The stack(s) in question will not only handle TEXT.

Thanks for any insight!


Best

Klaus

--
Klaus Major
https://www.major-k.de
https://www.major-k.de/bass
kl...@major-k.de


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode