mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-10 16:43:33 +02:00
Bug1300: make Ctrl+V work in text field of Save dialog, 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. The file dialog, which can call up the Finder, is implemented in the AppKit so it's not wholly under our control. But I could bolt on an event filter, after the fashion of CommandManager, to intercept key events. Perhaps later versions of the toolkit than 10.6 will have a better save dialog in the AppKit, making this change unnecessary.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include "wx/choice.h"
|
||||
#endif
|
||||
|
||||
#include "wx/clipbrd.h"
|
||||
#include "wx/filename.h"
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/evtloop.h"
|
||||
@@ -607,6 +608,45 @@ 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_TEXT)) {
|
||||
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();
|
||||
NSString *myString = [[NSString alloc]
|
||||
initWithCharacters:
|
||||
(unsigned short*)text.c_str().AsWChar()
|
||||
length:text.Length()
|
||||
];
|
||||
[sPanel setNameFieldStringValue:myString];
|
||||
[myString release];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
// makes things more convenient:
|
||||
[sPanel setCanCreateDirectories:YES];
|
||||
[sPanel setMessage:cf.AsNSString()];
|
||||
@@ -636,6 +676,9 @@ int FileDialog::ShowModal()
|
||||
|
||||
returnCode = [sPanel runModalForDirectory: m_dir.IsEmpty() ? nil : dir.AsNSString() file:file.AsNSString() ];
|
||||
ModalFinishedCallback(sPanel, returnCode);
|
||||
|
||||
if (wxTheClipboard->IsSupported(wxDF_TEXT))
|
||||
[NSEvent removeMonitor:handler];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user