[Xfce4-commits] <xfce4-appfinder:master> Add a custom completion match function.

Nick Schermer noreply at xfce.org
Sun Oct 30 12:04:01 CET 2011


Updating branch refs/heads/master
         to f25c64ef9ccc25fecd67ba47d00b8d3dd47c8906 (commit)
       from a8869432e8cc9e7c89d25394f09bb392bc3c807a (commit)

commit f25c64ef9ccc25fecd67ba47d00b8d3dd47c8906
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Oct 30 12:03:14 2011 +0100

    Add a custom completion match function.

 src/appfinder-model.c  |   28 ++++++++++++++++++++++++++++
 src/appfinder-model.h  |    6 +++++-
 src/appfinder-window.c |   28 ++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletions(-)

diff --git a/src/appfinder-model.c b/src/appfinder-model.c
index 959e6f6..2f8e4cc 100644
--- a/src/appfinder-model.c
+++ b/src/appfinder-model.c
@@ -1537,6 +1537,34 @@ xfce_appfinder_model_get_visible (XfceAppfinderModel        *model,
 
 
 gboolean
+xfce_appfinder_model_get_visible_command (XfceAppfinderModel *model,
+                                          const GtkTreeIter  *iter,
+                                          const gchar        *string)
+{
+  ModelItem *item;
+
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
+  appfinder_return_val_if_fail (iter->stamp == model->stamp, FALSE);
+
+  item = ITER_GET_DATA (iter);
+
+  if (item->item != NULL)
+    {
+      appfinder_return_val_if_fail (GARCON_IS_MENU_ITEM (item->item), FALSE);
+
+      if (item->not_visible)
+        return FALSE;
+    }
+
+  if (item->command != NULL && string != NULL)
+    return strncmp (item->command, string, strlen (string)) == 0;
+
+  return FALSE;
+}
+
+
+
+gboolean
 xfce_appfinder_model_execute (XfceAppfinderModel  *model,
                               const GtkTreeIter   *iter,
                               GdkScreen           *screen,
diff --git a/src/appfinder-model.h b/src/appfinder-model.h
index 34bc486..1cc43ec 100644
--- a/src/appfinder-model.h
+++ b/src/appfinder-model.h
@@ -65,6 +65,10 @@ gboolean             xfce_appfinder_model_get_visible          (XfceAppfinderMod
                                                                 const GarconMenuDirectory *category,
                                                                 const gchar               *string);
 
+gboolean             xfce_appfinder_model_get_visible_command  (XfceAppfinderModel        *model,
+                                                                const GtkTreeIter         *iter,
+                                                                const gchar               *string);
+
 gboolean             xfce_appfinder_model_execute              (XfceAppfinderModel        *model,
                                                                 const GtkTreeIter         *iter,
                                                                 GdkScreen                 *screen,
@@ -85,7 +89,7 @@ void                 xfce_appfinder_model_icon_theme_changed   (XfceAppfinderMod
 
 GarconMenuDirectory *xfce_appfinder_model_get_command_category (void);
 
-void                 xfce_appfinder_model_history_clear       (XfceAppfinderModel        *model);
+void                 xfce_appfinder_model_history_clear        (XfceAppfinderModel        *model);
 
 void                 xfce_appfinder_model_category_free        (CategoryItem              *category);
 
diff --git a/src/appfinder-window.c b/src/appfinder-window.c
index cdd4b78..a334efd 100644
--- a/src/appfinder-window.c
+++ b/src/appfinder-window.c
@@ -50,6 +50,10 @@ static gboolean   xfce_appfinder_window_key_press_event               (GtkWidget
                                                                        GdkEventKey                 *event);
 static void       xfce_appfinder_window_set_padding                   (GtkWidget                   *entry,
                                                                        GtkWidget                   *align);
+static gboolean   xfce_appfinder_window_completion_match_func         (GtkEntryCompletion          *completion,
+                                                                       const gchar                 *key,
+                                                                       GtkTreeIter                 *iter,
+                                                                       gpointer                     data);
 static void       xfce_appfinder_window_entry_changed                 (XfceAppfinderWindow         *window);
 static void       xfce_appfinder_window_entry_activate                (GtkEditable                 *entry,
                                                                        XfceAppfinderWindow         *window);
@@ -229,6 +233,7 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
 
   window->completion = completion = gtk_entry_completion_new ();
   gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (window->model));
+  gtk_entry_completion_set_match_func (completion, xfce_appfinder_window_completion_match_func, window, NULL);
   gtk_entry_completion_set_text_column (completion, XFCE_APPFINDER_MODEL_COLUMN_COMMAND);
   gtk_entry_completion_set_popup_completion (completion, TRUE);
   gtk_entry_completion_set_popup_single_match (completion, FALSE);
@@ -460,6 +465,29 @@ xfce_appfinder_window_set_padding (GtkWidget *entry,
 
 
 static gboolean
+xfce_appfinder_window_completion_match_func (GtkEntryCompletion *completion,
+                                             const gchar        *key,
+                                             GtkTreeIter        *iter,
+                                             gpointer            data)
+{
+  const gchar *text;
+
+  XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (data);
+
+  appfinder_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), FALSE);
+  appfinder_return_val_if_fail (XFCE_IS_APPFINDER_WINDOW (data), FALSE);
+  appfinder_return_val_if_fail (GTK_TREE_MODEL (window->model)
+      == gtk_entry_completion_get_model (completion), FALSE);
+
+  /* don't use the casefolded key generated by gtk */
+  text = gtk_entry_get_text (GTK_ENTRY (window->entry));
+
+  return xfce_appfinder_model_get_visible_command (window->model, iter, text);
+}
+
+
+
+static gboolean
 xfce_appfinder_window_entry_changed_idle (gpointer data)
 {
   XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (data);


More information about the Xfce4-commits mailing list