Skip to content

Commit

Permalink
PropertiesWindow: handle permpanel failure case in permpanel widget (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Sep 5, 2024
1 parent ec600cf commit ed1fb9a
Showing 1 changed file with 50 additions and 62 deletions.
112 changes: 50 additions & 62 deletions src/Dialogs/PropertiesWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 ("<tt>%s</tt>".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 ("<tt>%s</tt>".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;
}
Expand Down

0 comments on commit ed1fb9a

Please sign in to comment.