diff --git a/plugin/editor.cpp b/plugin/editor.cpp index b909bec..cd08706 100644 --- a/plugin/editor.cpp +++ b/plugin/editor.cpp @@ -231,6 +231,36 @@ YsfxEditor::~YsfxEditor() } } +//------------------------------------------------------------------------------ +bool YsfxEditor::isInterestedInFileDrag(const juce::StringArray &files) +{ + (void)files; + + YsfxInfo::Ptr info = m_impl->m_info; + ysfx_t *fx = info->effect.get(); + + return !ysfx_is_compiled(fx); +} + +void YsfxEditor::filesDropped(const juce::StringArray &files, int x, int y) +{ + (void)x; + (void)y; + + // We only allow jsfx drops if no JSFX was loaded. + YsfxInfo::Ptr info = m_impl->m_info; + ysfx_t *fx = info->effect.get(); + + if (!ysfx_is_compiled(fx)) { + if (files.size() == 1) { + juce::File file{files[0]}; + if (file.existsAsFile()) { + m_impl->loadFile(files[0]); + } + } + } +} + void YsfxEditor::resized() { m_impl->relayoutUILater(); diff --git a/plugin/editor.h b/plugin/editor.h index ed8119e..5de698f 100644 --- a/plugin/editor.h +++ b/plugin/editor.h @@ -20,7 +20,7 @@ #include class YsfxProcessor; -class YsfxEditor : public juce::AudioProcessorEditor { +class YsfxEditor : public juce::AudioProcessorEditor, public juce::FileDragAndDropTarget { public: explicit YsfxEditor(YsfxProcessor &proc); ~YsfxEditor() override; @@ -28,6 +28,8 @@ class YsfxEditor : public juce::AudioProcessorEditor { protected: void resized() override; void paint (juce::Graphics& g) override; + bool isInterestedInFileDrag(const juce::StringArray &files) override; + void filesDropped(const juce::StringArray &files, int x, int y) override; private: void readTheme();