• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Undoable controls
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Undoable controls


  • Subject: Re: Undoable controls
  • From: Frode <email@hidden>
  • Date: Thu, 8 Sep 2005 19:56:49 +0200


2005-09-08 kl. 10.11 skrev Sherm Pendley:


My software needs undoable controls for NSControls, in particular for textfields (NSTextField, not NSTextView!) and checkboxes (NSButton).

That's not the usual way of thinking about it. Normally, undo is thought of as applying to your application's data - that is, the Model layer objects in an MVC design. The controls you're speaking of - the View layer - reflect the state of the data, and update themselves accordingly when they're notified of data changes.

Yes, I somewhat agree with you but my document data include true/false-values that is represented by checkboxes. And I found no way of implementing the undo mechanism in the model-layer when data is represented as NSButtons. (Read pragraph below.) Now, I can discard undo-mechanism for them, but that I think this is even worser. :-) [Until now, I didn't know I can get the NSTextView of current NSTextField from NSWindow. I will look into this later. Thanks very much for the hint!]


For NSButtons, I have searched for a "-(void)buttonClickNotification:(NSNotification*)" (or controlClickNotification) that is called when the NSButton is clicked, but it seems to be missing. If it had existed, I could take control over default control click behaviour and set the value in "model layer", which would set the value in the "view layer". But I found no way of doing so, and the change must be tracked in the "view layer". Isn't I correct?

For a generetic undoable NSControl, I need the following methods
1. a -(void)controlClickNotification:(NSNotification *)-notifier for NSControls. Is there a such notification?
2. a -(NSButtonType)buttonType-accessor. Then all NSButton could have a common undo-selector, where the so-called undoer changes button state, data or text depeding on type. Is there such NSButton accessor?
Are there other methods that provides me the same functionality?


I will not show my primitive undo-implementation of text-fields, since I will consider changing it to use its NSTextView's undoer. :-)

However, for the the undoable checkbox-button: the NSButton's action is connected to document's toggleCheckbox:-receiver, which I wrote as
@implementation MyDocument
- (void)toggleCheckbox:(NSButton *)sender {
NSUndoManager *um = [self undoManager];
if ([um isRedoing] || [um isUndoing])
[sender setState:([sender state] == NSOffState ? NSOnState : NSOffState)];
// change if invoced from undoer, but not if invoced from action


[um registerUndoWithTarget:self selector:@selector(toggleRadio:) object:sender];
[um setActionName:NSLocalizedString(@"Change", @"Message indicating what undo")];
// register (or reregister) undoer
}
@end


Does this code look reasonable to you ? :-)

Anyway, thanks for the big help so long.

Sincerely,
Roger
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Undoable controls (From: Frode <email@hidden>)
 >Re: Undoable controls (From: Sherm Pendley <email@hidden>)

  • Prev by Date: [SOLVED] Trouble with FSMountServerVolumeSync
  • Next by Date: Icons in menus
  • Previous by thread: Re: Undoable controls
  • Next by thread: Re: Undoable controls
  • Index(es):
    • Date
    • Thread