Recent

Author Topic: Undo/redo  (Read 2454 times)

fmolina

  • New Member
  • *
  • Posts: 40
Undo/redo
« on: May 30, 2020, 05:22:34 pm »
Hi,
Is there any support for undo/redo operations? If not, is it planned?
Thanks

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: Undo/redo
« Reply #1 on: May 31, 2020, 07:54:08 pm »
No / not in the near future.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Undo/redo
« Reply #2 on: May 31, 2020, 08:24:47 pm »
@wp
It is already done a long time ago, but the documentation is cryptic: it does not explain it is about undo/redo.... Limitation is published only.
It is also Delphi compatible:
https://www.freepascal.org/docs-html/rtl/classes/trecall.html

E.g. the memo lines are published Tstrings and can use Trecall and actually to quite some depth...Or most of the db related icon properties.
« Last Edit: May 31, 2020, 08:29:44 pm by Thaddy »
Specialize a type, not a var.

tonse

  • Newbie
  • Posts: 6
Re: Undo/redo
« Reply #3 on: December 31, 2022, 07:12:32 pm »
Are there any examples of working with TRecall?
I have a small program where users need to be able to resize and reposition Panels . SO far so good.. I am just looking for a way to implement an undo/redo function

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Undo/redo
« Reply #4 on: December 31, 2022, 10:06:56 pm »
Well, then you will have to wait for next year... Happy New Year
« Last Edit: January 01, 2023, 01:14:24 pm by Thaddy »
Specialize a type, not a var.

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Undo/redo
« Reply #5 on: January 01, 2023, 06:19:31 am »
Its not hugely hard to implement yourself. Its just a case of working what are the changes you want to 'undo' and storing a representation of them on a circular buffer.

I made a undo/redo unit for KMemo, https://github.com/tomboy-notes/tomboy-ng/blob/master/source/tbundo.pas - its almost certainly no direct use to you unless you use KMemo but it  might give you a few ideas to follow up on. KMemo, being a text thingo, is text focused.

Sounds like you will want to record control positions, just a case of, perhaps, making a record that contains the name of a control, its position. Poke that record into the buffer each time someone moves moves things. On undo, Pop each record back out and restore the control to the position recorded in the popped record.

Obviously, some housekeeping is required, you need to manage the most recent and oldest record, decide when to throw away the oldest to make room for a new one. And probably implement some sort of delay before recording a new record to make sure the user has finished moving ...

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Undo/redo
« Reply #6 on: January 01, 2023, 10:26:15 am »
Dead giveaway:
It is a stack. (or basicallly a singly linked list)

If you can't write a stack you are not a programmer.( Yet 8) :D)

Happy new year!

p.s.  I propose you order https://www.amazon.com/Tomes-Delphi-Algorithms-Data-Structures-ebook/dp/B007FKB0EI although that may seem a blatant advert, it is not! all example code compiles with FreePascal.
There are many more links about algorithms and data structures. You will NEED that knowlege at some point.
Use a TStack<T>............
« Last Edit: January 01, 2023, 01:30:30 pm by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018