gimp r26859 - in trunk: . app/dialogs app/widgets
- From: mitch svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r26859 - in trunk: . app/dialogs app/widgets
- Date: Thu, 4 Sep 2008 13:46:46 +0000 (UTC)
Author: mitch
Date: Thu Sep 4 13:46:45 2008
New Revision: 26859
URL: http://svn.gnome.org/viewvc/gimp?rev=26859&view=rev
Log:
2008-09-04 Michael Natterer <mitch gimp org>
* app/widgets/gimpactionview.[ch]: add an GtkTreeModelFilter
between the GtkTreeView and the actual GtkTreeStore. Add API to
set the filter which is simply a string that's matched with
strstr(). Quite some things improvable here...
* app/dialogs/keyboard-shortcuts-dialog.c: add a "Filter" entry
and set the filter on the action view.
Modified:
trunk/ChangeLog
trunk/app/dialogs/keyboard-shortcuts-dialog.c
trunk/app/widgets/gimpactionview.c
trunk/app/widgets/gimpactionview.h
Modified: trunk/app/dialogs/keyboard-shortcuts-dialog.c
==============================================================================
--- trunk/app/dialogs/keyboard-shortcuts-dialog.c (original)
+++ trunk/app/dialogs/keyboard-shortcuts-dialog.c Thu Sep 4 13:46:45 2008
@@ -35,11 +35,21 @@
#include "gimp-intl.h"
+static void
+keyboard_shortcuts_dialog_filter_changed (GtkEntry *entry,
+ GimpActionView *view)
+{
+ gimp_action_view_set_filter (view, gtk_entry_get_text (entry));
+}
+
GtkWidget *
keyboard_shortcuts_dialog_new (Gimp *gimp)
{
GtkWidget *dialog;
GtkWidget *vbox;
+ GtkWidget *hbox;
+ GtkWidget *label;
+ GtkWidget *entry;
GtkWidget *scrolled_window;
GtkWidget *view;
GtkWidget *box;
@@ -66,6 +76,20 @@
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
gtk_widget_show (vbox);
+ hbox = gtk_hbox_new (FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+ gtk_widget_show (hbox);
+
+ label = gtk_label_new_with_mnemonic (_("_Filter:"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_widget_show (label);
+
+ entry = gtk_entry_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+ gtk_widget_show (entry);
+
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
@@ -80,6 +104,10 @@
gtk_container_add (GTK_CONTAINER (scrolled_window), view);
gtk_widget_show (view);
+ g_signal_connect (entry, "changed",
+ G_CALLBACK (keyboard_shortcuts_dialog_filter_changed),
+ view);
+
box = gimp_hint_box_new (_("To edit a shortcut key, click on the "
"corresponding row and type a new "
"accelerator, or press backspace to "
Modified: trunk/app/widgets/gimpactionview.c
==============================================================================
--- trunk/app/widgets/gimpactionview.c (original)
+++ trunk/app/widgets/gimpactionview.c Thu Sep 4 13:46:45 2008
@@ -45,6 +45,7 @@
/* local function prototypes */
static void gimp_action_view_dispose (GObject *object);
+static void gimp_action_view_finalize (GObject *object);
static gboolean gimp_action_view_accel_find_func (GtkAccelKey *key,
GClosure *closure,
@@ -75,7 +76,8 @@
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->dispose = gimp_action_view_dispose;
+ object_class->dispose = gimp_action_view_dispose;
+ object_class->finalize = gimp_action_view_finalize;
}
static void
@@ -108,12 +110,26 @@
G_OBJECT_CLASS (parent_class)->dispose (object);
}
+static void
+gimp_action_view_finalize (GObject *object)
+{
+ GimpActionView *view = GIMP_ACTION_VIEW (object);
+
+ if (view->filter)
+ {
+ g_free (view->filter);
+ view->filter = NULL;
+ }
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
static gboolean
idle_start_editing (GtkTreeView *tree_view)
{
GtkTreePath *path;
- path = g_object_get_data (G_OBJECT (tree_view), "start_editing_path");
+ path = g_object_get_data (G_OBJECT (tree_view), "start-editing-path");
if (path)
{
@@ -123,7 +139,7 @@
gtk_tree_view_get_column (tree_view, 1),
TRUE);
- g_object_set_data (G_OBJECT (tree_view), "start_editing_path", NULL);
+ g_object_set_data (G_OBJECT (tree_view), "start-editing-path", NULL);
}
return FALSE;
@@ -154,7 +170,7 @@
return FALSE;
}
- g_object_set_data_full (G_OBJECT (tree_view), "start_editing_path",
+ g_object_set_data_full (G_OBJECT (tree_view), "start-editing-path",
path, (GDestroyNotify) gtk_tree_path_free);
g_signal_stop_emission_by_name (tree_view, "button-press-event");
@@ -180,6 +196,7 @@
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
GtkTreeStore *store;
+ GtkTreeModel *filter;
GtkAccelGroup *accel_group;
GList *list;
GtkTreePath *select_path = NULL;
@@ -187,6 +204,7 @@
g_return_val_if_fail (GIMP_IS_UI_MANAGER (manager), NULL);
store = gtk_tree_store_new (GIMP_ACTION_VIEW_NUM_COLUMNS,
+ G_TYPE_BOOLEAN, /* COLUMN_VISIBLE */
GTK_TYPE_ACTION, /* COLUMN_ACTION */
G_TYPE_STRING, /* COLUMN_STOCK_ID */
G_TYPE_STRING, /* COLUMN_LABEL */
@@ -273,6 +291,7 @@
gtk_tree_store_append (store, &action_iter, &group_iter);
gtk_tree_store_set (store, &action_iter,
+ GIMP_ACTION_VIEW_COLUMN_VISIBLE, TRUE,
GIMP_ACTION_VIEW_COLUMN_ACTION, action,
GIMP_ACTION_VIEW_COLUMN_STOCK_ID, stock_id,
GIMP_ACTION_VIEW_COLUMN_LABEL, label,
@@ -295,12 +314,19 @@
g_list_free (actions);
}
+ filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
+
+ g_object_unref (store);
+
view = g_object_new (GIMP_TYPE_ACTION_VIEW,
- "model", store,
+ "model", filter,
"rules-hint", TRUE,
NULL);
- g_object_unref (store);
+ g_object_unref (filter);
+
+ gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter),
+ GIMP_ACTION_VIEW_COLUMN_VISIBLE);
GIMP_ACTION_VIEW (view)->manager = g_object_ref (manager);
GIMP_ACTION_VIEW (view)->show_shortcuts = show_shortcuts;
@@ -396,6 +422,76 @@
return GTK_WIDGET (view);
}
+void
+gimp_action_view_set_filter (GimpActionView *view,
+ const gchar *filter)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gboolean iter_valid;
+
+ g_return_if_fail (GIMP_IS_ACTION_VIEW (view));
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
+
+ if (filter && ! strlen (filter))
+ filter = NULL;
+
+ g_free (view->filter);
+ view->filter = g_strdup (filter);
+
+ for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
+ iter_valid;
+ iter_valid = gtk_tree_model_iter_next (model, &iter))
+ {
+ GtkTreeIter child_iter;
+ gboolean child_valid;
+ gint n_children = 0;
+
+ for (child_valid = gtk_tree_model_iter_children (model, &child_iter,
+ &iter);
+ child_valid;
+ child_valid = gtk_tree_model_iter_next (model, &child_iter))
+ {
+ gboolean visible = TRUE;
+
+ if (view->filter)
+ {
+ gchar *label;
+ gchar *name;
+
+ gtk_tree_model_get (model, &child_iter,
+ GIMP_ACTION_VIEW_COLUMN_LABEL, &label,
+ GIMP_ACTION_VIEW_COLUMN_NAME, &name,
+ -1);
+
+ visible = (strstr (label, view->filter) != NULL ||
+ strstr (name, view->filter) != NULL);
+
+ g_free (label);
+ g_free (name);
+ }
+
+ gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
+ GIMP_ACTION_VIEW_COLUMN_VISIBLE, visible,
+ -1);
+
+ if (visible)
+ n_children++;
+ }
+
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
+ GIMP_ACTION_VIEW_COLUMN_VISIBLE, n_children > 0,
+ -1);
+ }
+
+ if (view->filter)
+ gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
+ else
+ gtk_tree_view_collapse_all (GTK_TREE_VIEW (view));
+}
+
/* private functions */
@@ -422,6 +518,10 @@
if (! model)
return;
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
+ if (! model)
+ return;
+
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
@@ -647,6 +747,7 @@
gboolean iter_valid;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
+ model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
Modified: trunk/app/widgets/gimpactionview.h
==============================================================================
--- trunk/app/widgets/gimpactionview.h (original)
+++ trunk/app/widgets/gimpactionview.h Thu Sep 4 13:46:45 2008
@@ -25,6 +25,7 @@
enum
{
+ GIMP_ACTION_VIEW_COLUMN_VISIBLE,
GIMP_ACTION_VIEW_COLUMN_ACTION,
GIMP_ACTION_VIEW_COLUMN_STOCK_ID,
GIMP_ACTION_VIEW_COLUMN_LABEL,
@@ -52,6 +53,8 @@
GimpUIManager *manager;
gboolean show_shortcuts;
+
+ gchar *filter;
};
struct _GimpActionViewClass
@@ -60,11 +63,14 @@
};
-GType gimp_action_view_get_type (void) G_GNUC_CONST;
+GType gimp_action_view_get_type (void) G_GNUC_CONST;
+
+GtkWidget * gimp_action_view_new (GimpUIManager *manager,
+ const gchar *select_action,
+ gboolean show_shortcuts);
-GtkWidget * gimp_action_view_new (GimpUIManager *manager,
- const gchar *select_action,
- gboolean show_shortcuts);
+void gimp_action_view_set_filter (GimpActionView *view,
+ const gchar *filter);
#endif /* __GIMP_ACTION_VIEW_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]