diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 7aad4666a8..9d2cb256ab 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -284,6 +284,10 @@ void AppConfig::set_defaults() if (get("mouse_wheel").empty()) { set("mouse_wheel", "0"); } + + if (get("max_recent_count").empty()) { + set("max_recent_count", "18"); + } if (get("staff_pick_switch").empty()) { set_bool("staff_pick_switch", true); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index fe490c1053..8b0cbc3c42 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -178,6 +178,10 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ wxGetApp().app_config->set_bool("dump_video", false); + wxString max_recent_count_str = wxGetApp().app_config->get("max_recent_count"); + long max_recent_count = 18; + if (max_recent_count_str.ToLong(&max_recent_count)) + set_max_recent_count((int)max_recent_count); //reset log level auto loglevel = wxGetApp().app_config->get("severity_level"); @@ -2498,6 +2502,23 @@ void MainFrame::show_publish_button(bool show) } } +void MainFrame::set_max_recent_count(int max) +{ + max = max < 0 ? 0 : max > 10000 ? 10000 : max; + size_t count = m_recent_projects.GetCount(); + m_recent_projects.SetMaxFiles(max); + if (count != m_recent_projects.GetCount()) { + count = m_recent_projects.GetCount(); + std::vector recent_projects; + for (size_t i = 0; i < count; ++i) { + recent_projects.push_back(into_u8(m_recent_projects.GetHistoryFile(i))); + } + wxGetApp().app_config->set_recent_projects(recent_projects); + wxGetApp().app_config->save(); + m_webview->SendRecentList(""); + } +} + void MainFrame::open_menubar_item(const wxString& menu_name,const wxString& item_name) { if (m_menubar == nullptr) @@ -3007,6 +3028,14 @@ void MainFrame::FileHistory::LoadThumbnails() m_load_called = true; } +inline void MainFrame::FileHistory::SetMaxFiles(int max) +{ + m_fileMaxFiles = max; + size_t numFiles = m_fileHistory.size(); + while (numFiles > m_fileMaxFiles) + RemoveFileFromHistory(--numFiles); +} + void MainFrame::get_recent_projects(boost::property_tree::wptree &tree) { for (size_t i = 0; i < m_recent_projects.GetCount(); ++i) { diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 58ed9314c4..437a9079cb 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -154,6 +154,8 @@ class MainFrame : public DPIFrame size_t FindFileInHistory(const wxString &file); void LoadThumbnails(); + + void SetMaxFiles(int max); private: std::deque m_thumbnails; bool m_load_called = false; @@ -243,6 +245,7 @@ public: void update_title(); void show_publish_button(bool show); + void set_max_recent_count(int max); void update_title_colour_after_set_title(); void show_option(bool show); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 6a4eaaa45b..fac62a3f54 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -378,6 +378,51 @@ wxBoxSizer *PreferencesDialog::create_item_multiple_combobox( return m_sizer_tcombox; } +wxBoxSizer *PreferencesDialog::create_item_input(wxString title, wxString title2, wxWindow *parent, wxString tooltip, std::string param, std::function onchange) +{ + wxBoxSizer *sizer_input = new wxBoxSizer(wxHORIZONTAL); + auto input_title = new wxStaticText(parent, wxID_ANY, title); + input_title->SetForegroundColour(DESIGN_GRAY900_COLOR); + input_title->SetFont(::Label::Body_13); + input_title->SetToolTip(tooltip); + input_title->Wrap(-1); + + auto input = new ::TextInput(parent, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, DESIGN_INPUT_SIZE, wxTE_PROCESS_ENTER); + StateColor input_bg(std::pair(wxColour("#F0F0F1"), StateColor::Disabled), std::pair(*wxWHITE, StateColor::Enabled)); + input->SetBackgroundColor(input_bg); + input->GetTextCtrl()->SetValue(app_config->get(param)); + + auto second_title = new wxStaticText(parent, wxID_ANY, title2, wxDefaultPosition, DESIGN_TITLE_SIZE, 0); + second_title->SetForegroundColour(DESIGN_GRAY900_COLOR); + second_title->SetFont(::Label::Body_13); + second_title->SetToolTip(tooltip); + second_title->Wrap(-1); + + sizer_input->Add(0, 0, 0, wxEXPAND | wxLEFT, 23); + sizer_input->Add(input_title, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3); + sizer_input->Add(input, 0, wxALIGN_CENTER_VERTICAL, 0); + sizer_input->Add(0, 0, 0, wxEXPAND | wxLEFT, 3); + sizer_input->Add(second_title, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3); + + input->GetTextCtrl()->Bind(wxEVT_TEXT_ENTER, [this, param, input, onchange](wxCommandEvent &e) { + auto value = input->GetTextCtrl()->GetValue(); + app_config->set(param, std::string(value.mb_str())); + app_config->save(); + onchange(value); + e.Skip(); + }); + + input->GetTextCtrl()->Bind(wxEVT_KILL_FOCUS, [this, param, input, onchange](wxFocusEvent &e) { + auto value = input->GetTextCtrl()->GetValue(); + app_config->set(param, std::string(value.mb_str())); + app_config->save(); + onchange(value); + e.Skip(); + }); + + return sizer_input; +} + wxBoxSizer *PreferencesDialog::create_item_backup_input(wxString title, wxWindow *parent, wxString tooltip, std::string param) { wxBoxSizer *m_sizer_input = new wxBoxSizer(wxHORIZONTAL); @@ -400,10 +445,10 @@ wxBoxSizer *PreferencesDialog::create_item_backup_input(wxString title, wxWindow second_title->Wrap(-1); m_sizer_input->Add(0, 0, 0, wxEXPAND | wxLEFT, 23); - m_sizer_input->Add(input_title, 0, wxALIGN_CENTER | wxALL, 3); - m_sizer_input->Add(input, 0, wxALIGN_CENTER, 0); + m_sizer_input->Add(input_title, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3); + m_sizer_input->Add(input, 0, wxALIGN_CENTER_VERTICAL, 0); m_sizer_input->Add(0, 0, 0, wxEXPAND | wxLEFT, 3); - m_sizer_input->Add(second_title, 0, wxALIGN_CENTER| wxALL, 3); + m_sizer_input->Add(second_title, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3); input->GetTextCtrl()->Bind(wxEVT_COMMAND_TEXT_UPDATED, [this, param, input](wxCommandEvent &e) { @@ -856,10 +901,15 @@ wxWindow* PreferencesDialog::create_general_page() auto item_modelmall = create_item_checkbox(_L("Show staff-picks"), page, _L("Show staff-picks"), 50, "staff_pick_switch"); - auto title_backup = create_item_title(_L("Backup"), page, _L("Backup")); - //auto item_backup = create_item_switch(_L("Backup switch"), page, _L("Backup switch"), "units"); - auto item_backup = create_item_checkbox(_L("Auto-Backup"), page,_L("Auto-Backup"), 50, "backup_switch"); - auto item_backup_interval = create_item_backup_input(_L("Backup interval"), page, _L("Backup interval"), "backup_interval"); + auto title_project = create_item_title(_L("Project"), page, ""); + auto item_max_recent_count = create_item_input(_L("Maximum recent projects"), "", page, _L("Maximum count of recent projects"), "max_recent_count", [](wxString value) { + long max = 0; + if (value.ToLong(&max)) + wxGetApp().mainframe->set_max_recent_count(max); + }); + // auto item_backup = create_item_switch(_L("Backup switch"), page, _L("Backup switch"), "units"); + auto item_backup = create_item_checkbox(_L("Auto-Backup"), page,_L("Backup your project periodically for restoring from the occasional crash."), 50, "backup_switch"); + auto item_backup_interval = create_item_backup_input(_L("every"), page, _L("The peroid of backup in seconds."), "backup_interval"); //downloads auto title_downloads = create_item_title(_L("Downloads"), page, _L("Downloads")); @@ -888,9 +938,10 @@ wxWindow* PreferencesDialog::create_general_page() sizer_page->Add(title_modelmall, 0, wxTOP | wxEXPAND, FromDIP(20)); sizer_page->Add(item_modelmall, 0, wxTOP, FromDIP(3)); - sizer_page->Add(title_backup, 0, wxTOP| wxEXPAND, FromDIP(20)); + sizer_page->Add(title_project, 0, wxTOP| wxEXPAND, FromDIP(20)); + sizer_page->Add(item_max_recent_count, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_backup, 0, wxTOP,FromDIP(3)); - sizer_page->Add(item_backup_interval, 0, wxTOP, FromDIP(3)); + item_backup->Add(item_backup_interval, 0, wxLEFT, 0); sizer_page->Add(title_downloads, 0, wxTOP| wxEXPAND, FromDIP(20)); sizer_page->Add(item_downloads, 0, wxEXPAND, FromDIP(3)); diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index cd497110d3..bfe3c98cde 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -111,7 +111,7 @@ public: wxBoxSizer *create_item_darkmode_checkbox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, std::string param); void set_dark_mode(); wxWindow* create_item_downloads(wxWindow* parent, int padding_left, std::string param); - wxBoxSizer* create_item_backup_checkbox(wxString title, wxWindow* parent, wxString tooltip, int padding_left, std::string param); + wxBoxSizer *create_item_input(wxString title, wxString title2, wxWindow *parent, wxString tooltip, std::string param, std::function onchange = {}); wxBoxSizer *create_item_backup_input(wxString title, wxWindow *parent, wxString tooltip, std::string param); wxBoxSizer *create_item_multiple_combobox( wxString title, wxWindow *parent, wxString tooltip, int padding_left, std::string parama, std::vector vlista, std::vector vlistb);