nswindowcontroller

MVC in a Cocoa document-based application

老子叫甜甜 提交于 2019-12-07 13:01:05
问题 I'm going through a refactoring and reorganization of my application at the moment. I've realized that some of the separation between models and views, and their controllers has diminished and I wish to do some cleaning up. I have several key classes used in my app: NSPersistentDocument, NSWindowController, and a model class. The NSPersistentDocument class acts as a "model-controller"; it owns an instance of the model class, and manages all interactions with the model. The NSWindowController

Handle close event of the window in Swift

萝らか妹 提交于 2019-12-07 03:10:07
问题 How to handle close event of the window using swift, for example, to ask "Are you sure you want to close the form?" The form will be closed in the case "yes" and not closed in the case "no". Showing message box is not a problem for me. viewWillDisappear() works for minimizing also, but I need only close event. Thanks. 回答1: Like said above, you should make the ViewController an NSWindowDelegate , but you should handle windowWillClose , not windowShouldClose . windowShouldClose is to determine

How can I set the title of non-main-windows in an NSDocument application?

核能气质少年 提交于 2019-12-06 11:50:09
I am working on a document-based OSX application, with master-detail style windows. I understand how to open additional windows, to display additional information, by using -makeWindowControllers and adding extra window controllers, but I can't set the title of the new windows. I have tried using -setTitle and -windowTitleForDocumentDisplayName in both Document.m and in my sub-classed window controller class, but I can't get the window title to change. How do I change the title of non-main-windows, which have a sub-classed window controller, in an NSDocument based application? EDIT: I know

Why do I have to call showWindow on my NSWindowController twice on 10.5?

情到浓时终转凉″ 提交于 2019-12-06 07:28:27
问题 I've got a subclass of an NSWindowController that I'm using to load a window from a nib and show it on the screen. Below is the code that is called when I want to show the window. On 10.6 when showCustomWindow is called the window is displayed, but on 10.5 this method has to be called twice to get the window to display. -(IBAction)showCustomWindow:(id)sender { if(!windowController){ windowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindow"]; } [windowController

How to give focus to NSWindow loaded from NIB?

我怕爱的太早我们不能终老 提交于 2019-12-06 05:44:34
问题 I'm using NSWindowController to load a window from a NIB. However, when I call showWindow: , the window is visually topmost, but the focus remains where it was (instead of moving it to the new window). It's easy to see this happening when the first window (with keyboard focus) is moved slightly, before creating the new window (via cmd+n). This is the result: The bottom, focused window is the original window. The unfocused window on top is the newly created window. This is the relevant code:

How to detect that my window is being closed using the red window button?

▼魔方 西西 提交于 2019-12-06 02:32:40
问题 I have a dialog window that can be cancelled through a custom Cancel button or using the system red window button. I need to perform some simple logic when the dialog is cancelled. How do I detect that the user has pressed the red button? I know I can detect the window being closed using the -windowWillClose: delegate callback. But this callback is also called when I close the window programmatically after the dialog succeeds. I also know I could simply set up a BOOL flag, but is there a

MVC in a Cocoa document-based application

萝らか妹 提交于 2019-12-05 19:23:41
I'm going through a refactoring and reorganization of my application at the moment. I've realized that some of the separation between models and views, and their controllers has diminished and I wish to do some cleaning up. I have several key classes used in my app: NSPersistentDocument, NSWindowController, and a model class. The NSPersistentDocument class acts as a "model-controller"; it owns an instance of the model class, and manages all interactions with the model. The NSWindowController class acts as a "view-controller"; it owns the main window, and manages interactions of the views

Open NSWindowController from NSMenu

帅比萌擦擦* 提交于 2019-12-05 15:06:57
I'm with a NSMenu in an agent application (without the icon in the dock) . When a button from this menu is tapped, I want to show a generic NSWindowController. My menu button action: - (IBAction)menuButtonTapped:(id)sender { MyWindowController *myWindow = [[MyWindowController alloc] initWithWindowNibName:@"MyWindowController"]; [myWindow showWindow:nil]; [[myWindow window] makeMainWindow]; } But the window just "flashes" in the screen (it shows and disappears really fast). Any solution? The reason the window is showing up for a split second and then disappearing has to do with ARC and how you

Handle close event of the window in Swift

白昼怎懂夜的黑 提交于 2019-12-05 06:03:16
How to handle close event of the window using swift, for example, to ask "Are you sure you want to close the form?" The form will be closed in the case "yes" and not closed in the case "no". Showing message box is not a problem for me. viewWillDisappear() works for minimizing also, but I need only close event. Thanks. Thomas Alvarez Like said above, you should make the ViewController an NSWindowDelegate , but you should handle windowWillClose , not windowShouldClose . windowShouldClose is to determine if the window is able to close or not, not an event that the window is actually closing. I

Cocoa document based app, NSWindowController subclass as “main window”

烂漫一生 提交于 2019-12-05 04:30:15
问题 I have a Cocoa document based app. I want the "main window" to be managed by my subclass of NSWindowController . I have created the subclass and laid out its interface in a .xib file with the same name. I ultimately want the same behaviour as if the NSDocument managed the window, but instead have it managed by an NSWindowController . First of all, how do I do it? Second, are the anything special I have to think about when going with this approach, such as how to handle open and save? 回答1: