From b4a0be99cdd130e8be1950fcb67980044542cb58 Mon Sep 17 00:00:00 2001 From: Leland Lucius Date: Thu, 21 Jan 2021 18:45:01 -0600 Subject: [PATCH] Bug 1579 - Mac: Cut/Copy from file save dialogs using shortcuts does not work And Bug 1300 - Mac: COMMAND + V paste limitations in standard file save dialogs --- src/commands/CommandManager.cpp | 13 ++++++ .../FileDialog/mac/FileDialogPrivate.mm | 43 ------------------- 2 files changed, 13 insertions(+), 43 deletions(-) diff --git a/src/commands/CommandManager.cpp b/src/commands/CommandManager.cpp index 74e9bc8d1..3e552c579 100644 --- a/src/commands/CommandManager.cpp +++ b/src/commands/CommandManager.cpp @@ -722,6 +722,19 @@ CommandListEntry *CommandManager::NewIdentifier(const CommandID & nameIn, entry->id = wxID_EXIT; 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. + else if (name == wxT("Copy")) + entry->id = wxID_CUT; + else if (name == wxT("Cut")) + entry->id = wxID_COPY; + else if (name == wxT("Delete")) + entry->id = wxID_CLEAR; + else if (name == wxT("Paste")) + entry->id = wxID_PASTE; + else if (name == wxT("SelectAll")) + entry->id = wxID_SELECTALL; #endif entry->name = name; diff --git a/src/widgets/FileDialog/mac/FileDialogPrivate.mm b/src/widgets/FileDialog/mac/FileDialogPrivate.mm index 3a44509a0..0660a11c4 100644 --- a/src/widgets/FileDialog/mac/FileDialogPrivate.mm +++ b/src/widgets/FileDialog/mac/FileDialogPrivate.mm @@ -508,47 +508,6 @@ int FileDialog::ShowModal() SetupExtraControls(sPanel); - // PRL: - // Hack for bug 1300: intercept key down events, implement a - // Command+V handler, but it's a bit crude. It always pastes - // the entire text field, ignoring the insertion cursor, and ignoring - // which control really has the focus. - id handler; - if (wxTheClipboard->IsSupported(wxDF_UNICODETEXT)) { - handler = [ - NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask - handler:^NSEvent *(NSEvent *event) - { - if ([event modifierFlags] & NSCommandKeyMask) - { - auto chars = [event charactersIgnoringModifiers]; - auto character = [chars characterAtIndex:0]; - if (character == 'v') - { - if (wxTheClipboard->Open()) { - wxTextDataObject data; - wxTheClipboard->GetData(data); - wxTheClipboard->Close(); - wxString text = data.GetText(); - auto rawText = text.utf8_str(); - auto length = text.Length(); - NSString *myString = [[NSString alloc] - initWithBytes:rawText.data() - length: rawText.length() - encoding: NSUTF8StringEncoding - ]; - [sPanel setNameFieldStringValue:myString]; - [myString release]; - return nil; - } - } - } - - return event; - } - ]; - } - // makes things more convenient: [sPanel setCanCreateDirectories:YES]; [sPanel setMessage:cf.AsNSString()]; @@ -581,8 +540,6 @@ int FileDialog::ShowModal() [sPanel setNameFieldStringValue:file.AsNSString()]; returnCode = [sPanel runModal]; ModalFinishedCallback(sPanel, returnCode); - if (wxTheClipboard->IsSupported(wxDF_UNICODETEXT)) - [NSEvent removeMonitor:handler]; } else {