From 08725a70397ed2af138fb11952fbd3798a6b1a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 3 Sep 2024 12:14:30 -0700 Subject: [PATCH] PropertiesWindow: handle permpanel failure case in permpanel widget --- src/Dialogs/PropertiesWindow.vala | 112 +++++++++++++----------------- 1 file changed, 50 insertions(+), 62 deletions(-) diff --git a/src/Dialogs/PropertiesWindow.vala b/src/Dialogs/PropertiesWindow.vala index cbe3c25c4..1791c9703 100644 --- a/src/Dialogs/PropertiesWindow.vala +++ b/src/Dialogs/PropertiesWindow.vala @@ -80,7 +80,6 @@ public class Files.View.PropertiesWindow : AbstractPropertiesDialog { private uint selected_files = 0; private signal void uncounted_folders_changed (); - private Gtk.Grid perm_grid; private int owner_perm_code = 0; private int group_perm_code = 0; private int everyone_perm_code = 0; @@ -218,24 +217,7 @@ public class Files.View.PropertiesWindow : AbstractPropertiesDialog { create_header_title (); /* Permissions */ - if (construct_perm_panel () != null) { - if (!goffile.can_set_permissions ()) { - foreach (var widget in perm_grid.get_children ()) { - widget.set_sensitive (false); - } - } - } else { - var label = new Gtk.Label (_("Unable to determine file ownership and permissions")); - - perm_grid = new Gtk.Grid () { - hexpand = true, - vexpand = true, - valign = Gtk.Align.CENTER - }; - perm_grid.attach (label, 0, 0); - } - - stack.add_titled (perm_grid, PanelType.PERMISSIONS.to_string (), _("Permissions")); + stack.add_titled (construct_perm_panel (), PanelType.PERMISSIONS.to_string (), _("Permissions")); var stack_switcher = new Gtk.StackSwitcher () { homogeneous = true, @@ -952,58 +934,64 @@ public class Files.View.PropertiesWindow : AbstractPropertiesDialog { } } - private Gtk.Grid? construct_perm_panel () { + private Gtk.Widget construct_perm_panel () { var owner_user_choice = create_owner_choice (); if (owner_user_choice == null) { - return null; - } else { - var owner_user_label = make_key_label (_("Owner:")); - var group_combo_label = make_key_label (_("Group:")); - group_combo_label.margin_bottom = 12; + return new Gtk.Label (_("Unable to determine file ownership and permissions")) { + hexpand = true, + vexpand = true, + valign = CENTER + }; + } - var group_combo = create_group_choice (); - group_combo.margin_bottom = 12; + var owner_user_label = make_key_label (_("Owner:")); + var group_combo_label = make_key_label (_("Group:")); + group_combo_label.margin_bottom = 12; - perm_button_user = create_perm_choice (Permissions.Type.USER); - perm_button_group = create_perm_choice (Permissions.Type.GROUP); - perm_button_other = create_perm_choice (Permissions.Type.OTHER); + var group_combo = create_group_choice (); + group_combo.margin_bottom = 12; - perm_code = new Gtk.Entry (); - perm_code.text = "000"; - perm_code.max_length = perm_code.max_width_chars = perm_code.width_chars = 3; + perm_button_user = create_perm_choice (Permissions.Type.USER); + perm_button_group = create_perm_choice (Permissions.Type.GROUP); + perm_button_other = create_perm_choice (Permissions.Type.OTHER); - l_perm = new Gtk.Label ("%s".printf (goffile.get_permissions_as_string ())); - l_perm.halign = Gtk.Align.START; - l_perm.use_markup = true; + perm_code = new Gtk.Entry (); + perm_code.text = "000"; + perm_code.max_length = perm_code.max_width_chars = perm_code.width_chars = 3; - var permission_box = new Gtk.ListBox () { - selection_mode = NONE - }; - // FIXME: use constants in Gtk4 - permission_box.get_style_context ().add_class ("frame"); - permission_box.get_style_context ().add_class ("rich-list"); - permission_box.get_style_context ().add_class ("boxed-list"); - permission_box.get_style_context ().add_class ("separators"); - permission_box.add (perm_button_user); - permission_box.add (perm_button_group); - permission_box.add (perm_button_other); - - perm_grid = new Gtk.Grid () { - column_spacing = 6, - row_spacing = 6 - }; - perm_grid.attach (owner_user_label, 0, 0); - perm_grid.attach (owner_user_choice, 1, 0); - perm_grid.attach (group_combo_label, 0, 1); - perm_grid.attach (group_combo, 1, 1); - perm_grid.attach (permission_box, 0, 2, 2); - perm_grid.attach (l_perm, 0, 3); - perm_grid.attach (perm_code, 1, 3); + l_perm = new Gtk.Label ("%s".printf (goffile.get_permissions_as_string ())); + l_perm.halign = Gtk.Align.START; + l_perm.use_markup = true; - update_perm_grid_toggle_states (goffile.permissions); + var permission_box = new Gtk.ListBox () { + selection_mode = NONE + }; + // FIXME: use constants in Gtk4 + permission_box.get_style_context ().add_class ("frame"); + permission_box.get_style_context ().add_class ("rich-list"); + permission_box.get_style_context ().add_class ("boxed-list"); + permission_box.get_style_context ().add_class ("separators"); + permission_box.add (perm_button_user); + permission_box.add (perm_button_group); + permission_box.add (perm_button_other); + + var perm_grid = new Gtk.Grid () { + column_spacing = 6, + row_spacing = 6 + }; + perm_grid.attach (owner_user_label, 0, 0); + perm_grid.attach (owner_user_choice, 1, 0); + perm_grid.attach (group_combo_label, 0, 1); + perm_grid.attach (group_combo, 1, 1); + perm_grid.attach (permission_box, 0, 2, 2); + perm_grid.attach (l_perm, 0, 3); + perm_grid.attach (perm_code, 1, 3); - perm_code.changed.connect (entry_changed); - } + perm_grid.sensitive = goffile.can_set_permissions (); + + update_perm_grid_toggle_states (goffile.permissions); + + perm_code.changed.connect (entry_changed); return perm_grid; }