NEW:add the download path edit in the preferences

Change-Id: I8dfd3373a25bdd9d70360b61605d92f20052d478
This commit is contained in:
tao wang 2022-10-11 13:05:36 +08:00 committed by Lane.Wei
parent 79480405a0
commit b5979375b4
5 changed files with 88 additions and 3 deletions

View file

@ -273,6 +273,10 @@ void AppConfig::set_defaults()
set("precise_control", "none/mouse left"); set("precise_control", "none/mouse left");
} }
if (get("download_path").empty()) {
set("download_path", "");
}
if (get("mouse_wheel").empty()) { if (get("mouse_wheel").empty()) {
set("mouse_wheel", "0"); set("mouse_wheel", "0");
} }

View file

@ -1174,6 +1174,7 @@ GUI_App::GUI_App()
{ {
//app config initializes early becasuse it is used in instance checking in BambuStudio.cpp //app config initializes early becasuse it is used in instance checking in BambuStudio.cpp
this->init_app_config(); this->init_app_config();
this->init_download_path();
reset_to_active(); reset_to_active();
} }
@ -1764,6 +1765,26 @@ static boost::optional<Semver> parse_semver_from_ini(std::string path)
return Semver::parse(body); return Semver::parse(body);
} }
void GUI_App::init_download_path()
{
std::string down_path = app_config->get("download_path");
if (down_path.empty()) {
std::string user_down_path = wxStandardPaths::Get().GetUserDir(wxStandardPaths::Dir_Downloads).ToUTF8().data();
app_config->set("download_path", user_down_path);
}
else {
fs::path dp(down_path);
if (!fs::exists(dp)) {
if (!fs::create_directory(dp)) {
std::string user_down_path = wxStandardPaths::Get().GetUserDir(wxStandardPaths::Dir_Downloads).ToUTF8().data();
app_config->set("download_path", user_down_path);
}
}
}
}
void GUI_App::init_app_config() void GUI_App::init_app_config()
{ {
// Profiles for the alpha are stored into the PrusaSlicer-alpha directory to not mix with the current release. // Profiles for the alpha are stored into the PrusaSlicer-alpha directory to not mix with the current release.

View file

@ -301,6 +301,7 @@ public:
wxGLContext* init_glcontext(wxGLCanvas& canvas); wxGLContext* init_glcontext(wxGLCanvas& canvas);
bool init_opengl(); bool init_opengl();
void init_download_path();
static unsigned get_colour_approx_luma(const wxColour& colour); static unsigned get_colour_approx_luma(const wxColour& colour);
static bool dark_mode(); static bool dark_mode();
const wxColour get_label_default_clr_system(); const wxColour get_label_default_clr_system();

View file

@ -526,6 +526,57 @@ wxBoxSizer *PreferencesDialog::create_item_checkbox(wxString title, wxWindow *pa
return m_sizer_checkbox; return m_sizer_checkbox;
} }
wxWindow* PreferencesDialog::create_item_downloads(wxWindow* parent, int padding_left, std::string param)
{
wxString download_path = wxString::FromUTF8(app_config->get("download_path"));
auto item_panel = new wxWindow(parent, wxID_ANY);
item_panel->SetBackgroundColour(*wxWHITE);
wxBoxSizer* m_sizer_checkbox = new wxBoxSizer(wxHORIZONTAL);
m_sizer_checkbox->Add(0, 0, 0, wxEXPAND | wxLEFT, 23);
auto m_staticTextPath = new wxStaticText(item_panel, wxID_ANY, download_path, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
//m_staticTextPath->SetMaxSize(wxSize(FromDIP(440), -1));
m_staticTextPath->SetForegroundColour(DESIGN_GRAY600_COLOR);
m_staticTextPath->SetFont(::Label::Body_13);
m_staticTextPath->Wrap(-1);
auto m_button_download = new Button(item_panel, _L("Browse"));
StateColor abort_bg(std::pair<wxColour, int>(wxColour(255, 255, 255), StateColor::Disabled), std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed),
std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered), std::pair<wxColour, int>(wxColour(255, 255, 255), StateColor::Enabled),
std::pair<wxColour, int>(wxColour(255, 255, 255), StateColor::Normal));
m_button_download->SetBackgroundColor(abort_bg);
StateColor abort_bd(std::pair<wxColour, int>(wxColour(144, 144, 144), StateColor::Disabled), std::pair<wxColour, int>(wxColour(38, 46, 48), StateColor::Enabled));
m_button_download->SetBorderColor(abort_bd);
StateColor abort_text(std::pair<wxColour, int>(wxColour(144, 144, 144), StateColor::Disabled), std::pair<wxColour, int>(wxColour(38, 46, 48), StateColor::Enabled));
m_button_download->SetTextColor(abort_text);
m_button_download->SetFont(Label::Body_10);
m_button_download->SetMinSize(wxSize(FromDIP(58), FromDIP(22)));
m_button_download->SetSize(wxSize(FromDIP(58), FromDIP(22)));
m_button_download->SetCornerRadius(FromDIP(12));
m_button_download->Bind(wxEVT_BUTTON, [this, m_staticTextPath, item_panel](auto& e) {
wxString defaultPath = wxT("/");
wxDirDialog dialog(this, _L("Choose Download Directory"), defaultPath, wxDD_NEW_DIR_BUTTON);
if (dialog.ShowModal() == wxID_OK) {
wxString download_path = dialog.GetPath();
std::string download_path_str = download_path.ToUTF8().data();
app_config->set("download_path", download_path_str);
m_staticTextPath->SetLabelText(download_path);
item_panel->Layout();
}
});
m_sizer_checkbox->Add(m_staticTextPath, 0, wxALIGN_CENTER_VERTICAL | wxALL, FromDIP(5));
m_sizer_checkbox->Add(m_button_download, 0, wxALL, FromDIP(5));
item_panel->SetSizer(m_sizer_checkbox);
item_panel->Layout();
return item_panel;
}
wxWindow *PreferencesDialog ::create_item_radiobox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, int groupid, std::string param) wxWindow *PreferencesDialog ::create_item_radiobox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, int groupid, std::string param)
{ {
wxWindow *item = new wxWindow(parent, wxID_ANY, wxDefaultPosition, wxSize(-1, FromDIP(28))); wxWindow *item = new wxWindow(parent, wxID_ANY, wxDefaultPosition, wxSize(-1, FromDIP(28)));
@ -711,6 +762,10 @@ wxWindow* PreferencesDialog::create_general_page()
auto item_backup = create_item_checkbox(_L("Auto-Backup"), page,_L("Auto-Backup"), 50, "backup_switch"); 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 item_backup_interval = create_item_backup_input(_L("Backup interval"), page, _L("Backup interval"), "backup_interval");
//downloads
auto title_downloads = create_item_title(_L("Downloads"), page, _L("Downloads"));
auto item_downloads = create_item_downloads(page,50,"download_path");
sizer_page->Add(title_general_settings, 0, wxEXPAND, 0); sizer_page->Add(title_general_settings, 0, wxEXPAND, 0);
sizer_page->Add(item_language, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_language, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_region, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_region, 0, wxTOP, FromDIP(3));
@ -729,6 +784,9 @@ wxWindow* PreferencesDialog::create_general_page()
sizer_page->Add(item_backup_interval, 0, wxTOP,FromDIP(3)); sizer_page->Add(item_backup_interval, 0, wxTOP,FromDIP(3));
//sizer_page->Add(0, 0, 0, wxTOP, 26); //sizer_page->Add(0, 0, 0, wxTOP, 26);
sizer_page->Add(title_downloads, 0, wxTOP| wxEXPAND, FromDIP(20));
sizer_page->Add(item_downloads, 0, wxEXPAND, FromDIP(3));
page->SetSizer(sizer_page); page->SetSizer(sizer_page);
page->Layout(); page->Layout();

View file

@ -20,6 +20,7 @@ namespace Slic3r { namespace GUI {
#define DESIGN_SELECTOR_NOMORE_COLOR wxColour(248, 248, 248) #define DESIGN_SELECTOR_NOMORE_COLOR wxColour(248, 248, 248)
#define DESIGN_GRAY900_COLOR wxColour(38, 46, 48) #define DESIGN_GRAY900_COLOR wxColour(38, 46, 48)
#define DESIGN_GRAY800_COLOR wxColour(50, 58, 61) #define DESIGN_GRAY800_COLOR wxColour(50, 58, 61)
#define DESIGN_GRAY600_COLOR wxColour(144, 144, 144)
#define DESIGN_GRAY400_COLOR wxColour(166, 169, 170) #define DESIGN_GRAY400_COLOR wxColour(166, 169, 170)
class Selector class Selector
@ -106,6 +107,7 @@ public:
wxBoxSizer *create_item_language_combobox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, std::string param, std::vector<const wxLanguageInfo *> vlist); wxBoxSizer *create_item_language_combobox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, std::string param, std::vector<const wxLanguageInfo *> vlist);
wxBoxSizer *create_item_loglevel_combobox(wxString title, wxWindow *parent, wxString tooltip, std::vector<wxString> vlist); wxBoxSizer *create_item_loglevel_combobox(wxString title, wxWindow *parent, wxString tooltip, std::vector<wxString> vlist);
wxBoxSizer *create_item_checkbox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, std::string param); wxBoxSizer *create_item_checkbox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, std::string param);
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_backup_checkbox(wxString title, wxWindow* parent, wxString tooltip, int padding_left, std::string param);
wxBoxSizer *create_item_backup_input(wxString title, wxWindow *parent, wxString tooltip, std::string param); wxBoxSizer *create_item_backup_input(wxString title, wxWindow *parent, wxString tooltip, std::string param);
wxBoxSizer *create_item_multiple_combobox( wxBoxSizer *create_item_multiple_combobox(
@ -125,7 +127,6 @@ public:
void create_select_domain_widget(); void create_select_domain_widget();
void Split(const std::string &src, const std::string &separator, std::vector<wxString> &dest); void Split(const std::string &src, const std::string &separator, std::vector<wxString> &dest);
int m_current_language_selected = {0}; int m_current_language_selected = {0};
protected: protected: