質問

In Mavericks there is a new emoticon menu by pressing ctrl+cmd+space. I want to add a small button beside a textfield that opens this menu and send the emoticon to the textfield.

I thought about sending a keystroke event, but this could change. Is there any other way ? Thank you.

役に立ちましたか?

解決

Does orderFrontCharacterPalette: work for you?

[NSApp orderFrontCharacterPalette:nil];

It's been around for a while (10.3), but the meaning of ordering the palette to the front might have changed in 10.9.

In case it's interesting, I found the method by inserting a dummy subclass of NSTextView:

@interface LoggingTextView : NSTextView
@end

It logs the respondsToSelector: calls it receives:

- (BOOL)respondsToSelector:(SEL)aSelector
{
    NSLog(@"selector: %@", NSStringFromSelector(aSelector));
    return [super respondsToSelector:aSelector];
}

In IB/the XIB I configured the text view to use this subclass. Then I ran the app and pressed Cmd-Ctrl-Space and checked for interesting selector names. You could probably also do it with an auto-continue breakpoint command in LLDB.

If you do this, make sure that whatever comes up is published API and not some internal method that could change at any moment.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top