[gnome-builder] greeter: use SELECT_FOLDER when appropriate



commit 3ad83a67915cb3aa85c24934bd6d74a7a489bd1b
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jul 2 01:12:22 2016 -0700

    greeter: use SELECT_FOLDER when appropriate
    
    If we have a file filter that is of type inode/directory, then we really
    need SELECT_FOLDER so that the user can select the directory instead of
    diving into the directory. This will break things that have content types
    mixed with inode/directory, but I think that is okay.

 libide/greeter/ide-greeter-perspective.c |   39 +++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)
---
diff --git a/libide/greeter/ide-greeter-perspective.c b/libide/greeter/ide-greeter-perspective.c
index 1f1479b..16ee4a8 100644
--- a/libide/greeter/ide-greeter-perspective.c
+++ b/libide/greeter/ide-greeter-perspective.c
@@ -621,6 +621,28 @@ ide_greeter_perspective_dialog_response (IdeGreeterPerspective *self,
 }
 
 static void
+ide_greeter_perspective_dialog_notify_filter (IdeGreeterPerspective *self,
+                                              GParamSpec            *pspec,
+                                              GtkFileChooserDialog  *dialog)
+{
+  GtkFileFilter *filter;
+  GtkFileChooserAction action;
+
+  g_assert (IDE_IS_GREETER_PERSPECTIVE (self));
+  g_assert (pspec != NULL);
+  g_assert (GTK_IS_FILE_CHOOSER_DIALOG (dialog));
+
+  filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog));
+
+  if (filter && g_object_get_data (G_OBJECT (filter), "IS_DIRECTORY"))
+    action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
+  else
+    action = GTK_FILE_CHOOSER_ACTION_OPEN;
+
+  gtk_file_chooser_set_action (GTK_FILE_CHOOSER (dialog), action);
+}
+
+static void
 ide_greeter_perspective_open_clicked (IdeGreeterPerspective *self,
                                       GtkButton             *open_button)
 {
@@ -652,6 +674,12 @@ ide_greeter_perspective_open_clicked (IdeGreeterPerspective *self,
                           NULL);
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
+  g_signal_connect_object (dialog,
+                           "notify::filter",
+                           G_CALLBACK (ide_greeter_perspective_dialog_notify_filter),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   for (; list != NULL; list = list->next)
     {
       PeasPluginInfo *plugin_info = list->data;
@@ -692,7 +720,16 @@ ide_greeter_perspective_open_clicked (IdeGreeterPerspective *self,
       for (i = 0; content_types [i] != NULL; i++)
         {
           if (*content_types [i])
-            gtk_file_filter_add_mime_type (filter, content_types [i]);
+            {
+              gtk_file_filter_add_mime_type (filter, content_types [i]);
+
+              /* Helper so we can change the file chooser action to OPEN_DIRECTORY,
+               * otherwise the user won't be able to choose a directory, it will
+               * instead dive into the directory.
+               */
+              if (g_strcmp0 (content_types [i], "inode/directory") == 0)
+                g_object_set_data (G_OBJECT (filter), "IS_DIRECTORY", GINT_TO_POINTER (1));
+            }
         }
 
       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);


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