[gnome-text-editor: 1/2] window-actions: Allow opening multiple files at once




commit 2e6ffe19f7704421921c2feeff0939d7834bd170
Author: vanadiae <vanadiae35 gmail com>
Date:   Sun Jul 4 15:41:30 2021 +0200

    window-actions: Allow opening multiple files at once
    
    When one wants to open several documents, it can be a bit
    annoying to open files one by one.
    
    So this commit allows opening multiple files with a single
    file chooser dialog.

 src/editor-window-actions.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/src/editor-window-actions.c b/src/editor-window-actions.c
index 28f53d6..44767af 100644
--- a/src/editor-window-actions.c
+++ b/src/editor-window-actions.c
@@ -305,10 +305,18 @@ editor_window_actions_open_response_cb (EditorWindow         *self,
 
   if (response_id == GTK_RESPONSE_ACCEPT)
     {
-      g_autoptr(GFile) file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (native));
+      g_autoptr(GListModel) files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (native));
+      guint i = 0;
+      GFile *file = NULL;
       const GtkSourceEncoding *encoding = _editor_file_chooser_get_encoding (GTK_FILE_CHOOSER (native));
 
-      editor_session_open (EDITOR_SESSION_DEFAULT, self, file, encoding);
+      g_assert (g_list_model_get_item_type (files) == G_TYPE_FILE);
+
+      while ((file = G_FILE (g_list_model_get_object (files, i++))))
+        {
+          editor_session_open (EDITOR_SESSION_DEFAULT, self, file, encoding);
+          g_object_unref (file);
+        }
     }
 
   gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
@@ -366,6 +374,8 @@ editor_window_actions_open_cb (GtkWidget  *widget,
 
   _editor_file_chooser_add_encodings (GTK_FILE_CHOOSER (native));
 
+  gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (native), TRUE);
+
   g_signal_connect_object (native,
                            "response",
                            G_CALLBACK (editor_window_actions_open_response_cb),


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