mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
PopupMenu: Avoid giving focus back to previous component on dismiss
This change is designed to fix issues with views stealing focus and being brought to the front when popup menus are dismissed. To test this behaviour: - Open two instances "a" and "b" of a plugin editor containing a ComboBox - Click the ComboBox in editor "a", opening its PopupMenu - Drag the titlebar of editor "b" to move it - The PopupMenu should be dismissed, but editor "a" should *not* steal keyboard focus or be brought to the front
This commit is contained in:
parent
f562517939
commit
c2f661171a
1 changed files with 12 additions and 21 deletions
|
|
@ -2013,38 +2013,29 @@ struct PopupMenuCompletionCallback : public ModalComponentManager::Callback
|
|||
if (PopupMenuSettings::menuWasHiddenBecauseOfAppChange)
|
||||
return;
|
||||
|
||||
auto* focusComponent = getComponentToPassFocusTo();
|
||||
|
||||
const auto focusedIsNotMinimised = [focusComponent]
|
||||
if (auto* focusComponent = Component::getCurrentlyFocusedComponent())
|
||||
{
|
||||
if (focusComponent != nullptr)
|
||||
const auto focusedIsNotMinimised = [focusComponent]
|
||||
{
|
||||
if (auto* peer = focusComponent->getPeer())
|
||||
return ! peer->isMinimised();
|
||||
|
||||
return false;
|
||||
}();
|
||||
return false;
|
||||
}();
|
||||
|
||||
if (focusedIsNotMinimised)
|
||||
{
|
||||
if (auto* topLevel = focusComponent->getTopLevelComponent())
|
||||
topLevel->toFront (true);
|
||||
if (focusedIsNotMinimised)
|
||||
{
|
||||
if (auto* topLevel = focusComponent->getTopLevelComponent())
|
||||
topLevel->toFront (true);
|
||||
|
||||
if (focusComponent->isShowing() && ! focusComponent->hasKeyboardFocus (true))
|
||||
focusComponent->grabKeyboardFocus();
|
||||
if (focusComponent->isShowing() && ! focusComponent->hasKeyboardFocus (true))
|
||||
focusComponent->grabKeyboardFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component* getComponentToPassFocusTo() const
|
||||
{
|
||||
if (auto* current = Component::getCurrentlyFocusedComponent())
|
||||
return current;
|
||||
|
||||
return prevFocused.get();
|
||||
}
|
||||
|
||||
ApplicationCommandManager* managerOfChosenCommand = nullptr;
|
||||
std::unique_ptr<Component> component;
|
||||
WeakReference<Component> prevFocused { Component::getCurrentlyFocusedComponent() };
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE (PopupMenuCompletionCallback)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue