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 "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:
- $
textundo->ConfirmDiscard - Displays a messageBox that says "Save edits?". Returns 0 if
yesorcancel, 1 ifno. $textundo->ConfirmEmptyDocument- Displays a messageBox that says "Save edits?." The widget is cleared if the reply is
no. $textundo->ConfirmExit- Destroys the widget if you answer
yes. $textundo->CreateFileSelect- Creates a popup file browser to select a filename.
$textundo->deleteStringAtStartOfSelectedLines(string)- Deletes
from the start of every selected line.string $textundo>->EmptyDocument- Deletes all text and undo/redo information;
undefs the filename. $textundo->FileName(?pathName?)- Optionally updates the current filename to
. Returns the current filename.pathName $textundo->IncludeFile- Similar to
Load, except it does not callEmptyDocumentfirst. $textundo->insertStringAtStartOfSelectedLines(string)- Inserts
at the start of every selected line.string $textundo->Load(pathName)- Loads the contents of
into the widget.pathName $textundo->numberChanges- Returns the number of current undo operations.
$textundo->redo- Redoes the previous operation.
$textundo->ResetUndo- Deletes all undo and redo information.
$textundo->Save(?pathName?)- Saves the contents of the widget to a file. If
is not specified, the filename from the lastpathNameLoadcall is used. If no file was previously loaded an error message pops up. The default filename of the lastLoadcall is not overwriten by.pathName $textundo->SizeRedo- Returns the number of current redo operations.
$textundo->undo- Undoes the previous operation.
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>>.