nswindow

How to put SwiftUI button into NSToolbar?

为君一笑 提交于 2020-05-13 03:46:41
问题 This is how SwiftUI can be inserted into NSToolbar using an accessory view controller: import SwiftUI import PlaygroundSupport var hostingView = NSHostingView(rootView: ZStack { Color.clear HStack { Text("Hey") Text("SwiftUI") } } .padding() .edgesIgnoringSafeArea(.all) ) hostingView.frame.size = hostingView.fittingSize let titlebarAccessory = NSTitlebarAccessoryViewController() titlebarAccessory.view = hostingView titlebarAccessory.layoutAttribute = .trailing let mask: NSWindow.StyleMask = [

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

你。 提交于 2020-02-02 11:09:12
问题 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

Inject keyboard event into NSRunningApplication immediately after foregrounding it

天大地大妈咪最大 提交于 2020-01-30 10:50:46
问题 I am trying to bring to foreground a NSRunningApplication* instance, and inject a keyboard event. NSRunningApplication* app = ...; [app activateWithOptions: 0]; inject_keystrokes(); ... fails to inject keyboard events, but: NSRunningApplication* app = ...; [app activateWithOptions: 0]; dispatch_time_t _100ms = dispatch_time( DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC) ); dispatch_after( _100ms, dispatch_get_main_queue(), ^{ inject_keystrokes(); } ); ... succeeds. I imagine it takes a

Inject keyboard event into NSRunningApplication immediately after foregrounding it

≯℡__Kan透↙ 提交于 2020-01-30 10:48:06
问题 I am trying to bring to foreground a NSRunningApplication* instance, and inject a keyboard event. NSRunningApplication* app = ...; [app activateWithOptions: 0]; inject_keystrokes(); ... fails to inject keyboard events, but: NSRunningApplication* app = ...; [app activateWithOptions: 0]; dispatch_time_t _100ms = dispatch_time( DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC) ); dispatch_after( _100ms, dispatch_get_main_queue(), ^{ inject_keystrokes(); } ); ... succeeds. I imagine it takes a

How to access items in the main nib from a document nib?

允我心安 提交于 2020-01-17 03:46:10
问题 I'm making an NSDocument-based application in which I have an inspector window. This inspector window is part of Pwnshop.nib which is my main nib. I have another nib called 'Document.nib,' which is the document window. I want to be able to change the inspector based on which document window is the active one, sorta like Interface Builder's inspector. The problem is that I want to access an object in another nib . Note that there are multiple document windows, but only one inspector window.

Open NSWindowController from NSMenu

微笑、不失礼 提交于 2020-01-13 11:52:37
问题 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? 回答1:

Open NSWindowController from NSMenu

∥☆過路亽.° 提交于 2020-01-13 11:52:14
问题 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? 回答1:

Round corners on a borderless NSWindow

大城市里の小女人 提交于 2020-01-13 03:41:51
问题 I'm creating an application and I don't want a title bar: If the title remains the same all the time, does it make sense to show it? For example, if an app doesn’t show the names of documents, or any other assets that it opens, and there is plenty of space at the top around other controls to grab onto if you want to move the window around, does the title serve much purpose? The problem is: how do I do this? I tried using [mainWindow setStyleMask:NSBorderlessWindowMask]; but I can't make it