[gtk/wip/ebassi/shortcut: 85/85] filechooser: Trigger the location popup via bindings



commit d27bdbd53959eeb2fe61543ea118090796ff49af
Author: Benjamin Otte <otte redhat com>
Date:   Sun Aug 26 18:39:51 2018 +0200

    filechooser: Trigger the location popup via bindings
    
    Simplifies code quite a bit.

 gtk/gtkfilechooserwidget.c | 55 ++++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 29 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 73c363da93..0808224507 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -1286,41 +1286,22 @@ places_sidebar_show_error_message_cb (GtkPlacesSidebar *sidebar,
 }
 
 static gboolean
-should_trigger_location_entry (GtkFileChooserWidget *impl,
-                               guint                 keyval,
-                               GdkModifierType       state,
-                               const char          **string)
+trigger_location_entry (GtkWidget *widget,
+                        GVariant  *arguments,
+                        gpointer   unused)
 {
-  GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
-  GdkModifierType no_text_input_mask;
+  GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (widget);
+  GtkFileChooserWidgetPrivate *priv = impl->priv;
 
   if (priv->operation_mode == OPERATION_MODE_SEARCH)
     return FALSE;
 
-  no_text_input_mask =
-    gtk_widget_get_modifier_mask (GTK_WIDGET (impl), GDK_MODIFIER_INTENT_NO_TEXT_INPUT);
-
-  if (state & no_text_input_mask)
+  if (priv->action != GTK_FILE_CHOOSER_ACTION_OPEN &&
+      priv->action != GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
     return FALSE;
 
-  switch (keyval)
-    {
-    case GDK_KEY_slash:
-    case GDK_KEY_KP_Divide:
-      *string = "/";
-      return TRUE;
-
-    case GDK_KEY_period:
-      *string = ".";
-      return TRUE;
-
-    case GDK_KEY_asciitilde:
-      *string = "~";
-      return TRUE;
-
-    default:
-      return FALSE;
-    }
+  location_popup_handler (impl, g_variant_get_string (arguments, NULL));
+  return TRUE;
 }
 
 /* Handles key press events on the file list, so that we can trap Enter to
@@ -1390,7 +1371,7 @@ widget_key_press_cb (GtkEventControllerKey *controller,
           handled = TRUE;
         }
     }
-  else
+  else if (gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (priv->search_entry), (GdkEvent *) event))
     {
       priv->starting_search = TRUE;
       if (gtk_event_controller_key_forward (controller, priv->search_entry))
@@ -8248,6 +8229,22 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
                                        GDK_KEY_p, GDK_MOD1_MASK,
                                        "places-shortcut",
                                        NULL);
+  gtk_widget_class_add_binding (widget_class,
+                                GDK_KEY_slash, 0,
+                                trigger_location_entry,
+                                "s", "/");
+  gtk_widget_class_add_binding (widget_class,
+                                GDK_KEY_KP_Divide, 0,
+                                trigger_location_entry,
+                                "s", "/");
+  gtk_widget_class_add_binding (widget_class,
+                                GDK_KEY_period, 0,
+                                trigger_location_entry,
+                                "s", ".");
+  gtk_widget_class_add_binding (widget_class,
+                                GDK_KEY_asciitilde, 0,
+                                trigger_location_entry,
+                                "s", "~");
 
   for (i = 0; i < G_N_ELEMENTS (quick_bookmark_keyvals); i++)
     gtk_widget_class_add_binding_signal (widget_class,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]