From cc39a32ed9e0bbaa24cc691399f358e6db3802d4 Mon Sep 17 00:00:00 2001 From: Randalphwa <38287198+Randalphwa@users.noreply.github.com> Date: Wed, 29 Nov 2023 20:04:02 -0800 Subject: [PATCH 1/3] Sizers: Ignore hide_children if showing hidden This was fixed for wxStaticBoxSizer because it contained a parent window. However, all the other sizers need to ensure they didn't hide the children if the user has the Show Hidden toggle button on. --- src/generate/gen_box_sizer.cpp | 4 +++- src/generate/gen_flexgrid_sizer.cpp | 18 +++++++++--------- src/generate/gen_grid_sizer.cpp | 2 +- src/generate/gen_gridbag_sizer.cpp | 2 +- src/generate/gen_statchkbox_sizer.cpp | 2 +- src/generate/gen_statradiobox_sizer.cpp | 2 +- src/generate/gen_wrap_sizer.cpp | 2 +- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/generate/gen_box_sizer.cpp b/src/generate/gen_box_sizer.cpp index e0b6fb0cc..b5c2a1d42 100644 --- a/src/generate/gen_box_sizer.cpp +++ b/src/generate/gen_box_sizer.cpp @@ -31,7 +31,9 @@ void BoxSizerGenerator::AfterCreation(wxObject* wxobject, wxWindow* /*wxparent*/ if (node->as_bool(prop_hide_children)) { if (auto sizer = wxStaticCast(wxobject, wxSizer); sizer) - sizer->ShowItems(false); + { + sizer->ShowItems(getMockup()->IsShowingHidden()); + } } } diff --git a/src/generate/gen_flexgrid_sizer.cpp b/src/generate/gen_flexgrid_sizer.cpp index a35122468..785f9cc57 100644 --- a/src/generate/gen_flexgrid_sizer.cpp +++ b/src/generate/gen_flexgrid_sizer.cpp @@ -144,6 +144,15 @@ bool FlexGridSizerGenerator::ConstructionCode(Code& code) return true; } +void FlexGridSizerGenerator::AfterCreation(wxObject* wxobject, wxWindow* /*wxparent*/, Node* node, bool /* is_preview */) +{ + if (node->as_bool(prop_hide_children)) + { + if (auto sizer = wxStaticCast(wxobject, wxSizer); sizer) + sizer->ShowItems(getMockup()->IsShowingHidden()); + } +} + bool FlexGridSizerGenerator::AfterChildrenCode(Code& code) { if (code.IsTrue(prop_hide_children)) @@ -179,15 +188,6 @@ bool FlexGridSizerGenerator::AfterChildrenCode(Code& code) return true; } -void FlexGridSizerGenerator::AfterCreation(wxObject* wxobject, wxWindow* /*wxparent*/, Node* node, bool /* is_preview */) -{ - if (node->as_bool(prop_hide_children)) - { - if (auto sizer = wxStaticCast(wxobject, wxSizer); sizer) - sizer->ShowItems(false); - } -} - bool FlexGridSizerGenerator::GetIncludes(Node* node, std::set& set_src, std::set& set_hdr, int /* language */) { diff --git a/src/generate/gen_grid_sizer.cpp b/src/generate/gen_grid_sizer.cpp index 1395c43ad..ea69c828f 100644 --- a/src/generate/gen_grid_sizer.cpp +++ b/src/generate/gen_grid_sizer.cpp @@ -35,7 +35,7 @@ void GridSizerGenerator::AfterCreation(wxObject* wxobject, wxWindow* /*wxparent* if (node->as_bool(prop_hide_children)) { if (auto sizer = wxStaticCast(wxobject, wxSizer); sizer) - sizer->ShowItems(false); + sizer->ShowItems(getMockup()->IsShowingHidden()); } } diff --git a/src/generate/gen_gridbag_sizer.cpp b/src/generate/gen_gridbag_sizer.cpp index e1a8070f1..7495fb829 100644 --- a/src/generate/gen_gridbag_sizer.cpp +++ b/src/generate/gen_gridbag_sizer.cpp @@ -40,7 +40,7 @@ void GridBagSizerGenerator::AfterCreation(wxObject* wxobject, wxWindow* /*wxpare if (node->as_bool(prop_hide_children)) { if (auto sizer = wxStaticCast(wxobject, wxSizer); sizer) - sizer->ShowItems(false); + sizer->ShowItems(getMockup()->IsShowingHidden()); } // For storing objects whose postion needs to be determined diff --git a/src/generate/gen_statchkbox_sizer.cpp b/src/generate/gen_statchkbox_sizer.cpp index 4cdabf49e..4361e1f96 100644 --- a/src/generate/gen_statchkbox_sizer.cpp +++ b/src/generate/gen_statchkbox_sizer.cpp @@ -69,7 +69,7 @@ void StaticCheckboxBoxSizerGenerator::AfterCreation(wxObject* wxobject, wxWindow if (node->as_bool(prop_hidden)) { if (auto sizer = wxStaticCast(wxobject, wxSizer); sizer) - sizer->ShowItems(false); + sizer->ShowItems(getMockup()->IsShowingHidden()); } } diff --git a/src/generate/gen_statradiobox_sizer.cpp b/src/generate/gen_statradiobox_sizer.cpp index f7a3b7ce4..a9642f204 100644 --- a/src/generate/gen_statradiobox_sizer.cpp +++ b/src/generate/gen_statradiobox_sizer.cpp @@ -63,7 +63,7 @@ void StaticRadioBtnBoxSizerGenerator::AfterCreation(wxObject* wxobject, wxWindow if (node->as_bool(prop_hidden)) { if (auto sizer = wxStaticCast(wxobject, wxSizer); sizer) - sizer->ShowItems(false); + sizer->ShowItems(getMockup()->IsShowingHidden()); } } diff --git a/src/generate/gen_wrap_sizer.cpp b/src/generate/gen_wrap_sizer.cpp index 35504ba4f..91bc27d9e 100644 --- a/src/generate/gen_wrap_sizer.cpp +++ b/src/generate/gen_wrap_sizer.cpp @@ -32,7 +32,7 @@ void WrapSizerGenerator::AfterCreation(wxObject* wxobject, wxWindow* /*wxparent* if (node->as_bool(prop_hide_children)) { if (auto sizer = wxStaticCast(wxobject, wxSizer); sizer) - sizer->ShowItems(false); + sizer->ShowItems(getMockup()->IsShowingHidden()); } } From 15f80f7995bb930aa43d56601e00098a69f876ae Mon Sep 17 00:00:00 2001 From: Randalphwa <38287198+Randalphwa@users.noreply.github.com> Date: Wed, 29 Nov 2023 20:39:03 -0800 Subject: [PATCH 2/3] Fix crash after turning off dark mode This also displays the dark mode settings in the Preferences dialog when run under Windows. --- src/mainapp.cpp | 2 +- src/preferences.cpp | 6 +++++- src/preferences.h | 11 +++++++++++ src/ui/preferences_dlg.cpp | 25 ++++++++++++++----------- src/ui/preferences_dlg.h | 1 + src/wxui/wxUiEditor.wxui | 3 ++- 6 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/mainapp.cpp b/src/mainapp.cpp index 69ba3b687..55706ea49 100644 --- a/src/mainapp.cpp +++ b/src/mainapp.cpp @@ -69,7 +69,7 @@ wxIMPLEMENT_APP(App); tt_string tt_empty_cstr; -#if wxCHECK_VERSION(3, 3, 0) && defined(_WIN32) +#if defined(_WIN32) #include class DarkSettings : public wxDarkModeSettings diff --git a/src/preferences.cpp b/src/preferences.cpp index e6f40a2a1..f39991c8c 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -56,7 +56,6 @@ void Prefs::WriteConfig() config->Write("fullpath_title", m_fullpath_title); config->Write("enable_wakatime", m_enable_wakatime); - config->Write("dark_mode", m_dark_mode); config->Write("high_contrast", m_high_constrast); config->Write("load_last_project", m_is_load_last_project); config->Write("right_propgrid", m_is_right_propgrid); @@ -72,6 +71,11 @@ void Prefs::WriteConfig() config->Write("python_line_length", m_python_line_length); config->Write("ruby_line_length", m_ruby_line_length); + if (m_dark_mode_pending & PENDING_DARK_MODE_ENABLE) + { + config->Write("dark_mode", m_dark_mode_pending & PENDING_DARK_MODE_ON ? true : false); + } + config->SetPath("/"); } diff --git a/src/preferences.h b/src/preferences.h index d13c48e04..00e9aa141 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -43,7 +43,9 @@ class Prefs bool is_WakaTimeEnabled() const { return m_enable_wakatime; } bool is_DarkMode() const { return m_dark_mode; } + bool is_DarkModePending() const { return m_dark_mode_pending; } void set_DarkMode(bool value) { m_dark_mode = value; } + void set_DarkModePending(size_t value) { m_dark_mode_pending = value; } bool is_HighContrast() const { return m_high_constrast; } void set_HighContrast(bool value) { m_high_constrast = value; } @@ -128,6 +130,13 @@ class Prefs PREFS_PJT_MEMBER_PREFIX = 1 << 1, }; + enum : size_t + { + PENDING_DARK_MODE_ENABLE = 1, + PENDING_DARK_MODE_ON = 1 << 1, + PENDING_DARK_MODE_OFF = 1 << 2, + }; + // clang-format on private: @@ -144,6 +153,8 @@ class Prefs wxColour m_colour_python { wxColour("#FF00FF") }; wxColour m_colour_ruby { wxColour("#FF00FF") }; + size_t m_dark_mode_pending { 0 }; // 0 = no change, 1 = dark_mode_on, 2 = dark_mode_off + int m_cpp_line_length { 110 }; int m_python_line_length { 90 }; int m_ruby_line_length { 80 }; diff --git a/src/ui/preferences_dlg.cpp b/src/ui/preferences_dlg.cpp index 889db2412..0d7f4a8d0 100644 --- a/src/ui/preferences_dlg.cpp +++ b/src/ui/preferences_dlg.cpp @@ -31,7 +31,7 @@ bool PreferencesDlg::Create(wxWindow* parent, wxWindowID id, const wxString& tit auto* page_general = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); notebook->AddPage(page_general, "General", true); - auto* page_sizer_1 = new wxBoxSizer(wxVERTICAL); + m_general_page_sizer = new wxBoxSizer(wxVERTICAL); m_box_dark_settings = new wxBoxSizer(wxHORIZONTAL); @@ -43,25 +43,25 @@ bool PreferencesDlg::Create(wxWindow* parent, wxWindowID id, const wxString& tit m_check_high_contrast->SetToolTip("Only used if Dark Mode is selected"); m_box_dark_settings->Add(m_check_high_contrast, wxSizerFlags().Border(wxALL)); m_box_dark_settings->ShowItems(false); - page_sizer_1->Add(m_box_dark_settings, + m_general_page_sizer->Add(m_box_dark_settings, wxSizerFlags().Expand().Border(wxRIGHT|wxTOP|wxBOTTOM, wxSizerFlags::GetDefaultBorder())); m_check_right_propgrid = new wxCheckBox(page_general, wxID_ANY, "Property Panel on Right"); m_check_right_propgrid->SetToolTip("If checked, the Property panel will be moved to the right side"); - page_sizer_1->Add(m_check_right_propgrid, wxSizerFlags(1).Border(wxALL)); + m_general_page_sizer->Add(m_check_right_propgrid, wxSizerFlags(1).Border(wxALL)); m_check_load_last = new wxCheckBox(page_general, wxID_ANY, "Always load last project"); - page_sizer_1->Add(m_check_load_last, wxSizerFlags(1).Border(wxALL)); + m_general_page_sizer->Add(m_check_load_last, wxSizerFlags(1).Border(wxALL)); m_check_fullpath = new wxCheckBox(page_general, wxID_ANY, "Full project path in title bar"); - page_sizer_1->Add(m_check_fullpath, wxSizerFlags(1).Border(wxALL)); + m_general_page_sizer->Add(m_check_fullpath, wxSizerFlags(1).Border(wxALL)); auto* checkBox_wakatime = new wxCheckBox(page_general, wxID_ANY, "Enable WakaTime"); checkBox_wakatime->SetValue(true); checkBox_wakatime->SetValidator(wxGenericValidator(&m_isWakaTimeEnabled)); checkBox_wakatime->SetToolTip( "If you have WakaTime installed, checking this will record time spent in the editor as \"designing\". (See https://wakatime.com/about)"); - page_sizer_1->Add(checkBox_wakatime, wxSizerFlags().Border(wxALL)); + m_general_page_sizer->Add(checkBox_wakatime, wxSizerFlags().Border(wxALL)); m_box_code_font = new wxBoxSizer(wxHORIZONTAL); @@ -74,8 +74,8 @@ bool PreferencesDlg::Create(wxWindow* parent, wxWindowID id, const wxString& tit m_code_font_picker->SetToolTip("This font will be used for all of the Code panels"); m_box_code_font->Add(m_code_font_picker, wxSizerFlags(1).Expand().Border(wxALL)); - page_sizer_1->Add(m_box_code_font, wxSizerFlags().Expand().Border(wxALL)); - page_general->SetSizerAndFit(page_sizer_1); + m_general_page_sizer->Add(m_box_code_font, wxSizerFlags().Expand().Border(wxALL)); + page_general->SetSizerAndFit(m_general_page_sizer); auto* page_cpp = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); notebook->AddPage(page_cpp, "C++"); @@ -234,8 +234,9 @@ void PreferencesDlg::OnInit(wxInitDialogEvent& event) m_box_code_font->ShowItems(false); // m_code_font_picker = UserPrefs.get_CodeDisplayFont(); -#if !wxCHECK_VERSION(3, 3, 0) || !defined(_WIN32) - m_box_dark_settings->ShowItems(false); +#if defined(__WXMSW__) + m_box_dark_settings->ShowItems(true); + m_general_page_sizer->Layout(); Fit(); #endif @@ -274,7 +275,9 @@ void PreferencesDlg::OnOK(wxCommandEvent& WXUNUSED(event)) if (m_check_fullpath->GetValue() != UserPrefs.is_FullPathTitle()) is_fullpath_changed = true; - UserPrefs.set_DarkMode(m_check_dark_mode->GetValue()); + UserPrefs.set_DarkModePending( + Prefs::PENDING_DARK_MODE_ENABLE | + (m_check_dark_mode->GetValue() ? Prefs::PENDING_DARK_MODE_ON : Prefs::PENDING_DARK_MODE_OFF)); UserPrefs.set_HighContrast(m_check_high_contrast->GetValue()); UserPrefs.set_FullPathTitle(m_check_fullpath->GetValue()); diff --git a/src/ui/preferences_dlg.h b/src/ui/preferences_dlg.h index 65e3df56b..0578597a4 100644 --- a/src/ui/preferences_dlg.h +++ b/src/ui/preferences_dlg.h @@ -52,6 +52,7 @@ class PreferencesDlg : public wxDialog wxBoxSizer* m_box_code_font; wxBoxSizer* m_box_dark_settings; + wxBoxSizer* m_general_page_sizer; wxCheckBox* m_check_cpp_snake_case; wxCheckBox* m_check_dark_mode; wxCheckBox* m_check_fullpath; diff --git a/src/wxui/wxUiEditor.wxui b/src/wxui/wxUiEditor.wxui index d2db2c981..22c36cadc 100644 --- a/src/wxui/wxUiEditor.wxui +++ b/src/wxui/wxUiEditor.wxui @@ -6456,8 +6456,9 @@ window_style="wxTAB_TRAVERSAL"> + var_name="m_general_page_sizer"> Date: Wed, 29 Nov 2023 20:39:50 -0800 Subject: [PATCH 3/3] Update CHANGELOG to reflect 1.2.1 changes This includes the information about Dark Mode now being available. --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e88d6e4e9..a1d2a4959 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,21 @@ # Change Log All notable changes to this project will be documented in this file. +## [unreleased (1.2.1)] + +### Added + +- Dark Mode and High Contrast Dark Mode are now available in the Prefences dialog on Windows. + +### Changed + +- The `hide_children` property in the wxStaticBoxSizer has been removed since the `hidden` property does exactly the same thing. Projects where `hide_children` was set will be automatically converted to use `hidden` instead. + +### Fixed + +- The Show Hidden on the toolbar now shows (in the Mockup panel) the children of sizers that have their children hidden. +- Setting `hidden` in a wxStaticBoxSizer did not generate any code to hide the wxStaticBox and it's children (you had to check `hide_children` to get the code). This has been fixed. + ## [Released (1.2.0)] ### Added