diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp index fcf7c05a19..6db6e17d2d 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.cpp @@ -42,7 +42,8 @@ public: void trigger() { - startTimer (70); + if (! isTimerRunning()) + startTimer (100); } private: @@ -101,7 +102,6 @@ LiveValueBase::~LiveValueBase() { } - //============================================================================== LivePropertyEditorBase::LivePropertyEditorBase (LiveValueBase& v, CodeDocument& d) : value (v), document (d), sourceEditor (document, &tokeniser) @@ -286,10 +286,20 @@ public: setVisible (false); } - void addItem (LiveValueBase& v, CodeDocument& doc) + void updateItems (ValueList& list) { if (ValueListHolderComponent* l = dynamic_cast (viewport.getViewedComponent())) - l->addItem (viewport.getMaximumVisibleWidth(), v, doc); + { + while (l->getNumChildComponents() < list.values.size()) + { + if (LiveValueBase* v = list.values [l->getNumChildComponents()]) + l->addItem (viewport.getMaximumVisibleWidth(), *v, list.getDocument (v->sourceFile)); + else + break; + } + + setVisible (true); + } } void resized() override @@ -304,7 +314,45 @@ public: LookAndFeel_V3 lookAndFeel; }; +//============================================================================== +ValueList::ValueList() {} +ValueList::~ValueList() {} +ValueList& ValueList::getInstance() +{ + static ValueList* i = new ValueList(); + return *i; +} + +void ValueList::addValue (LiveValueBase* v) +{ + values.add (v); + triggerAsyncUpdate(); +} + +void ValueList::handleAsyncUpdate() +{ + if (editorWindow == nullptr) + editorWindow = new EditorWindow (*this); + + editorWindow->updateItems (*this); +} + +CodeDocument& ValueList::getDocument (const File& file) +{ + const int index = documentFiles.indexOf (file.getFullPathName()); + + if (index >= 0) + return *documents.getUnchecked (index); + + CodeDocument* doc = documents.add (new CodeDocument()); + documentFiles.add (file); + doc->replaceAllContent (file.loadFileAsString()); + doc->clearUndoHistory(); + return *doc; +} + +//============================================================================== struct ColourEditorComp : public Component, private ChangeListener { @@ -403,42 +451,6 @@ private: Component* createIntegerSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, false); } Component* createFloatSlider (LivePropertyEditorBase& editor) { return new SliderComp (editor, true); } -//============================================================================== -ValueList::ValueList() -{ -} - -ValueList& ValueList::getInstance() -{ - static ValueList* i = new ValueList(); - return *i; -} - -void ValueList::addValue (LiveValueBase* v) -{ - values.add (v); - - if (editorWindow == nullptr) - editorWindow = new EditorWindow (*this); - - editorWindow->addItem (*v, getDocument (v->sourceFile)); - editorWindow->setVisible (true); -} - -CodeDocument& ValueList::getDocument (const File& file) -{ - const int index = documentFiles.indexOf (file.getFullPathName()); - - if (index >= 0) - return *documents.getUnchecked (index); - - CodeDocument* doc = documents.add (new CodeDocument()); - documentFiles.add (file); - doc->replaceAllContent (file.loadFileAsString()); - doc->clearUndoHistory(); - return *doc; -} - } #endif \ No newline at end of file diff --git a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h index 6865deb7a2..f8e7b4b14f 100644 --- a/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h +++ b/modules/juce_gui_extra/misc/juce_LiveConstantEditor.h @@ -80,7 +80,7 @@ namespace LiveConstantEditor struct LivePropertyEditorBase; //============================================================================== - struct LiveValueBase + struct JUCE_API LiveValueBase { LiveValueBase (const char* file, int line); virtual ~LiveValueBase(); @@ -97,8 +97,8 @@ namespace LiveConstantEditor }; //============================================================================== - struct LivePropertyEditorBase : public Component, - private TextEditor::Listener + struct JUCE_API LivePropertyEditorBase : public Component, + private TextEditor::Listener { LivePropertyEditorBase (LiveValueBase&, CodeDocument&); @@ -176,10 +176,13 @@ namespace LiveConstantEditor }; //============================================================================== - class ValueList : private DeletedAtShutdown + class JUCE_API ValueList : private AsyncUpdater, + private DeletedAtShutdown { public: ValueList(); + ~ValueList(); + static ValueList& getInstance(); template @@ -193,8 +196,7 @@ namespace LiveConstantEditor LiveValueBase* v = values.getUnchecked(i); if (v->sourceLine == line && v->sourceFile == file) - if (ValueType* vt = dynamic_cast (v)) - return *vt; + return *static_cast (v); } ValueType* v = new ValueType (file, line, initialValue); @@ -207,11 +209,14 @@ namespace LiveConstantEditor OwnedArray documents; Array documentFiles; class EditorWindow; + friend class EditorWindow; + friend struct ContainerDeletePolicy; Component::SafePointer editorWindow; CriticalSection lock; CodeDocument& getDocument (const File&); void addValue (LiveValueBase*); + void handleAsyncUpdate() override; }; template