[nautilus/wip/coreyberla/app-picker-followups: 61/67] app-chooser: Add property single-content-type




commit d2ad33b3a3605dbfd80ed8fc397450d414948bdd
Author: Corey Berla <corey berla me>
Date:   Fri Aug 5 12:51:22 2022 -0700

    app-chooser: Add property single-content-type
    
    If we are acting on a single item or multiple items that all have the
    same mime type, set to true. This will be used for setting the title
    and ability to change file type association.

 src/nautilus-app-chooser.c | 36 ++++++++++++++++++++++++++++++++++--
 src/nautilus-app-chooser.h |  4 ++--
 src/nautilus-files-view.c  |  4 +---
 3 files changed, 37 insertions(+), 7 deletions(-)
---
diff --git a/src/nautilus-app-chooser.c b/src/nautilus-app-chooser.c
index f9704d689..599e1c38d 100644
--- a/src/nautilus-app-chooser.c
+++ b/src/nautilus-app-chooser.c
@@ -9,6 +9,7 @@
 #include <libadwaita-1/adwaita.h>
 #include <glib/gi18n.h>
 
+#include "nautilus-file.h"
 #include "nautilus-signaller.h"
 
 struct _NautilusAppChooser
@@ -16,6 +17,7 @@ struct _NautilusAppChooser
     GtkDialog parent_instance;
 
     gchar *content_type;
+    gboolean single_content_type;
 
     GtkWidget *app_chooser_widget_box;
     GtkWidget *reset_button;
@@ -30,6 +32,7 @@ enum
 {
     PROP_0,
     PROP_CONTENT_TYPE,
+    PROP_SINGLE_CONTENT_TYPE,
     LAST_PROP
 };
 
@@ -111,6 +114,12 @@ nautilus_app_chooser_set_property (GObject      *object,
         }
         break;
 
+        case PROP_SINGLE_CONTENT_TYPE:
+        {
+            self->single_content_type = g_value_get_boolean (value);
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -199,16 +208,39 @@ nautilus_app_chooser_class_init (NautilusAppChooserClass *klass)
                                      g_param_spec_string ("content-type", "", "",
                                                           NULL,
                                                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+    g_object_class_install_property (object_class,
+                                     PROP_SINGLE_CONTENT_TYPE,
+                                     g_param_spec_boolean ("single-content-type", "", "",
+                                                           TRUE,
+                                                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
 }
 
 NautilusAppChooser *
-nautilus_app_chooser_new (const char *content_type,
-                          GtkWindow  *parent_window)
+nautilus_app_chooser_new (GList     *files,
+                          GtkWindow *parent_window)
 {
+    gboolean single_content_type = TRUE;
+    g_autofree gchar *content_type = NULL;
+
+    content_type = nautilus_file_get_mime_type (files->data);
+
+    for (GList *l = files; l != NULL; l = l->next)
+    {
+        g_autofree gchar *temp_mime_type = NULL;
+        temp_mime_type = nautilus_file_get_mime_type (l->data);
+        if (g_strcmp0 (content_type, temp_mime_type) != 0)
+        {
+            single_content_type = FALSE;
+            break;
+        }
+    }
+
     return NAUTILUS_APP_CHOOSER (g_object_new (NAUTILUS_TYPE_APP_CHOOSER,
                                                "transient-for", parent_window,
                                                "content-type", content_type,
                                                "use-header-bar", TRUE,
+                                               "single-content-type", single_content_type,
                                                NULL));
 }
 
diff --git a/src/nautilus-app-chooser.h b/src/nautilus-app-chooser.h
index bab09845d..3131f4935 100644
--- a/src/nautilus-app-chooser.h
+++ b/src/nautilus-app-chooser.h
@@ -14,8 +14,8 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (NautilusAppChooser, nautilus_app_chooser, NAUTILUS, APP_CHOOSER, GtkDialog)
 
-NautilusAppChooser *nautilus_app_chooser_new (const char *content_type,
-                                              GtkWindow  *parent_window);
+NautilusAppChooser *nautilus_app_chooser_new (GList     *files,
+                                              GtkWindow *parent_window);
 
 GAppInfo           *nautilus_app_chooser_get_app_info (NautilusAppChooser *self);
 
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 22fbf810a..937f9af7f 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1485,15 +1485,13 @@ choose_program (NautilusFilesView *view,
                 GList             *files)
 {
     GtkWidget *dialog;
-    g_autofree gchar *mime_type = NULL;
     GtkWindow *parent_window;
 
     g_assert (NAUTILUS_IS_FILES_VIEW (view));
 
-    mime_type = nautilus_file_get_mime_type (files->data);
     parent_window = nautilus_files_view_get_containing_window (view);
 
-    dialog = GTK_WIDGET (nautilus_app_chooser_new (mime_type, parent_window));
+    dialog = GTK_WIDGET (nautilus_app_chooser_new (files, parent_window));
     g_object_set_data_full (G_OBJECT (dialog),
                             "directory-view:files",
                             files,


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