Fix for #7419 - Non-modal settings window loses focus after accepting dialog (MSW specific issue)

MessageDialog is used instead of wxMessageDialog on MSW for supporting of the Light/Dark color mode.
But a constructor of the MsgDialog replaces a parent which is equal to nullptr with the MainFrame .
That is why non-modal dialog with Preset Settings loses a focus after close of the MessageDialog.

"m_msg_dlg_parent" is added to ConfigManipulation class. ConfigManipulation's instance owed by Tab will use the Tab as a parent for MessageDialogs.
=> The MessageDialog with information about configuration incompatibility will always appear over related SettingsTab
and a non-modal dialog with Preset Settings will not lose the focus.
This commit is contained in:
YuSanka 2021-12-06 11:39:28 +01:00
parent c7a4f61238
commit f5dc746e94
3 changed files with 14 additions and 19 deletions

View File

@ -47,8 +47,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
if (config->opt_float("layer_height") < EPSILON) if (config->opt_float("layer_height") < EPSILON)
{ {
const wxString msg_text = _(L("Layer height is not valid.\n\nThe layer height will be reset to 0.01.")); const wxString msg_text = _(L("Layer height is not valid.\n\nThe layer height will be reset to 0.01."));
//wxMessageDialog dialog(nullptr, msg_text, _(L("Layer height")), wxICON_WARNING | wxOK); MessageDialog dialog(m_msg_dlg_parent, msg_text, _(L("Layer height")), wxICON_WARNING | wxOK);
MessageDialog dialog(nullptr, msg_text, _(L("Layer height")), wxICON_WARNING | wxOK);
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
is_msg_dlg_already_exist = true; is_msg_dlg_already_exist = true;
dialog.ShowModal(); dialog.ShowModal();
@ -60,8 +59,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
if (config->option<ConfigOptionFloatOrPercent>("first_layer_height")->value < EPSILON) if (config->option<ConfigOptionFloatOrPercent>("first_layer_height")->value < EPSILON)
{ {
const wxString msg_text = _(L("First layer height is not valid.\n\nThe first layer height will be reset to 0.01.")); const wxString msg_text = _(L("First layer height is not valid.\n\nThe first layer height will be reset to 0.01."));
//wxMessageDialog dialog(nullptr, msg_text, _(L("First layer height")), wxICON_WARNING | wxOK); MessageDialog dialog(m_msg_dlg_parent, msg_text, _(L("First layer height")), wxICON_WARNING | wxOK);
MessageDialog dialog(nullptr, msg_text, _(L("First layer height")), wxICON_WARNING | wxOK);
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
is_msg_dlg_already_exist = true; is_msg_dlg_already_exist = true;
dialog.ShowModal(); dialog.ShowModal();
@ -90,8 +88,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
"- Detect thin walls disabled")); "- Detect thin walls disabled"));
if (is_global_config) if (is_global_config)
msg_text += "\n\n" + _(L("Shall I adjust those settings in order to enable Spiral Vase?")); msg_text += "\n\n" + _(L("Shall I adjust those settings in order to enable Spiral Vase?"));
//wxMessageDialog dialog(nullptr, msg_text, _(L("Spiral Vase")), MessageDialog dialog(m_msg_dlg_parent, msg_text, _(L("Spiral Vase")),
MessageDialog dialog(nullptr, msg_text, _(L("Spiral Vase")),
wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK)); wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK));
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
auto answer = dialog.ShowModal(); auto answer = dialog.ShowModal();
@ -126,8 +123,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
"(both support_material_extruder and support_material_interface_extruder need to be set to 0).")); "(both support_material_extruder and support_material_interface_extruder need to be set to 0)."));
if (is_global_config) if (is_global_config)
msg_text += "\n\n" + _(L("Shall I adjust those settings in order to enable the Wipe Tower?")); msg_text += "\n\n" + _(L("Shall I adjust those settings in order to enable the Wipe Tower?"));
//wxMessageDialog dialog (nullptr, msg_text, _(L("Wipe Tower")), MessageDialog dialog (m_msg_dlg_parent, msg_text, _(L("Wipe Tower")),
MessageDialog dialog (nullptr, msg_text, _(L("Wipe Tower")),
wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK)); wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK));
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
auto answer = dialog.ShowModal(); auto answer = dialog.ShowModal();
@ -147,8 +143,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
"need to be synchronized with the object layers.")); "need to be synchronized with the object layers."));
if (is_global_config) if (is_global_config)
msg_text += "\n\n" + _(L("Shall I synchronize support layers in order to enable the Wipe Tower?")); msg_text += "\n\n" + _(L("Shall I synchronize support layers in order to enable the Wipe Tower?"));
//wxMessageDialog dialog(nullptr, msg_text, _(L("Wipe Tower")), MessageDialog dialog(m_msg_dlg_parent, msg_text, _(L("Wipe Tower")),
MessageDialog dialog(nullptr, msg_text, _(L("Wipe Tower")),
wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK)); wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK));
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
auto answer = dialog.ShowModal(); auto answer = dialog.ShowModal();
@ -169,7 +164,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
"- Detect bridging perimeters")); "- Detect bridging perimeters"));
if (is_global_config) if (is_global_config)
msg_text += "\n\n" + _(L("Shall I adjust those settings for supports?")); msg_text += "\n\n" + _(L("Shall I adjust those settings for supports?"));
MessageDialog dialog(nullptr, msg_text, _L("Support Generator"), wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK)); MessageDialog dialog(m_msg_dlg_parent, msg_text, _L("Support Generator"), wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK));
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
auto answer = dialog.ShowModal(); auto answer = dialog.ShowModal();
if (!is_global_config || answer == wxID_YES) { if (!is_global_config || answer == wxID_YES) {
@ -200,8 +195,7 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
_(fill_pattern_def->enum_labels[it_pattern - fill_pattern_def->enum_values.begin()])); _(fill_pattern_def->enum_labels[it_pattern - fill_pattern_def->enum_values.begin()]));
if (is_global_config) if (is_global_config)
msg_text += "\n\n" + _L("Shall I switch to rectilinear fill pattern?"); msg_text += "\n\n" + _L("Shall I switch to rectilinear fill pattern?");
//wxMessageDialog dialog(nullptr, msg_text, _L("Infill"), MessageDialog dialog(m_msg_dlg_parent, msg_text, _L("Infill"),
MessageDialog dialog(nullptr, msg_text, _L("Infill"),
wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK) ); wxICON_WARNING | (is_global_config ? wxYES | wxNO : wxOK) );
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
auto answer = dialog.ShowModal(); auto answer = dialog.ShowModal();
@ -331,8 +325,7 @@ void ConfigManipulation::update_print_sla_config(DynamicPrintConfig* config, con
if (head_penetration > head_width) { if (head_penetration > head_width) {
wxString msg_text = _(L("Head penetration should not be greater than the head width.")); wxString msg_text = _(L("Head penetration should not be greater than the head width."));
//wxMessageDialog dialog(nullptr, msg_text, _(L("Invalid Head penetration")), wxICON_WARNING | wxOK); MessageDialog dialog(m_msg_dlg_parent, msg_text, _(L("Invalid Head penetration")), wxICON_WARNING | wxOK);
MessageDialog dialog(nullptr, msg_text, _(L("Invalid Head penetration")), wxICON_WARNING | wxOK);
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
if (dialog.ShowModal() == wxID_OK) { if (dialog.ShowModal() == wxID_OK) {
new_conf.set_key_value("support_head_penetration", new ConfigOptionFloat(head_width)); new_conf.set_key_value("support_head_penetration", new ConfigOptionFloat(head_width));
@ -345,8 +338,7 @@ void ConfigManipulation::update_print_sla_config(DynamicPrintConfig* config, con
if (pinhead_d > pillar_d) { if (pinhead_d > pillar_d) {
wxString msg_text = _(L("Pinhead diameter should be smaller than the pillar diameter.")); wxString msg_text = _(L("Pinhead diameter should be smaller than the pillar diameter."));
//wxMessageDialog dialog(nullptr, msg_text, _(L("Invalid pinhead diameter")), wxICON_WARNING | wxOK); MessageDialog dialog(m_msg_dlg_parent, msg_text, _(L("Invalid pinhead diameter")), wxICON_WARNING | wxOK);
MessageDialog dialog(nullptr, msg_text, _(L("Invalid pinhead diameter")), wxICON_WARNING | wxOK);
DynamicPrintConfig new_conf = *config; DynamicPrintConfig new_conf = *config;
if (dialog.ShowModal() == wxID_OK) { if (dialog.ShowModal() == wxID_OK) {

View File

@ -30,15 +30,18 @@ class ConfigManipulation
// callback to propagation of changed value, if needed // callback to propagation of changed value, if needed
std::function<void(const std::string&, const boost::any&)> cb_value_change = nullptr; std::function<void(const std::string&, const boost::any&)> cb_value_change = nullptr;
ModelConfig* local_config = nullptr; ModelConfig* local_config = nullptr;
wxWindow* m_msg_dlg_parent {nullptr};
public: public:
ConfigManipulation(std::function<void()> load_config, ConfigManipulation(std::function<void()> load_config,
std::function<void(const std::string&, bool toggle, int opt_index)> cb_toggle_field, std::function<void(const std::string&, bool toggle, int opt_index)> cb_toggle_field,
std::function<void(const std::string&, const boost::any&)> cb_value_change, std::function<void(const std::string&, const boost::any&)> cb_value_change,
ModelConfig* local_config = nullptr) : ModelConfig* local_config = nullptr,
wxWindow* msg_dlg_parent = nullptr) :
load_config(load_config), load_config(load_config),
cb_toggle_field(cb_toggle_field), cb_toggle_field(cb_toggle_field),
cb_value_change(cb_value_change), cb_value_change(cb_value_change),
m_msg_dlg_parent(msg_dlg_parent),
local_config(local_config) {} local_config(local_config) {}
ConfigManipulation() {} ConfigManipulation() {}

View File

@ -4481,7 +4481,7 @@ ConfigManipulation Tab::get_config_manipulation()
return on_value_change(opt_key, value); return on_value_change(opt_key, value);
}; };
return ConfigManipulation(load_config, cb_toggle_field, cb_value_change); return ConfigManipulation(load_config, cb_toggle_field, cb_value_change, nullptr, this);
} }