From e5abc58277b9da2a3afbeae32380caa48bd87065 Mon Sep 17 00:00:00 2001 From: Randalphwa <38287198+Randalphwa@users.noreply.github.com> Date: Wed, 29 Nov 2023 20:41:38 -0800 Subject: [PATCH] Merge pull request #1322 from KeyWorksRW/darkmode Darkmode --- CHANGELOG.md | 15 +++++++++++++++ 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 ++- 7 files changed, 49 insertions(+), 14 deletions(-) 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 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">