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
This commit is contained in:
Leland Lucius 2021-01-21 18:45:01 -06:00
parent b5ee77f737
commit b4a0be99cd
2 changed files with 13 additions and 43 deletions

View File

@ -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;

View File

@ -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
{