]> Pileus Git - ~andy/gtk/commitdiff
Add a property to suppress the popup for single matches. (#154711)
authorMatthias Clasen <mclasen@redhat.com>
Thu, 26 May 2005 20:36:36 +0000 (20:36 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 26 May 2005 20:36:36 +0000 (20:36 +0000)
2005-05-26  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtk.symbols:
* gtk/gtkentrycompletion.c: Add a property to suppress the
popup for single matches.  (#154711)

* gtk/gtkentry.c (gtk_entry_completion_timeout): Respect it here.

* gtk/gtkfilechooserentry.c (_gtk_file_chooser_entry_set_action):
Use it here.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-8
gtk/gtk.symbols
gtk/gtkentry.c
gtk/gtkentrycompletion.c
gtk/gtkentryprivate.h
gtk/gtkfilechooserentry.c

index 7db7bb8c48b7eaaf483ceaef4c3b2c0c75edcee9..5ccddf45ccd3d9204485ea69886c83402ca30f1d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2005-05-26  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtkentrycompletion.c: Add a property to suppress the
+       popup for single matches.  (#154711)
+
+       * gtk/gtkentry.c (gtk_entry_completion_timeout): Respect it here.
+
+       * gtk/gtkfilechooserentry.c (_gtk_file_chooser_entry_set_action): 
+       Use it here.
+
        * gtk/gtktextbtree.c (_gtk_text_btree_tag): Queue the 
        redisplay after modifying the tag in the btree, otherwise 
        we end up showing the old tags until the next redraw comes 
index 7db7bb8c48b7eaaf483ceaef4c3b2c0c75edcee9..5ccddf45ccd3d9204485ea69886c83402ca30f1d 100644 (file)
@@ -1,5 +1,14 @@
 2005-05-26  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtkentrycompletion.c: Add a property to suppress the
+       popup for single matches.  (#154711)
+
+       * gtk/gtkentry.c (gtk_entry_completion_timeout): Respect it here.
+
+       * gtk/gtkfilechooserentry.c (_gtk_file_chooser_entry_set_action): 
+       Use it here.
+
        * gtk/gtktextbtree.c (_gtk_text_btree_tag): Queue the 
        redisplay after modifying the tag in the btree, otherwise 
        we end up showing the old tags until the next redraw comes 
index 7db7bb8c48b7eaaf483ceaef4c3b2c0c75edcee9..5ccddf45ccd3d9204485ea69886c83402ca30f1d 100644 (file)
@@ -1,5 +1,14 @@
 2005-05-26  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtkentrycompletion.c: Add a property to suppress the
+       popup for single matches.  (#154711)
+
+       * gtk/gtkentry.c (gtk_entry_completion_timeout): Respect it here.
+
+       * gtk/gtkfilechooserentry.c (_gtk_file_chooser_entry_set_action): 
+       Use it here.
+
        * gtk/gtktextbtree.c (_gtk_text_btree_tag): Queue the 
        redisplay after modifying the tag in the btree, otherwise 
        we end up showing the old tags until the next redraw comes 
index 8ada4d43616c75df72b74d5ecb6858cd8aec4460..3c8ed952a73660c10d4301bd9652cd179f85ebe5 100644 (file)
@@ -1108,6 +1108,7 @@ gtk_entry_completion_get_minimum_key_length
 gtk_entry_completion_get_model
 gtk_entry_completion_get_popup_completion
 gtk_entry_completion_get_popup_set_width
+gtk_entry_completion_get_popup_single_match
 gtk_entry_completion_get_text_column
 gtk_entry_completion_get_type G_GNUC_CONST
 gtk_entry_completion_insert_action_markup
@@ -1120,6 +1121,7 @@ gtk_entry_completion_set_minimum_key_length
 gtk_entry_completion_set_model
 gtk_entry_completion_set_popup_completion
 gtk_entry_completion_set_popup_set_width
+gtk_entry_completion_set_popup_single_match
 gtk_entry_completion_set_text_column
 #endif
 #endif
index 88badc5e4fa224cb58d9e14ee725d7c10cdc902f..f44e75c20b41222eb9b59dfc7c00be0474eb4f85 100644 (file)
@@ -4934,6 +4934,7 @@ gtk_entry_completion_timeout (gpointer data)
       gint matches;
       gint actions;
       GtkTreeSelection *s;
+      gboolean popup_single;
 
       gtk_entry_completion_complete (completion);
       matches = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->filter_model), NULL);
@@ -4946,7 +4947,8 @@ gtk_entry_completion_timeout (gpointer data)
 
       actions = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (completion->priv->actions), NULL);
 
-      if (matches > 0 || actions > 0)
+      g_object_get (completion, "popup-single-match", &popup_single, NULL);
+      if ((matches > (popup_single ? 0: 1)) || actions > 0)
        { 
          if (GTK_WIDGET_VISIBLE (completion->priv->popup_window))
            _gtk_entry_completion_resize_popup (completion);
index 9c16116c1921898f73c0ba9249e74d027908f1cf..e9d03f6c1a6f1d3bf0ed8cb63e574fb3de58983a 100644 (file)
@@ -59,7 +59,8 @@ enum
   PROP_TEXT_COLUMN,
   PROP_INLINE_COMPLETION,
   PROP_POPUP_COMPLETION,
-  PROP_POPUP_SET_WIDTH
+  PROP_POPUP_SET_WIDTH,
+  PROP_POPUP_SINGLE_MATCH
 };
 
 #define GTK_ENTRY_COMPLETION_GET_PRIVATE(obj)(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ENTRY_COMPLETION, GtkEntryCompletionPrivate))
@@ -351,6 +352,25 @@ gtk_entry_completion_class_init (GtkEntryCompletionClass *klass)
                                                         TRUE,
                                                         GTK_PARAM_READWRITE));
 
+  /**
+   * GtkEntryCompletion:popup-single-match:
+   * 
+   * Determines whether the completions popup window will shown
+   * for a single possible completion. You probably want to set
+   * this to %FALSE if you are using 
+   * <link linkend="GtkEntryCompletion--inline-completion">inline 
+   * completion</link>.
+   *
+   * Since: 2.8
+   */
+  g_object_class_install_property (object_class,
+                                  PROP_POPUP_SINGLE_MATCH,
+                                  g_param_spec_boolean ("popup-single-match",
+                                                        P_("Popup single match"),
+                                                        P_("If TRUE, the popup window will appear for a single match."),
+                                                        TRUE,
+                                                        GTK_PARAM_READWRITE));
+
   g_type_class_add_private (object_class, sizeof (GtkEntryCompletionPrivate));
 }
 
