Printhost: Persist upload path & start print checkbox (re-add lost code)
Fixes #1219 Fixes #1004 Fixes #1106 Fixes #1678
This commit is contained in:
parent
35b4777e0e
commit
08f1459ab7
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "GUI.hpp"
|
#include "GUI.hpp"
|
||||||
#include "GUI_App.hpp"
|
#include "GUI_App.hpp"
|
||||||
|
#include "AppConfig.hpp"
|
||||||
#include "MsgDialog.hpp"
|
#include "MsgDialog.hpp"
|
||||||
#include "I18N.hpp"
|
#include "I18N.hpp"
|
||||||
#include "../Utils/PrintHost.hpp"
|
#include "../Utils/PrintHost.hpp"
|
||||||
@ -24,10 +25,12 @@ namespace fs = boost::filesystem;
|
|||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
static const char *CONFIG_KEY_PATH = "printhost_path";
|
||||||
|
static const char *CONFIG_KEY_PRINT = "printhost_print";
|
||||||
|
|
||||||
PrintHostSendDialog::PrintHostSendDialog(const fs::path &path)
|
PrintHostSendDialog::PrintHostSendDialog(const fs::path &path)
|
||||||
: MsgDialog(nullptr, _(L("Send G-Code to printer host")), _(L("Upload to Printer Host with the following filename:")), wxID_NONE)
|
: MsgDialog(nullptr, _(L("Send G-Code to printer host")), _(L("Upload to Printer Host with the following filename:")), wxID_NONE)
|
||||||
, txt_filename(new wxTextCtrl(this, wxID_ANY, path.filename().wstring()))
|
, txt_filename(new wxTextCtrl(this, wxID_ANY))
|
||||||
, box_print(new wxCheckBox(this, wxID_ANY, _(L("Start printing after upload"))))
|
, box_print(new wxCheckBox(this, wxID_ANY, _(L("Start printing after upload"))))
|
||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@ -44,11 +47,30 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path)
|
|||||||
|
|
||||||
btn_sizer->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL));
|
btn_sizer->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL));
|
||||||
|
|
||||||
txt_filename->SetFocus();
|
const AppConfig *app_config = wxGetApp().app_config;
|
||||||
|
box_print->SetValue(app_config->get("recent", CONFIG_KEY_PRINT) == "1");
|
||||||
|
|
||||||
|
wxString recent_path = from_u8(app_config->get("recent", CONFIG_KEY_PATH));
|
||||||
|
if (recent_path.Length() > 0 && recent_path[recent_path.Length() - 1] != '/') {
|
||||||
|
recent_path += '/';
|
||||||
|
}
|
||||||
|
const auto recent_path_len = recent_path.Length();
|
||||||
|
recent_path += path.filename().wstring();
|
||||||
wxString stem(path.stem().wstring());
|
wxString stem(path.stem().wstring());
|
||||||
txt_filename->SetSelection(0, stem.Length());
|
const auto stem_len = stem.Length();
|
||||||
|
|
||||||
|
txt_filename->SetValue(recent_path);
|
||||||
|
txt_filename->SetFocus();
|
||||||
|
|
||||||
Fit();
|
Fit();
|
||||||
|
|
||||||
|
Bind(wxEVT_SHOW, [=](const wxShowEvent &) {
|
||||||
|
// Another similar case where the function only works with EVT_SHOW + CallAfter,
|
||||||
|
// this time on Mac.
|
||||||
|
CallAfter([=]() {
|
||||||
|
txt_filename->SetSelection(recent_path_len, recent_path_len + stem_len);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path PrintHostSendDialog::filename() const
|
fs::path PrintHostSendDialog::filename() const
|
||||||
@ -61,6 +83,24 @@ bool PrintHostSendDialog::start_print() const
|
|||||||
return box_print->GetValue();
|
return box_print->GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrintHostSendDialog::EndModal(int ret)
|
||||||
|
{
|
||||||
|
if (ret == wxID_OK) {
|
||||||
|
// Persist path and print settings
|
||||||
|
wxString path = txt_filename->GetValue();
|
||||||
|
int last_slash = path.Find('/', true);
|
||||||
|
if (last_slash != wxNOT_FOUND) {
|
||||||
|
path = path.SubString(0, last_slash);
|
||||||
|
wxGetApp().app_config->set("recent", CONFIG_KEY_PATH, into_u8(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool print = box_print->GetValue();
|
||||||
|
GUI::get_app_config()->set("recent", CONFIG_KEY_PRINT, print ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
MsgDialog::EndModal(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
wxDEFINE_EVENT(EVT_PRINTHOST_PROGRESS, PrintHostQueueDialog::Event);
|
wxDEFINE_EVENT(EVT_PRINTHOST_PROGRESS, PrintHostQueueDialog::Event);
|
||||||
|
@ -33,6 +33,7 @@ public:
|
|||||||
boost::filesystem::path filename() const;
|
boost::filesystem::path filename() const;
|
||||||
bool start_print() const;
|
bool start_print() const;
|
||||||
|
|
||||||
|
virtual void EndModal(int ret) override;
|
||||||
private:
|
private:
|
||||||
wxTextCtrl *txt_filename;
|
wxTextCtrl *txt_filename;
|
||||||
wxCheckBox *box_print;
|
wxCheckBox *box_print;
|
||||||
|
Loading…
Reference in New Issue
Block a user