mirror of
https://codeberg.org/armin/monoslicer.git
synced 2026-11-20 13:07:56 +01:00
Normalise file:// URLs for drag-and-drop loading
This commit is contained in:
parent
16322a2bb6
commit
6a8d2aa84d
2 changed files with 51 additions and 11 deletions
|
|
@ -1,5 +1,35 @@
|
|||
#include "PluginEditor.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
// Drag sources don't always hand us a plain filesystem path: some send a
|
||||
// file:// URL, with spaces and other characters percent-encoded. Normalise
|
||||
// everything to a plain path before looking at the extension or opening it.
|
||||
juce::String normaliseDragPath (const juce::String& rawPath)
|
||||
{
|
||||
auto path = rawPath.trim();
|
||||
|
||||
if (path.startsWithIgnoreCase ("file:"))
|
||||
{
|
||||
juce::URL url (path);
|
||||
if (url.isLocalFile())
|
||||
return url.getLocalFile().getFullPathName();
|
||||
|
||||
// Fall back to manual parsing for URLs JUCE doesn't recognise.
|
||||
if (path.startsWith ("file://"))
|
||||
path = path.substring (7);
|
||||
else if (path.startsWith ("file:/"))
|
||||
path = path.substring (5);
|
||||
|
||||
path = path.replace ("%20", " ").replace ("%5B", "[").replace ("%5D", "]")
|
||||
.replace ("%28", "(").replace ("%29", ")").replace ("%2C", ",")
|
||||
.replace ("%27", "'").replace ("%22", "\"");
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
MonoslicerEditor::MonoslicerEditor(MonoslicerProcessor& p)
|
||||
: AudioProcessorEditor(p),
|
||||
processorRef(p),
|
||||
|
|
@ -585,7 +615,7 @@ void MonoslicerEditor::comboBoxChanged(juce::ComboBox* comboBoxThatHasChanged)
|
|||
bool MonoslicerEditor::isInterestedInFileDrag(const juce::StringArray& files)
|
||||
{
|
||||
for (const auto& f : files)
|
||||
if (processorRef.canLoadFileExtension(f))
|
||||
if (processorRef.canLoadFileExtension (normaliseDragPath (f)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
@ -618,8 +648,8 @@ void MonoslicerEditor::filesDropped(const juce::StringArray& files, int, int)
|
|||
|
||||
for (const auto& f : files)
|
||||
{
|
||||
juce::File file(f);
|
||||
if (file.existsAsFile() && processorRef.canLoadFileExtension(f))
|
||||
juce::File file (normaliseDragPath (f));
|
||||
if (file.existsAsFile() && processorRef.canLoadFileExtension (file.getFullPathName()))
|
||||
{
|
||||
handleDroppedSample(file);
|
||||
break;
|
||||
|
|
@ -629,11 +659,9 @@ void MonoslicerEditor::filesDropped(const juce::StringArray& files, int, int)
|
|||
|
||||
bool MonoslicerEditor::isInterestedInTextDrag(const juce::String& text)
|
||||
{
|
||||
juce::File file(text);
|
||||
if (text.startsWithIgnoreCase("file://"))
|
||||
file = juce::URL(text).getLocalFile();
|
||||
juce::File file (normaliseDragPath (text));
|
||||
|
||||
return file.existsAsFile() && processorRef.canLoadFileExtension(file.getFullPathName());
|
||||
return file.existsAsFile() && processorRef.canLoadFileExtension (file.getFullPathName());
|
||||
}
|
||||
|
||||
void MonoslicerEditor::textDragEnter(const juce::String& text, int, int)
|
||||
|
|
@ -655,11 +683,9 @@ void MonoslicerEditor::textDropped(const juce::String& text, int, int)
|
|||
{
|
||||
dropOverlay.setVisible(false);
|
||||
|
||||
juce::File file(text);
|
||||
if (text.startsWithIgnoreCase("file://"))
|
||||
file = juce::URL(text).getLocalFile();
|
||||
juce::File file (normaliseDragPath (text));
|
||||
|
||||
if (processorRef.canLoadFileExtension(file.getFullPathName()))
|
||||
if (file.existsAsFile() && processorRef.canLoadFileExtension (file.getFullPathName()))
|
||||
handleDroppedSample(file);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue