1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

FileChooser: Ensure that macOS preview component always receives user events

Previously, when a file dialog was launched synchronously, the 'dummy' modal
component was preventing user input events from reaching the preview component.

Now, we explicitly allow input events to reach the file preview component, if
it exists.
This commit is contained in:
reuk 2020-10-19 18:18:04 +01:00
parent dd62aec528
commit fdf09a6dde
2 changed files with 24 additions and 12 deletions

View file

@ -182,7 +182,7 @@ public:
std::unique_ptr<TemporaryMainMenuWithStandardCommands> tempMenu;
if (JUCEApplicationBase::isStandaloneApp())
tempMenu.reset (new TemporaryMainMenuWithStandardCommands());
tempMenu = std::make_unique<TemporaryMainMenuWithStandardCommands> (preview);
jassert (panel != nil);
auto result = [panel runModal];
@ -191,13 +191,7 @@ public:
bool canModalEventBeSentToComponent (const Component* targetComponent) override
{
if (targetComponent == nullptr)
return false;
if (targetComponent == preview)
return true;
return targetComponent->findParentComponentOfClass<FilePreviewComponent>() != nullptr;
return TemporaryMainMenuWithStandardCommands::checkModalEvent (preview, targetComponent);
}
private:

View file

@ -550,8 +550,8 @@ JuceMainMenuHandler* JuceMainMenuHandler::instance = nullptr;
class TemporaryMainMenuWithStandardCommands
{
public:
TemporaryMainMenuWithStandardCommands()
: oldMenu (MenuBarModel::getMacMainMenu())
explicit TemporaryMainMenuWithStandardCommands (FilePreviewComponent* filePreviewComponent)
: oldMenu (MenuBarModel::getMacMainMenu()), dummyModalComponent (filePreviewComponent)
{
if (auto* appleMenu = MenuBarModel::getMacExtraAppleItemsMenu())
oldAppleMenu = std::make_unique<PopupMenu> (*appleMenu);
@ -601,8 +601,17 @@ public:
MenuBarModel::setMacMainMenu (oldMenu, oldAppleMenu.get(), oldRecentItems);
}
static bool checkModalEvent (FilePreviewComponent* preview, const Component* targetComponent)
{
if (targetComponent == nullptr)
return false;
return (targetComponent == preview
|| targetComponent->findParentComponentOfClass<FilePreviewComponent>() != nullptr);
}
private:
MenuBarModel* const oldMenu;
MenuBarModel* const oldMenu = nullptr;
std::unique_ptr<PopupMenu> oldAppleMenu;
String oldRecentItems;
NSInteger editMenuIndex;
@ -615,8 +624,17 @@ private:
// recursive when file dialogs are involved
struct SilentDummyModalComp : public Component
{
SilentDummyModalComp() {}
explicit SilentDummyModalComp (FilePreviewComponent* p)
: preview (p) {}
void inputAttemptWhenModal() override {}
bool canModalEventBeSentToComponent (const Component* targetComponent) override
{
return checkModalEvent (preview, targetComponent);
}
FilePreviewComponent* preview = nullptr;
};
SilentDummyModalComp dummyModalComponent;