diff --git a/src/prefs/PrefsDialog.cpp b/src/prefs/PrefsDialog.cpp index 6b9f7e0ab..f5b07bbaf 100644 --- a/src/prefs/PrefsDialog.cpp +++ b/src/prefs/PrefsDialog.cpp @@ -75,6 +75,7 @@ BEGIN_EVENT_TABLE(PrefsDialog, wxDialog) EVT_BUTTON(wxID_OK, PrefsDialog::OnOK) EVT_BUTTON(wxID_CANCEL, PrefsDialog::OnCancel) + EVT_BUTTON(wxID_APPLY, PrefsDialog::OnApply) EVT_TREE_KEY_DOWN(wxID_ANY, PrefsDialog::OnTreeKeyDown) // Handles key events when tree has focus END_EVENT_TABLE() @@ -108,6 +109,16 @@ int wxTreebookExt::SetSelection(size_t n) wxString Temp = wxString(mTitlePrefix) + GetPageText( n ); ((wxDialog*)GetParent())->SetTitle( Temp ); ((wxDialog*)GetParent())->SetName( Temp ); + + PrefsPanel *const panel = static_cast(GetPage(n)); + const bool showApply = panel->ShowsApplyButton(); + wxWindow *const applyButton = wxWindow::FindWindowById(wxID_APPLY, GetParent()); + if (applyButton) { // might still be NULL during population + const bool changed = applyButton->Show(showApply); + if (changed) + GetParent()->Layout(); + } + return i; } @@ -255,7 +266,13 @@ PrefsDialog::PrefsDialog } S.EndVerticalLay(); - S.AddStandardButtons(eOkButton | eCancelButton); + S.AddStandardButtons(eOkButton | eCancelButton | eApplyButton); + + if (mUniquePage && !mUniquePage->ShowsApplyButton()) { + wxWindow *const applyButton = + wxWindow::FindWindowById(wxID_APPLY, GetParent()); + applyButton->Show(false); + } #if defined(__WXGTK__) if (mCategories) @@ -343,6 +360,14 @@ void PrefsDialog::OnCancel(wxCommandEvent & WXUNUSED(event)) EndModal(false); } +void PrefsDialog::OnApply(wxCommandEvent & WXUNUSED(event)) +{ + if (mCategories) + static_cast(mCategories->GetCurrentPage())->Apply(); + else + mUniquePage->Apply(); +} + void PrefsDialog::OnTreeKeyDown(wxTreeEvent & event) { if(event.GetKeyCode() == WXK_RETURN) @@ -479,3 +504,16 @@ void PrefsDialog::RecordExpansionState() else mFactories[0].expanded = true; } + +PrefsPanel::~PrefsPanel() +{ +} + +void PrefsPanel::Cancel() +{ +} + +bool PrefsPanel::ShowsApplyButton() +{ + return false; +} diff --git a/src/prefs/PrefsDialog.h b/src/prefs/PrefsDialog.h index 981128a95..723c67805 100644 --- a/src/prefs/PrefsDialog.h +++ b/src/prefs/PrefsDialog.h @@ -58,6 +58,7 @@ class PrefsDialog:public wxDialog void OnCategoryChange(wxCommandEvent & e); void OnOK(wxCommandEvent & e); void OnCancel(wxCommandEvent & e); + void OnApply(wxCommandEvent & e); void OnTreeKeyDown(wxTreeEvent & e); // Used to dismiss the dialog when enter is pressed with focus on tree void SelectPageByName(wxString pageName); diff --git a/src/prefs/PrefsPanel.h b/src/prefs/PrefsPanel.h index 2af21079a..c6cd0688d 100644 --- a/src/prefs/PrefsPanel.h +++ b/src/prefs/PrefsPanel.h @@ -50,15 +50,15 @@ class PrefsPanel:public wxPanel SetName(title); // Provide audible label } - virtual ~PrefsPanel() - { - } + virtual ~PrefsPanel(); virtual bool Apply() = 0; - virtual void Cancel() - { - } + // If it returns True, the Apply button is added below the panel + // Default returns false + virtual bool ShowsApplyButton(); + + virtual void Cancel(); }; class PrefsPanelFactory diff --git a/src/prefs/SpectrumPrefs.cpp b/src/prefs/SpectrumPrefs.cpp index f60f42d1c..7636dad2f 100644 --- a/src/prefs/SpectrumPrefs.cpp +++ b/src/prefs/SpectrumPrefs.cpp @@ -70,7 +70,6 @@ enum { ID_SPECTRAL_SELECTION, #endif ID_DEFAULTS, - ID_APPLY, }; void SpectrumPrefs::Populate(int windowSize) @@ -289,12 +288,6 @@ void SpectrumPrefs::PopulateOrExchange(ShuttleGui & S) S.EndStatic(); #endif - S.StartMultiColumn(2, wxALIGN_RIGHT); - { - S.Id(ID_APPLY).AddButton(_("Appl&y")); - } - S.EndMultiColumn(); - EnableDisableSTFTOnlyControls(); mPopulating = false; @@ -408,6 +401,17 @@ bool SpectrumPrefs::Apply() partner->SetDisplay(WaveTrack::Spectrum); } + if (isOpenPage) { + TrackPanel *const tp = ::GetActiveProject()->GetTrackPanel(); + tp->UpdateVRulers(); + tp->Refresh(false); + } + + return true; +} + +bool SpectrumPrefs::ShowsApplyButton() +{ return true; } @@ -468,16 +472,6 @@ void SpectrumPrefs::EnableDisableSTFTOnlyControls() #endif } -void SpectrumPrefs::OnApply(wxCommandEvent &) -{ - if (Validate()) { - Apply(); - TrackPanel *const tp = ::GetActiveProject()->GetTrackPanel(); - tp->UpdateVRulers(); - tp->Refresh(false); - } -} - BEGIN_EVENT_TABLE(SpectrumPrefs, PrefsPanel) EVT_CHOICE(ID_WINDOW_SIZE, SpectrumPrefs::OnWindowSize) EVT_CHECKBOX(ID_DEFAULTS, SpectrumPrefs::OnDefaults) @@ -495,8 +489,6 @@ BEGIN_EVENT_TABLE(SpectrumPrefs, PrefsPanel) EVT_CHECKBOX(ID_GRAYSCALE, SpectrumPrefs::OnControl) EVT_CHECKBOX(ID_SPECTRAL_SELECTION, SpectrumPrefs::OnControl) - EVT_BUTTON(ID_APPLY, SpectrumPrefs::OnApply) - END_EVENT_TABLE() SpectrumPrefsFactory::SpectrumPrefsFactory(WaveTrack *wt) diff --git a/src/prefs/SpectrumPrefs.h b/src/prefs/SpectrumPrefs.h index 84feb2869..cceef7955 100644 --- a/src/prefs/SpectrumPrefs.h +++ b/src/prefs/SpectrumPrefs.h @@ -44,6 +44,7 @@ class SpectrumPrefs:public PrefsPanel SpectrumPrefs(wxWindow * parent, WaveTrack *wt); virtual ~SpectrumPrefs(); virtual bool Apply(); + virtual bool ShowsApplyButton(); virtual bool Validate(); private: @@ -55,7 +56,6 @@ class SpectrumPrefs:public PrefsPanel void OnWindowSize(wxCommandEvent &event); void OnDefaults(wxCommandEvent&); void OnAlgorithm(wxCommandEvent &); - void OnApply(wxCommandEvent &); DECLARE_EVENT_TABLE() void EnableDisableSTFTOnlyControls(); diff --git a/src/prefs/WaveformPrefs.cpp b/src/prefs/WaveformPrefs.cpp index da9d24975..cb3e5b2cd 100644 --- a/src/prefs/WaveformPrefs.cpp +++ b/src/prefs/WaveformPrefs.cpp @@ -50,7 +50,6 @@ WaveformPrefs::~WaveformPrefs() enum { ID_DEFAULTS = 10001, - ID_APPLY, ID_SCALE, ID_RANGE, @@ -112,12 +111,6 @@ void WaveformPrefs::PopulateOrExchange(ShuttleGui & S) S.EndStatic(); */ - S.StartMultiColumn(2, wxALIGN_RIGHT); - { - S.Id(ID_APPLY).AddButton(_("Appl&y")); - } - S.EndMultiColumn(); - EnableDisableRange(); mPopulating = false; @@ -184,6 +177,17 @@ bool WaveformPrefs::Apply() partner->SetDisplay(WaveTrack::Waveform); } + if (isOpenPage) { + TrackPanel *const tp = ::GetActiveProject()->GetTrackPanel(); + tp->UpdateVRulers(); + tp->Refresh(false); + } + + return true; +} + +bool WaveformPrefs::ShowsApplyButton() +{ return true; } @@ -219,16 +223,6 @@ void WaveformPrefs::OnDefaults(wxCommandEvent &) } } -void WaveformPrefs::OnApply(wxCommandEvent &) -{ - if (Validate()) { - Apply(); - TrackPanel *const tp = ::GetActiveProject()->GetTrackPanel(); - tp->UpdateVRulers(); - tp->Refresh(false); - } -} - void WaveformPrefs::EnableDisableRange() { mRangeChoice->Enable @@ -241,7 +235,6 @@ EVT_CHOICE(ID_SCALE, WaveformPrefs::OnScale) EVT_CHOICE(ID_RANGE, WaveformPrefs::OnControl) EVT_CHECKBOX(ID_DEFAULTS, WaveformPrefs::OnDefaults) -EVT_BUTTON(ID_APPLY, WaveformPrefs::OnApply) END_EVENT_TABLE() WaveformPrefsFactory::WaveformPrefsFactory(WaveTrack *wt) diff --git a/src/prefs/WaveformPrefs.h b/src/prefs/WaveformPrefs.h index 23f0d826f..7145172d6 100644 --- a/src/prefs/WaveformPrefs.h +++ b/src/prefs/WaveformPrefs.h @@ -26,6 +26,7 @@ public: WaveformPrefs(wxWindow * parent, WaveTrack *wt); virtual ~WaveformPrefs(); virtual bool Apply(); + virtual bool ShowsApplyButton(); virtual bool Validate(); private: @@ -35,7 +36,6 @@ private: void OnControl(wxCommandEvent&); void OnScale(wxCommandEvent&); void OnDefaults(wxCommandEvent&); - void OnApply(wxCommandEvent &); DECLARE_EVENT_TABLE() void EnableDisableRange();