home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Book HomeMastering Perl/TkSearch this book

8.20. The TextUndo Widget

The TextUndo widget is derived from the Text widget, which simply means that it shares all the capabilities of its ancestor. In object-oriented terminology, we say that TextUndo is a subclass of Text (or, Text is a superclass of TextUndo). You'll learn more about this subject in Chapter 14, "Creating Custom Widgets in Pure Perl/Tk".

Of course, we expect TextUndo to do something different from Text, and it does: it has unlimited undos and redos so that previous editing operations can be rescinded or redone.

Here are the TextUndo methods above and beyond those available for a Text widget:

Displays a messageBox that says "Save edits?". Returns 0 if yes or cancel, 1 if no.

Displays a messageBox that says "Save edits?." The widget is cleared if the reply is no.

Destroys the widget if you answer yes.

Creates a popup file browser to select a filename.

Deletes string from the start of every selected line.

Deletes all text and undo/redo information; undef s the filename.

Optionally updates the current filename to pathName. Returns the current filename.

Similar to Load, except it does not call EmptyDocument first.

Inserts string at the start of every selected line.

Loads the contents of pathName into the widget.

Returns the number of current undo operations.

Redoes the previous operation.

Deletes all undo and redo information.

Saves the contents of the widget to a file. If pathName is not specified, the filename from the last Load call is used. If no file was previously loaded an error message pops up. The default filename of the last Load call is not overwriten by pathName.

Returns the number of current redo operations.

Undoes the previous operation.

8.20.1. TextUndo Virtual Events

The TextUndo widget supports two virtual events, <<Undo>> and <<Redo>>, which invoke the undo and redo methods, respectively. The key sequence Control-Z is bound to <<Undo>>, and Control-Y is bound to <<Redo>>.

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.