From 839f492784150e646fa72dc14f53105a3e4bb494 Mon Sep 17 00:00:00 2001 From: George Reales Date: Sun, 16 May 2021 12:29:57 +0200 Subject: [PATCH] FXB/FXP drag and drop --- Source/PluginEditor.cpp | 58 +++++++++++++++++++++++++++++++++++++++++ Source/PluginEditor.h | 5 +++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 89c275a..c31a7af 100755 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -878,6 +878,64 @@ void ObxdAudioProcessorEditor::paint(Graphics& g) } + +bool ObxdAudioProcessorEditor::isInterestedInFileDrag(const StringArray& files) +{ + StringArray extensions; + extensions.add(".fxp"); + extensions.add(".fxb"); + + if (files.size() == 1) { + File file = File(files[0]); + String ext = file.getFileExtension().toLowerCase(); + return file.existsAsFile() && extensions.contains(ext); + } else { + for (int q = 0; q < files.size(); q++) { + File file = File(files[q]); + String ext = file.getFileExtension().toLowerCase(); + + if (ext == ".fxb" || ext == ".fxp") { + return true; + } + } + } + return false; +} + +void ObxdAudioProcessorEditor::filesDropped(const StringArray& files, int x, int y) +{ + if (files.size() == 1) { + File file = File(files[0]); + String ext = file.getFileExtension().toLowerCase(); + + if (ext == ".fxp") { + processor.loadPreset(file); + createMenu(); + } else if (ext == ".fxb") { + auto name = file.getFileName().replace("%20", " "); + auto result = processor.getBanksFolder().getChildFile(name); + + if (file.copyFileTo(result)){ + processor.loadFromFXBFile(result); + processor.scanAndUpdateBanks(); + createMenu(); + } + } + } else { + int i = processor.getCurrentProgram(); + + for (int q = 0; q < files.size(); q++) { + File file = File(files[q]); + String ext = file.getFileExtension().toLowerCase(); + if (ext == ".fxp") { + processor.setCurrentProgram(i++); + processor.loadPreset(file); + } + } + processor.sendChangeMessage(); + createMenu(); + } +} /* bool ObxdAudioProcessorEditor::keyPressed(const KeyPress & press) { if (press.getKeyCode() == '+' || press.getKeyCode() == KeyPress::numberPadAdd) diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index fa1b9c5..a493a25 100755 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -55,12 +55,15 @@ class ObxdAudioProcessorEditor : public AudioProcessorEditor // , public ComboBox::Listener , public ApplicationCommandTarget , public Timer + , public FileDragAndDropTarget { public: ObxdAudioProcessorEditor(ObxdAudioProcessor& ownerFilter); ~ObxdAudioProcessorEditor(); - + + bool isInterestedInFileDrag(const StringArray& files) override; + void filesDropped(const StringArray& files, int x, int y) override; void mouseUp (const MouseEvent& e) override; void paint (Graphics& g) override;