Keep the Run Script dialog in front after its file picker closes on macOS

This commit is contained in:
SoftFever committed 2026-10-31 00:15:14 +08:00
1 parent a4dffc92de
commit 58fee96e30
6 files changed
+30 -21

No files matched your search

@@ -496,16 +496,18 @@ name — for any other window call `window_pos_save/restore` with its own name.
through `EndModal`. The `Raise()` is deferred to run after the modal has fully torn down, and guarded
because the dialog may be destroyed while queued.
```cpp
void PluginsDialog::restore_z_order()
void WebViewHostDialog::restore_z_order()
{
wxGetApp().CallAfter([this, alive = m_alive]() {
if (alive->load(std::memory_order_acquire) && IsShown())
wxGetApp().CallAfter([this, alive = m_host_alive] {
if (alive->load() && IsShown())
Raise();
});
}
```
Cite: 0a0d59b76b (`PluginsDialog::restore_z_order`; also passed as the `restore` callback of
`detail::run_off_thread_with_progress`).
A `WebViewHostDialog` subclass calls the inherited `restore_z_order()` after each such modal, on every
outcome including Cancel.
Cite: 0a0d59b76b (`PluginsDialog`: also passed as the `restore` callback of
`detail::run_off_thread_with_progress`); `ScriptRunnerDialog::open_file`.
- **Rule:** Never position windows by absolute coordinates on Wayland, and never expect `SetIcon` to show on
macOS or Wayland.
-10
View File
@@ -1019,16 +1019,6 @@ void PluginsDialog::handle_plugin_menu_action(const std::string& plugin_key, con
}
}
void PluginsDialog::restore_z_order()
{
// Deferred so it runs on a clean stack after the modal has fully torn down; the
// alive guard covers the dialog being destroyed while the CallAfter is queued.
wxGetApp().CallAfter([this, alive = m_alive]() {
if (alive->load(std::memory_order_acquire) && IsShown())
Raise();
});
}
void PluginsDialog::install_plugin_from_file()
{
wxFileDialog dialog(this, _L("Select plugin package"), wxEmptyString, wxEmptyString, _L("Plugin files (*.py;*.whl)|*.py;*.whl"),
-5
View File
@@ -241,11 +241,6 @@ private:
nlohmann::json localized_strings() const override;
// Runs one web command on a clean main-loop stack; see on_script_message.
void handle_web_command(const nlohmann::json& payload);
// Re-raises this dialog after a transient modal it opened (file dialog, message box,
// progress dialog). Native macOS panels end by re-activating the app's main window
// (the mainframe) instead of this webview-hosting dialog, burying it; wx only
// compensates for generic wxDialog modals (wxDialog::EndModal raises the parent).
void restore_z_order();
void send_plugins();
void set_plugin_sort(const std::string& sort_key, const std::string& sort_order);
+8 -1
View File
@@ -344,7 +344,11 @@ void ScriptRunnerDialog::open_file()
{
wxFileDialog dialog(this, _L("Open a script"), wxEmptyString, wxEmptyString,
format_wxstr("%1% (*.json)|*.json", _L("Script files")), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dialog.ShowModal() != wxID_OK || !m_alive->load())
const int result = dialog.ShowModal();
if (!m_alive->load())
return;
restore_z_order();
if (result != wxID_OK)
return;
const fs::path path = into_path(dialog.GetPath());
boost::nowide::ifstream in(Mcp::path_to_utf8(path).c_str(), std::ios::binary);
@@ -519,6 +523,9 @@ void ScriptRunnerDialog::run(const nlohmann::json& payload)
return;
if (answer == wxID_YES) {
if (plater->save_project() != wxID_YES) {
// Saving a new project asks for a file name in a native panel, which leaves the
// main window in front; the run isn't going ahead, so bring this dialog back.
restore_z_order();
refuse({});
return;
}
@@ -250,6 +250,16 @@ void WebViewHostDialog::call_web_handler(const nlohmann::json& payload, const wx
});
}
void WebViewHostDialog::restore_z_order()
{
// Deferred so it runs on a clean stack after the modal has fully torn down; the
// alive guard covers the dialog being destroyed while the CallAfter is queued.
wxGetApp().CallAfter([this, alive = m_host_alive] {
if (alive->load() && IsShown())
Raise();
});
}
WebViewHostDialog::~WebViewHostDialog() { m_host_alive->store(false); }
bool WebViewHostDialog::handle_common_script_command(const nlohmann::json& payload, int close_return_code)
@@ -78,6 +78,11 @@ protected:
wxString build_resource_url(const std::string& resource_path) const;
bool handle_common_script_command(const nlohmann::json& payload, int close_return_code = wxID_CANCEL);
// Re-raises this dialog after a transient modal it opened (file dialog, message box,
// progress dialog). Native macOS panels end by re-activating the app's main window
// (the mainframe) instead of this webview-hosting dialog, burying it; wx only
// compensates for generic wxDialog modals (wxDialog::EndModal raises the parent).
void restore_z_order();
void on_dpi_changed(const wxRect& suggested_rect) override;