commit 68d18830c2efb23fc05788f16930330737912b53
parent 7643cdb334d93d7920fbada2781020fd3b68ced7
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Sun, 5 May 2024 17:04:53 +0200
allow to drag patches onto "Favourites" root tree item and create a favourites default tag automatically
Diffstat:
5 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/source/jucePluginEditorLib/patchmanager/grouptreeitem.cpp b/source/jucePluginEditorLib/patchmanager/grouptreeitem.cpp
@@ -225,6 +225,10 @@ namespace jucePluginEditorLib::patchManager
bool GroupTreeItem::isInterestedInDragSource(const juce::DragAndDropTarget::SourceDetails& _dragSourceDetails)
{
+ // if there are no favourites yet, allow to drag onto this group node and create a default tag automatically if patches are dropped
+ if(m_type == GroupType::Favourites && m_itemsByTag.empty() && TreeItem::isInterestedInDragSource(_dragSourceDetails))
+ return true;
+
if (isOpen())
return false;
@@ -279,6 +283,35 @@ namespace jucePluginEditorLib::patchManager
}
}
+ bool GroupTreeItem::isInterestedInPatchList(const List* _list, const juce::Array<juce::var>& _indices)
+ {
+ if(m_type == GroupType::Favourites)
+ return true;
+ return TreeItem::isInterestedInPatchList(_list, _indices);
+ }
+
+ void GroupTreeItem::patchesDropped(const std::vector<pluginLib::patchDB::PatchPtr>& _patches, const SavePatchDesc* _savePatchDesc)
+ {
+ if(!m_itemsByTag.empty() || m_type != GroupType::Favourites)
+ {
+ TreeItem::patchesDropped(_patches, _savePatchDesc);
+ return;
+ }
+
+ const auto tagType = toTagType(m_type);
+
+ if(tagType == pluginLib::patchDB::TagType::Invalid)
+ {
+ TreeItem::patchesDropped(_patches, _savePatchDesc);
+ return;
+ }
+
+ constexpr const char* const tag = "Favourites";
+
+ getPatchManager().addTag(tagType, tag);
+ TagTreeItem::modifyTags(getPatchManager(), tagType, tag, _patches);
+ }
+
DatasourceTreeItem* GroupTreeItem::createItemForDataSource(const pluginLib::patchDB::DataSourceNodePtr& _dataSource)
{
const auto it = m_itemsByDataSource.find(_dataSource);
diff --git a/source/jucePluginEditorLib/patchmanager/grouptreeitem.h b/source/jucePluginEditorLib/patchmanager/grouptreeitem.h
@@ -44,6 +44,9 @@ namespace jucePluginEditorLib::patchManager
void setParentSearchRequest(const pluginLib::patchDB::SearchRequest& _parentSearch) override;
void onParentSearchChanged(const pluginLib::patchDB::SearchRequest& _parentSearchRequest) override;
+ bool isInterestedInPatchList(const List* _list, const juce::Array<juce::var>& _indices) override;
+ void patchesDropped(const std::vector<pluginLib::patchDB::PatchPtr>& _patches, const SavePatchDesc* _savePatchDesc) override;
+
private:
DatasourceTreeItem* createItemForDataSource(const pluginLib::patchDB::DataSourceNodePtr& _dataSource);
TagTreeItem* createSubItem(const std::string& _tag);
diff --git a/source/jucePluginEditorLib/patchmanager/tagtreeitem.cpp b/source/jucePluginEditorLib/patchmanager/tagtreeitem.cpp
@@ -38,14 +38,7 @@ namespace jucePluginEditorLib::patchManager
if (tagType == pluginLib::patchDB::TagType::Invalid)
return;
- pluginLib::patchDB::TypedTags tags;
- if (juce::ModifierKeys::currentModifiers.isShiftDown())
- tags.addRemoved(tagType, getTag());
- else
- tags.add(tagType, getTag());
-
- getPatchManager().modifyTags(_patches, tags);
- getPatchManager().repaint();
+ modifyTags(getPatchManager(), tagType, getTag(), _patches);
}
void TagTreeItem::onParentSearchChanged(const pluginLib::patchDB::SearchRequest& _parentSearchRequest)
@@ -61,6 +54,18 @@ namespace jucePluginEditorLib::patchManager
search(std::move(sr));
}
+ void TagTreeItem::modifyTags(PatchManager& _pm, pluginLib::patchDB::TagType _type, const std::string& _tag, const std::vector<pluginLib::patchDB::PatchPtr>& _patches)
+ {
+ pluginLib::patchDB::TypedTags tags;
+ if (juce::ModifierKeys::currentModifiers.isShiftDown())
+ tags.addRemoved(_type, _tag);
+ else
+ tags.add(_type, _tag);
+
+ _pm.modifyTags(_patches, tags);
+ _pm.repaint();
+ }
+
void TagTreeItem::itemClicked(const juce::MouseEvent& _mouseEvent)
{
if(!_mouseEvent.mods.isPopupMenu())
diff --git a/source/jucePluginEditorLib/patchmanager/tagtreeitem.h b/source/jucePluginEditorLib/patchmanager/tagtreeitem.h
@@ -22,6 +22,8 @@ namespace jucePluginEditorLib::patchManager
void patchesDropped(const std::vector<pluginLib::patchDB::PatchPtr>& _patches, const SavePatchDesc* _savePatchDesc = nullptr) override;
void onParentSearchChanged(const pluginLib::patchDB::SearchRequest& _parentSearchRequest) override;
+ static void modifyTags(PatchManager& _pm, pluginLib::patchDB::TagType _type, const std::string& _tag, const std::vector<pluginLib::patchDB::PatchPtr>& _patches);
+
const auto& getTag() const { return m_tag; }
void itemClicked(const juce::MouseEvent&) override;
diff --git a/source/jucePluginEditorLib/patchmanager/treeitem.cpp b/source/jucePluginEditorLib/patchmanager/treeitem.cpp
@@ -162,7 +162,7 @@ namespace jucePluginEditorLib::patchManager
if (list)
{
const auto* arr = _dragSourceDetails.description.getArray();
- if (!arr)
+ if (!arr || arr->isEmpty())
return false;
for (const auto& var : *arr)