From 82a2535c9b83e6cbcdcaf3dea11e7547dd8a0a62 Mon Sep 17 00:00:00 2001 From: dpage Date: Thu, 26 Feb 2009 16:03:18 +0000 Subject: [PATCH] Allow app categories to be hierarchical. We simply use a separator ('\') in the category string to do this, to ensure backwards compatibility with older versions of StackBuilder. [Sachin Srivastava] --- AppList.cpp | 48 +++++++++++++++++++++++++++++------------------ include/AppList.h | 3 ++- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/AppList.cpp b/AppList.cpp index 2a3785e..d04b957 100644 --- a/AppList.cpp +++ b/AppList.cpp @@ -3,7 +3,7 @@ // Purpose: Maintains the list of applications // Author: Dave Page // Created: 2007-02-13 -// RCS-ID: $Id: AppList.cpp,v 1.20 2008/09/12 10:26:11 dpage Exp $ +// RCS-ID: $Id: AppList.cpp,v 1.21 2009/02/26 16:03:18 dpage Exp $ // Copyright: (c) EnterpriseDB // Licence: BSD Licence ///////////////////////////////////////////////////////////////////////////// @@ -16,6 +16,7 @@ #include #include #include +#include // Application headers #include "App.h" @@ -173,33 +174,44 @@ wxString AppList::DeHTMLise(const wxString &string) return ret; } -bool AppList::PopulateTreeCtrl() +wxTreeItemId AppList::FindCategory(wxTreeItemId parent, wxString &category) { wxTreeItemIdValue cookie; - wxTreeItemId node, root, category, application; + wxTreeItemId node; + + node = m_treectrl->GetFirstChild(parent, cookie); + + while (node) + { + if (m_treectrl->GetItemText(node) == category) + return node; + node = m_treectrl->GetNextChild(parent, cookie); + } + return node; +} + + +bool AppList::PopulateTreeCtrl() +{ + wxTreeItemId node, root, category, application, parentNode; bool found; root = m_treectrl->AddRoot(_("Categories"), 3); for (unsigned int i=0; iGetFirstChild(root, cookie); + parentNode = root; - while (node) + wxStringTokenizer tokens(m_apps[i].category, wxT("\\")); + while (tokens.HasMoreTokens()) { - if (m_treectrl->GetItemText(node) == m_apps[i].category) - { - category = node; - found = true; - break; - } - node = m_treectrl->GetNextChild(root, cookie); - } - - if (!found) - category = m_treectrl->AppendItem(root, m_apps[i].category, 3); + wxString ctg = tokens.GetNextToken(); + node = FindCategory(parentNode, ctg); + if (!node) + node = m_treectrl->AppendItem(parentNode, ctg, 3); + parentNode = node; + } + category = node; // We used to disable installed apps here (by using image #2), but that // may not be the best strategy as it prevents us from reinstalling apps. diff --git a/include/AppList.h b/include/AppList.h index cddcc4a..c2d4cf7 100644 --- a/include/AppList.h +++ b/include/AppList.h @@ -3,7 +3,7 @@ // Purpose: Maintains the list of applications // Author: Dave Page // Created: 2007-02-13 -// RCS-ID: $Id: AppList.h,v 1.10 2008/08/14 15:54:08 dpage Exp $ +// RCS-ID: $Id: AppList.h,v 1.11 2009/02/26 16:03:18 dpage Exp $ // Copyright: (c) EnterpriseDB // Licence: BSD Licence ///////////////////////////////////////////////////////////////////////////// @@ -48,6 +48,7 @@ class AppList private: wxString DeHTMLise(const wxString &string); + wxTreeItemId FindCategory(wxTreeItemId root, wxString &category); AppArray m_apps; wxString m_applicationListUrl;