mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-28 08:09:55 -05:00
fix: warn on preset save when plugin not found (#16929)
* fix: warn on preset save when plugin not found * refactor: build the unsaved-changes save config in one place * Fixes clang-tidy --------- Co-authored-by: Lam Wei Lun <weilun.lam@gmail.com>
This commit is contained in:
1 parent
3322f6101c
commit
3a0517831f
15 files changed
+411
-66
No files matched your search
@@ -2,12 +2,17 @@
|
||||
#include "GUI_Utils.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "MsgDialog.hpp"
|
||||
#include "format.hpp"
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "slic3r/Utils/NetworkAgentFactory.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <wx/event.h>
|
||||
@@ -47,8 +52,6 @@
|
||||
#include <wx/display.h>
|
||||
#include <wx/utils.h>
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
@@ -230,6 +233,122 @@ void open_ms_store_product_page()
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// True when this unresolved value is worth warning about. printer_agent also stores ids of
|
||||
// built-in agents (Orca, Bambu Lab, Qidi, ...): those are not plugin capabilities, so the resolver
|
||||
// cannot map them and they need no manifest reference. Only a plugin-provided agent that is
|
||||
// unavailable is reportable.
|
||||
bool is_reportable_unresolved_plugin(const UnresolvedPluginCapability& item)
|
||||
{
|
||||
if (item.opt_key != "printer_agent")
|
||||
return true;
|
||||
const PrinterAgentInfo* agent = NetworkAgentFactory::get_printer_agent_info(item.capability_name);
|
||||
return agent == nullptr || agent->is_plugin();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool has_unresolved_plugin_capabilities(const ConfigBase& config)
|
||||
{
|
||||
for (const UnresolvedPluginCapability& item : config.unresolved_plugin_capabilities())
|
||||
if (is_reportable_unresolved_plugin(item))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Appends one row per unresolved plugin-backed value. `preset_name` is empty for a single-preset
|
||||
// or project warning and set when several presets are reported together. Returns true if any row
|
||||
// was appended, so a batch whose entries are all built-in printer agents stays silent.
|
||||
bool append_unresolved_plugin_rows(const ConfigBase& config, const wxString& preset_name, wxString& rows)
|
||||
{
|
||||
const std::vector<UnresolvedPluginCapability> unresolved = config.unresolved_plugin_capabilities();
|
||||
if (unresolved.empty())
|
||||
return false;
|
||||
|
||||
const ConfigDef* def = config.def();
|
||||
bool appended = false;
|
||||
for (const UnresolvedPluginCapability& item : unresolved) {
|
||||
if (!is_reportable_unresolved_plugin(item))
|
||||
continue;
|
||||
|
||||
const ConfigOptionDef* opt_def = def != nullptr ? def->get(item.opt_key) : nullptr;
|
||||
wxString label = opt_def != nullptr && !opt_def->label.empty() ? _L(opt_def->label) : from_u8(item.opt_key);
|
||||
wxString value = from_u8(item.capability_name);
|
||||
// The message is rendered as a Label, where '&' introduces a mnemonic. Escape both the
|
||||
// translated label and the stored value.
|
||||
label.Replace("&", "&&");
|
||||
value.Replace("&", "&&");
|
||||
if (!rows.IsEmpty())
|
||||
rows += "\n";
|
||||
if (preset_name.IsEmpty()) {
|
||||
// TRN %1% is a setting's label and %2% the plugin capability name stored in that setting.
|
||||
rows += format_wxstr(_L("• %1%: %2%"), label, value);
|
||||
} else {
|
||||
wxString escaped_name = preset_name;
|
||||
escaped_name.Replace("&", "&&");
|
||||
// TRN %1% is a preset name, %2% a setting's label and %3% the plugin capability name.
|
||||
rows += format_wxstr(_L("• %1% — %2%: %3%"), escaped_name, label, value);
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(warning) << "Unresolved plugin capability on save: " << item.opt_key
|
||||
<< " = " << item.capability_name;
|
||||
appended = true;
|
||||
}
|
||||
return appended;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool confirm_save_with_unresolved_plugins(wxWindow* parent, const ConfigBase& config, SaveSubject subject)
|
||||
{
|
||||
wxString rows;
|
||||
if (!append_unresolved_plugin_rows(config, wxString(), rows))
|
||||
return true;
|
||||
|
||||
// TRN %1% is the list of affected settings built above, one "label: value" per line.
|
||||
const wxString message =
|
||||
subject == SaveSubject::Preset
|
||||
? format_wxstr(_L("The following settings refer to plugins Orca Slicer can't identify on this computer:\n\n%1%\n\n"
|
||||
"If you save anyway, the preset won't keep the plugin references for these settings. On another computer, "
|
||||
"Orca Slicer won't know which plugins to offer, and the settings may not work there."),
|
||||
rows)
|
||||
: format_wxstr(_L("The following settings refer to plugins Orca Slicer can't identify on this computer:\n\n%1%\n\n"
|
||||
"If you save anyway, the project won't keep the plugin references for these settings. On another computer, "
|
||||
"Orca Slicer won't know which plugins to offer, and the settings may not work there."),
|
||||
rows);
|
||||
|
||||
MessageDialog dlg(parent, message, _L("Plugin Not Identified"), wxOK | wxCANCEL | wxICON_WARNING);
|
||||
dlg.SetButtonLabel(wxID_OK, _L("Save anyway"));
|
||||
dlg.SetButtonLabel(wxID_CANCEL, _L("Cancel"), true); // the safe choice gets the focus
|
||||
return dlg.ShowModal() == wxID_OK;
|
||||
}
|
||||
|
||||
bool confirm_save_presets_with_unresolved_plugins(wxWindow* parent, const std::vector<SaveConfigToCheck>& configs)
|
||||
{
|
||||
wxString rows;
|
||||
bool any = false;
|
||||
for (const SaveConfigToCheck& entry : configs)
|
||||
if (entry.config != nullptr && append_unresolved_plugin_rows(*entry.config, entry.name, rows))
|
||||
any = true;
|
||||
if (!any)
|
||||
return true;
|
||||
|
||||
// TRN %1% is the list of affected presets and settings built above, one "preset — setting: value" per line.
|
||||
const wxString message = format_wxstr(
|
||||
_L("The presets being saved refer to plugins Orca Slicer can't identify on this computer:\n\n%1%\n\n"
|
||||
"If you save anyway, the presets won't keep the plugin references for these settings. On another computer, "
|
||||
"Orca Slicer won't know which plugins to offer, and the settings may not work there."),
|
||||
rows);
|
||||
|
||||
MessageDialog dlg(parent, message, _L("Plugin Not Identified"), wxOK | wxCANCEL | wxICON_WARNING);
|
||||
dlg.SetButtonLabel(wxID_OK, _L("Save anyway"));
|
||||
dlg.SetButtonLabel(wxID_CANCEL, _L("Cancel"), true); // the safe choice gets the focus
|
||||
return dlg.ShowModal() == wxID_OK;
|
||||
}
|
||||
|
||||
// If called with nullptr, a DPI for the primary monitor is returned.
|
||||
int get_dpi_for_window(const wxWindow *window)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user