From 2caad0f40775f2d9c1028636abc5c0af9fec25d6 Mon Sep 17 00:00:00 2001 From: James Crook Date: Sat, 10 Feb 2018 16:31:10 +0000 Subject: [PATCH] Implement ReloadPreferences for SetPreferences Command. --- src/Menus.cpp | 33 +++++++++++++++++++++++++++++ src/Menus.h | 1 + src/commands/PreferenceCommands.cpp | 5 +++-- src/prefs/PrefsDialog.cpp | 5 ++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 8217d3968..a70789c02 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -1618,6 +1618,8 @@ void AudacityProject::CreateMenusAndCommands() AudioIONotBusyFlag, AudioIONotBusyFlag); c->AddItem(wxT("SetTrack"), _("Set Track..."), FN(OnAudacityCommand), AudioIONotBusyFlag, AudioIONotBusyFlag); + c->AddItem(wxT("ReloadPreferences"), _("&Reload Preferences..."), FN(OnReloadPreferences), + AudioIONotBusyFlag, AudioIONotBusyFlag); c->EndSubMenu(); @@ -4892,6 +4894,37 @@ void AudacityProject::OnPreferences(const CommandContext &WXUNUSED(context) ) } } +void AudacityProject::OnReloadPreferences(const CommandContext &WXUNUSED(context) ) +{ + { + GlobalPrefsDialog dialog(this /* parent */ ); + wxCommandEvent Evt; + //dialog.Show(); + dialog.OnOK(Evt); + } + + // LL: Moved from PrefsDialog since wxWidgets on OSX can't deal with + // rebuilding the menus while the PrefsDialog is still in the modal + // state. + for (size_t i = 0; i < gAudacityProjects.size(); i++) { + AudacityProject *p = gAudacityProjects[i].get(); + + p->RebuildMenuBar(); + p->RebuildOtherMenus(); +// TODO: The comment below suggests this workaround is obsolete. +#if defined(__WXGTK__) + // Workaround for: + // + // http://bugzilla.audacityteam.org/show_bug.cgi?id=458 + // + // This workaround should be removed when Audacity updates to wxWidgets 3.x which has a fix. + wxRect r = p->GetRect(); + p->SetSize(wxSize(1,1)); + p->SetSize(r.GetSize()); +#endif + } +} + void AudacityProject::OnPageSetup(const CommandContext &WXUNUSED(context) ) { HandlePageSetup(this); diff --git a/src/Menus.h b/src/Menus.h index d570e7c26..0a42ebdaa 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -235,6 +235,7 @@ void OnExportLabels(const CommandContext &context ); void OnExportMIDI(const CommandContext &context ); void OnPreferences(const CommandContext &context ); +void OnReloadPreferences(const CommandContext &context ); void OnPageSetup(const CommandContext &context ); void OnPrint(const CommandContext &context ); diff --git a/src/commands/PreferenceCommands.cpp b/src/commands/PreferenceCommands.cpp index eee79ac9f..bfccb87aa 100644 --- a/src/commands/PreferenceCommands.cpp +++ b/src/commands/PreferenceCommands.cpp @@ -20,6 +20,7 @@ SetPreferenceCommand classes #include "../Prefs.h" #include "../ShuttleGui.h" #include "../commands/CommandContext.h" +#include "../Project.h" // for "OnReloadPreferences". bool GetPreferenceCommand::DefineParams( ShuttleParams & S ){ S.Define( mName, wxT("Name"), wxT("") ); @@ -68,11 +69,11 @@ void SetPreferenceCommand::PopulateOrExchange(ShuttleGui & S) S.EndMultiColumn(); } -bool SetPreferenceCommand::Apply(const CommandContext & WXUNUSED(context)) +bool SetPreferenceCommand::Apply(const CommandContext & context) { bool bOK = gPrefs->Write(mName, mValue) && gPrefs->Flush(); if( bOK && mbReload ) - bOK = bOK; // Not yet implemented. + context.GetProject()->OnReloadPreferences( context ); return bOK; } diff --git a/src/prefs/PrefsDialog.cpp b/src/prefs/PrefsDialog.cpp index d550771e3..027baf04d 100644 --- a/src/prefs/PrefsDialog.cpp +++ b/src/prefs/PrefsDialog.cpp @@ -518,7 +518,10 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event)) WaveformSettings::defaults().LoadPrefs(); - EndModal(true); + if( IsModal() ) + EndModal(true); + else + Destroy(); } void PrefsDialog::SelectPageByName(const wxString &pageName)