undo and redo ?

B

black

I'm coding with Tkinter and i wonder whether we could get current OS' clipboard available, and event more, anyone can inspires me how we can achieve undo and redo function ?

thanx~
 
D

Diez B. Roggisch

I'm coding with Tkinter and i wonder whether we could get current OS'
clipboard available, and event more, anyone can inspires me how we can
achieve undo and redo function ?

When working with a MVC-approach, the actions you the user can invoke on the
model could be created as objects that know how to undo/invert their
effects. Then you store a list of these actions and performing undo takes
the last action and apply its inverted action to your model. Right from my
head:

class InsertAction:
def __init__(_, index, needle):
_.index = index
_.needle = needle

def do(_, haystack):
haystack[index:index] = _.needle

def undo(_, haystack):
del haystack[_.index : _.index + len(_.needle)]


Hope this gives you an idea. You can also have to types of actions -
primitive and complex. Performing undo will then undo all primitve actions
until the action queue is empty or a complex actions is reached. This
allows e.g. in a text-editor to perform undo subsequently inserted
characters at once.

HTH,

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top