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 }; }
118 bool needsAnUpdate =
false, hasNotifiedListenersOfDeletion =
false, isCallingListeners =
false;
120 void sendChangeCallbackToListenersIfNeeded();
137 items.addArray (initialItems);
140 template<
typename SelectableType>
143 items.addArray (initialItems);
146 template<
typename SelectableType>
149 items.addArray (initialItems);
152 template<
typename SelectableType>
155 items.addArray (initialItems.
data(),
static_cast<int> (initialItems.
size()));
168 template <
typename Sub
classType>
174 if (
auto i =
dynamic_cast<SubclassType*
> (s))
180 template <
typename Sub
classType>
181 SubclassType* getFirstOfType()
const
183 return dynamic_cast<SubclassType*
> (items.getFirst());
186 template <
typename Sub
classType>
187 bool containsType()
const
190 if (
dynamic_cast<SubclassType*
> (s) !=
nullptr)
197 int size()
const {
return items.size(); }
198 bool isEmpty()
const {
return items.isEmpty(); }
199 bool isNotEmpty()
const {
return ! isEmpty(); }
201 inline Selectable** begin() {
return items.begin(); }
202 inline Selectable*
const* begin()
const {
return items.begin(); }
203 inline Selectable** end() {
return items.end(); }
204 inline Selectable*
const* end()
const {
return items.end(); }
205 inline Selectable** data() {
return begin(); }
206 inline Selectable*
const* data()
const {
return begin(); }
208 Selectable* operator[] (
int index)
const {
return items[index]; }
209 inline Selectable* getUnchecked (
int index)
const {
return items.getUnchecked (index); }
210 inline Selectable* getFirst()
const {
return items.getFirst(); }
211 inline Selectable* getLast()
const {
return items.getLast(); }
213 template <
class OtherArrayType>
214 inline void addArray (
const OtherArrayType& arrayToAddFrom,
int startIndex = 0,
int numElementsToAdd = -1)
216 classes.clearQuick();
217 items.addArray (arrayToAddFrom, startIndex, numElementsToAdd);
220 template <
class OtherArrayType>
221 inline void mergeArray (
const OtherArrayType& arrayToMergeFrom)
223 classes.clearQuick();
225 for (
auto& s : arrayToMergeFrom)
226 addIfNotAlreadyThere (s);
229 inline void add (
Selectable* newElement) { items.add (newElement); }
230 inline bool addIfNotAlreadyThere (
Selectable* newElement) {
return items.addIfNotAlreadyThere (newElement); }
232 inline void clear() { classes.clear(); items.clear(); }
233 inline void remove (
int indexToRemove) { classes.clearQuick();
return items.remove (indexToRemove); }
234 inline int removeAllInstancesOf (
Selectable* s) { classes.clearQuick();
return items.removeAllInstancesOf (s); }
235 inline Selectable* removeAndReturn (
int indexToRemove) { classes.clearQuick();
return items.removeAndReturn (indexToRemove); }
236 inline bool contains (
Selectable* elementToLookFor)
const {
return items.contains (elementToLookFor); }
237 inline int indexOf (
Selectable* elementToLookFor)
const {
return items.indexOf (elementToLookFor); }
239 template <
class OtherArrayType>
240 inline bool operator== (
const OtherArrayType& other)
const {
return items == other; }
242 template <
class OtherArrayType>
243 inline bool operator!= (
const OtherArrayType& other)
const {
return items != other; }
245 inline bool operator== (
const SelectableList& other)
const {
return items == other.items; }
246 inline bool operator!= (
const SelectableList& other)
const {
return items != other.items; }
263template<
typename SelectableType>
286 SelectableType*
get() const noexcept {
return dynamic_cast<SelectableType*
> (weakRef.get()); }
289 operator SelectableType*()
const noexcept {
return get(); }
294 bool operator== (SelectableType* other)
const noexcept {
return weakRef.get() == other; }
295 bool operator!= (SelectableType* other)
const noexcept {
return weakRef.get() != other; }
297 bool operator== (
const SafeSelectable& other)
const noexcept {
return weakRef.get() == other.weakRef.get(); }
298 bool operator!= (
const SafeSelectable& other)
const noexcept {
return weakRef.get() != other.weakRef.get(); }
300 bool operator== (
const SelectableType& other)
const noexcept {
return weakRef.get() == &other; }
301 bool operator!= (
const SelectableType& other)
const noexcept {
return weakRef.get() != &other; }
303 bool operator== (
decltype(
nullptr)) const noexcept {
return weakRef ==
nullptr; }
304 bool operator!= (
decltype(
nullptr)) const noexcept {
return weakRef !=
nullptr; }
311template<
typename SelectableType>
318template<
typename Iterable>
324 v.reserve (
static_cast<size_t> (selectables.size()));
326 for (
auto* s : selectables)
360 ref->removeSelectableListener (
this);
365 ref->addSelectableListener (
this);
374 void selectableObjectChanged (
Selectable*)
override
376 if (onSelectableChanged)
377 onSelectableChanged();
380 void selectableObjectAboutToBeDeleted (
Selectable*)
override
382 if (onSelectableAboutToBeDeleted)
383 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.