Physical printers dialog: Update Test button in respect to the inputted printhost

This commit is contained in:
YuSanka 2020-11-12 15:22:03 +01:00
parent 8c8ad70c58
commit 353536ab86
2 changed files with 28 additions and 3 deletions

View file

@ -269,6 +269,8 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value) {
if (opt_key == "host_type" || opt_key == "printhost_authorization_type")
this->update();
if (opt_key == "print_host")
this->update_printhost_buttons();
};
m_optgroup->append_single_option_line("host_type");
@ -413,6 +415,23 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
m_optgroup->activate();
Field* printhost_field = m_optgroup->get_field("print_host");
if (printhost_field)
{
wxTextCtrl* temp = dynamic_cast<wxTextCtrl*>(printhost_field->getWindow());
if (temp)
temp->Bind(wxEVT_TEXT, ([this, printhost_field, temp](wxEvent& e)
{
#ifndef __WXGTK__
e.Skip();
temp->GetToolTip()->Enable(true);
#endif // __WXGTK__
TextCtrl* field = dynamic_cast<TextCtrl*>(printhost_field);
if (field)
field->propagate_value();
}), temp->GetId());
}
// Always fill in the "printhost_port" combo box from the config and select it.
{
Choice* choice = dynamic_cast<Choice*>(m_optgroup->get_field("printhost_port"));
@ -423,6 +442,13 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
update();
}
void PhysicalPrinterDialog::update_printhost_buttons()
{
std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
m_printhost_test_btn->Enable(!m_config->opt_string("print_host").empty() && host->can_test());
m_printhost_browse_btn->Enable(host->has_auto_discovery());
}
void PhysicalPrinterDialog::update()
{
m_optgroup->reload_config();
@ -455,9 +481,7 @@ void PhysicalPrinterDialog::update()
m_optgroup->show_field("printhost_port", supports_multiple_printers);
m_printhost_port_browse_btn->Show(supports_multiple_printers);
std::unique_ptr<PrintHost> host(PrintHost::get_print_host(m_config));
m_printhost_test_btn->Enable(!m_config->opt_string("print_host").empty() && host->can_test());
m_printhost_browse_btn->Enable(host->has_auto_discovery());
update_printhost_buttons();
this->SetSize(this->GetBestSize());
this->Layout();

View file

@ -86,6 +86,7 @@ public:
~PhysicalPrinterDialog();
void update();
void update_printhost_buttons();
void update_printers();
wxString get_printer_name();
void update_full_printer_names();