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




commit 76119baa50b8da0556b2936e7db5d20ee70b6ff5
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 | 34 +++++++++++++++++++++++++++++++++-
 src/nautilus-app-chooser.h |  2 +-
 src/nautilus-files-view.c  |  4 +---
 3 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/src/nautilus-app-chooser.c b/src/nautilus-app-chooser.c
index 24a006aa7..b861bb863 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 *label_content_type_description;
@@ -31,6 +33,7 @@ enum
 {
     PROP_0,
     PROP_CONTENT_TYPE,
+    PROP_SINGLE_CONTENT_TYPE,
     LAST_PROP
 };
 
@@ -109,6 +112,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);
@@ -206,16 +215,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,
+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..3b2c0558f 100644
--- a/src/nautilus-app-chooser.h
+++ b/src/nautilus-app-chooser.h
@@ -14,7 +14,7 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (NautilusAppChooser, nautilus_app_chooser, NAUTILUS, APP_CHOOSER, GtkDialog)
 
-NautilusAppChooser *nautilus_app_chooser_new (const char *content_type,
+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 3d644da3f..19a187f48 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]