On 08/11/2013 03:03 PM, Fred Kiefer wrote: > At the current state of gui breaking the ABI is fine, we do it with > almost every release. The only thing we should think about is whether we > want to make a 0.23.2 release of gui before that. > > I can see what you need the _completionHandler ivar for, but what is the > purpose of the _modelessWindowController? > > One other way to implement this would be to extend the sheet code in > NSApplication. At the moment sheets are just modal windows. > One simple way would be to implement a sheet delegate class that just > executes the completion block. In the long run, the other way around, > implementing sheet delegates with completion blocks will be more > elegant, but for now this could do. > > Fred
That is used to save a reference of an NSWindowController responsible for that modeless window until it's closed. See the attached patch. RELEASE()ing it here would close the window immediately, and not keeping the reference somewhere would leak it. If I'm missing something and it can be done differently, please let me know. -- Luboš Doležel
Index: Source/NSSavePanel.m =================================================================== --- Source/NSSavePanel.m (revision 36950) +++ Source/NSSavePanel.m (working copy) @@ -55,6 +55,7 @@ #import "AppKit/NSDragging.h" #import "AppKit/NSSavePanel.h" #import "AppKit/NSTextField.h" +#import "AppKit/NSWindowController.h" #import "AppKit/NSWorkspace.h" #import "GSGuiPrivate.h" @@ -1110,6 +1111,26 @@ return [self runModalForDirectory: [self directory] file: [self filename]]; } +- (void) beginSheetModalForWindow:(NSWindow *)window + completionHandler:(GSSavePanelCompletionHandler)handler +{ + NSInteger result = [NSApp runModalForWindow: self + relativeToWindow: window]; + CALL_BLOCK(handler, result); +} + +- (void) beginWithCompletionHandler:(GSSavePanelCompletionHandler)handler +{ + /* This destroys any previous modeless dialogs using this instance */ + AUTORELEASE(self->_modelessWindowController); + + self->_modelessWindowController = + [[NSWindowController alloc] initWithWindow: self]; + + self->_completionHandler = Block_copy(handler); + [self->_modelessWindowController showWindow: self]; +} + /**<p> Initializes the panel to the directory specified by path and, optionally, the file specified by filename, then displays it and begins its modal event loop; path and filename can be empty @@ -1218,7 +1239,18 @@ { ASSIGN(_directory, pathToColumn(_browser, [_browser lastColumn])); [self _updateDefaultDirectory]; - [NSApp stopModalWithCode: NSCancelButton]; + + if (self->_completionHandler == NULL) + [NSApp stopModalWithCode: NSCancelButton]; + else + { + CALL_BLOCK(self->_completionHandler, NSCancelButton); + Block_release(self->_completionHandler); + self->_completionHandler = NULL; + + RELEASE(self->_modelessWindowController); + } + [_okButton setEnabled: NO]; [self close]; } @@ -1389,7 +1421,18 @@ return; [self _updateDefaultDirectory]; - [NSApp stopModalWithCode: NSOKButton]; + + if (self->_completionHandler == NULL) + [NSApp stopModalWithCode: NSOKButton]; + else + { + CALL_BLOCK(self->_completionHandler, NSOKButton); + Block_release(self->_completionHandler); + self->_completionHandler = NULL; + + RELEASE(self->_modelessWindowController); + } + [_okButton setEnabled: NO]; [self close]; }
_______________________________________________ Gnustep-dev mailing list Gnustep-dev@gnu.org https://lists.gnu.org/mailman/listinfo/gnustep-dev