commit 5590de8162646348cadd689e1fc7a50d5fe88fff
parent 3fedce01bb027e8eb946a41f84fd472d7bb0ae32
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Mon, 18 Nov 2024 22:01:44 +0100
allow to add patch to user bank by dragging onto free space of list
Diffstat:
4 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/source/jucePluginEditorLib/patchmanager/listmodel.cpp b/source/jucePluginEditorLib/patchmanager/listmodel.cpp
@@ -5,6 +5,7 @@
#include "patchmanager.h"
#include "savepatchdesc.h"
#include "search.h"
+#include "treeitem.h"
#include "../pluginEditor.h"
@@ -661,4 +662,36 @@ namespace jucePluginEditorLib::patchManager
const auto t = Search::lowercase(name);
return t.find(m_filter) != std::string::npos;
}
+
+ bool ListModel::isInterestedInDragSource(const SourceDetails& dragSourceDetails)
+ {
+ auto ds = getPatchManager().getSelectedDataSourceTreeItem();
+ if (!ds)
+ return false;
+ return ds->isInterestedInDragSource(dragSourceDetails);
+ }
+
+ void ListModel::itemDropped(const SourceDetails& dragSourceDetails)
+ {
+ auto ds = getPatchManager().getSelectedDataSourceTreeItem();
+ if (!ds)
+ return;
+ return ds->itemDropped(dragSourceDetails, std::numeric_limits<int>::max());
+ }
+
+ bool ListModel::isInterestedInFileDrag(const juce::StringArray& files)
+ {
+ auto ds = getPatchManager().getSelectedDataSourceTreeItem();
+ if (!ds)
+ return false;
+ return ds->isInterestedInFileDrag(files);
+ }
+
+ void ListModel::filesDropped(const juce::StringArray& files, int x, int y)
+ {
+ auto ds = getPatchManager().getSelectedDataSourceTreeItem();
+ if (!ds)
+ return;
+ ds->filesDropped(files, std::numeric_limits<int>::max());
+ }
}
diff --git a/source/jucePluginEditorLib/patchmanager/listmodel.h b/source/jucePluginEditorLib/patchmanager/listmodel.h
@@ -19,7 +19,7 @@ namespace jucePluginEditorLib::patchManager
{
class PatchManager;
- class ListModel : public juce::ListBoxModel, Editable
+ class ListModel : public juce::ListBoxModel, Editable, public juce::DragAndDropTarget, public juce::FileDragAndDropTarget
{
public:
using Patch = pluginLib::patchDB::PatchPtr;
@@ -129,6 +129,12 @@ namespace jucePluginEditorLib::patchManager
virtual void setSelectedEntries(const juce::SparseSet<int>&) = 0;
virtual juce::Rectangle<int> getEntryPosition(int _row, bool _relativeToComponentTopLeft) = 0;
+ // drag & drop support
+ bool isInterestedInDragSource(const SourceDetails& dragSourceDetails) override;
+ void itemDropped(const SourceDetails& dragSourceDetails) override;
+ bool isInterestedInFileDrag(const juce::StringArray& files) override;
+ void filesDropped(const juce::StringArray& files, int x, int y) override;
+
private:
void sortPatches();
void sortPatches(Patches& _patches) const;
diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.cpp b/source/jucePluginEditorLib/patchmanager/patchmanager.cpp
@@ -337,6 +337,16 @@ namespace jucePluginEditorLib::patchManager
return item->getDataSource();
}
+ TreeItem* PatchManager::getSelectedDataSourceTreeItem() const
+ {
+ if (!m_treeDS)
+ return nullptr;
+ auto ds = getSelectedDataSource();
+ if (!ds)
+ return nullptr;
+ return m_treeDS->getItem(*ds);
+ }
+
bool PatchManager::setSelectedPatch(const uint32_t _part, const pluginLib::patchDB::PatchPtr& _patch)
{
if(!isValid(_patch))
diff --git a/source/jucePluginEditorLib/patchmanager/patchmanager.h b/source/jucePluginEditorLib/patchmanager/patchmanager.h
@@ -84,6 +84,7 @@ namespace jucePluginEditorLib::patchManager
bool setSelectedDataSource(const pluginLib::patchDB::DataSourceNodePtr& _ds) const;
pluginLib::patchDB::DataSourceNodePtr getSelectedDataSource() const;
+ TreeItem* getSelectedDataSourceTreeItem() const;
const State& getState() const { return m_state; }