Merge lp:~elementary-apps/pantheon-files/props-dialog-perm-button-update into lp:~elementary-apps/pantheon-files/trunk

Proposed by Danielle Foré
Status: Merged
Approved by: Danielle Foré
Approved revision: 2419
Merged at revision: 2424
Proposed branch: lp:~elementary-apps/pantheon-files/props-dialog-perm-button-update
Merge into: lp:~elementary-apps/pantheon-files/trunk
Diff against target: 84 lines (+31/-14)
2 files modified
src/Dialogs/PropertiesWindow.vala (+3/-12)
src/View/Widgets/PermissionButton.vala (+28/-2)
To merge this branch: bzr merge lp:~elementary-apps/pantheon-files/props-dialog-perm-button-update
Reviewer Review Type Date Requested Status
Jeremy Wootten code Approve
Review via email: mp+313868@code.launchpad.net

Commit message

Move update_permission_type_buttons in PropertiesWindow.vala to update_buttons in PermissionButton.vala

Description of the change

This duplicates the array vfs_perms, but I'm thinking that's a little less clumsy than trying to access it across the classes. I think maybe a way to move forward more cleanly is to have a utility class instead of having these things in the properties dialog and permissions button

I changed the foreach to a set of if/else statements so that this method doesn't rely on widgets been read in a certain order

Since the permissionbutton widget knows about itself (and its permission type), we only need to pass the new permissions int, which I think really helps with clarity here

To post a comment you must log in.
Revision history for this message
Jeremy Wootten (jeremywootten) wrote :

The update buttons function assumes the children are returned in a certain order. This is probably OK, but you could make use of the data set on the buttons (PermissionType and PermissionValue) to index into the vfs_perm array to avoid this.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Yep you're right and this is definitely something I want to address in a future branch. Specifically this breaks when we change the widget from being a Gtk.Box to a Gtk.Grid.

2419. By Danielle Foré

move update_button to permsbutton

Revision history for this message
Jeremy Wootten (jeremywootten) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Dialogs/PropertiesWindow.vala'
2--- src/Dialogs/PropertiesWindow.vala 2016-12-26 02:09:47 +0000
3+++ src/Dialogs/PropertiesWindow.vala 2016-12-26 22:45:29 +0000
4@@ -741,19 +741,10 @@
5 return vfs_perm;
6 }
7
8- private void update_permission_type_buttons (PermissionButton hbox, uint32 permissions, PermissionType pt) {
9- int i=0;
10- foreach (var widget in hbox.get_children ()) {
11- Gtk.ToggleButton btn = (Gtk.ToggleButton) widget;
12- ((permissions & vfs_perms[pt, i]) != 0) ? btn.active = true : btn.active = false;
13- i++;
14- }
15- }
16-
17 private void update_perm_grid_toggle_states (uint32 permissions) {
18- update_permission_type_buttons (perm_button_user, permissions, PermissionType.USER);
19- update_permission_type_buttons (perm_button_group, permissions, PermissionType.GROUP);
20- update_permission_type_buttons (perm_button_other, permissions, PermissionType.OTHER);
21+ perm_button_user.update_buttons (permissions);
22+ perm_button_group.update_buttons (permissions);
23+ perm_button_other.update_buttons (permissions);
24 }
25
26 private bool is_chmod_code (string str) {
27
28=== modified file 'src/View/Widgets/PermissionButton.vala'
29--- src/View/Widgets/PermissionButton.vala 2016-12-23 19:15:06 +0000
30+++ src/View/Widgets/PermissionButton.vala 2016-12-26 22:45:29 +0000
31@@ -17,7 +17,7 @@
32 * Boston, MA 02111-1307, USA.
33 */
34
35-public class PermissionButton : Gtk.Box {
36+public class PermissionButton : Gtk.Grid {
37 public Gtk.ToggleButton btn_read;
38 public Gtk.ToggleButton btn_write;
39 public Gtk.ToggleButton btn_exe;
40@@ -30,6 +30,12 @@
41 EXE
42 }
43
44+ private Posix.mode_t[,] vfs_perms = {
45+ { Posix.S_IRUSR, Posix.S_IWUSR, Posix.S_IXUSR },
46+ { Posix.S_IRGRP, Posix.S_IWGRP, Posix.S_IXGRP },
47+ { Posix.S_IROTH, Posix.S_IWOTH, Posix.S_IXOTH }
48+ };
49+
50 public PermissionButton (Marlin.View.PropertiesWindow.PermissionType permission_type) {
51 Object (permission_type: permission_type);
52 }
53@@ -47,10 +53,30 @@
54 btn_exe.set_data ("permissiontype", permission_type);
55 btn_exe.set_data ("permissionvalue", Value.EXE);
56
57- homogeneous = true;
58+ column_homogeneous = true;
59 get_style_context ().add_class (Gtk.STYLE_CLASS_LINKED);
60 add (btn_read);
61 add (btn_write);
62 add (btn_exe);
63 }
64+
65+ public void update_buttons (uint32 permissions) {
66+ if ((permissions & vfs_perms[permission_type, 0]) != 0) {
67+ btn_read.active = true;
68+ } else {
69+ btn_read.active = false;
70+ }
71+
72+ if ((permissions & vfs_perms[permission_type, 1]) != 0) {
73+ btn_write.active = true;
74+ } else {
75+ btn_write.active = false;
76+ }
77+
78+ if ((permissions & vfs_perms[permission_type, 2]) != 0) {
79+ btn_exe.active = true;
80+ } else {
81+ btn_exe.active = false;
82+ }
83+ }
84 }

Subscribers

People subscribed via source and target branches