[nautilus/wip/antoniof/properties-followup: 21/21] properties-window: Add star button




commit 254902f75070aacf411acd5b02e5bc535499761a
Author: António Fernandes <antoniof gnome org>
Date:   Fri Aug 5 08:17:40 2022 +0100

    properties-window: Add star button
    
    Starred status can be perceived as a property, also in grid view there
    is no visual indication or easy way to change it.
    
    Furthermore, we are to remove the star action from the view menu.

 src/nautilus-properties-window.c               | 75 ++++++++++++++++++++++++++
 src/resources/ui/nautilus-properties-window.ui | 63 +++++++++++++---------
 2 files changed, 114 insertions(+), 24 deletions(-)
---
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 97ad5036b..878f5daaa 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -48,6 +48,7 @@
 #include "nautilus-module.h"
 #include "nautilus-property-page.h"
 #include "nautilus-signaller.h"
+#include "nautilus-tag-manager.h"
 #include "nautilus-ui-utilities.h"
 
 static GHashTable *windows;
@@ -90,6 +91,8 @@ struct _NautilusPropertiesWindow
     GtkWidget *icon_button_image;
     GtkWidget *icon_chooser;
 
+    GtkWidget *star_button;
+
     GtkLabel *name_value_label;
     GtkWidget *type_value_label;
     GtkLabel *type_file_system_label;
@@ -742,6 +745,71 @@ nautilus_properties_window_drag_drop_cb (GtkDropTarget *target,
     }
 }
 
+static void
+star_clicked (NautilusPropertiesWindow *self)
+{
+    NautilusTagManager *tag_manager = nautilus_tag_manager_get ();
+    NautilusFile *file = get_original_file (self);
+    g_autofree gchar *uri = nautilus_file_get_uri (file);
+
+    if (nautilus_tag_manager_file_is_starred (tag_manager, uri))
+    {
+        nautilus_tag_manager_unstar_files (tag_manager, G_OBJECT (self),
+                                           &(GList){ file, NULL }, NULL, NULL);
+    }
+    else
+    {
+        nautilus_tag_manager_star_files (tag_manager, G_OBJECT (self),
+                                         &(GList){ file, NULL }, NULL, NULL);
+    }
+}
+
+static void
+update_star (NautilusPropertiesWindow *self,
+             NautilusTagManager       *tag_manager)
+{
+    gboolean is_starred;
+    g_autofree gchar *file_uri = NULL;
+
+    file_uri = nautilus_file_get_uri (get_target_file (self));
+    is_starred = nautilus_tag_manager_file_is_starred (tag_manager, file_uri);
+
+    gtk_button_set_icon_name (GTK_BUTTON (self->star_button),
+                              is_starred ? "starred-symbolic" : "non-starred-symbolic");
+    /* Translators: This is a verb for tagging or untagging a file with a star. */
+    gtk_widget_set_tooltip_text (self->star_button, is_starred ? _("Unstar") : _("Star"));
+}
+
+static void
+on_starred_changed (NautilusTagManager *tag_manager,
+                    GList              *changed_files,
+                    gpointer            user_data)
+{
+    NautilusPropertiesWindow *self = user_data;
+    NautilusFile *file = get_target_file (self);
+
+    if (g_list_find (changed_files, file))
+    {
+        update_star (self, tag_manager);
+    }
+}
+
+static void
+setup_star_button (NautilusPropertiesWindow *self)
+{
+    NautilusTagManager *tag_manager = nautilus_tag_manager_get ();
+    NautilusFile *file = get_target_file (self);
+    g_autoptr (GFile) parent_location = nautilus_file_get_parent_location (file);
+
+    if (nautilus_tag_manager_can_star_contents (tag_manager, parent_location))
+    {
+        gtk_widget_show (self->star_button);
+        update_star (self, tag_manager);
+        g_signal_connect_object (tag_manager, "starred-changed",
+                                 G_CALLBACK (on_starred_changed), self, 0);
+    }
+}
+
 static void
 setup_image_widget (NautilusPropertiesWindow *self,
                     gboolean                  is_customizable)
