1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-16 08:34:10 +02:00

ThemePrefs.cpp has fewer dependencies...

... Send an event via the app that projects listen to for theme update; don't
push it to projects directly.

This frees three files from dependency cycles.
This commit is contained in:
Paul Licameli 2019-05-13 03:39:08 -04:00
parent 519a988467
commit 7fc3adb54d
4 changed files with 27 additions and 15 deletions

View File

@ -165,6 +165,7 @@ scroll information. It also has some status flags.
#include "commands/CommandTargets.h" #include "commands/CommandTargets.h"
#include "commands/CommandType.h" #include "commands/CommandType.h"
#include "prefs/ThemePrefs.h"
#include "prefs/QualityPrefs.h" #include "prefs/QualityPrefs.h"
#include "prefs/TracksPrefs.h" #include "prefs/TracksPrefs.h"
@ -1425,6 +1426,8 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
&AudacityProject::OnCapture, &AudacityProject::OnCapture,
this); this);
wxTheApp->Bind(EVT_THEME_CHANGE, &AudacityProject::OnThemeChange, this);
#ifdef EXPERIMENTAL_DA2 #ifdef EXPERIMENTAL_DA2
ClearBackground();// For wxGTK. ClearBackground();// For wxGTK.
#endif #endif
@ -1566,6 +1569,19 @@ void AudacityProject::OnCapture(wxCommandEvent& evt)
mIsCapturing = false; mIsCapturing = false;
} }
void AudacityProject::OnThemeChange(wxCommandEvent& evt)
{
evt.Skip();
ApplyUpdatedTheme();
for( int ii = 0; ii < ToolBarCount; ++ii )
{
ToolBar *pToolBar = GetToolManager()->GetToolBar(ii);
if( pToolBar )
pToolBar->ReCreateButtons();
}
GetRulerPanel()->ReCreateButtons();
}
const std::shared_ptr<DirManager> &AudacityProject::GetDirManager() const std::shared_ptr<DirManager> &AudacityProject::GetDirManager()
{ {

View File

@ -541,6 +541,7 @@ public:
private: private:
void OnCapture(wxCommandEvent & evt); void OnCapture(wxCommandEvent & evt);
void OnThemeChange(wxCommandEvent & evt);
void InitialState(); void InitialState();
public: public:

View File

@ -31,13 +31,15 @@ Provides:
#include "../Audacity.h" #include "../Audacity.h"
#include "ThemePrefs.h" #include "ThemePrefs.h"
#include <wx/app.h>
#include <wx/wxprec.h> #include <wx/wxprec.h>
#include "../Prefs.h" #include "../Prefs.h"
#include "../Theme.h" #include "../Theme.h"
#include "../Project.h"
#include "../ShuttleGui.h" #include "../ShuttleGui.h"
#include "../AColor.h" #include "../AColor.h"
wxDEFINE_EVENT(EVT_THEME_CHANGE, wxCommandEvent);
enum eThemePrefsIds { enum eThemePrefsIds {
idLoadThemeCache=7000, idLoadThemeCache=7000,
idSaveThemeCache, idSaveThemeCache,
@ -207,24 +209,12 @@ void ThemePrefs::OnSaveThemeAsCode(wxCommandEvent & WXUNUSED(event))
theTheme.WriteImageDefs();// bonus - give them the Defs too. theTheme.WriteImageDefs();// bonus - give them the Defs too.
} }
#include "../AdornedRulerPanel.h"
#include "../toolbars/ToolManager.h"
void ThemePrefs::ApplyUpdatedImages() void ThemePrefs::ApplyUpdatedImages()
{ {
AColor::ReInit(); AColor::ReInit();
for (size_t i = 0; i < gAudacityProjects.size(); i++) { wxCommandEvent e{ EVT_THEME_CHANGE };
AudacityProject *p = gAudacityProjects[i].get(); wxTheApp->SafelyProcessEvent( e );
p->ApplyUpdatedTheme();
for( int ii = 0; ii < ToolBarCount; ++ii )
{
ToolBar *pToolBar = p->GetToolManager()->GetToolBar(ii);
if( pToolBar )
pToolBar->ReCreateButtons();
}
p->GetRulerPanel()->ReCreateButtons();
}
} }
/// Update the preferences stored on disk. /// Update the preferences stored on disk.

View File

@ -15,11 +15,16 @@
#define __AUDACITY_THEME_PREFS__ #define __AUDACITY_THEME_PREFS__
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/event.h> // to declare a custom event type
#include "PrefsPanel.h" #include "PrefsPanel.h"
class ShuttleGui; class ShuttleGui;
// An event sent to the application when the user changes choice of theme
wxDECLARE_EXPORTED_EVENT(AUDACITY_DLL_API,
EVT_THEME_CHANGE, wxCommandEvent);
#define THEME_PREFS_PLUGIN_SYMBOL ComponentInterfaceSymbol{ XO("Theme") } #define THEME_PREFS_PLUGIN_SYMBOL ComponentInterfaceSymbol{ XO("Theme") }
class ThemePrefs final : public PrefsPanel class ThemePrefs final : public PrefsPanel