This commit is contained in:
yw4z
2026-09-07 13:16:31 +03:00
parent 886d43d37a
commit 8740696e75
6 changed files with 111 additions and 127 deletions
+56 -25
View File
@@ -9,12 +9,16 @@
#include "GUI.hpp"
#include "I18N.hpp"
#include "GUI_App.hpp"
#include "Widgets/DialogButtons.hpp"
namespace Slic3r { namespace GUI {
PluginPickerDialog::PluginPickerDialog(wxWindow* parent,
const wxString& plugin_type_label,
const std::vector<Slic3r::PluginDescriptor>& plugins)
: wxDialog(parent, wxID_ANY, wxString::Format(_L("Select %s Plugin"), plugin_type_label))
: DPIDialog(parent, wxID_ANY, wxString::Format(_L("Select %s Plugin"), plugin_type_label))
, m_plugins(plugins)
, m_capability_mode(false)
{
@@ -25,7 +29,7 @@ PluginPickerDialog::PluginPickerDialog(wxWindow* parent,
PluginPickerDialog::PluginPickerDialog(wxWindow* parent,
const wxString& plugin_type_label,
std::vector<CapabilityEntry> capabilities)
: wxDialog(parent, wxID_ANY, wxString::Format(_L("Select %s Plugin"), plugin_type_label))
: DPIDialog(parent, wxID_ANY, wxString::Format(_L("Select %s Plugin"), plugin_type_label))
, m_capabilities(std::move(capabilities))
, m_capability_mode(true)
{
@@ -35,12 +39,18 @@ PluginPickerDialog::PluginPickerDialog(wxWindow* parent,
void PluginPickerDialog::build_ui(const wxString& plugin_type_label)
{
SetBackgroundColour(*wxWHITE);
const bool has_plugins = !m_plugins.empty();
auto* top_sizer = new wxBoxSizer(wxVERTICAL);
auto* info_text = new wxStaticText(this, wxID_ANY,
wxString::Format(_L("Choose a %s plugin from the list below."), plugin_type_label));
top_sizer->Add(info_text, 0, wxALL | wxEXPAND, 10);
info_text->SetFont(Label::Body_14);
info_text->SetForegroundColour(wxColour("#363636"));
top_sizer->Add(info_text, 0, wxALL | wxEXPAND, FromDIP(10));
top_sizer->AddSpacer(FromDIP(5));
wxArrayString choices;
choices.reserve(m_plugins.size());
@@ -51,54 +61,69 @@ void PluginPickerDialog::build_ui(const wxString& plugin_type_label)
choices.Add(label);
}
m_choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
m_choice = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY);
for (const wxString &opt : choices) { m_choice->Append(opt); }
if (has_plugins) {
m_choice->SetSelection(0);
m_choice->Bind(wxEVT_CHOICE, [this](wxCommandEvent& evt) {
m_choice->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) {
update_description(evt.GetSelection());
});
} else {
m_choice->Enable(false);
}
top_sizer->Add(m_choice, 0, wxLEFT | wxRIGHT | wxEXPAND, 10);
top_sizer->Add(m_choice, 0, wxLEFT | wxRIGHT | wxEXPAND, FromDIP(10));
m_description = new wxStaticText(this, wxID_ANY, wxEmptyString);
m_description->SetFont(Label::Body_14);
m_description->SetForegroundColour(wxColour("#363636"));
m_description->Wrap(400);
top_sizer->Add(m_description, 0, wxALL | wxEXPAND, 10);
top_sizer->Add(m_description, 0, wxALL | wxEXPAND, FromDIP(10));
if (has_plugins)
update_description(0);
else
m_description->SetLabel(_L("No plugins found for this type."));
auto* button_sizer = new wxStdDialogButtonSizer();
auto* ok_button = new wxButton(this, wxID_OK);
ok_button->Enable(has_plugins);
button_sizer->AddButton(ok_button);
button_sizer->AddButton(new wxButton(this, wxID_CANCEL));
button_sizer->Realize();
auto dlg_btns = new DialogButtons(this, {"OK", "Cancel"});
top_sizer->Add(button_sizer, 0, wxALL | wxALIGN_RIGHT, 10);
dlg_btns->GetOK()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { EndModal(wxID_OK); });
dlg_btns->GetOK()->Enable(has_plugins);
dlg_btns->GetCANCEL()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { EndModal(wxID_CANCEL); });
top_sizer->Add(dlg_btns, 0, wxEXPAND);
SetSizerAndFit(top_sizer);
wxGetApp().UpdateDlgDarkUI(this);
}
void PluginPickerDialog::build_capability_ui(const wxString& plugin_type_label)
{
SetBackgroundColour(*wxWHITE);
const bool has_capabilities = !m_capabilities.empty();
auto* top_sizer = new wxBoxSizer(wxVERTICAL);
auto* info_text = new wxStaticText(this, wxID_ANY,
wxString::Format(_L("Choose a %s plugin from the list below."), plugin_type_label));
top_sizer->Add(info_text, 0, wxALL | wxEXPAND, 10);
info_text->SetFont(Label::Body_14);
info_text->SetForegroundColour(wxColour("#363636"));
top_sizer->Add(info_text, 0, wxALL | wxEXPAND, FromDIP(10));
top_sizer->AddSpacer(FromDIP(5));
wxArrayString choices;
choices.reserve(m_capabilities.size());
for (const auto& cap : m_capabilities)
choices.Add(cap.label);
m_choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
m_choice = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY);
for (const wxString &opt : choices) { m_choice->Append(opt); }
if (has_capabilities) {
m_choice->SetSelection(0);
m_choice->Bind(wxEVT_CHOICE, [this](wxCommandEvent& evt) {
@@ -108,27 +133,31 @@ void PluginPickerDialog::build_capability_ui(const wxString& plugin_type_label)
m_choice->Enable(false);
}
top_sizer->Add(m_choice, 0, wxLEFT | wxRIGHT | wxEXPAND, 10);
top_sizer->Add(m_choice, 0, wxLEFT | wxRIGHT | wxEXPAND, FromDIP(10));
m_description = new wxStaticText(this, wxID_ANY, wxEmptyString);
m_description->SetFont(Label::Body_14);
m_description->SetForegroundColour(wxColour("#363636"));
m_description->Wrap(400);
top_sizer->Add(m_description, 0, wxALL | wxEXPAND, 10);
top_sizer->Add(m_description, 0, wxALL | wxEXPAND, FromDIP(10));
if (has_capabilities)
update_capability_description(0);
else
m_description->SetLabel(_L("No plugins found for this type."));
auto* button_sizer = new wxStdDialogButtonSizer();
auto* ok_button = new wxButton(this, wxID_OK);
ok_button->Enable(has_capabilities);
button_sizer->AddButton(ok_button);
button_sizer->AddButton(new wxButton(this, wxID_CANCEL));
button_sizer->Realize();
auto dlg_btns = new DialogButtons(this, {"OK", "Cancel"});
top_sizer->Add(button_sizer, 0, wxALL | wxALIGN_RIGHT, 10);
dlg_btns->GetOK()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { EndModal(wxID_OK); });
dlg_btns->GetOK()->Enable(has_capabilities);
dlg_btns->GetCANCEL()->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { EndModal(wxID_CANCEL); });
top_sizer->Add(dlg_btns, 0, wxEXPAND);
SetSizerAndFit(top_sizer);
wxGetApp().UpdateDlgDarkUI(this);
}
PluginPickerDialog::CapabilityEntry PluginPickerDialog::selected_capability() const
@@ -187,4 +216,6 @@ void PluginPickerDialog::update_description(int selection)
Layout();
}
void PluginPickerDialog::on_dpi_changed(const wxRect &suggested_rect) {}
}} // namespace Slic3r::GUI