1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +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/CommandType.h"
#include "prefs/ThemePrefs.h"
#include "prefs/QualityPrefs.h"
#include "prefs/TracksPrefs.h"
@ -1425,6 +1426,8 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
&AudacityProject::OnCapture,
this);
wxTheApp->Bind(EVT_THEME_CHANGE, &AudacityProject::OnThemeChange, this);
#ifdef EXPERIMENTAL_DA2
ClearBackground();// For wxGTK.
#endif
@ -1566,6 +1569,19 @@ void AudacityProject::OnCapture(wxCommandEvent& evt)
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()
{

View File

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

View File

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

View File

@ -15,11 +15,16 @@
#define __AUDACITY_THEME_PREFS__
#include <wx/defs.h>
#include <wx/event.h> // to declare a custom event type
#include "PrefsPanel.h"
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") }
class ThemePrefs final : public PrefsPanel