Undo/Text Field/Checkbox Issue
Undo/Text Field/Checkbox Issue
- Subject: Undo/Text Field/Checkbox Issue
- From: "Erik J. Barzeski" <email@hidden>
- Date: Sun, 25 May 2003 11:43:23 -0400
Hi,
I've researched this issue, tried about twenty different things, and asked a
number of pals. I've yet to find a "best" solution.
I'm working on a simple document-based app (well, it's simple right now). I
have both checkboxes and text fields. I have undo/redo working everywhere.
Each text field and checkbox is wired to to an action in the controller
("MyDocument"). The flow of control is as follows:
A) user types into text field, tabs or returns (to get the "set" action
called in the controller)
B) set action called in controller (with id sender as parameter). Method
does comparison with sender's stringValue or state and model to make sure
the text or checkbox state isn't the same (I don't want to undo 72 times if
the user presses return 72 times, and in the checkbox case it's simply a
matter of sanity and consistency).
C) if the string/state is not the same, it calls the "set" method in the
model, setting the model's NSString or state.
D) the model's set method registers an undo (as MVC documentation suggest it
should) using MyDocument's undo manager (the model isn't in the responder
chain of course) and posts an "update UI" notification. Nothing weird here:
the registered undo call uses the same set method with the existing value.
E) the "update UI" notification is received by the controller. It gets the
values in the model and sets the appropriate values and appearance in the
UI.
----------------
This works beautifully except in a case like this:
1) user types some text
2) without tabbing or pressing enter, user clicks a checkbox. (I imagine
other actions would cause these issues as well - switching tab views, an
external AppleScript changing a value somewhere, etc.)
----------------
None of the methods tried already (I'd list them, but there are quite a few)
have worked as expected. The various results include:
A) "undo" undoes both the text field and the checkbox in one action.
B) the first click sets the text, but doesn't change the value of the
checkbox, requiring a second click
C) the text is cleared, but undo on the checkbox works (this is the default
case)
D) the text field loses focus (ideally, it shouldn't).
----------------
I've got a test project if anyone wants to check it out:
http://iacas.org/asm/checktext.tgz
So, the question is simply this: what's the best way to proceed here? I want
to maintain the first responder status (if they have one). I want to
maintain an MVC model. I want to maintain unique undo for both the text
field and the checkboxes. What works?
--
Best wishes,
Erik J. Barzeski
Whoever dies with the most software, wins. :)
###################################################################
Email: erik@(anything below) AIM: iacas, email@hidden
http://nslog.com http://cocoadevcentral.com
http://barzeski.com/ http://freshlysqueezedsoftware.com
###################################################################
_______________________________________________
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.