mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-06 15:37:44 +02:00
Prefs dialog, when constructed with a single page, does not show the tree
This commit is contained in:
parent
4868b6afeb
commit
28d552c39b
@ -196,15 +196,22 @@ PrefsDialog::PrefsDialog
|
|||||||
wxDefaultSize,
|
wxDefaultSize,
|
||||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||||
, mFactories(factories)
|
, mFactories(factories)
|
||||||
|
, mCategories(NULL)
|
||||||
|
, mUniquePage(NULL)
|
||||||
, mTitlePrefix(titlePrefix)
|
, mTitlePrefix(titlePrefix)
|
||||||
{
|
{
|
||||||
|
wxASSERT(factories.size() > 0);
|
||||||
|
const bool uniquePage = (factories.size() == 1);
|
||||||
|
|
||||||
ShuttleGui S(this, eIsCreating);
|
ShuttleGui S(this, eIsCreating);
|
||||||
|
|
||||||
S.StartVerticalLay(true);
|
S.StartVerticalLay(true);
|
||||||
{
|
{
|
||||||
|
wxASSERT(factories.size() > 0);
|
||||||
|
if (!uniquePage) {
|
||||||
|
mCategories = new wxTreebookExt(this, wxID_ANY, mTitlePrefix);
|
||||||
S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, true);
|
S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, true);
|
||||||
{
|
{
|
||||||
mCategories = new wxTreebookExt(this, wxID_ANY, mTitlePrefix);
|
|
||||||
S.Prop(1);
|
S.Prop(1);
|
||||||
S.AddWindow(mCategories, wxEXPAND);
|
S.AddWindow(mCategories, wxEXPAND);
|
||||||
|
|
||||||
@ -237,6 +244,14 @@ PrefsDialog::PrefsDialog
|
|||||||
}
|
}
|
||||||
S.EndHorizontalLay();
|
S.EndHorizontalLay();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// Unique page, don't show the factory
|
||||||
|
const PrefsNode &node = factories[0];
|
||||||
|
PrefsPanelFactory &factory = *node.pFactory;
|
||||||
|
mUniquePage = factory.Create(this);
|
||||||
|
S.AddWindow(mUniquePage, wxEXPAND);
|
||||||
|
}
|
||||||
|
}
|
||||||
S.EndVerticalLay();
|
S.EndVerticalLay();
|
||||||
|
|
||||||
S.AddStandardButtons(eOkButton | eCancelButton);
|
S.AddStandardButtons(eOkButton | eCancelButton);
|
||||||
@ -251,6 +266,7 @@ PrefsDialog::PrefsDialog
|
|||||||
wxSize sz = GetSize();
|
wxSize sz = GetSize();
|
||||||
|
|
||||||
// Collapse nodes only after layout so the tree is wide enough
|
// Collapse nodes only after layout so the tree is wide enough
|
||||||
|
if (mCategories)
|
||||||
{
|
{
|
||||||
int iPage = 0;
|
int iPage = 0;
|
||||||
for (Factories::const_iterator it = factories.begin(), end = factories.end();
|
for (Factories::const_iterator it = factories.begin(), end = factories.end();
|
||||||
@ -290,6 +306,7 @@ PrefsDialog::~PrefsDialog()
|
|||||||
|
|
||||||
int PrefsDialog::ShowModal()
|
int PrefsDialog::ShowModal()
|
||||||
{
|
{
|
||||||
|
if (mCategories) {
|
||||||
/* long is signed, size_t is unsigned. On some platforms they are different
|
/* 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
|
* 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
|
* and within the possible range of categories, making the first check on the
|
||||||
@ -299,6 +316,12 @@ int PrefsDialog::ShowModal()
|
|||||||
if (selected < 0 || size_t(selected) >= mCategories->GetPageCount())
|
if (selected < 0 || size_t(selected) >= mCategories->GetPageCount())
|
||||||
selected = 0; // clamp to available range of tabs
|
selected = 0; // clamp to available range of tabs
|
||||||
mCategories->SetSelection(selected);
|
mCategories->SetSelection(selected);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wxString Temp = mTitlePrefix + mUniquePage->GetLabel();
|
||||||
|
SetTitle(Temp);
|
||||||
|
SetName(Temp);
|
||||||
|
}
|
||||||
|
|
||||||
return wxDialog::ShowModal();
|
return wxDialog::ShowModal();
|
||||||
}
|
}
|
||||||
@ -307,9 +330,13 @@ void PrefsDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
|
|||||||
{
|
{
|
||||||
RecordExpansionState();
|
RecordExpansionState();
|
||||||
|
|
||||||
|
if (mCategories) {
|
||||||
for (size_t i = 0; i < mCategories->GetPageCount(); i++) {
|
for (size_t i = 0; i < mCategories->GetPageCount(); i++) {
|
||||||
((PrefsPanel *)mCategories->GetPage(i))->Cancel();
|
((PrefsPanel *)mCategories->GetPage(i))->Cancel();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mUniquePage->Cancel();
|
||||||
|
|
||||||
EndModal(false);
|
EndModal(false);
|
||||||
}
|
}
|
||||||
@ -327,6 +354,7 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event))
|
|||||||
RecordExpansionState();
|
RecordExpansionState();
|
||||||
|
|
||||||
// Validate all pages first
|
// Validate all pages first
|
||||||
|
if (mCategories) {
|
||||||
for (size_t i = 0; i < mCategories->GetPageCount(); i++) {
|
for (size_t i = 0; i < mCategories->GetPageCount(); i++) {
|
||||||
PrefsPanel *panel = (PrefsPanel *)mCategories->GetPage(i);
|
PrefsPanel *panel = (PrefsPanel *)mCategories->GetPage(i);
|
||||||
|
|
||||||
@ -336,13 +364,22 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event))
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!mUniquePage->Validate())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mCategories) {
|
||||||
// Now apply the changes
|
// Now apply the changes
|
||||||
for (size_t i = 0; i < mCategories->GetPageCount(); i++) {
|
for (size_t i = 0; i < mCategories->GetPageCount(); i++) {
|
||||||
PrefsPanel *panel = (PrefsPanel *)mCategories->GetPage(i);
|
PrefsPanel *panel = (PrefsPanel *)mCategories->GetPage(i);
|
||||||
|
|
||||||
panel->Apply();
|
panel->Apply();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mUniquePage->Apply();
|
||||||
|
|
||||||
SavePreferredPage();
|
SavePreferredPage();
|
||||||
|
|
||||||
@ -386,6 +423,7 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event))
|
|||||||
|
|
||||||
void PrefsDialog::SelectPageByName(wxString pageName)
|
void PrefsDialog::SelectPageByName(wxString pageName)
|
||||||
{
|
{
|
||||||
|
if (mCategories) {
|
||||||
size_t n = mCategories->GetPageCount();
|
size_t n = mCategories->GetPageCount();
|
||||||
|
|
||||||
for (size_t i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
@ -395,10 +433,14 @@ void PrefsDialog::SelectPageByName(wxString pageName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int PrefsDialog::GetSelectedPage() const
|
int PrefsDialog::GetSelectedPage() const
|
||||||
{
|
{
|
||||||
|
if (mCategories)
|
||||||
return mCategories->GetSelection();
|
return mCategories->GetSelection();
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalPrefsDialog::GlobalPrefsDialog(wxWindow * parent, Factories &factories)
|
GlobalPrefsDialog::GlobalPrefsDialog(wxWindow * parent, Factories &factories)
|
||||||
@ -425,10 +467,13 @@ void GlobalPrefsDialog::SavePreferredPage()
|
|||||||
void PrefsDialog::RecordExpansionState()
|
void PrefsDialog::RecordExpansionState()
|
||||||
{
|
{
|
||||||
// Remember expansion state of the tree control
|
// Remember expansion state of the tree control
|
||||||
|
if (mCategories)
|
||||||
{
|
{
|
||||||
int iPage = 0;
|
int iPage = 0;
|
||||||
for (Factories::iterator it = mFactories.begin(), end = mFactories.end();
|
for (Factories::iterator it = mFactories.begin(), end = mFactories.end();
|
||||||
it != end; ++it, ++iPage)
|
it != end; ++it, ++iPage)
|
||||||
it->expanded = mCategories->IsNodeExpanded(iPage);
|
it->expanded = mCategories->IsNodeExpanded(iPage);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
mFactories[0].expanded = true;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <wx/treebook.h>
|
#include <wx/treebook.h>
|
||||||
#include <wx/window.h>
|
#include <wx/window.h>
|
||||||
|
|
||||||
|
class PrefsPanel;
|
||||||
class PrefsPanelFactory;
|
class PrefsPanelFactory;
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
@ -75,6 +76,7 @@ class PrefsDialog:public wxDialog
|
|||||||
private:
|
private:
|
||||||
void RecordExpansionState();
|
void RecordExpansionState();
|
||||||
wxTreebook *mCategories;
|
wxTreebook *mCategories;
|
||||||
|
PrefsPanel *mUniquePage;
|
||||||
Factories &mFactories;
|
Factories &mFactories;
|
||||||
const wxString mTitlePrefix;
|
const wxString mTitlePrefix;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user