mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-30 00:41:58 +08:00
TopBar: Show/Hide "Log in" button in respect to the Preferences settings
(SPE-2352)
This commit is contained in:
parent
87d7f9fe7f
commit
7ec2f3439a
@ -472,7 +472,9 @@ void MainFrame::update_layout()
|
||||
|
||||
if (m_layout == ESettingsLayout::Old)
|
||||
m_tabpanel->InsertNewPage(0, m_plater, _L("Plater"), "", true);
|
||||
|
||||
|
||||
update_topbars();
|
||||
|
||||
Layout();
|
||||
Thaw();
|
||||
}
|
||||
@ -596,6 +598,22 @@ static wxString GetTooltipForSettingsButton(PrinterTechnology pt)
|
||||
return from_u8(tooltip);
|
||||
}
|
||||
|
||||
void MainFrame::update_topbars()
|
||||
{
|
||||
if (wxGetApp().is_gcode_viewer())
|
||||
return;
|
||||
|
||||
const bool show_login = !wxGetApp().app_config->has("show_login_button") || wxGetApp().app_config->get_bool("show_login_button");
|
||||
m_tmp_top_bar->ShowUserAccount(show_login);
|
||||
m_tabpanel->ShowUserAccount(show_login);
|
||||
|
||||
if (!show_login) {
|
||||
if (auto user_account = wxGetApp().plater()->get_user_account();
|
||||
user_account && user_account->is_logged())
|
||||
user_account->do_logout();
|
||||
}
|
||||
}
|
||||
|
||||
void MainFrame::set_callbacks_for_topbar_menus()
|
||||
{
|
||||
m_bar_menus.set_workspaces_menu_callbacks(
|
||||
@ -607,6 +625,20 @@ void MainFrame::set_callbacks_for_topbar_menus()
|
||||
m_bar_menus.set_account_menu_callbacks(
|
||||
[]() -> void { wxGetApp().plater()->toggle_remember_user_account_session(); },
|
||||
[]() -> void { wxGetApp().plater()->act_with_user_account(); },
|
||||
[this]() -> void {
|
||||
wxString preferences_item = _L("Show \"Log in\" button in application top bar");
|
||||
wxString msg =
|
||||
_L("PrusaSlicer will remember your choice.") + "\n\n" +
|
||||
format_wxstr(_L("Visit \"Preferences\" and check \"%1%\"\nto changes your choice."), preferences_item);
|
||||
|
||||
MessageDialog msg_dlg(this, msg, _L("PrusaSlicer: Don't ask me again"), wxOK | wxCANCEL | wxICON_INFORMATION);
|
||||
if (msg_dlg.ShowModal() == wxID_OK) {
|
||||
wxGetApp().app_config->set("show_login_button", "0");
|
||||
|
||||
m_bar_menus.RemoveHideLoginItem();
|
||||
update_topbars();
|
||||
}
|
||||
},
|
||||
[]() -> TopBarMenus::UserAccountInfo {
|
||||
if (auto user_account = wxGetApp().plater()->get_user_account())
|
||||
return { user_account->is_logged(),
|
||||
@ -616,6 +648,10 @@ void MainFrame::set_callbacks_for_topbar_menus()
|
||||
return TopBarMenus::UserAccountInfo();
|
||||
}
|
||||
);
|
||||
|
||||
// we need "Hide Log in button" menu item only till "show_login_button" wasn't changed
|
||||
if (wxGetApp().app_config->has("show_login_button"))
|
||||
m_bar_menus.RemoveHideLoginItem();
|
||||
}
|
||||
|
||||
void MainFrame::init_tabpanel()
|
||||
@ -2160,6 +2196,8 @@ void MainFrame::update_ui_from_settings()
|
||||
// m_plater->sidebar().show_export(bp_on);
|
||||
// m_plater->sidebar().Layout();
|
||||
|
||||
update_topbars();
|
||||
|
||||
if (m_plater)
|
||||
m_plater->update_ui_from_settings();
|
||||
for (auto tab: wxGetApp().tabs_list)
|
||||
|
@ -172,6 +172,7 @@ public:
|
||||
void update_title();
|
||||
|
||||
void set_callbacks_for_topbar_menus();
|
||||
void update_topbars();
|
||||
void init_tabpanel();
|
||||
void create_preset_tabs();
|
||||
void add_created_tab(Tab* panel, const std::string& bmp_name = "");
|
||||
|
@ -6965,8 +6965,11 @@ void Plater::act_with_user_account()
|
||||
if (p->user_account) {
|
||||
if (p->user_account->is_logged())
|
||||
p->user_account->do_logout();
|
||||
else
|
||||
else {
|
||||
p->user_account->do_login();
|
||||
if (!wxGetApp().app_config->has("show_login_button"))
|
||||
wxGetApp().app_config->set("show_login_button", "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,8 +135,11 @@ void PreferencesDialog::show(const std::string& highlight_opt_key /*= std::strin
|
||||
downloader->set_path_name(app_config->get("url_downloader_dest"));
|
||||
downloader->allow(!app_config->has("downloader_url_registered") || app_config->get_bool("downloader_url_registered"));
|
||||
|
||||
for (const std::string& opt_key : {"suppress_hyperlinks", "downloader_url_registered"})
|
||||
for (const std::string& opt_key : {"suppress_hyperlinks", "downloader_url_registered", "show_login_button"})
|
||||
m_optgroup_other->set_value(opt_key, app_config->get_bool(opt_key));
|
||||
// by default "Log in" button is visible
|
||||
if (!app_config->has("show_login_button"))
|
||||
m_optgroup_other->set_value("show_login_button", true);
|
||||
|
||||
for (const std::string& opt_key : { "default_action_on_close_application"
|
||||
,"default_action_on_new_project"
|
||||
@ -626,6 +629,11 @@ void PreferencesDialog::build()
|
||||
//L("If enabled, the descriptions of configuration parameters in settings tabs wouldn't work as hyperlinks. "
|
||||
// "If disabled, the descriptions of configuration parameters in settings tabs will work as hyperlinks."),
|
||||
app_config->get_bool("suppress_hyperlinks"));
|
||||
|
||||
append_bool_option(m_optgroup_other, "show_login_button",
|
||||
L("Show \"Log in\" button in application top bar"),
|
||||
L("If enabled, PrusaSlicer will show up \"Log in\" button in application top bar."),
|
||||
app_config->get_bool("show_login_button"));
|
||||
|
||||
append_bool_option(m_optgroup_other, "downloader_url_registered",
|
||||
L("Allow downloads from Printables.com"),
|
||||
|
@ -517,6 +517,12 @@ void TopBarItemsCtrl::UpdateMode()
|
||||
this->Layout();
|
||||
}
|
||||
|
||||
void TopBarItemsCtrl::ShowUserAccount(bool show)
|
||||
{
|
||||
m_account_btn->Show(show);
|
||||
this->Layout();
|
||||
}
|
||||
|
||||
void TopBarItemsCtrl::Rescale()
|
||||
{
|
||||
update_margins();
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
|
||||
void SetSelection(int sel, bool force = false);
|
||||
void UpdateMode();
|
||||
void ShowUserAccount(bool show);
|
||||
void Rescale();
|
||||
void OnColorsChanged();
|
||||
void UpdateModeMarkers();
|
||||
@ -324,6 +325,11 @@ public:
|
||||
GetTopBarItemsCtrl()->UpdateMode();
|
||||
}
|
||||
|
||||
void ShowUserAccount(bool show)
|
||||
{
|
||||
GetTopBarItemsCtrl()->ShowUserAccount(show);
|
||||
}
|
||||
|
||||
void Rescale()
|
||||
{
|
||||
GetTopBarItemsCtrl()->Rescale();
|
||||
|
@ -89,6 +89,9 @@ void TopBarMenus::CreateAccountMenu()
|
||||
|
||||
m_login_item = append_menu_item(&account, wxID_ANY, "", "",
|
||||
[this](wxCommandEvent&) { if (m_cb_act_with_user_account) m_cb_act_with_user_account(); }, "login");
|
||||
|
||||
m_hide_login_item = append_menu_item(&account, wxID_ANY, _L("Hide \"Log in\" button"), "",
|
||||
[this](wxCommandEvent&) { if (m_cb_hide_user_account) m_cb_hide_user_account(); });
|
||||
}
|
||||
|
||||
void TopBarMenus::UpdateAccountMenu()
|
||||
@ -96,12 +99,20 @@ void TopBarMenus::UpdateAccountMenu()
|
||||
bool is_logged{ false };
|
||||
if (m_cb_get_user_account_info)
|
||||
is_logged = m_cb_get_user_account_info().is_logged;
|
||||
if (is_logged)
|
||||
RemoveHideLoginItem();
|
||||
if (m_login_item) {
|
||||
m_login_item->SetItemLabel(is_logged ? _L("Prusa Account Log out") : _L("Prusa Account Log in"));
|
||||
set_menu_item_bitmap(m_login_item, is_logged ? "logout" : "login");
|
||||
}
|
||||
}
|
||||
|
||||
void TopBarMenus::RemoveHideLoginItem()
|
||||
{
|
||||
if (m_hide_login_item)
|
||||
account.Remove(m_hide_login_item);
|
||||
}
|
||||
|
||||
void TopBarMenus::Popup(TopBarItemsCtrl* popup_ctrl, wxMenu* menu, wxPoint pos)
|
||||
{
|
||||
m_popup_ctrl = popup_ctrl;
|
||||
|
@ -21,6 +21,7 @@ private:
|
||||
|
||||
// Prusa Account menu items
|
||||
wxMenuItem* m_login_item { nullptr };
|
||||
wxMenuItem* m_hide_login_item { nullptr };
|
||||
|
||||
TopBarItemsCtrl* m_popup_ctrl { nullptr };
|
||||
|
||||
@ -30,6 +31,7 @@ private:
|
||||
|
||||
std::function<void()> m_cb_toggle_remember_session { nullptr };
|
||||
std::function<void()> m_cb_act_with_user_account { nullptr };
|
||||
std::function<void()> m_cb_hide_user_account { nullptr };
|
||||
std::function<UserAccountInfo()>m_cb_get_user_account_info { nullptr };
|
||||
|
||||
public:
|
||||
@ -46,6 +48,7 @@ public:
|
||||
void ApplyWorkspacesMenu();
|
||||
void CreateAccountMenu();
|
||||
void UpdateAccountMenu();
|
||||
void RemoveHideLoginItem();
|
||||
|
||||
void Popup(TopBarItemsCtrl* popup_ctrl, wxMenu* menu, wxPoint pos);
|
||||
void BindEvtClose();
|
||||
@ -70,10 +73,12 @@ public:
|
||||
|
||||
void set_account_menu_callbacks(std::function<void()> cb_toggle_remember_session,
|
||||
std::function<void()> cb_act_with_user_account ,
|
||||
std::function<void()> cb_hide_user_account ,
|
||||
std::function<UserAccountInfo()> cb_get_user_account_info )
|
||||
{
|
||||
m_cb_toggle_remember_session = cb_toggle_remember_session;
|
||||
m_cb_act_with_user_account = cb_act_with_user_account;
|
||||
m_cb_hide_user_account = cb_hide_user_account;
|
||||
m_cb_get_user_account_info = cb_get_user_account_info;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user