From 98e94c3329b987d23e91e77154d7b81b532eb2a8 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 24 Aug 2022 16:48:23 +0200 Subject: [PATCH] Fix for #8728 - Remember Size/Location of Shape Gallery window box --- src/slic3r/GUI/GUI_App.cpp | 5 +++++ src/slic3r/GUI/GUI_App.hpp | 2 ++ src/slic3r/GUI/GUI_ObjectList.cpp | 11 +++++------ src/slic3r/GUI/GalleryDialog.cpp | 19 ++++++++++++------- src/slic3r/GUI/GalleryDialog.hpp | 4 +++- src/slic3r/GUI/MainFrame.cpp | 14 ++++++++++---- src/slic3r/GUI/MainFrame.hpp | 3 +++ 7 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index ca0b82c9a1..0a13239c81 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2828,6 +2828,11 @@ NotificationManager * GUI_App::notification_manager() return plater_->get_notification_manager(); } +GalleryDialog* GUI_App::gallery_dialog() +{ + return mainframe->gallery_dialog(); +} + // extruders count from selected printer preset int GUI_App::extruders_cnt() const { diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index a5b998fdae..a329995e0c 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -47,6 +47,7 @@ class ObjectLayers; class Plater; class NotificationManager; struct GUI_InitParams; +class GalleryDialog; @@ -296,6 +297,7 @@ public: const Plater* plater() const; Model& model(); NotificationManager * notification_manager(); + GalleryDialog * gallery_dialog(); // Parameters extracted from the command line to be passed to GUI after initialization. GUI_InitParams* init_params { nullptr }; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 6b315bbeba..3627f27dbc 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1409,9 +1409,8 @@ void ObjectList::load_subobject(ModelVolumeType type, bool from_galery/* = false wxArrayString input_files; if (from_galery) { - GalleryDialog dlg(this); - if (dlg.ShowModal() != wxID_CLOSE) - dlg.get_input_files(input_files); + if (wxGetApp().gallery_dialog()->show() != wxID_CLOSE) + wxGetApp().gallery_dialog()->get_input_files(input_files); } else wxGetApp().import_model(wxGetApp().tab_panel()->GetPage(0), input_files); @@ -1737,10 +1736,10 @@ void ObjectList::load_shape_object_from_gallery() return;// Add nothing if something is selected on 3DScene wxArrayString input_files; - GalleryDialog gallery_dlg(this); - if (gallery_dlg.ShowModal() == wxID_CLOSE) + GalleryDialog* gallery_dlg = wxGetApp().gallery_dialog(); + if (gallery_dlg->show() == wxID_CLOSE) return; - gallery_dlg.get_input_files(input_files); + gallery_dlg->get_input_files(input_files); if (input_files.IsEmpty()) return; load_shape_object_from_gallery(input_files); diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp index 6be6a94fed..9dc7dec9f0 100644 --- a/src/slic3r/GUI/GalleryDialog.cpp +++ b/src/slic3r/GUI/GalleryDialog.cpp @@ -65,7 +65,7 @@ bool GalleryDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& f } -GalleryDialog::GalleryDialog(wxWindow* parent, bool modify_gallery/* = false*/) : +GalleryDialog::GalleryDialog(wxWindow* parent) : DPIDialog(parent, wxID_ANY, _L("Shape Gallery"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { #ifndef _WIN32 @@ -94,12 +94,9 @@ GalleryDialog::GalleryDialog(wxWindow* parent, bool modify_gallery/* = false*/) #endif wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK | wxCLOSE); - wxButton* ok_btn = static_cast(FindWindowById(wxID_OK, this)); - ok_btn->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(!m_selected_items.empty()); }); - if (modify_gallery) { - ok_btn->SetLabel(_L("Add to bed")); - ok_btn->SetToolTip(_L("Add selected shape(s) to the bed")); - } + m_ok_btn = static_cast(FindWindowById(wxID_OK, this)); + m_ok_btn->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(!m_selected_items.empty()); }); + static_cast(FindWindowById(wxID_CLOSE, this))->Bind(wxEVT_BUTTON, [this](wxCommandEvent&){ this->EndModal(wxID_CLOSE); }); this->SetEscapeId(wxID_CLOSE); auto add_btn = [this, buttons]( size_t pos, int& ID, wxString title, wxString tooltip, @@ -140,6 +137,14 @@ GalleryDialog::~GalleryDialog() { } +int GalleryDialog::show(bool show_from_menu) +{ + m_ok_btn->SetLabel( show_from_menu ? _L("Add to bed") : _L("OK")); + m_ok_btn->SetToolTip(show_from_menu ? _L("Add selected shape(s) to the bed") : ""); + + return this->ShowModal(); +} + bool GalleryDialog::can_delete() { if (m_selected_items.empty()) diff --git a/src/slic3r/GUI/GalleryDialog.hpp b/src/slic3r/GUI/GalleryDialog.hpp index 2aa04ffa2e..7d56d1af1b 100644 --- a/src/slic3r/GUI/GalleryDialog.hpp +++ b/src/slic3r/GUI/GalleryDialog.hpp @@ -20,6 +20,7 @@ class GalleryDialog : public DPIDialog { wxListCtrl* m_list_ctrl { nullptr }; wxImageList* m_image_list { nullptr }; + wxButton* m_ok_btn { nullptr }; struct Item { std::string name; @@ -48,9 +49,10 @@ class GalleryDialog : public DPIDialog void update(); public: - GalleryDialog(wxWindow* parent, bool modify_gallery = false); + GalleryDialog(wxWindow* parent); ~GalleryDialog(); + int show(bool show_from_menu = false); void get_input_files(wxArrayString& input_files); bool load_files(const wxArrayString& input_files); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 0a716c91cc..04b95da464 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -622,6 +622,13 @@ void MainFrame::shutdown() wxGetApp().plater_ = nullptr; } +GalleryDialog* MainFrame::gallery_dialog() +{ + if (!m_gallery_dialog) + m_gallery_dialog = new GalleryDialog(this); + return m_gallery_dialog; +} + void MainFrame::update_title() { wxString title = wxEmptyString; @@ -1413,11 +1420,10 @@ void MainFrame::init_menubar_as_editor() windowMenu->AppendSeparator(); append_menu_item(windowMenu, wxID_ANY, _L("Shape Gallery"), _L("Open the dialog to modify shape gallery"), - [this](wxCommandEvent&) { - GalleryDialog dlg(this, true); - if (dlg.ShowModal() == wxID_OK) { + [this](wxCommandEvent&) { + if (gallery_dialog()->show(true) == wxID_OK) { wxArrayString input_files; - dlg.get_input_files(input_files); + m_gallery_dialog->get_input_files(input_files); if (!input_files.IsEmpty()) m_plater->sidebar().obj_list()->load_shape_object_from_gallery(input_files); } diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index f385ee8f85..893febf4bd 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -33,6 +33,7 @@ class PrintHostQueueDialog; class Plater; class MainFrame; class PreferencesDialog; +class GalleryDialog; enum QuickSlice { @@ -146,6 +147,7 @@ public: void shutdown(); Plater* plater() { return m_plater; } + GalleryDialog* gallery_dialog(); void update_title(); @@ -207,6 +209,7 @@ public: PreferencesDialog* preferences_dialog { nullptr }; PrintHostQueueDialog* m_printhost_queue_dlg; // std::shared_ptr m_statusbar; + GalleryDialog* m_gallery_dialog{ nullptr }; #ifdef __APPLE__ std::unique_ptr m_taskbar_icon;