Update Web Link Association in Preferences (#5791)

* Fix check_url_association return value

* Update Web Link Association Preferences

Uses a checkbox in place of button to show if the current instance is registered at a quick look
New function is added to build the link association item
Current association line shows "None" for no app associated, "Current Instance" if the current instance is associated, and the formatted path to the registered app (Removes quotes and other extra chars)

* Update to use localization

* Fix Linux Build

---------

Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
Ocraftyone 2024-06-21 09:06:12 -04:00 committed by GitHub
parent 6c5cd0a31f
commit 5c9b82d6ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 88 additions and 26 deletions

View file

@ -6581,10 +6581,7 @@ bool GUI_App::check_url_association(std::wstring url_prefix, std::wstring& reg_b
reg_bin = key_full.QueryDefaultValue().ToStdWstring();
boost::filesystem::path binary_path(boost::filesystem::canonical(boost::dll::program_location()));
// wxString wbinary = wxString::FromUTF8(binary_path.string());
// std::string binary_string = (boost::format("%1%") % wbinary).str();
std::wstring key_string = L"\"" + binary_path.wstring() + L"\" L\"%1\"";
// return boost::iequals(key_string,(boost::format("%1%") % reg_bin).str());
std::wstring key_string = L"\"" + binary_path.wstring() + L"\" \"%1\"";
return key_string == reg_bin;
#else
return false;

View file

@ -862,6 +862,85 @@ wxWindow *PreferencesDialog ::create_item_radiobox(wxString title, wxWindow *par
return item;
}
#ifdef WIN32
wxBoxSizer* PreferencesDialog::create_item_link_association(wxWindow* parent, wxString url_prefix, wxString website_name)
{
wxString title = _L("Associate") + (boost::format(" %1%://") % url_prefix.c_str()).str();
wxString tooltip = _L("Associate") + " " + url_prefix + ":// " + _L("with OrcaSlicer so that Orca can open models from") + " " + website_name;
std::wstring registered_bin; // not used, just here to provide a ref to check fn
bool reg_to_current_instance = wxGetApp().check_url_association(url_prefix.ToStdWstring(), registered_bin);
auto* h_sizer = new wxBoxSizer(wxHORIZONTAL); // contains checkbox and other elements on the first line
h_sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, 23);
// build checkbox
auto checkbox = new ::CheckBox(parent);
checkbox->SetToolTip(tooltip);
checkbox->SetValue(reg_to_current_instance); // If registered to the current instance, checkbox should be checked
checkbox->Enable(!reg_to_current_instance); // Since unregistering isn't supported, checkbox is disabled when checked
h_sizer->Add(checkbox, 0, wxALIGN_CENTER, 0);
h_sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, 8);
// build text next to checkbox
auto checkbox_title = new wxStaticText(parent, wxID_ANY, title);
checkbox_title->SetToolTip(tooltip);
checkbox_title->SetForegroundColour(DESIGN_GRAY900_COLOR);
checkbox_title->SetFont(::Label::Body_13);
auto size = checkbox_title->GetTextExtent(title);
checkbox_title->SetMinSize({ size.x + FromDIP(5), -1 });
checkbox_title->Wrap(-1);
h_sizer->Add(checkbox_title, 0, wxALIGN_CENTER | wxALL, 3);
auto* v_sizer = new wxBoxSizer(wxVERTICAL);
v_sizer->Add(h_sizer);
// build text below checkbox that indicates the instance currently registered to handle the link type
auto* registered_instance_title = new wxStaticText(parent, wxID_ANY, "");
registered_instance_title->SetForegroundColour(DESIGN_GRAY900_COLOR);
registered_instance_title->SetFont(::Label::Body_13);
registered_instance_title->Wrap(-1);
// update the text below checkbox
auto update_current_association_str = [=, &reg_to_current_instance](){
// get registered binary for given link type
std::wstring registered_bin;
reg_to_current_instance = wxGetApp().check_url_association(url_prefix.wc_str(), registered_bin);
// format registered binary to get only the path and remove excess chars
if (!registered_bin.empty())
// skip idx 0 because it is the first quotation mark
registered_bin = registered_bin.substr(1, registered_bin.find(L'\"', 1) - 1);
wxString current_association_str = _L("Current Association: ");
if (reg_to_current_instance) {
current_association_str += _L("Current Instance");
registered_instance_title->SetToolTip(_L("Current Instance Path: ") + registered_bin);
} else if (registered_bin.empty())
current_association_str += _L("None");
else
current_association_str += registered_bin;
registered_instance_title->SetLabel(current_association_str);
auto size = registered_instance_title->GetTextExtent(current_association_str);
registered_instance_title->SetMinSize({ size.x + FromDIP(5), -1 });
};
update_current_association_str();
v_sizer->Add(registered_instance_title, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 60);
checkbox->Bind(wxEVT_TOGGLEBUTTON, [=](wxCommandEvent& e) {
wxGetApp().associate_url(url_prefix.ToStdWstring());
checkbox->Disable();
update_current_association_str();
e.Skip();
});
return v_sizer;
}
#endif // WIN32
PreferencesDialog::PreferencesDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos, const wxSize &size, long style)
: DPIDialog(parent, id, _L("Preferences"), pos, size, style)
{
@ -1072,28 +1151,13 @@ wxWindow* PreferencesDialog::create_general_page()
_L("If enabled, sets OrcaSlicer as default application to open .stl files"), 50, "associate_stl");
auto item_associate_step = create_item_checkbox(_L("Associate .step/.stp files to OrcaSlicer"), page,
_L("If enabled, sets OrcaSlicer as default application to open .step files"), 50, "associate_step");
#endif // _WIN32
#if !defined(__APPLE__)
auto title_associate_url = create_item_title(_L("Associate web links to OrcaSlicer"), page, _L("Associate URLs to OrcaSlicer"));
std::wstring reg_bin;
wxGetApp().check_url_association(L"prusaslicer", reg_bin);
auto associate_url_prusaslicer = create_item_button(_L("Current association: ") + reg_bin, _L("Associate prusaslicer://"), page,
reg_bin.empty() ? _L("Not associated to any application") : reg_bin,
_L("Associate OrcaSlicer with prusaslicer:// links so that Orca can open models from Printable.com"),
[]() { wxGetApp().associate_url(L"prusaslicer"); }, false);
wxGetApp().check_url_association(L"bambustudio", reg_bin);
auto associate_url_bambustudio = create_item_button(_L("Current association: ") + reg_bin, _L("Associate bambustudio://"), page,
reg_bin.empty() ? _L("Not associated to any application") : reg_bin,
_L("Associate OrcaSlicer with bambustudio:// links so that Orca can open models from makerworld.com"),
[]() { wxGetApp().associate_url(L"bambustudio"); }, false);
wxGetApp().check_url_association(L"cura", reg_bin);
auto associate_url_cura = create_item_button(_L("Current association: ") + reg_bin, _L("Associate cura://"), page,
reg_bin.empty() ? _L("Not associated to any application") : reg_bin,
_L("Associate OrcaSlicer with cura:// links so that Orca can open models from thingiverse.com"),
[]() { wxGetApp().associate_url(L"cura"); }, false);
#endif
auto associate_url_prusaslicer = create_item_link_association(page, L"prusaslicer", "Printables.com");
auto associate_url_bambustudio = create_item_link_association(page, L"bambustudio", "Makerworld.com");
auto associate_url_cura = create_item_link_association(page, L"cura", "Thingiverse.com");
#endif // _WIN32
// auto title_modelmall = create_item_title(_L("Online Models"), page, _L("Online Models"));
// auto item_backup = create_item_switch(_L("Backup switch"), page, _L("Backup switch"), "units");
@ -1156,13 +1220,11 @@ wxWindow* PreferencesDialog::create_general_page()
sizer_page->Add(item_associate_3mf, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_associate_stl, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_associate_step, 0, wxTOP, FromDIP(3));
#endif // _WIN32
#if !defined(__APPLE__)
sizer_page->Add(title_associate_url, 0, wxTOP| wxEXPAND, FromDIP(20));
sizer_page->Add(associate_url_prusaslicer, 0, wxTOP, FromDIP(3));
sizer_page->Add(associate_url_bambustudio, 0, wxTOP, FromDIP(3));
sizer_page->Add(associate_url_cura, 0, wxTOP, FromDIP(3));
#endif
#endif // _WIN32
// auto item_title_modelmall = sizer_page->Add(title_modelmall, 0, wxTOP | wxEXPAND, FromDIP(20));
// auto item_item_modelmall = sizer_page->Add(item_modelmall, 0, wxTOP, FromDIP(3));
// auto update_modelmall = [this, item_title_modelmall, item_item_modelmall] (wxEvent & e) {

View file

@ -119,6 +119,9 @@ public:
wxString title, wxWindow *parent, wxString tooltip, int padding_left, std::string parama, std::vector<wxString> vlista, std::vector<wxString> vlistb);
wxBoxSizer *create_item_switch(wxString title, wxWindow *parent, wxString tooltip, std::string param);
wxWindow * create_item_radiobox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, int groupid, std::string param);
#ifdef WIN32
wxBoxSizer* create_item_link_association(wxWindow* parent, wxString url_prefix, wxString website_name);
#endif // WIN32
wxWindow* create_general_page();
void create_gui_page();