appkit

How to make NSArrayController preservesSelection work for custom object?

无人久伴 提交于 2019-12-11 09:05:59
问题 I have a Cocoa app with a view-based table view bound to an NSArrayController with a list of custom Employee objects. The table view shows the list of employees. In a subview, the employee's details can be changed. Everything is set up, so that when an employee's details are changed, the table view contents are reloaded, showing the changes. So far, so good. Now NSArrayController has the ability to preserve the selected object across reloads via preservesSelection . For my custom Employee

Emoji List in NSPopover on macOS like Messages App

时光总嘲笑我的痴心妄想 提交于 2019-12-11 08:57:31
问题 I want to show an NSPopover in my Mac app that lists the emoji just like Apple's Messages app does like this: All I can figure out so far is that I can show the character palette in my app using this: NSApp.orderFrontCharacterPalette(nil) But that shows the palette as a separate window like this: Does anyone know how I can embed the character palette in an NSPopover and retrieve the selected emoji in my app (similar to how Apple does it in Messages)? 回答1: Set your textView, textField, or any

NSTextView cursor doesn't appear when typing text on macOS 10.14

南笙酒味 提交于 2019-12-11 07:57:08
问题 I'm observing a strange issue on macOS 10.12 Mojave with NSTextView. . I'm changing the textStorage attributes in didChangeText() like this : self.textStorage?.beginEditing() ARTokenManager.getToken(text: text, language: language) { (tokens) in // This line reset the attributes // If I remove it, the cursor appear properly // But the attributes are conserved self.textStorage?.setAttributes([NSAttributedString.Key.font: self.font!, NSAttributedString.Key.foregroundColor: self.defaultTextColor]

NSUndoManager custom coalescing changes to NSTextField results in crash

匆匆过客 提交于 2019-12-11 04:17:00
问题 I have a basic Cocoa app using NSUndoManager to support undo/redo. My data model's title can be updated by editing an NSTextField . Out of the box NSTextField supports coalescing changes into a single "Undo Typing" undo action so that when the user presses Cmd-Z, the text is reverted in full instead of only the last letter. I'd like to have a single "Undo Changing Model Title" undo action that undoes multiple changes to my model's title (made in a NSTextField). I tried grouping changes myself

Adding slide-down view in NSWindow

你说的曾经没有我的故事 提交于 2019-12-11 03:48:40
问题 How do I implement the view in following image. The view which appears when + button is clicked in System Preferences > Network I have following questions: Does this view system has a specific name (like popover), because I have seen it in many places in Mac. How to implement it in IB ? Can this be done in a popover window instead of NSWindow ?(or is it only possible in NSWindow like toolbar) 回答1: In Cocoa these are called sheets. Take a look at the sheet programming guide, however, this is

Why isn't application:openFile: called when the application is already running?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 02:59:43
问题 I would like to handle open events when a user double-clicks on a file that was created by my application, or drags such a file onto the dock icon. I've therefore implemented NSApplicationDelegate 's application:openFile: and application:openFiles: methods, which work as expected when the application is not running. However, if the application is already running when the open event occurs, the application becomes focused, but the above methods are never called (breakpoints inside them are not

NSApplication windows property - windows not removed?

浪子不回头ぞ 提交于 2019-12-11 02:39:21
问题 I have a NSWindow/Controller that I display modal. It has a "Close" button hooked up to an action like this: - (IBAction)close:(id)sender { [self.window orderOut:sender]; [self.window close]; [[NSApplication sharedApplication] stopModal]; } From my main window, I display the modal: - (IBAction)modal:(id)sender { NSLog(@"Before: %lu", [[[NSApplication sharedApplication] windows] count]); ModalWindowController *modal = [[ModalWindowController alloc] initWithWindowNibName:@"ModalWindowController

Using autolayout, how can I center a subview in an NSSplitView without forcing the width NSSplitView to be static?

大憨熊 提交于 2019-12-11 02:06:29
问题 I have an NSSplitView with content in both NSViews. The left NSView has 2 constraints – Equal Widths and Equal Heights . The right NSView has something simple, say an NSTextField, which is centered via constraints Center X Alignment and Center Y Alighment . This is what I hoped it would look like as I resize the window and/or the NSSplitView divider: This is what's happening: I've tried a great deal of configuration changes, I've tried using an NSSplitViewController vs just dropping an

Overriding NSSearchFieldCell causes placeholder not centered

99封情书 提交于 2019-12-11 01:58:53
问题 I'm doing some custom drawing in a NSSearchFieldCell subclass. However overriding any of its two drawing methods causes the placeholder text not aligned. For example, just by using this custom NSSearchFieldCell subclass that overrides NSCell 's drawing method would cause the placeholder text to be left-aligned. class CustomSearchFieldCell: NSSearchFieldCell { override func draw(withFrame cellFrame: NSRect, in controlView: NSView) { super.draw(withFrame: cellFrame, in: controlView) } override

How to get the range of characters that are visible from within -textStorageDidProcessEditing:?

孤街醉人 提交于 2019-12-11 01:58:42
问题 For my syntax highlighting implementation, I observe changes to an NSTextView using -[<NSTextStorageDelegate> textStorageDidProcessEditing:] . - (void)textStorageDidProcessEditing:(NSNotification *)notification { if (!self.languageGrammar) return; NSTextStorage *textStorage = self.textView.textStorage; NSRange glyphRange = [self.textView.layoutManager glyphRangeForBoundingRect:self.scrollView.documentVisibleRect inTextContainer:self.textView.textContainer]; NSRange editedRange = [self