12namespace tracktion {
inline namespace engine
17class SelectionManager;
21class SelectableListener
24 virtual ~SelectableListener() {}
26 virtual void selectableObjectChanged (Selectable*) = 0;
27 virtual void selectableObjectAboutToBeDeleted (Selectable*) = 0;
44 static void initialise();
73 void selectableObjectChanged (
Selectable*)
override {}
74 void selectableObjectAboutToBeDeleted (
Selectable*)
override {}
102 void propertiesChanged();
105 void notifyListenersOfDeletion();
110 WeakRef::Master masterReference;
111 [[ deprecated (
"Use makeSafeRef() and SafeSelectable instead") ]]
WeakRef getWeakRef() {
return {
this }; }
113 Ase::VirtualBase *ase_obj_ =
nullptr;
120 bool needsAnUpdate =
false, hasNotifiedListenersOfDeletion =
false, isCallingListeners =
false;
122 void sendChangeCallbackToListenersIfNeeded();
139 items.addArray (initialItems);
142 template<
typename SelectableType>
145 items.addArray (initialItems);
148 template<
typename SelectableType>
151 items.addArray (initialItems);
154 template<
typename SelectableType>
157 items.addArray (initialItems.
data(),
static_cast<int> (initialItems.
size()));
170 template <
typename Sub
classType>
176 if (
auto i =
dynamic_cast<SubclassType*
> (s))
182 template <
typename Sub
classType>
183 SubclassType* getFirstOfType()
const
185 return dynamic_cast<SubclassType*
> (items.getFirst());
188 template <
typename Sub
classType>
189 bool containsType()
const
192 if (
dynamic_cast<SubclassType*
> (s) !=
nullptr)
199 int size()
const {
return items.size(); }
200 bool isEmpty()
const {
return items.isEmpty(); }
201 bool isNotEmpty()
const {
return ! isEmpty(); }
203 inline Selectable** begin() {
return items.begin(); }
204 inline Selectable*
const* begin()
const {
return items.begin(); }
205 inline Selectable** end() {
return items.end(); }
206 inline Selectable*
const* end()
const {
return items.end(); }
207 inline Selectable** data() {
return begin(); }
208 inline Selectable*
const* data()
const {
return begin(); }
210 Selectable* operator[] (
int index)
const {
return items[index]; }
211 inline Selectable* getUnchecked (
int index)
const {
return items.getUnchecked (index); }
212 inline Selectable* getFirst()
const {
return items.getFirst(); }
213 inline Selectable* getLast()
const {
return items.getLast(); }
215 template <
class OtherArrayType>
216 inline void addArray (
const OtherArrayType& arrayToAddFrom,
int startIndex = 0,
int numElementsToAdd = -1)
218 classes.clearQuick();
219 items.addArray (arrayToAddFrom, startIndex, numElementsToAdd);
222 template <
class OtherArrayType>
223 inline void mergeArray (
const OtherArrayType& arrayToMergeFrom)
225 classes.clearQuick();
227 for (
auto& s : arrayToMergeFrom)
228 addIfNotAlreadyThere (s);
231 inline void add (
Selectable* newElement) { items.add (newElement); }
232 inline bool addIfNotAlreadyThere (
Selectable* newElement) {
return items.addIfNotAlreadyThere (newElement); }
234 inline void clear() { classes.clear(); items.clear(); }
235 inline void remove (
int indexToRemove) { classes.clearQuick();
return items.remove (indexToRemove); }
236 inline int removeAllInstancesOf (
Selectable* s) { classes.clearQuick();
return items.removeAllInstancesOf (s); }
237 inline Selectable* removeAndReturn (
int indexToRemove) { classes.clearQuick();
return items.removeAndReturn (indexToRemove); }
238 inline bool contains (
Selectable* elementToLookFor)
const {
return items.contains (elementToLookFor); }
239 inline int indexOf (
Selectable* elementToLookFor)
const {
return items.indexOf (elementToLookFor); }
241 template <
class OtherArrayType>
242 inline bool operator== (
const OtherArrayType& other)
const {
return items == other; }
244 template <
class OtherArrayType>
245 inline bool operator!= (
const OtherArrayType& other)
const {
return items != other; }
247 inline bool operator== (
const SelectableList& other)
const {
return items == other.items; }
248 inline bool operator!= (
const SelectableList& other)
const {
return items != other.items; }
265template<
typename SelectableType>
288 SelectableType*
get() const noexcept {
return dynamic_cast<SelectableType*
> (weakRef.get()); }
291 operator SelectableType*()
const noexcept {
return get(); }
296 bool operator== (SelectableType* other)
const noexcept {
return weakRef.get() == other; }
297 bool operator!= (SelectableType* other)
const noexcept {
return weakRef.get() != other; }
299 bool operator== (
const SafeSelectable& other)
const noexcept {
return weakRef.get() == other.weakRef.get(); }
300 bool operator!= (
const SafeSelectable& other)
const noexcept {
return weakRef.get() != other.weakRef.get(); }
302 bool operator== (
const SelectableType& other)
const noexcept {
return weakRef.get() == &other; }
303 bool operator!= (
const SelectableType& other)
const noexcept {
return weakRef.get() != &other; }
305 bool operator== (
decltype(
nullptr)) const noexcept {
return weakRef ==
nullptr; }
306 bool operator!= (
decltype(
nullptr)) const noexcept {
return weakRef !=
nullptr; }
313template<
typename SelectableType>
320template<
typename Iterable>
326 v.reserve (
static_cast<size_t> (selectables.size()));
328 for (
auto* s : selectables)
362 ref->removeSelectableListener (
this);
367 ref->addSelectableListener (
this);
376 void selectableObjectChanged (
Selectable*)
override
378 if (onSelectableChanged)
379 onSelectableChanged();
382 void selectableObjectAboutToBeDeleted (
Selectable*)
override
384 if (onSelectableAboutToBeDeleted)
385 onSelectableAboutToBeDeleted();
typename TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType
void add(const ElementType &newElement)
A SelectableListener that safely handles listener to a Selectable and uses a lambda for its callback.
LambdaSelectableListener()=default
Constructs an empty listener.
~LambdaSelectableListener() override
Destructor.
LambdaSelectableListener(Selectable &s)
Constructs a listener for a Selectable.
void reset(Selectable *s=nullptr)
Resets the Selectable.
Holds a pointer to some type of Selectable, which automatically becomes null if the selectable is del...
SafeSelectable & operator=(const SafeSelectable &other)
Copies another pointer to this one.
SelectableType * get() const noexcept
Returns the selectable that this pointer refers to, or null if the selectable no longer exists.
SafeSelectable(SelectableType *selectable)
Creates a SafeSelectable that points at the given selectable.
SafeSelectable()=default
Creates a null SafeSelectable.
SafeSelectable(const SafeSelectable &other) noexcept
Creates a copy of another SafeSelectable.
SelectableType * operator->() const noexcept
Returns the selectable that this pointer refers to, or null if the selectable no longer exists.
SafeSelectable(SelectableType &selectable)
Creates a SafeSelectable that points at the given selectable.
Represents a type of object that can be selected.
Base class for things that can be selected, and whose properties can appear in the properties panel.
virtual void changed()
This should be called to send a change notification to any SelectableListeners that are registered wi...
virtual void selectionStatusChanged(bool isNowSelected)
Can be overridden to tell this object that it has just been selected or deselected.
static bool isSelectableValid(const Selectable *) noexcept
checks whether this object has been deleted.
virtual void selectableAboutToBeDeleted()
Called just before the selectable is about to be deleted so any subclasses should still be valid at t...
void cancelAnyPendingUpdates()
If changed() has been called, this will cancel any pending async change notificaions.
virtual juce::String getSelectableDescription()=0
Subclasses must return a description of what they are.
auto makeSafeVector(const Iterable &selectables) -> std::vector< SafeSelectable< typename std::remove_reference< decltype(*selectables[0])>::type > >
Creates a std::vector<SafeSelectable<Something>> for a given juce::Array of selectable objects.
SafeSelectable< SelectableType > makeSafeRef(SelectableType &selectable)
Creates a SafeSelectable for a given selectable object.
A list of Selectables, similar to a juce::Array but contains a cached list of the SelectableClasses f...
std::pair< Selectable *, SelectableClass * > getSelectableAndClass(int index) const
Returns the selectable and it's associated class.
SelectableClass * getSelectableClass(int index) const
Returns the selectable class for a given Selectable in the list.