diff --git a/src/prefs/PrefsDialog.cpp b/src/prefs/PrefsDialog.cpp index dd32fc714..fa1368d81 100644 --- a/src/prefs/PrefsDialog.cpp +++ b/src/prefs/PrefsDialog.cpp @@ -196,46 +196,61 @@ PrefsDialog::PrefsDialog wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) , mFactories(factories) +, mCategories(NULL) +, mUniquePage(NULL) , mTitlePrefix(titlePrefix) { + wxASSERT(factories.size() > 0); + const bool uniquePage = (factories.size() == 1); + ShuttleGui S(this, eIsCreating); S.StartVerticalLay(true); { - S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, true); - { + wxASSERT(factories.size() > 0); + if (!uniquePage) { mCategories = new wxTreebookExt(this, wxID_ANY, mTitlePrefix); - S.Prop(1); - S.AddWindow(mCategories, wxEXPAND); - + S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, true); { - typedef std::pair IntPair; - std::vector stack; - int iPage = 0; - for (Factories::const_iterator it = factories.begin(), end = factories.end(); - it != end; ++it, ++iPage) + S.Prop(1); + S.AddWindow(mCategories, wxEXPAND); + { - const PrefsNode &node = *it; - PrefsPanelFactory &factory = *node.pFactory; - wxWindow *const w = factory.Create(mCategories); - if (stack.empty()) - // Parameters are: AddPage(page, name, IsSelected, imageId). - mCategories->AddPage(w, w->GetName(), false, 0); - else { - IntPair &top = *stack.rbegin(); - mCategories->InsertSubPage(top.first, w, w->GetName(), false, 0); - if (--top.second == 0) { - // Expand all nodes before the layout calculation - mCategories->ExpandNode(top.first, true); - stack.pop_back(); + typedef std::pair IntPair; + std::vector stack; + int iPage = 0; + for (Factories::const_iterator it = factories.begin(), end = factories.end(); + it != end; ++it, ++iPage) + { + const PrefsNode &node = *it; + PrefsPanelFactory &factory = *node.pFactory; + wxWindow *const w = factory.Create(mCategories); + if (stack.empty()) + // Parameters are: AddPage(page, name, IsSelected, imageId). + mCategories->AddPage(w, w->GetName(), false, 0); + else { + IntPair &top = *stack.rbegin(); + mCategories->InsertSubPage(top.first, w, w->GetName(), false, 0); + if (--top.second == 0) { + // Expand all nodes before the layout calculation + mCategories->ExpandNode(top.first, true); + stack.pop_back(); + } } + if (node.nChildren > 0) + stack.push_back(IntPair(iPage, node.nChildren)); } - if (node.nChildren > 0) - stack.push_back(IntPair(iPage, node.nChildren)); } } + 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.EndHorizontalLay(); } S.EndVerticalLay(); @@ -251,6 +266,7 @@ PrefsDialog::PrefsDialog wxSize sz = GetSize(); // Collapse nodes only after layout so the tree is wide enough + if (mCategories) { int iPage = 0; for (Factories::const_iterator it = factories.begin(), end = factories.end(); @@ -290,15 +306,22 @@ 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); + if (mCategories) { + /* 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); + } + else { + wxString Temp = mTitlePrefix + mUniquePage->GetLabel(); + SetTitle(Temp); + SetName(Temp); + } return wxDialog::ShowModal(); } @@ -307,9 +330,13 @@ void PrefsDialog::OnCancel(wxCommandEvent & WXUNUSED(event)) { RecordExpansionState(); - for (size_t i = 0; i < mCategories->GetPageCount(); i++) { - ((PrefsPanel *) mCategories->GetPage(i))->Cancel(); + if (mCategories) { + for (size_t i = 0; i < mCategories->GetPageCount(); i++) { + ((PrefsPanel *)mCategories->GetPage(i))->Cancel(); + } } + else + mUniquePage->Cancel(); EndModal(false); } @@ -327,23 +354,33 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event)) RecordExpansionState(); // Validate all pages first - for (size_t i = 0; i < mCategories->GetPageCount(); i++) { - PrefsPanel *panel = (PrefsPanel *) mCategories->GetPage(i); + if (mCategories) { + for (size_t i = 0; i < mCategories->GetPageCount(); i++) { + PrefsPanel *panel = (PrefsPanel *)mCategories->GetPage(i); - // The dialog doesn't end until all the input is valid - if (!panel->Validate()) { - mCategories->SetSelection(i); - return; + // The dialog doesn't end until all the input is valid + if (!panel->Validate()) { + mCategories->SetSelection(i); + return; + } } } - - // Now apply the changes - for (size_t i = 0; i < mCategories->GetPageCount(); i++) { - PrefsPanel *panel = (PrefsPanel *) mCategories->GetPage(i); - - panel->Apply(); + else { + if (!mUniquePage->Validate()) + return; } + if (mCategories) { + // Now apply the changes + for (size_t i = 0; i < mCategories->GetPageCount(); i++) { + PrefsPanel *panel = (PrefsPanel *)mCategories->GetPage(i); + + panel->Apply(); + } + } + else + mUniquePage->Apply(); + SavePreferredPage(); #if USE_PORTMIXER @@ -386,19 +423,24 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event)) void PrefsDialog::SelectPageByName(wxString pageName) { - size_t n = mCategories->GetPageCount(); + if (mCategories) { + size_t n = mCategories->GetPageCount(); - for (size_t i = 0; i < n; i++) { - if (mCategories->GetPageText(i) == pageName) { - mCategories->SetSelection(i); - return; + for (size_t i = 0; i < n; i++) { + if (mCategories->GetPageText(i) == pageName) { + mCategories->SetSelection(i); + return; + } } } } int PrefsDialog::GetSelectedPage() const { - return mCategories->GetSelection(); + if (mCategories) + return mCategories->GetSelection(); + else + return 0; } GlobalPrefsDialog::GlobalPrefsDialog(wxWindow * parent, Factories &factories) @@ -425,10 +467,13 @@ void GlobalPrefsDialog::SavePreferredPage() void PrefsDialog::RecordExpansionState() { // Remember expansion state of the tree control + if (mCategories) { int iPage = 0; for (Factories::iterator it = mFactories.begin(), end = mFactories.end(); it != end; ++it, ++iPage) it->expanded = mCategories->IsNodeExpanded(iPage); } + else + mFactories[0].expanded = true; } diff --git a/src/prefs/PrefsDialog.h b/src/prefs/PrefsDialog.h index 0cb7da5d9..981128a95 100644 --- a/src/prefs/PrefsDialog.h +++ b/src/prefs/PrefsDialog.h @@ -20,6 +20,7 @@ #include #include +class PrefsPanel; class PrefsPanelFactory; #ifdef __GNUC__ @@ -75,6 +76,7 @@ class PrefsDialog:public wxDialog private: void RecordExpansionState(); wxTreebook *mCategories; + PrefsPanel *mUniquePage; Factories &mFactories; const wxString mTitlePrefix;