@@ -2521,6 +2589,11 @@ setup_basic_page (NautilusPropertiesWindow *self)
 
     self->icon_chooser = NULL;
 
+    if (!is_multi_file_window (self))
+    {
+        setup_star_button (self);
+    }
+
     update_name_field (self);
 
     if (should_show_volume_usage (self))
@@ -4280,6 +4353,7 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_image);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_button);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_button_image);
+    gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, star_button);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, name_value_label);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, type_value_label);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, type_file_system_label);
@@ -4333,6 +4407,7 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, 
change_permissions_button_box);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, change_permissions_button);
 
+    gtk_widget_class_bind_template_callback (widget_class, star_clicked);
     gtk_widget_class_bind_template_callback (widget_class, open_in_disks);
     gtk_widget_class_bind_template_callback (widget_class, open_parent_folder);
     gtk_widget_class_bind_template_callback (widget_class, open_link_target);
diff --git a/src/resources/ui/nautilus-properties-window.ui b/src/resources/ui/nautilus-properties-window.ui
index 8002afa25..8299c93d1 100644
--- a/src/resources/ui/nautilus-properties-window.ui
+++ b/src/resources/ui/nautilus-properties-window.ui
@@ -39,33 +39,48 @@
                             <property name="orientation">vertical</property>
                             <property name="spacing">12</property>
                             <child>
-                              <object class="GtkStack" id="icon_stack">
-                                <property name="halign">center</property>
-                                <property name="valign">start</property>
-                                <child>
-                                  <object class="GtkStackPage">
-                                    <property name="name">icon_image</property>
-                                    <property name="child">
-                                      <object class="GtkImage" id="icon_image">
-                                        <property name="icon-name">image-missing</property>
-                                      </object>
-                                    </property>
-                                  </object>
-                                </child>
-                                <child>
-                                  <object class="GtkStackPage">
-                                    <property name="name">icon_button</property>
-                                    <property name="child">
-                                      <object class="GtkButton" id="icon_button">
-                                        <property name="focusable">True</property>
-                                        <property name="receives_default">True</property>
-                                        <child>
-                                          <object class="GtkImage" id="icon_button_image">
+                              <object class="GtkCenterBox">
+                                <child type="center">
+                                  <object class="GtkStack" id="icon_stack">
+                                    <property name="halign">center</property>
+                                    <property name="valign">start</property>
+                                    <child>
+                                      <object class="GtkStackPage">
+                                        <property name="name">icon_image</property>
+                                        <property name="child">
+                                          <object class="GtkImage" id="icon_image">
                                             <property name="icon-name">image-missing</property>
                                           </object>
-                                        </child>
+                                        </property>
+                                      </object>
+                                    </child>
+                                    <child>
+                                      <object class="GtkStackPage">
+                                        <property name="name">icon_button</property>
+                                        <property name="child">
+                                          <object class="GtkButton" id="icon_button">
+                                            <property name="focusable">True</property>
+                                            <property name="receives_default">True</property>
+                                            <child>
+                                              <object class="GtkImage" id="icon_button_image">
+                                                <property name="icon-name">image-missing</property>
+                                              </object>
+                                            </child>
+                                          </object>
+                                        </property>
                                       </object>
-                                    </property>
+                                    </child>
+                                  </object>
+                                </child>
+                                <child type="end">
+                                  <object class="GtkButton" id="star_button">
+                                    <property name="visible">false</property>
+                                    <property name="valign">start</property>
+                                    <signal name="clicked" handler="star_clicked" swapped="yes"/>
+                                    <style>
+                                      <class name="circular"/>
+                                      <class name="flat"/>
+                                    </style>
                                   </object>
                                 </child>
                               </object>


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