From 09aa257c762da11845de8f136f8645f4eeeb9aa5 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Sat, 7 Nov 2026 12:41:59 +0800 Subject: [PATCH] Let install_local_plugin take a plugin file's path --- docs/HLSD/mcp-server.md | 1 + src/slic3r/GUI/GUI_App.cpp | 24 ----------------------- src/slic3r/GUI/GUI_App.hpp | 3 +-- src/slic3r/GUI/NativeCommands.cpp | 32 +++++++++++++++++++++++++++---- src/slic3r/GUI/PluginsDialog.cpp | 12 +++++++----- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/docs/HLSD/mcp-server.md b/docs/HLSD/mcp-server.md index 7f8ea3b0ad..6e4a5b8af2 100644 --- a/docs/HLSD/mcp-server.md +++ b/docs/HLSD/mcp-server.md @@ -1319,6 +1319,7 @@ turns a bad path into an Error result. | `export_stl_multi` | existing directory | `Plater::export_stl(..., multiple, dir)` | | `add_primitive_svg` | `.svg` | `GLGizmoSVG::create_volume(path, type)`: a new object, or a part of the selected one; a job | | `export_config` | existing directory | `ExportConfigsDialog(parent, dir)`: the dialog still opens, and its OK writes there | +| `install_local_plugin` | `.py`, `.whl` | `install_local_plugin_package(path, parent, message)`, the Plugins dialog's install: it still asks before replacing an installed plugin, in Orca's own "Overwrite Plugin" message dialog, which `dialog_respond` answers on every platform. Cancel makes the command an error saying that the plugin was not installed. A file that is not a `.py` or `.whl` is refused before that. A package that does not install is an Error. | The six shape commands (`add_primitive_cube`, `_cylinder`, `_sphere`, `_cone`, `_disc`, `_torus`) take a `Text` param, the size the Primitive size dialog asks for (`"40 40 10"`, `"90 4"`), and then diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 6979bb1e2b..f822413ec0 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -9217,30 +9217,6 @@ void GUI_App::refresh_plugins() }).detach(); } -void GUI_App::install_local_plugin() -{ - if (mainframe == nullptr) - return; - - wxFileDialog dialog(mainframe, _L("Select plugin package"), wxEmptyString, wxEmptyString, _L("Plugin files (*.py;*.whl)|*.py;*.whl"), - wxFD_OPEN | wxFD_FILE_MUST_EXIST); - if (dialog.ShowModal() != wxID_OK) - return; - - wxString message; - const bool ok = install_local_plugin_package(boost::filesystem::path(dialog.GetPath().ToUTF8().data()), mainframe, message); - if (message.IsEmpty()) - return; // user cancelled the overwrite prompt - - Plater* plater = this->plater(); - if (plater == nullptr) - return; - plater->get_notification_manager()->push_notification( - NotificationType::CustomNotification, - ok ? NotificationManager::NotificationLevel::RegularNotificationLevel : NotificationManager::NotificationLevel::ErrorNotificationLevel, - into_u8(message)); -} - void GUI_App::open_terminal_dialog() { // Reached from the plugins dialog's webview ("open_terminal" command), i.e. from diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 47a02b0c77..af8bf7e7cf 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -755,9 +755,8 @@ public: // Called on the GUI thread after an audit prompt stores a grant outside the Plugins dialog. // Refreshes an existing dialog instance; never creates or raises it. void notify_plugin_permissions_changed(const std::string& plugin_key); - // Dialog-free plugin actions used by the speed dial: they never require the Plugins dialog to be open. + // Dialog-free plugin action used by the speed dial: it never requires the Plugins dialog to be open. void refresh_plugins(); - void install_local_plugin(); void open_terminal_dialog(); void open_speed_dial(); ActionRegistry& action_registry() { return *m_action_registry; } diff --git a/src/slic3r/GUI/NativeCommands.cpp b/src/slic3r/GUI/NativeCommands.cpp index b379ec9e8d..e637d15a4f 100644 --- a/src/slic3r/GUI/NativeCommands.cpp +++ b/src/slic3r/GUI/NativeCommands.cpp @@ -77,6 +77,7 @@ #include #include +#include #include #include #include @@ -619,7 +620,10 @@ void describe_commands(std::vector& commands) {"open_plugins", "Open the plugins dialog."}, {"refresh_plugins", "Reload plugins."}, {"install_plugin", "Open the plugin hub to install a plugin."}, - {"install_local_plugin", "Install a plugin from a local file (opens a file dialog)."}, + {"install_local_plugin", "Install a plugin from a .py or .whl file, as the Plugins dialog's Install local plugin does. With a " + "path, installs that file without a dialog. Replacing a plugin installed already asks first " + "(answer with dialog_respond); the message names the plugin installed, or why it was not.", + CommandParamType::Path, "absolute path of a .py or .whl plugin package"}, // Filament slots {"filament_add", "Add a filament slot, as the + button above the filament list does; the message names the new slot. It " "takes the next colour and the last slot's preset (change them with select_preset filament_slot and " @@ -1561,9 +1565,29 @@ std::vector build_command_catalog() open_plugin_hub(); return AppActionRunResult{AppActionRunResult::Level::Success}; }); - add("install_local_plugin", L("Install Local Plugin"), L("Plugins"), [](const std::string&) { - wxGetApp().install_local_plugin(); - return AppActionRunResult{AppActionRunResult::Level::Success}; + add("install_local_plugin", L("Install Local Plugin"), L("Plugins"), [](const std::string& param) { + MainFrame* mf = wxGetApp().mainframe; + if (mf == nullptr) + return AppActionRunResult{}; + boost::filesystem::path package; + if (param.empty()) { + wxFileDialog dialog(mf, _L("Select plugin package"), wxEmptyString, wxEmptyString, _L("Plugin files (*.py;*.whl)|*.py;*.whl"), + wxFD_OPEN | wxFD_FILE_MUST_EXIST); + if (dialog.ShowModal() != wxID_OK) + return AppActionRunResult{AppActionRunResult::Level::Success}; + package = into_path(dialog.GetPath()); + } else { + AppActionRunResult fail; + const auto path = path_param(param, false, fail); + if (!path) + return fail; + package = *path; + } + wxString message; + const bool installed = install_local_plugin_package(package, mf, message); + if (message.IsEmpty()) // the overwrite prompt was cancelled + return AppActionRunResult{AppActionRunResult::Level::Info, _L("The plugin was not installed."), false}; + return AppActionRunResult{installed ? AppActionRunResult::Level::Success : AppActionRunResult::Level::Error, message}; }); describe_commands(out); diff --git a/src/slic3r/GUI/PluginsDialog.cpp b/src/slic3r/GUI/PluginsDialog.cpp index 0f0f8fcf79..b29e368be4 100644 --- a/src/slic3r/GUI/PluginsDialog.cpp +++ b/src/slic3r/GUI/PluginsDialog.cpp @@ -583,11 +583,13 @@ bool install_local_plugin_package(const boost::filesystem::path& package_file, w if (existing_installation) { const wxString plugin_name = from_u8(plugin_descriptor.name.empty() ? package_file.filename().string() : plugin_descriptor.name); - wxMessageDialog dialog(parent, - wxString::Format(_L("Plugin \"%s\" is already installed.\n\nInstalling this package will overwrite the existing plugin."), - plugin_name), - kOverwritePluginTitle, wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxICON_WARNING); - dialog.SetOKCancelLabels(_L("Overwrite"), _L("Cancel")); + // Orca's own message dialog rather than a native box, which dialog_respond can't press on every platform. + MessageDialog dialog(parent, + wxString::Format(_L("Plugin \"%s\" is already installed.\n\nInstalling this package will overwrite the existing plugin."), + plugin_name), + kOverwritePluginTitle, wxOK | wxCANCEL | wxICON_WARNING); + dialog.SetButtonLabel(wxID_OK, _L("Overwrite")); + dialog.SetButtonLabel(wxID_CANCEL, _L("Cancel"), /*set_focus=*/true); if (dialog.ShowModal() != wxID_OK) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Plugin package installation cancelled before overwrite. package=" << package_file << " plugin=" << plugin_descriptor.name;