[Xfce4-commits] <xfce4-appfinder:master> Remember last selected category.
Nick Schermer
noreply at xfce.org
Sat Jul 9 16:18:11 CEST 2011
Updating branch refs/heads/master
to 4b9f45419b4f908dc4040b227b9b47aeb6a66754 (commit)
from 00a875654fa7285e46882af34506d1936fb5eeb9 (commit)
commit 4b9f45419b4f908dc4040b227b9b47aeb6a66754
Author: Nick Schermer <nick at xfce.org>
Date: Sat Jun 25 20:08:26 2011 +0200
Remember last selected category.
src/appfinder-category-model.c | 26 ++++++++++++++++++++++++++
src/appfinder-category-model.h | 3 +++
src/appfinder-window.c | 37 ++++++++++++++++++++++++-------------
3 files changed, 53 insertions(+), 13 deletions(-)
diff --git a/src/appfinder-category-model.c b/src/appfinder-category-model.c
index 51dc156..3f5cb82 100644
--- a/src/appfinder-category-model.c
+++ b/src/appfinder-category-model.c
@@ -488,3 +488,29 @@ xfce_appfinder_category_model_icon_theme_changed (XfceAppfinderCategoryModel *mo
}
}
}
+
+
+
+GtkTreePath *
+xfce_appfinder_category_model_find_category (XfceAppfinderCategoryModel *model,
+ const gchar *name)
+{
+ CategoryItem *item;
+ GSList *li;
+ gint idx;
+
+ g_return_val_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model), NULL);
+
+ if (IS_STRING (name))
+ {
+ for (li = model->categories, idx = 0; li != NULL; li = li->next, idx++)
+ {
+ item = li->data;
+ if (item->directory != NULL
+ && g_strcmp0 (garcon_menu_directory_get_name (item->directory), name) == 0)
+ return gtk_tree_path_new_from_indices (idx, -1);
+ }
+ }
+
+ return gtk_tree_path_new_first ();
+}
diff --git a/src/appfinder-category-model.h b/src/appfinder-category-model.h
index 1c28a1c..78fd694 100644
--- a/src/appfinder-category-model.h
+++ b/src/appfinder-category-model.h
@@ -58,6 +58,9 @@ gboolean xfce_appfinder_category_model_row_separator_func (Gt
void xfce_appfinder_category_model_icon_theme_changed (XfceAppfinderCategoryModel *model);
+GtkTreePath *xfce_appfinder_category_model_find_category (XfceAppfinderCategoryModel *model,
+ const gchar *name);
+
G_END_DECLS
#endif /* !__XFCE_APPFINDER_CATEGORY_MODEL_H__ */
diff --git a/src/appfinder-window.c b/src/appfinder-window.c
index aff88e4..82c33db 100644
--- a/src/appfinder-window.c
+++ b/src/appfinder-window.c
@@ -95,6 +95,8 @@ struct _XfceAppfinderWindow
GtkEntryCompletion *completion;
+ XfconfChannel *channel;
+
GtkWidget *paned;
GtkWidget *entry;
GtkWidget *image;
@@ -161,11 +163,10 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
GtkWidget *button;
GtkEntryCompletion *completion;
GtkIconTheme *icon_theme;
- XfconfChannel *channel;
gint integer;
- channel = xfconf_channel_get ("xfce4-appfinder");
- window->last_window_height = xfconf_channel_get_int (channel, "/LastWindowHeight", DEFAULT_WINDOW_HEIGHT);
+ window->channel = xfconf_channel_get ("xfce4-appfinder");
+ window->last_window_height = xfconf_channel_get_int (window->channel, "/LastWindowHeight", DEFAULT_WINDOW_HEIGHT);
window->category_model = xfce_appfinder_category_model_new ();
window->model = xfce_appfinder_model_get ();
@@ -178,7 +179,7 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
window);
gtk_window_set_title (GTK_WINDOW (window), _("Application Finder"));
- integer = xfconf_channel_get_int (channel, "/LastWindowWidth", DEFAULT_WINDOW_WIDTH);
+ integer = xfconf_channel_get_int (window->channel, "/LastWindowWidth", DEFAULT_WINDOW_WIDTH);
gtk_window_set_default_size (GTK_WINDOW (window), integer, -1);
gtk_window_set_icon_name (GTK_WINDOW (window), GTK_STOCK_EXECUTE);
@@ -231,7 +232,7 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
window->paned = pane = gtk_hpaned_new ();
gtk_box_pack_start (GTK_BOX (vbox), pane, TRUE, TRUE, 0);
- integer = xfconf_channel_get_int (channel, "/LastPanedPosition", DEFAULT_PANED_POSITION);
+ integer = xfconf_channel_get_int (window->channel, "/LastPanedPosition", DEFAULT_PANED_POSITION);
gtk_paned_set_position (GTK_PANED (pane), integer);
g_object_set (G_OBJECT (pane), "position-set", TRUE, NULL);
@@ -370,7 +371,6 @@ xfce_appfinder_window_unmap (GtkWidget *widget)
XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (widget);
gint width, height;
gint position;
- XfconfChannel *channel;
position = gtk_paned_get_position (GTK_PANED (window->paned));
gtk_window_get_size (GTK_WINDOW (window), &width, &height);
@@ -379,10 +379,9 @@ xfce_appfinder_window_unmap (GtkWidget *widget)
(*GTK_WIDGET_CLASS (xfce_appfinder_window_parent_class)->unmap) (widget);
- channel = xfconf_channel_get ("xfce4-appfinder");
- xfconf_channel_set_int (channel, "/LastWindowHeight", height);
- xfconf_channel_set_int (channel, "/LastWindowWidth", width);
- xfconf_channel_set_int (channel, "/LastPanedPosition", position);
+ xfconf_channel_set_int (window->channel, "/LastWindowHeight", height);
+ xfconf_channel_set_int (window->channel, "/LastWindowWidth", width);
+ xfconf_channel_set_int (window->channel, "/LastPanedPosition", position);
}
@@ -595,10 +594,13 @@ xfce_appfinder_window_category_changed (GtkTreeSelection *selection,
GtkTreeIter iter;
GtkTreeModel *model;
GarconMenuDirectory *category;
+ gchar *name;
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
- gtk_tree_model_get (model, &iter, XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_DIRECTORY, &category, -1);
+ gtk_tree_model_get (model, &iter,
+ XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_DIRECTORY, &category,
+ XFCE_APPFINDER_CATEGORY_MODEL_COLUMN_NAME, &name, -1);
if (window->filter_category != NULL)
g_object_unref (G_OBJECT (window->filter_category));
@@ -608,9 +610,15 @@ xfce_appfinder_window_category_changed (GtkTreeSelection *selection,
else
window->filter_category = category;
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (window->treeview));
APPFINDER_DEBUG ("refilter category");
+
+ /* update visible items */
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (window->treeview));
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
+
+ /* store last category */
+ xfconf_channel_set_string (window->channel, "/LastCategory", name);
+ g_free (name);
}
}
@@ -621,14 +629,17 @@ xfce_appfinder_window_category_set_categories (XfceAppfinderWindow *window)
{
GSList *categories;
GtkTreePath *path;
+ gchar *name;
categories = xfce_appfinder_model_get_categories (window->model);
if (categories != NULL)
xfce_appfinder_category_model_set_categories (window->category_model, categories);
- path = gtk_tree_path_new_first ();
+ name = xfconf_channel_get_string (window->channel, "/LastCategory", NULL);
+ path = xfce_appfinder_category_model_find_category (window->category_model, name);
gtk_tree_view_set_cursor (GTK_TREE_VIEW (window->sidepane), path, NULL, FALSE);
gtk_tree_path_free (path);
+ g_free (name);
}
More information about the Xfce4-commits
mailing list