1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

Recode the Apply button of Spectrogram Preferences so it is next to OK/Cancel

This commit is contained in:
Paul Licameli 2015-08-20 13:25:36 -04:00
commit f4eaf070d8
7 changed files with 70 additions and 46 deletions

View File

@ -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<PrefsPanel *>(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<PrefsPanel*>(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;
}

View File

@ -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);

View File

@ -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

View File

@ -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)

View File

@ -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();

View File

@ -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)

View File

@ -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();