From 9f529e86ccb75fe49ddbb58ec39e0c84f600bcdb Mon Sep 17 00:00:00 2001
From: YuSanka <yusanka@gmail.com>
Date: Mon, 30 Dec 2019 15:56:51 +0100
Subject: [PATCH] Fixed filaments/materials preset list updating from
 ConfigWizard

if list of printers was changed but filaments/sal_materials page wasn't activated
---
 src/slic3r/GUI/ConfigWizard.cpp         | 29 ++++++++++++++++++++-----
 src/slic3r/GUI/ConfigWizard_private.hpp |  3 ++-
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp
index 971bd1f1d..265e7f203 100644
--- a/src/slic3r/GUI/ConfigWizard.cpp
+++ b/src/slic3r/GUI/ConfigWizard.cpp
@@ -1605,7 +1605,27 @@ void ConfigWizard::priv::on_3rdparty_install(const VendorProfile *vendor, bool i
     load_pages();
 }
 
-bool ConfigWizard::priv::check_material_config(Technology technology)
+bool ConfigWizard::priv::on_bnt_finish()
+{
+    /* When Filaments or Sla Materials pages are activated, 
+     * materials for this pages are automaticaly updated and presets are reloaded.
+     * 
+     * But, if _Finish_ button was clicked without activation of those pages 
+     * (for example, just some printers were added/deleted), 
+     * than last changes wouldn't be updated for filaments/materials.
+     * SO, do that before close of Wizard
+     */
+    update_materials(T_ANY);
+    if (any_fff_selected)
+        page_filaments->reload_presets();
+    if (any_sla_selected)
+        page_sla_materials->reload_presets();
+
+    // check, that there is selected at least one filament/material
+    return check_materials_in_config(T_ANY);
+}
+
+bool ConfigWizard::priv::check_materials_in_config(Technology technology)
 {
     const auto exist_preset = [this](const std::string& section, const Materials& materials)
     {
@@ -1899,16 +1919,15 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
         // check, that there is selected at least one filament/material
         ConfigWizardPage* active_page = this->p->index->active_page();
         if ( (active_page == p->page_filaments || active_page == p->page_sla_materials)
-            && !p->check_material_config(dynamic_cast<PageMaterials*>(active_page)->materials->technology))
+            && !p->check_materials_in_config(dynamic_cast<PageMaterials*>(active_page)->materials->technology))
             return;
         this->p->index->go_next();
     });
 
     p->btn_finish->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &)
     {
-        if (!p->check_material_config(T_ANY))
-            return;
-        this->EndModal(wxID_OK);
+        if (p->on_bnt_finish())
+            this->EndModal(wxID_OK);
     });
 
     p->btn_sel_all->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &) {
diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp
index fc91909e7..a90832a3f 100644
--- a/src/slic3r/GUI/ConfigWizard_private.hpp
+++ b/src/slic3r/GUI/ConfigWizard_private.hpp
@@ -489,7 +489,8 @@ struct ConfigWizard::priv
     void on_printer_pick(PagePrinters *page, const PrinterPickerEvent &evt);
     void on_3rdparty_install(const VendorProfile *vendor, bool install);
 
-    bool check_material_config(Technology technology);
+    bool on_bnt_finish();
+    bool check_materials_in_config(Technology technology);
     void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater);
     // #ys_FIXME_alise
     void update_presets_in_config(const std::string& section, const std::string& alias_key, bool add);