mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
Modal component deletion fix. Minor addition to ComponentAnimator.
This commit is contained in:
parent
ae30b5c50a
commit
cdd1778630
6 changed files with 36 additions and 36 deletions
|
|
@ -158,7 +158,7 @@ private:
|
|||
|
||||
File appConfigFile, binaryDataCpp;
|
||||
|
||||
// Recursively clears out a folder's contents, but leaves behind any folders
|
||||
// Recursively clears out a folder's contents, but leaves behind any folders
|
||||
// containing hidden files used by version-control systems.
|
||||
static bool deleteNonHiddenFilesIn (const File& parent)
|
||||
{
|
||||
|
|
@ -193,12 +193,18 @@ private:
|
|||
|
||||
return folderIsNowEmpty;
|
||||
}
|
||||
|
||||
|
||||
static bool shouldFileBeKept (const String& filename)
|
||||
{
|
||||
return filename == ".svn" || filename == ".cvs";
|
||||
const char* filesToKeep = { ".svn", ".cvs", "CMakeLists.txt" };
|
||||
|
||||
for (int i = 0; i < numElementsInArray (filesToKeep); ++i)
|
||||
if (filename == filesToKeep[i])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void writeMainProjectFile()
|
||||
{
|
||||
ScopedPointer <XmlElement> xml (project.getProjectRoot().createXml());
|
||||
|
|
|
|||
|
|
@ -1538,24 +1538,6 @@ int Component::runModalLoop()
|
|||
#endif
|
||||
|
||||
//==============================================================================
|
||||
class ModalAutoDeleteCallback : public ModalComponentManager::Callback
|
||||
{
|
||||
public:
|
||||
ModalAutoDeleteCallback (Component* const comp_)
|
||||
: comp (comp_)
|
||||
{}
|
||||
|
||||
void modalStateFinished (int)
|
||||
{
|
||||
delete comp.get();
|
||||
}
|
||||
|
||||
private:
|
||||
WeakReference<Component> comp;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ModalAutoDeleteCallback);
|
||||
};
|
||||
|
||||
void Component::enterModalState (const bool shouldTakeKeyboardFocus,
|
||||
ModalComponentManager::Callback* callback,
|
||||
const bool deleteWhenDismissed)
|
||||
|
|
@ -1571,12 +1553,9 @@ void Component::enterModalState (const bool shouldTakeKeyboardFocus,
|
|||
if (! isCurrentlyModal())
|
||||
{
|
||||
ModalComponentManager* const mcm = ModalComponentManager::getInstance();
|
||||
mcm->startModal (this);
|
||||
mcm->startModal (this, deleteWhenDismissed);
|
||||
mcm->attachCallback (this, callback);
|
||||
|
||||
if (deleteWhenDismissed)
|
||||
mcm->attachCallback (this, new ModalAutoDeleteCallback (this));
|
||||
|
||||
flags.currentlyModalFlag = true;
|
||||
setVisible (true);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@ BEGIN_JUCE_NAMESPACE
|
|||
class ModalComponentManager::ModalItem : public ComponentMovementWatcher
|
||||
{
|
||||
public:
|
||||
ModalItem (Component* const comp)
|
||||
ModalItem (Component* const comp, const bool autoDelete_)
|
||||
: ComponentMovementWatcher (comp),
|
||||
component (comp), returnValue (0), isActive (true)
|
||||
component (comp), returnValue (0),
|
||||
isActive (true), autoDelete (autoDelete_)
|
||||
{
|
||||
jassert (comp != nullptr);
|
||||
}
|
||||
|
|
@ -55,7 +56,10 @@ public:
|
|||
ComponentMovementWatcher::componentBeingDeleted (comp);
|
||||
|
||||
if (component == &comp || comp.isParentOf (component))
|
||||
{
|
||||
autoDelete = false;
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void cancel()
|
||||
|
|
@ -70,7 +74,7 @@ public:
|
|||
Component* component;
|
||||
OwnedArray<Callback> callbacks;
|
||||
int returnValue;
|
||||
bool isActive;
|
||||
bool isActive, autoDelete;
|
||||
|
||||
private:
|
||||
JUCE_DECLARE_NON_COPYABLE (ModalItem);
|
||||
|
|
@ -90,10 +94,10 @@ juce_ImplementSingleton_SingleThreaded (ModalComponentManager);
|
|||
|
||||
|
||||
//==============================================================================
|
||||
void ModalComponentManager::startModal (Component* component)
|
||||
void ModalComponentManager::startModal (Component* component, bool autoDelete)
|
||||
{
|
||||
if (component != nullptr)
|
||||
stack.add (new ModalItem (component));
|
||||
stack.add (new ModalItem (component, autoDelete));
|
||||
}
|
||||
|
||||
void ModalComponentManager::attachCallback (Component* component, Callback* callback)
|
||||
|
|
@ -191,9 +195,12 @@ void ModalComponentManager::handleAsyncUpdate()
|
|||
if (! item->isActive)
|
||||
{
|
||||
ScopedPointer<ModalItem> deleter (stack.removeAndReturn (i));
|
||||
Component::SafePointer<Component> compToDelete (item->autoDelete ? item->component : nullptr);
|
||||
|
||||
for (int j = item->callbacks.size(); --j >= 0;)
|
||||
item->callbacks.getUnchecked(j)->modalStateFinished (item->returnValue);
|
||||
|
||||
compToDelete.deleteAndZero();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ private:
|
|||
friend class OwnedArray <ModalItem>;
|
||||
OwnedArray <ModalItem> stack;
|
||||
|
||||
void startModal (Component*);
|
||||
void startModal (Component*, bool autoDelete);
|
||||
void endModal (Component*, int returnValue);
|
||||
void endModal (Component*);
|
||||
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ ComponentAnimator::~ComponentAnimator()
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
ComponentAnimator::AnimationTask* ComponentAnimator::findTaskFor (Component* const component) const
|
||||
ComponentAnimator::AnimationTask* ComponentAnimator::findTaskFor (Component* const component) const noexcept
|
||||
{
|
||||
for (int i = tasks.size(); --i >= 0;)
|
||||
if (component == tasks.getUnchecked(i)->component.get())
|
||||
|
|
@ -308,11 +308,16 @@ const Rectangle<int> ComponentAnimator::getComponentDestination (Component* cons
|
|||
return component->getBounds();
|
||||
}
|
||||
|
||||
bool ComponentAnimator::isAnimating (Component* component) const
|
||||
bool ComponentAnimator::isAnimating (Component* component) const noexcept
|
||||
{
|
||||
return findTaskFor (component) != nullptr;
|
||||
}
|
||||
|
||||
bool ComponentAnimator::isAnimating() const noexcept
|
||||
{
|
||||
return tasks.size() != 0;
|
||||
}
|
||||
|
||||
void ComponentAnimator::timerCallback()
|
||||
{
|
||||
const uint32 timeNow = Time::getMillisecondCounter();
|
||||
|
|
|
|||
|
|
@ -143,7 +143,10 @@ public:
|
|||
const Rectangle<int> getComponentDestination (Component* component);
|
||||
|
||||
/** Returns true if the specified component is currently being animated. */
|
||||
bool isAnimating (Component* component) const;
|
||||
bool isAnimating (Component* component) const noexcept;
|
||||
|
||||
/** Returns true if any components are currently being animated. */
|
||||
bool isAnimating() const noexcept;
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
|
|
@ -151,7 +154,7 @@ private:
|
|||
OwnedArray <AnimationTask> tasks;
|
||||
uint32 lastTime;
|
||||
|
||||
AnimationTask* findTaskFor (Component* component) const;
|
||||
AnimationTask* findTaskFor (Component* component) const noexcept;
|
||||
void timerCallback();
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComponentAnimator);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue