diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index b005d347e..f0c26f782 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -723,8 +723,10 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn, else if (name == wxT("About")) entry->id = wxID_ABOUT; - // This is a fix for bugs 1300 and 1579. Using the wx provides IDs - // allows wx to handle them in an macOS way. +#if defined(BE_CAREFUL) + // Don't be tempted to do this unless you're willing to change how + // HandleMenuID() decides if a menu action should be performed. + // (see comments 6-9 in bug #2642 for symptoms) else if (name == wxT("Copy")) entry->id = wxID_COPY; else if (name == wxT("Cut")) @@ -735,6 +737,8 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn, entry->id = wxID_PASTE; else if (name == wxT("SelectAll")) entry->id = wxID_SELECTALL; +#endif + #endif entry->name = name; diff --git a/src/widgets/FileDialog/mac/FileDialogPrivate.mm b/src/widgets/FileDialog/mac/FileDialogPrivate.mm index 0660a11c4..d451f8554 100644 --- a/src/widgets/FileDialog/mac/FileDialogPrivate.mm +++ b/src/widgets/FileDialog/mac/FileDialogPrivate.mm @@ -508,6 +508,42 @@ int FileDialog::ShowModal() SetupExtraControls(sPanel); + // PRL: + // Hack for bugs 1300/1579: Intercept key down events, implementing + // copy/cut/paste, by invoking appropriate selectors. This is done + // because we do not use the wxWidgets IDs for the menu equivalents. + id handler; + if (wxTheClipboard->IsSupported(wxDF_UNICODETEXT)) { + handler = [ + NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask + handler:^NSEvent *(NSEvent *event) + { + auto app = [NSApplication sharedApplication]; + if ([event modifierFlags] & NSCommandKeyMask) + { + auto chars = [event charactersIgnoringModifiers]; + if ([chars isEqualToString:@"a"]) + { + [app sendAction:@selector(selectAll:) to:nil from:nil]; + } + else if ([chars isEqualToString:@"c"]) + { + [app sendAction:@selector(copy:) to:nil from:nil]; + } + else if ([chars isEqualToString:@"x"]) + { + [app sendAction:@selector(cut:) to:nil from:nil]; + } + else if ([chars isEqualToString:@"v"]) + { + [app sendAction:@selector(paste:) to:nil from:nil]; + } + } + return event; + } + ]; + } + // makes things more convenient: [sPanel setCanCreateDirectories:YES]; [sPanel setMessage:cf.AsNSString()]; @@ -540,6 +576,8 @@ int FileDialog::ShowModal() [sPanel setNameFieldStringValue:file.AsNSString()]; returnCode = [sPanel runModal]; ModalFinishedCallback(sPanel, returnCode); + if (wxTheClipboard->IsSupported(wxDF_UNICODETEXT)) + [NSEvent removeMonitor:handler]; } else {