Undo when editing table cells
Undo when editing table cells
- Subject: Undo when editing table cells
- From: John Nairn <email@hidden>
- Date: Wed, 19 Nov 2003 09:30:23 -0700
In a window with a table having a single column of plain text, I
implemented undo when the user changes a row. In order to have the undo
or redo action correctly update the window, the basic process is
in tableView:setObjectValue:forTableColumn:row
call accessor to change text for that row in the model
the accessor to change the text does the following:
register undo action to call this accessor to change it back
set undo action name to "Row Change"
change the text
post notification that a row in the model has changed
the controller responds to the notification with [myTable
reloadData]
(needed otherwise undo/redo will not display the new values)
It all works fine unless I change the text of a row, begin editing
another row, and then select undo. Here I believe the sequence of
events is the undo manager calls my accessor which sets the name back
correctly, but then the notification reloads the table data. This
notification induces the new cell being edited to finish editing and
get committed (which registers its own undo action). Finally,
completion of the undo commands marks the document as clean even though
a row was changed as a consequence of undo. A redo changes the first
cell back to the edited form but it also changes the second cell back
to the original form. No number of undo's returns everything to the
original state - one is always original and the other is always
modified.
A better interface would be to have an undo command while typing in
another cell undo that typing instead of the last cell change, but undo
is not supported in NSTextField. Since this table has the only editing
fields in the window, I set the window's field editor to support undo,
but the problems got worse. Here is where it goes wrong
1. Edit a cell and tab to new cell. The undo command says "Undo Row
Change" and it works.
2. But, after undoing the row change (which changes the first row back
and terminates all table editing), the undo command changes to "Undo
Typing". I guess this corresponds the typing that was done before the
row was changed. Since that row is no longer being editing, selecting
undo causes as exception:
[NSBigMutableString _newSubstringWithRange:zone:]: Range or index
out of bounds
I figured I need to remove all undo actions for the field editor. I
tried (in the notification that reloads the table data which happens
whenever row change is committed or undone/redone)
[[myDocument undoManager]
removeAllActionsWithTarget:myWindowsFieldEditor]
but the "Undo Typing" command remained and still caused the exception.
Shouldn't the field editor be the target of the undo for typing changes?
------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page:
http://www.eng.utah.edu/~nairn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.