@@ -383,6 +403,7 @@ gtk_entry_completion_init (GtkEntryCompletion *completion)
   priv->inline_completion = FALSE;
   priv->popup_completion = TRUE;
   priv->popup_set_width = TRUE;
+  priv->popup_single_match = TRUE;
 
   /* completions */
   priv->filter_model = NULL;
@@ -516,6 +537,10 @@ gtk_entry_completion_set_property (GObject      *object,
        priv->popup_set_width = g_value_get_boolean (value);
         break;
 
+      case PROP_POPUP_SINGLE_MATCH:
+       priv->popup_single_match = g_value_get_boolean (value);
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -557,6 +582,10 @@ gtk_entry_completion_get_property (GObject    *object,
         g_value_set_boolean (value, gtk_entry_completion_get_popup_set_width (completion));
         break;
 
+      case PROP_POPUP_SINGLE_MATCH:
+        g_value_set_boolean (value, gtk_entry_completion_get_popup_single_match (completion));
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -1688,5 +1717,55 @@ gtk_entry_completion_get_popup_set_width (GtkEntryCompletion *completion)
 }
 
 
+/**
+ * gtk_entry_completion_set_popup_single_match:
+ * @completion: a #GtkEntryCompletion
+ * @popup_single_match: %TRUE if the popup should appear even for a single
+ *   match
+ *
+ * Sets whether the completion popup window will appear even if there is
+ * only a single match. You may want to set this to %FALSE if you
+ * are using <link linkend="GtkEntryCompletion--inline-completion">inline
+ * completion</link>.
+ *
+ * Since: 2.8
+ */
+void 
+gtk_entry_completion_set_popup_single_match (GtkEntryCompletion *completion,
+                                            gboolean            popup_single_match)
+{
+  g_return_if_fail (GTK_IS_ENTRY_COMPLETION (completion));
+  
+  popup_single_match = popup_single_match != FALSE;
+
+  if (completion->priv->popup_single_match != popup_single_match)
+    {
+      completion->priv->popup_single_match = popup_single_match;
+
+      g_object_notify (G_OBJECT (completion), "popup-single-match");
+    }
+}
+
+/**
+ * gtk_entry_completion_get_popup_single_match:
+ * @completion: a #GtkEntryCompletion
+ * 
+ * Returns whether the completion popup window will appear even if there is
+ * only a single match. 
+ * 
+ * Return value: %TRUE if the popup window will appear regardless of the
+ *    number of matches.
+ * 
+ * Since: 2.8
+ **/
+gboolean
+gtk_entry_completion_get_popup_single_match (GtkEntryCompletion *completion)
+{
+  g_return_val_if_fail (GTK_IS_ENTRY_COMPLETION (completion), TRUE);
+  
+  return completion->priv->popup_single_match;
+}
+
+
 #define __GTK_ENTRY_COMPLETION_C__
 #include "gtkaliasdef.c"
index 43eff46b0822c2d97218fa57df799c54e96889b0..75f11297f0bab6c4a9ec85f00d7cdc6612af738a 100644 (file)
@@ -62,6 +62,7 @@ struct _GtkEntryCompletionPrivate
   guint inline_completion : 1;
   guint popup_completion  : 1;
   guint popup_set_width   : 1;
+  guint popup_single_match : 1;
   GSource *check_completion_idle;
 };
 
index 9bfcafcf2baf66ee77a04457f7ad74f74bc023be..97b0f2327f9a83b920614abaad25a7dceef9dc33 100644 (file)
@@ -177,6 +177,7 @@ gtk_file_chooser_entry_init (GtkFileChooserEntry *chooser_entry)
   GtkCellRenderer *cell;
 
   comp = gtk_entry_completion_new ();
+  gtk_entry_completion_set_popup_single_match (comp, FALSE);
 
   gtk_entry_completion_set_match_func (comp,
                                       completion_match_func,
@@ -968,9 +969,25 @@ _gtk_file_chooser_entry_set_action (GtkFileChooserEntry *chooser_entry,
 {
   g_return_if_fail (GTK_IS_FILE_CHOOSER_ENTRY (chooser_entry));
   
-  if (  chooser_entry->action != action)
+  if (chooser_entry->action != action)
     {
+      GtkEntryCompletion *comp;
+
       chooser_entry->action = action;
+
+      comp = gtk_entry_get_completion (GTK_ENTRY (chooser_entry));
+
+      switch (action)
+       {
+       case GTK_FILE_CHOOSER_ACTION_OPEN:
+       case GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER:
+         gtk_entry_completion_set_popup_single_match (comp, FALSE);
+         break;
+       case GTK_FILE_CHOOSER_ACTION_SAVE:
+       case GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER:
+         gtk_entry_completion_set_popup_single_match (comp, TRUE);
+         break;
+       }
     }
 }