osx - NSWindowController/NSDocument lifecycle (closing) -


i have 'standard' os x document based app using nswindowcontroller, nsdocument etc. has nstextview part of ui.

question have (and it's driving me nuts) how best trap 'close document' , tell nstexview finish edit.

finishing edit may result in model being updated (and possibly change count of document) need before other nsdocument logic decides whether save necessary.

thanks

your textview doesn't allow undo.

-(void)setallowsundo:(bool)value; 

you either disabled calling former method or unchecked in interface builder (for textview). without undo support in textview document isn't made dirty automatically (no updatechangecount made document doesn't know edited).

cleaner solution (without allowing undo):

to fix have register delegate , implement textdidchange: (nstextviewdelegate method) or register nstextdidchangenotification. within methods can update model and/or make document dirty/edited.

alternatively:

when there attempt close window/document catch 1 of event. , resign responder. nstextview loose focus , update it's backing value.

[window makefirstresponder:nil]; 

list of possible methods catch closing.

- (void)close;  //you have call [super close];  - (bool)windowshouldclose:(nswindow *)window; - (void)canclosedocumentwithdelegate:(id)delegate shouldcloseselector:(sel)shouldcloseselector contextinfo:(void *)contextinfo; 

nstextviewdelegate inherits nstextdelegate

@protocol nstextviewdelegate <nstextdelegate> @optional @end  @protocol nstextdelegate <nsobject> @optional - (bool)textshouldbeginediting:(nstext *)textobject;        // yes means - (bool)textshouldendediting:(nstext *)textobject;          // yes means - (void)textdidbeginediting:(nsnotification *)notification; - (void)textdidendediting:(nsnotification *)notification; - (void)textdidchange:(nsnotification *)notification;       // keydown or paste changes contents causes @end 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -