1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-05 03:50:07 +00:00

FileChooser: Fix issue where preview component may not receive full filename

Some hosts (such as Reaper) weren't creating an instance of exactly
NSOpenPanel or NSSavePanel, which meant that the call to
`getSelectedPaths` was always returning an empty array.

Now, rather than trying to cast the sender to an appropriate type, we
assume that the sender is always the same panel that we opened earlier,
so that we can just query the panel directly for its selection.
This commit is contained in:
reuk 2020-10-20 19:36:39 +01:00
parent f27a7c7712
commit 1d29665e56

View file

@ -254,26 +254,32 @@ private:
void panelSelectionDidChange (id sender)
{
jassert (sender == panel);
ignoreUnused (sender);
// NB: would need to extend FilePreviewComponent to handle the full list rather than just the first one
if (preview != nullptr)
preview->selectedFileChanged (File (getSelectedPaths (sender)[0]));
preview->selectedFileChanged (File (getSelectedPaths()[0]));
}
static StringArray getSelectedPaths (id sender)
StringArray getSelectedPaths() const
{
if (panel == nullptr)
return {};
StringArray paths;
if ([sender isKindOfClass: [NSOpenPanel class]])
if (isSave)
{
NSArray* urls = [(NSOpenPanel*) sender URLs];
paths.add (nsStringToJuce ([[panel URL] path]));
}
else
{
auto* urls = [(NSOpenPanel*) panel URLs];
for (NSUInteger i = 0; i < [urls count]; ++i)
paths.add (nsStringToJuce ([[urls objectAtIndex: i] path]));
}
else if ([sender isKindOfClass: [NSSavePanel class]])
{
paths.add (nsStringToJuce ([[(NSSavePanel*) sender URL] path]));
}
return paths;
}