[nautilus/wip/apoos-maximus/gsoc2020: 13/27] properties-window: Port "Change Permissions..." dialog to GtkBuilder




commit 05ae4abc15058513f53de072470419f78f1a0437
Author: Apoorv Sachan <apoorv 99 sachan gmail com>
Date:   Thu Jul 2 17:09:37 2020 +0530

    properties-window: Port "Change Permissions..." dialog to GtkBuilder
    
    "Change Permissions of Enclosed Files" dialog is now built using XML
    UI definition. This is present as a seperate .ui file apart from
    nautilus-properties-window.ui because a .ui file file containing a
    widget declared as a template cannot have other external widgets to
    be built independently from the template.
    
    This .ui file is not produced or editable usingg Glade as it doesn't
    recognize "action" type children as found in GtkDialog. This issue is
    already reported in https://gitlab.gnome.org/GNOME/glade/-/issues/392

 src/nautilus-properties-window.c                   |  67 ++++-----
 src/resources/nautilus.gresource.xml               |   1 +
 .../nautilus-file-properties-change-permissions.ui | 163 +++++++++++++++++++++
 3 files changed, 190 insertions(+), 41 deletions(-)
---
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 904fca85c..199f7ed2e 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -4518,7 +4518,7 @@ on_change_permissions_response (GtkDialog                *dialog,
 }
 
 static void
-set_active_from_umask (GtkWidget      *combo,
+set_active_from_umask (GtkComboBox    *combo,
                        PermissionType  type,
                        gboolean        is_folder)
 {
@@ -4613,7 +4613,7 @@ set_active_from_umask (GtkWidget      *combo,
         }
     }
 
-    gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo), id);
+    gtk_combo_box_set_active_id (combo, id);
 }
 
 static void
@@ -4621,71 +4621,56 @@ on_change_permissions_clicked (GtkWidget                *button,
                                NautilusPropertiesWindow *window)
 {
     GtkWidget *dialog;
-    GtkWidget *label;
-    GtkWidget *combo;
-    GtkGrid *grid;
-
-    dialog = gtk_dialog_new_with_buttons (_("Change Permissions for Enclosed Files"),
-                                          GTK_WINDOW (window),
-                                          GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | 
GTK_DIALOG_USE_HEADER_BAR,
-                                          _("_Cancel"), GTK_RESPONSE_CANCEL,
-                                          _("Change"), GTK_RESPONSE_OK,
-                                          NULL);
+    GtkComboBox *combo;
+    GtkBuilder *change_permissions_builder;
 
-    grid = GTK_GRID (create_grid_with_standard_properties ());
-    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
-                        GTK_WIDGET (grid),
-                        TRUE, TRUE, 0);
+    change_permissions_builder = gtk_builder_new_from_resource 
("/org/gnome/nautilus/ui/nautilus-file-properties-change-permissions.ui");
 
-    label = gtk_label_new (_("Files"));
-    gtk_grid_attach (grid, label, 1, 0, 1, 1);
-    label = gtk_label_new (_("Folders"));
-    gtk_grid_attach (grid, label, 2, 0, 1, 1);
+    dialog = GTK_WIDGET (gtk_builder_get_object (change_permissions_builder, "change_permissions_dialog"));
+    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
 
-    label = gtk_label_new (_("Owner:"));
-    gtk_label_set_xalign (GTK_LABEL (label), 0);
-    gtk_grid_attach (grid, label, 0, 1, 1, 1);
-    combo = create_permissions_combo_box (PERMISSION_USER, FALSE);
+    /* Owner Permissions */
+    combo = GTK_COMBO_BOX (gtk_builder_get_object (change_permissions_builder, "file_owner_combo"));
+    setup_permissions_combo_box (combo, PERMISSION_USER, FALSE);
     window->change_permission_combos = g_list_prepend (window->change_permission_combos,
                                                        combo);
     set_active_from_umask (combo, PERMISSION_USER, FALSE);
-    gtk_grid_attach (grid, combo, 1, 1, 1, 1);
-    combo = create_permissions_combo_box (PERMISSION_USER, TRUE);
+
+    combo = GTK_COMBO_BOX (gtk_builder_get_object (change_permissions_builder, "folder_owner_combo"));
+    setup_permissions_combo_box (combo, PERMISSION_USER, TRUE);
     window->change_permission_combos = g_list_prepend (window->change_permission_combos,
                                                        combo);
     set_active_from_umask (combo, PERMISSION_USER, TRUE);
-    gtk_grid_attach (grid, combo, 2, 1, 1, 1);
 
-    label = gtk_label_new (_("Group:"));
-    gtk_label_set_xalign (GTK_LABEL (label), 0);
-    gtk_grid_attach (grid, label, 0, 2, 1, 1);
-    combo = create_permissions_combo_box (PERMISSION_GROUP, FALSE);
+    /* Group Permissions */
+    combo = GTK_COMBO_BOX (gtk_builder_get_object (change_permissions_builder, "file_group_combo"));
+    setup_permissions_combo_box (combo, PERMISSION_GROUP, FALSE);
     window->change_permission_combos = g_list_prepend (window->change_permission_combos,
                                                        combo);
     set_active_from_umask (combo, PERMISSION_GROUP, FALSE);
