[ARA] (May 2 2009) '''Question''' OK I have a good one. I am working on the Undo function for a program that saves automatically and I am going from a disaster to another. Here is why. Undo does the reverse of the last function which is what it is supposed to do. So far so good. But what happens when the last function is the automatic save? Then it '''unsaves''' and it screws up the page, deleting all the contents. Wonderful. Great saving of space. Seriously, what do I do to avoid this situation? I might decide to take out the Undo button altogether since it is a constant source of headaches. Perhaps the best would be to create a file that would hold all the deleted text and would disappear when I exit. Any suggestions on how to do this? Finally I'd like to do a back-up of the current page in a directory called back-up that would be attached to the current directory and would make back-ups every 6 minutes on top of the regular automatic saving. I don't want to keep all back-ups simply the latest one. Any suggestions? I am sure even Microsoft must have bumped into the problem at one point despite the fact that all their text editors save on demand. If you hit '''Undo''' after a save in Word, Notepad or in Wordpad, I am sure it won't screw up the page. The key here is to have the program discriminate between a save function and a regular text add-on, edit or delete. If it is a save function, the undo won't work, if if it is a text function (add, edit or delete text) it will work. The problem is: '''how to make the program discriminate between a text edit and a function such as save?''' This is the key to the problem. Easier said than done. The pseudo-code for this will be: if the last moves have been other moves then edit, delete or type in new text, don't do anything; if the last moves have been to edit text, delete text or type in new text, do Undo. I am learning little by little so please consider that I am not an all-around expert on programming. Thanks a great deal for your help. ---- '''Answer''' [MG] I'm not quite sure how you're running into this problem. The text widget has a built-in undo/redo feature which is only triggered by the editing of text. The widget itself has no "save" function, and coding your own normally just involves doing $textWidget get 1.0 end-1char and dumping the result into a file, so I'm not sure how saving is triggering your undo code. Can you give some more info on what you're doing, or put the code up somewhere? [ARA] Thanks a lot for your help, [MG]. Here is the code: proc do.undo {} { if [$::current_ht edit modified ] { if [catch {$::current_ht edit undo}] { return } } } Please note that I am not using a text widget. Also in the create menu function I have this: -undo 1 \ -maxundo 10 [NEM] Which widget are you using? The [text] widget is the only core widget with an undo feature, IIRC. ----- !!!!!! %| [Category Discussion] | [Category Development] |% !!!!!!