Check if Mac QSearchField has focus before handling the notification.

Otherwise, playlist's search field will always handle those shortcuts, and they won't work anywhere else on the same window.
Fixes #3320.
This commit is contained in:
Arnaud Bienner 2015-03-14 01:55:46 +01:00
parent fad0ccc8c6
commit fe7bc917de
1 changed files with 33 additions and 25 deletions

View File

@ -107,32 +107,40 @@ public:
@implementation QocoaSearchField @implementation QocoaSearchField
-(BOOL)performKeyEquivalent:(NSEvent*)event { -(BOOL)performKeyEquivalent:(NSEvent*)event {
if ([event type] == NSKeyDown && [event modifierFlags] & NSCommandKeyMask)
{ // First, check if we have the focus.
QString keyString = toQString([event characters]); // If no, it probably means this event isn't for us.
if (keyString == "a") // Cmd+a NSResponder* firstResponder = [[NSApp keyWindow] firstResponder];
if ([firstResponder isKindOfClass:[NSText class]] &&
[(NSText*)firstResponder delegate] == self) {
if ([event type] == NSKeyDown && [event modifierFlags] & NSCommandKeyMask)
{ {
[self performSelector:@selector(selectText:)]; QString keyString = toQString([event characters]);
return YES; if (keyString == "a") // Cmd+a
} {
else if (keyString == "c") // Cmd+c [self performSelector:@selector(selectText:)];
{ return YES;
QClipboard* clipboard = QApplication::clipboard(); }
clipboard->setText(toQString([self stringValue])); else if (keyString == "c") // Cmd+c
return YES; {
} QClipboard* clipboard = QApplication::clipboard();
else if (keyString == "v") // Cmd+v clipboard->setText(toQString([self stringValue]));
{ return YES;
QClipboard* clipboard = QApplication::clipboard(); }
[self setStringValue:fromQString(clipboard->text())]; else if (keyString == "v") // Cmd+v
return YES; {
} QClipboard* clipboard = QApplication::clipboard();
else if (keyString == "x") // Cmd+x [self setStringValue:fromQString(clipboard->text())];
{ return YES;
QClipboard* clipboard = QApplication::clipboard(); }
clipboard->setText(toQString([self stringValue])); else if (keyString == "x") // Cmd+x
[self setStringValue:@""]; {
return YES; QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(toQString([self stringValue]));
[self setStringValue:@""];
return YES;
}
} }
} }