-    gtk_grid_attach (grid, combo, 1, 2, 1, 1);
-    combo = create_permissions_combo_box (PERMISSION_GROUP, TRUE);
+
+    combo = GTK_COMBO_BOX (gtk_builder_get_object (change_permissions_builder, "folder_group_combo"));
+    setup_permissions_combo_box (combo, PERMISSION_GROUP, TRUE);
     window->change_permission_combos = g_list_prepend (window->change_permission_combos,
                                                        combo);
     set_active_from_umask (combo, PERMISSION_GROUP, TRUE);
-    gtk_grid_attach (grid, combo, 2, 2, 1, 1);
 
-    label = gtk_label_new (_("Others:"));
-    gtk_label_set_xalign (GTK_LABEL (label), 0);
-    gtk_grid_attach (grid, label, 0, 3, 1, 1);
-    combo = create_permissions_combo_box (PERMISSION_OTHER, FALSE);
+    /* Others Permissions */
+    combo = GTK_COMBO_BOX (gtk_builder_get_object (change_permissions_builder, "file_other_combo"));
+    setup_permissions_combo_box (combo, PERMISSION_OTHER, FALSE);
     window->change_permission_combos = g_list_prepend (window->change_permission_combos,
                                                        combo);
     set_active_from_umask (combo, PERMISSION_OTHER, FALSE);
-    gtk_grid_attach (grid, combo, 1, 3, 1, 1);
-    combo = create_permissions_combo_box (PERMISSION_OTHER, TRUE);
+
+    combo = GTK_COMBO_BOX (gtk_builder_get_object (change_permissions_builder, "folder_other_combo"));
+    setup_permissions_combo_box (combo, PERMISSION_OTHER, TRUE);
     window->change_permission_combos = g_list_prepend (window->change_permission_combos,
                                                        combo);
     set_active_from_umask (combo, PERMISSION_OTHER, TRUE);
-    gtk_grid_attach (grid, combo, 2, 3, 1, 1);
 
     g_signal_connect (dialog, "response", G_CALLBACK (on_change_permissions_response), window);
     gtk_widget_show_all (dialog);
+    g_object_unref (change_permissions_builder);
 }
 
 static void
diff --git a/src/resources/nautilus.gresource.xml b/src/resources/nautilus.gresource.xml
index 75dc62d46..158594e8d 100644
--- a/src/resources/nautilus.gresource.xml
+++ b/src/resources/nautilus.gresource.xml
@@ -21,6 +21,7 @@
     <file>ui/nautilus-batch-rename-dialog.ui</file>
     <file>ui/nautilus-batch-rename-dialog-menu.ui</file>
     <file>ui/nautilus-properties-window.ui</file>
+    <file>ui/nautilus-file-properties-change-permissions.ui</file>
     <file alias="gtk/ui/nautilusgtkplacesview.ui">../gtk/nautilusgtkplacesview.ui</file>
     <file alias="gtk/ui/nautilusgtkplacesviewrow.ui">../gtk/nautilusgtkplacesviewrow.ui</file>
     <file alias="icons/thumbnail_frame.png">../../icons/thumbnail_frame.png</file>
diff --git a/src/resources/ui/nautilus-file-properties-change-permissions.ui 
b/src/resources/ui/nautilus-file-properties-change-permissions.ui
new file mode 100644
index 000000000..aa77a1042
--- /dev/null
+++ b/src/resources/ui/nautilus-file-properties-change-permissions.ui
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.22"/>
+  <object class="GtkDialog" id="change_permissions_dialog">
+    <property name="title" translatable="yes">Change Permissions for Enclosed Files</property>
+    <property name="modal">True</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <property name="use-header-bar">1</property>
+    <child type="action">
+      <object class="GtkButton" id="cancel">
+        <property name="visible">True</property>
+        <property name="label">Cancel</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="change">
+        <property name="visible">True</property>
+        <property name="label">Change</property>
+      </object>
+    </child>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="can-focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkGrid" id="change_permissions_grid">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">6</property>
+            <property name="orientation">vertical</property>
+            <property name="row_spacing">6</property>
+            <property name="column_spacing">12</property>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Files</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Folders</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Owner:</property>
+                <property name="xalign">0</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="file_owner_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="folder_owner_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Group:</property>
+                <property name="xalign">0</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="file_group_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="folder_group_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="file_other_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkComboBox" id="folder_other_combo">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">Others:</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">3</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="cancel">cancel</action-widget>
+      <action-widget response="ok">change</action-widget>
+    </action-widgets>
+  </object>
+</interface>


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