[nautilus/wip/coreyberla/app-picker-followups: 1/4] app-chooser: Add property single-mime-type




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

    app-chooser: Add property single-mime-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 | 18 +++++++++++++++++-
 src/nautilus-app-chooser.h |  3 ++-
 src/nautilus-files-view.c  | 15 ++++++++++++++-
 3 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/src/nautilus-app-chooser.c b/src/nautilus-app-chooser.c
index 571687525..a5f7d626b 100644
--- a/src/nautilus-app-chooser.c
+++ b/src/nautilus-app-chooser.c
@@ -16,6 +16,7 @@ struct _NautilusAppChooser
     GtkDialog parent_instance;
 
     gchar *content_type;
+    gboolean single_content_type;
 
     GtkWidget *app_chooser_widget_box;
     GtkWidget *label_content_type_description;
@@ -30,6 +31,7 @@ enum
 {
     PROP_0,
     PROP_CONTENT_TYPE,
+    PROP_SINGLE_CONTENT_TYPE,
     LAST_PROP
 };
 
@@ -108,6 +110,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);
@@ -197,16 +205,24 @@ 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)
+                          GtkWindow  *parent_window,
+                          gboolean    single_content_type)
 {
     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..fe37969b4 100644
--- a/src/nautilus-app-chooser.h
+++ b/src/nautilus-app-chooser.h
@@ -15,7 +15,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);
+                                              GtkWindow  *parent_window,
+                                              gboolean    single_mime_type);
 
 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..f9c755cf9 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1486,14 +1486,27 @@ choose_program (NautilusFilesView *view,
 {
     GtkWidget *dialog;
     g_autofree gchar *mime_type = NULL;
+    gboolean single_mime_type = TRUE;
     GtkWindow *parent_window;
 
     g_assert (NAUTILUS_IS_FILES_VIEW (view));
 
     mime_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 (mime_type, temp_mime_type) != 0)
+        {
+            single_mime_type = FALSE;
+            break;
+        }
+    }
+
     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 (mime_type, parent_window, single_mime_type));
     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]