mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-26 07:13:49 +01:00
Future subclasses of PrefsDialog may choose the preferred page by other means.
This commit is contained in:
@@ -233,23 +233,6 @@ PrefsDialog::PrefsDialog
|
||||
|
||||
S.AddStandardButtons(eOkButton | eCancelButton);
|
||||
|
||||
/* long is signed, size_t is unsigned. On some platforms they are different
|
||||
* lengths as well. So we must check that the stored category is both > 0
|
||||
* and within the possible range of categories, making the first check on the
|
||||
* _signed_ value to avoid issues when converting an unsigned one.
|
||||
*/
|
||||
size_t selected;
|
||||
long prefscat = gPrefs->Read(wxT("/Prefs/PrefsCategory"), 0L);
|
||||
if (prefscat > 0L )
|
||||
selected = prefscat; // only assign if number will fit
|
||||
else
|
||||
selected = 0; // use 0 if value can't be assigned
|
||||
|
||||
if (selected >= mCategories->GetPageCount())
|
||||
selected = 0; // clamp to available range of tabs
|
||||
|
||||
mCategories->SetSelection(selected);
|
||||
|
||||
#if defined(__WXGTK__)
|
||||
mCategories->GetTreeCtrl()->EnsureVisible(mCategories->GetTreeCtrl()->GetRootItem());
|
||||
#endif
|
||||
@@ -297,6 +280,21 @@ PrefsDialog::~PrefsDialog()
|
||||
{
|
||||
}
|
||||
|
||||
int PrefsDialog::ShowModal()
|
||||
{
|
||||
/* long is signed, size_t is unsigned. On some platforms they are different
|
||||
* lengths as well. So we must check that the stored category is both > 0
|
||||
* and within the possible range of categories, making the first check on the
|
||||
* _signed_ value to avoid issues when converting an unsigned one.
|
||||
*/
|
||||
long selected = GetPreferredPage();
|
||||
if (selected < 0 || size_t(selected) >= mCategories->GetPageCount())
|
||||
selected = 0; // clamp to available range of tabs
|
||||
mCategories->SetSelection(selected);
|
||||
|
||||
return wxDialog::ShowModal();
|
||||
}
|
||||
|
||||
void PrefsDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
|
||||
{
|
||||
RecordExpansionState();
|
||||
@@ -338,8 +336,7 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event))
|
||||
panel->Apply();
|
||||
}
|
||||
|
||||
gPrefs->Write(wxT("/Prefs/PrefsCategory"), (long)mCategories->GetSelection());
|
||||
gPrefs->Flush();
|
||||
SavePreferredPage();
|
||||
|
||||
#if USE_PORTMIXER
|
||||
if (gAudioIO) {
|
||||
@@ -394,6 +391,32 @@ void PrefsDialog::ShowTempDirPage()
|
||||
SelectPageByName(_("Directories"));
|
||||
}
|
||||
|
||||
int PrefsDialog::GetSelectedPage() const
|
||||
{
|
||||
return mCategories->GetSelection();
|
||||
}
|
||||
|
||||
GlobalPrefsDialog::GlobalPrefsDialog(wxWindow * parent)
|
||||
: PrefsDialog(parent, _("Preferences: "), DefaultFactories())
|
||||
{
|
||||
}
|
||||
|
||||
GlobalPrefsDialog::~GlobalPrefsDialog()
|
||||
{
|
||||
}
|
||||
|
||||
long GlobalPrefsDialog::GetPreferredPage()
|
||||
{
|
||||
long prefscat = gPrefs->Read(wxT("/Prefs/PrefsCategory"), 0L);
|
||||
return prefscat;
|
||||
}
|
||||
|
||||
void GlobalPrefsDialog::SavePreferredPage()
|
||||
{
|
||||
gPrefs->Write(wxT("/Prefs/PrefsCategory"), (long)GetSelectedPage());
|
||||
gPrefs->Flush();
|
||||
}
|
||||
|
||||
void PrefsDialog::RecordExpansionState()
|
||||
{
|
||||
// Remember expansion state of the tree control
|
||||
|
||||
@@ -49,6 +49,9 @@ class PrefsDialog:public wxDialog
|
||||
Factories &factories = DefaultFactories());
|
||||
virtual ~PrefsDialog();
|
||||
|
||||
// Defined this so a protected virtual can be invoked after the constructor
|
||||
virtual int ShowModal();
|
||||
|
||||
void OnCategoryChange(wxCommandEvent & e);
|
||||
void OnOK(wxCommandEvent & e);
|
||||
void OnCancel(wxCommandEvent & e);
|
||||
@@ -57,9 +60,19 @@ class PrefsDialog:public wxDialog
|
||||
void SelectPageByName(wxString pageName);
|
||||
void ShowTempDirPage();
|
||||
|
||||
private:
|
||||
void RecordExpansionState();
|
||||
// Accessor to help implementations of SavePreferredPage(),
|
||||
// such as by saving a preference after DoModal() returns
|
||||
int GetSelectedPage() const;
|
||||
|
||||
protected:
|
||||
// Decide which page to open first; return -1 for undecided
|
||||
virtual long GetPreferredPage() = 0;
|
||||
|
||||
// Called after OK is clicked and all pages validate
|
||||
virtual void SavePreferredPage() = 0;
|
||||
|
||||
private:
|
||||
void RecordExpansionState();
|
||||
wxTreebook *mCategories;
|
||||
Factories &mFactories;
|
||||
const wxString mTitlePrefix;
|
||||
@@ -67,4 +80,15 @@ class PrefsDialog:public wxDialog
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
// This adds code appropriate only to the original use of PrefsDialog for
|
||||
// global settings -- not its reuses elsewhere as in View Settings
|
||||
class GlobalPrefsDialog : public PrefsDialog
|
||||
{
|
||||
public:
|
||||
GlobalPrefsDialog(wxWindow * parent);
|
||||
virtual ~GlobalPrefsDialog();
|
||||
virtual long GetPreferredPage();
|
||||
virtual void SavePreferredPage();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user