From bec6112f26c6b1bc4291093209ce170c1e6d4605 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Tue, 7 Jan 2025 18:41:57 +0100 Subject: [PATCH] Fix more tab management issues --- Source/Pd/Instance.cpp | 5 +++++ Source/Pd/Patch.h | 2 +- Source/TabComponent.cpp | 7 +------ Source/Utility/Containers.h | 9 ++++++++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Source/Pd/Instance.cpp b/Source/Pd/Instance.cpp index f3d0376fd..e68e91f3c 100644 --- a/Source/Pd/Instance.cpp +++ b/Source/Pd/Instance.cpp @@ -229,6 +229,11 @@ void Instance::initialisePd(String& pdlua_version) } MessageManager::callAsync([pd, subpatch] { + + if(pd->patches.contains(subpatch, [](auto const& ptr1, auto const& ptr2){ return *ptr1 == *ptr2; })) { + return; + } + for (auto* editor : pd->getEditors()) { if (!editor->isActiveWindow()) continue; diff --git a/Source/Pd/Patch.h b/Source/Pd/Patch.h index 8d37bd285..086ba0239 100644 --- a/Source/Pd/Patch.h +++ b/Source/Pd/Patch.h @@ -29,7 +29,7 @@ class Patch final : public ReferenceCountedObject { // The compare equal operator. bool operator==(Patch const& other) const { - return getUncheckedPointer() == other.getUncheckedPointer(); + return getRawPointer() == other.getRawPointer(); } // Gets the bounds of the patch. diff --git a/Source/TabComponent.cpp b/Source/TabComponent.cpp index ca3f0fa8b..69303bae1 100644 --- a/Source/TabComponent.cpp +++ b/Source/TabComponent.cpp @@ -92,13 +92,9 @@ Canvas* TabComponent::openPatch(pd::Patch::Ptr existingPatch, bool const warnIfA } } - auto unique = pd->patches.add_unique(existingPatch, [](pd::Patch::Ptr const& ptr1, pd::Patch::Ptr const& ptr2){ + pd->patches.add_unique(existingPatch, [](auto const& ptr1, auto const& ptr2){ return *ptr1 == *ptr2; }); - if(!unique) { - triggerAsyncUpdate(); - return nullptr; - } existingPatch->splitViewIndex = activeSplitIndex; existingPatch->windowIndex = editor->editorIndex; @@ -413,7 +409,6 @@ void TabComponent::handleAsyncUpdate() } } } - if (!exists) { canvases.remove(i); } diff --git a/Source/Utility/Containers.h b/Source/Utility/Containers.h index 2b3f2423c..2335c71af 100644 --- a/Source/Utility/Containers.h +++ b/Source/Utility/Containers.h @@ -703,6 +703,13 @@ class SmallArrayImpl : public SmallArrayTemplateBase { { return std::find(this->begin(), this->end(), to_find) != this->end(); } + + template + [[nodiscard]] bool contains(T const& to_find, Predicate pred) { + return std::find_if(this->begin(), this->end(), [&to_find, pred](T const& element) { + return pred(element, to_find); + }) != this->end(); + } template [[nodiscard]] int index_of(U const& to_find) const @@ -1888,7 +1895,7 @@ class HeapArray { { return std::find(data_.begin(), data_.end(), to_find) != end(); } - + template [[nodiscard]] int index_of(U const& to_find) const {