[nautilus/wip/coreyberla/app-picker-followups: 4/5] app-chooser: Add property filename




commit e0fb7f83b39fb03cc0028a18fe18b07cade78599
Author: Corey Berla <corey berla me>
Date:   Fri Aug 5 13:12:36 2022 -0700

    app-chooser: Add property filename
    
    We need this for the description within the app chooser.
    If we are working on multiple files, set to NULL.

 src/nautilus-app-chooser.c | 17 +++++++++++++++++
 src/nautilus-app-chooser.h |  1 +
 src/nautilus-files-view.c  |  5 ++++-
 3 files changed, 22 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-app-chooser.c b/src/nautilus-app-chooser.c
index 8f930596c..ea47021c8 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;
+    gchar *file_name;
     gboolean single_content_type;
 
     GtkWidget *app_chooser_widget_box;
@@ -32,6 +33,7 @@ enum
     PROP_0,
     PROP_CONTENT_TYPE,
     PROP_SINGLE_CONTENT_TYPE,
+    PROP_FILE_NAME,
     LAST_PROP
 };
 
@@ -116,6 +118,12 @@ nautilus_app_chooser_set_property (GObject      *object,
         }
         break;
 
+        case PROP_FILE_NAME:
+        {
+            self->file_name = g_value_dup_string (value);
+        }
+        break;
+
         default:
         {
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -193,6 +201,7 @@ nautilus_app_chooser_finalize (GObject *object)
     NautilusAppChooser *self = (NautilusAppChooser *) object;
 
     g_clear_pointer (&self->content_type, g_free);
+    g_clear_pointer (&self->file_name, g_free);
 
     G_OBJECT_CLASS (nautilus_app_chooser_parent_class)->finalize (object);
 }
@@ -219,6 +228,12 @@ nautilus_app_chooser_class_init (NautilusAppChooserClass *klass)
                                                           NULL,
                                                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
 
+    g_object_class_install_property (object_class,
+                                     PROP_FILE_NAME,
+                                     g_param_spec_string ("file-name", "", "",
+                                                          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", "", "",
@@ -229,12 +244,14 @@ nautilus_app_chooser_class_init (NautilusAppChooserClass *klass)
 NautilusAppChooser *
 nautilus_app_chooser_new (const char *content_type,
                           GtkWindow  *parent_window,
+                          gchar      *file_name,
                           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,
+                                               "file-name", file_name,
                                                "single-content-type", single_content_type,
                                                NULL));
 }
diff --git a/src/nautilus-app-chooser.h b/src/nautilus-app-chooser.h
index fe37969b4..840484a12 100644
--- a/src/nautilus-app-chooser.h
+++ b/src/nautilus-app-chooser.h
@@ -16,6 +16,7 @@ G_DECLARE_FINAL_TYPE (NautilusAppChooser, nautilus_app_chooser, NAUTILUS, APP_CH
 
 NautilusAppChooser *nautilus_app_chooser_new (const char *content_type,
                                               GtkWindow  *parent_window,
+                                              gchar      *file_name,
                                               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 f9c755cf9..aef2ae3e0 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -1486,12 +1486,14 @@ choose_program (NautilusFilesView *view,
 {
     GtkWidget *dialog;
     g_autofree gchar *mime_type = NULL;
+    g_autofree gchar *file_name = 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);
+    file_name = files->next ? NULL : nautilus_file_get_display_name (files->data);
 
     for (GList *l = files; l != NULL; l = l->next)
     {
@@ -1506,7 +1508,8 @@ choose_program (NautilusFilesView *view,
 
     parent_window = nautilus_files_view_get_containing_window (view);
 
-    dialog = GTK_WIDGET (nautilus_app_chooser_new (mime_type, parent_window, single_mime_type));
+    dialog = GTK_WIDGET (nautilus_app_chooser_new (mime_type, parent_window,
+                                                   file_name, 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]