[Xfce4-commits] [panel-plugins/xfce4-whiskermenu-plugin] 145/473: Add models to categories.
noreply at xfce.org
noreply at xfce.org
Mon Feb 16 23:55:15 CET 2015
This is an automated email from the git hooks/post-receive script.
gottcode pushed a commit to branch master
in repository panel-plugins/xfce4-whiskermenu-plugin.
commit 1eae68076e4530b167e00a004f27d2236db92222
Author: Graeme Gott <graeme at gottcode.org>
Date: Sat Jul 20 08:05:52 2013 -0400
Add models to categories.
---
src/applications_page.cpp | 33 +++++++++++++++++++++------------
src/applications_page.hpp | 2 +-
src/category.cpp | 35 ++++++++++++++++++++++++++++++++++-
src/category.hpp | 8 ++++++++
src/filter_page.cpp | 2 +-
5 files changed, 65 insertions(+), 15 deletions(-)
diff --git a/src/applications_page.cpp b/src/applications_page.cpp
index f37533c..46da7de 100644
--- a/src/applications_page.cpp
+++ b/src/applications_page.cpp
@@ -89,7 +89,15 @@ void ApplicationsPage::apply_filter(GtkToggleButton* togglebutton)
}
// Apply filter
- refilter();
+ if (m_current_category)
+ {
+ get_view()->set_model(m_current_category->get_model());
+ }
+ else
+ {
+ get_view()->set_model(get_model());
+ refilter();
+ }
m_current_category = NULL;
}
@@ -239,11 +247,12 @@ void ApplicationsPage::load_menu(GarconMenu* menu)
g_list_free(menus);
// Add items
- GarconMenuItemPool* pool = garcon_menu_get_item_pool(menu);
- if (G_LIKELY(pool))
+ GList* items = garcon_menu_get_items(menu);
+ for (GList* li = items; li != NULL; li = li->next)
{
- garcon_menu_item_pool_foreach(pool, (GHFunc)&ApplicationsPage::load_menu_item, this);
+ load_menu_item(GARCON_MENU_ITEM(li->data));
}
+ g_list_free(items);
// Only track single level of categories
if (first_level)
@@ -263,7 +272,7 @@ void ApplicationsPage::load_menu(GarconMenu* menu)
//-----------------------------------------------------------------------------
-void ApplicationsPage::load_menu_item(const gchar* desktop_id, GarconMenuItem* menu_item, ApplicationsPage* page)
+void ApplicationsPage::load_menu_item(GarconMenuItem* menu_item)
{
// Skip hidden items
if (!garcon_menu_element_get_visible(GARCON_MENU_ELEMENT(menu_item)))
@@ -272,21 +281,21 @@ void ApplicationsPage::load_menu_item(const gchar* desktop_id, GarconMenuItem* m
}
// Add to map
- std::string key(desktop_id);
- std::map<std::string, Launcher*>::iterator iter = page->m_items.find(key);
- if (iter == page->m_items.end())
+ std::string desktop_id(garcon_menu_item_get_desktop_id(menu_item));
+ std::map<std::string, Launcher*>::iterator iter = m_items.find(desktop_id);
+ if (iter == m_items.end())
{
- iter = page->m_items.insert(std::make_pair(key, new Launcher(menu_item))).first;
+ iter = m_items.insert(std::make_pair(desktop_id, new Launcher(menu_item))).first;
}
// Add menu item to current category
- if (page->m_current_category)
+ if (m_current_category)
{
- page->m_current_category->push_back(iter->second);
+ m_current_category->push_back(iter->second);
}
// Listen for menu changes
- g_signal_connect_swapped(menu_item, "changed", G_CALLBACK(ApplicationsPage::invalidate_applications_slot), page);
+ g_signal_connect_swapped(menu_item, "changed", G_CALLBACK(ApplicationsPage::invalidate_applications_slot), this);
}
//-----------------------------------------------------------------------------
diff --git a/src/applications_page.hpp b/src/applications_page.hpp
index a60f921..78cc349 100644
--- a/src/applications_page.hpp
+++ b/src/applications_page.hpp
@@ -54,7 +54,7 @@ private:
bool on_filter(GtkTreeModel* model, GtkTreeIter* iter);
void clear_applications();
void load_menu(GarconMenu* menu);
- static void load_menu_item(const gchar* desktop_id, GarconMenuItem* menu_item, ApplicationsPage* page);
+ void load_menu_item(GarconMenuItem* menu_item);
void load_categories();
private:
diff --git a/src/category.cpp b/src/category.cpp
index b326a3e..71bbe20 100644
--- a/src/category.cpp
+++ b/src/category.cpp
@@ -16,13 +16,15 @@
#include "category.hpp"
+#include "launcher_model.hpp"
#include "section_button.hpp"
using namespace WhiskerMenu;
//-----------------------------------------------------------------------------
-Category::Category(GarconMenuDirectory* directory)
+Category::Category(GarconMenuDirectory* directory) :
+ m_model(NULL)
{
// Fetch icon
const gchar* icon = garcon_menu_directory_get_icon_name(directory);
@@ -46,7 +48,38 @@ Category::Category(GarconMenuDirectory* directory)
Category::~Category()
{
+ unset_model();
+
delete m_button;
}
//-----------------------------------------------------------------------------
+
+GtkTreeModel* Category::get_model()
+{
+ if (!m_model)
+ {
+ LauncherModel model;
+ for (std::vector<Launcher*>::const_iterator i = m_items.begin(), end = m_items.end(); i != end; ++i)
+ {
+ model.append_item(*i);
+ }
+ m_model = model.get_model();
+ g_object_ref(m_model);
+ }
+
+ return m_model;
+}
+
+//-----------------------------------------------------------------------------
+
+void Category::unset_model()
+{
+ if (m_model)
+ {
+ g_object_unref(m_model);
+ m_model = NULL;
+ }
+}
+
+//-----------------------------------------------------------------------------
diff --git a/src/category.hpp b/src/category.hpp
index 341daa6..1238a59 100644
--- a/src/category.hpp
+++ b/src/category.hpp
@@ -23,6 +23,7 @@
extern "C"
{
#include <garcon/garcon.h>
+#include <gtk/gtk.h>
}
namespace WhiskerMenu
@@ -37,6 +38,8 @@ public:
explicit Category(GarconMenuDirectory* directory);
~Category();
+ GtkTreeModel* get_model();
+
SectionButton* get_button() const
{
return m_button;
@@ -55,11 +58,16 @@ public:
void push_back(Launcher* launcher)
{
m_items.push_back(launcher);
+ unset_model();
}
private:
+ void unset_model();
+
+private:
std::vector<Launcher*> m_items;
SectionButton* m_button;
+ GtkTreeModel* m_model;
};
}
diff --git a/src/filter_page.cpp b/src/filter_page.cpp
index 87d5476..5cbdfb9 100644
--- a/src/filter_page.cpp
+++ b/src/filter_page.cpp
@@ -39,7 +39,7 @@ FilterPage::~FilterPage()
GtkTreeModel* FilterPage::get_model() const
{
- return m_filter_model ? gtk_tree_model_filter_get_model(m_filter_model) : NULL;
+ return GTK_TREE_MODEL(m_filter_model);
}
//-----------------------------------------------------------------------------
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list