Skip to content

Commit de1812c

Browse files
danirabbitstsdc
authored andcommitted
ProcessInfoView: cleanup and code style
1 parent 4f38a4f commit de1812c

File tree

1 file changed

+35
-45
lines changed

1 file changed

+35
-45
lines changed

src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
*/
55

66
public class Monitor.ProcessInfoView : Gtk.Box {
7-
private Gtk.Box process_action_bar;
8-
private ProcessInfoIOStats process_info_io_stats = new ProcessInfoIOStats ();
9-
107
private Process _process;
11-
public Process ? process {
8+
public Process? process {
129
get {
1310
return _process;
1411
}
@@ -45,68 +42,47 @@ public class Monitor.ProcessInfoView : Gtk.Box {
4542
}
4643
}
4744
}
48-
public string ? icon_name;
45+
46+
private Gtk.Box process_action_bar;
47+
private ProcessInfoIOStats process_info_io_stats;
4948

5049
private Gtk.InfoBar permission_error_infobar;
5150
private Gtk.Label permission_error_label;
5251

5352
private ProcessInfoHeader process_info_header;
5453
private ProcessInfoCPURAM process_info_cpu_ram;
5554

56-
private Gtk.Button end_process_button;
57-
private Gtk.Button kill_process_button;
58-
59-
public ProcessInfoView () {
60-
orientation = Gtk.Orientation.VERTICAL;
61-
hexpand = true;
55+
construct {
56+
permission_error_label = new Gtk.Label (Utils.NO_DATA);
6257

6358
permission_error_infobar = new Gtk.InfoBar () {
64-
message_type = Gtk.MessageType.ERROR,
65-
revealed = false,
59+
message_type = ERROR,
60+
revealed = false
6661
};
67-
permission_error_label = new Gtk.Label (Utils.NO_DATA);
6862
permission_error_infobar.add_child (permission_error_label);
69-
append (permission_error_infobar);
70-
71-
var grid = new Gtk.Grid () {
72-
margin_top = 12,
73-
margin_bottom = 12,
74-
margin_start = 12,
75-
margin_end = 12,
76-
hexpand = true,
77-
column_spacing = 12
78-
};
79-
append (grid);
80-
8163

8264
process_info_header = new ProcessInfoHeader ();
83-
grid.attach (process_info_header, 0, 0, 1, 1);
8465

85-
var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
66+
var separator = new Gtk.Separator (HORIZONTAL) {
8667
margin_top = 12,
87-
margin_bottom = 12,
88-
margin_start = 12,
89-
margin_end = 12,
90-
hexpand = true
68+
margin_bottom = 12
9169
};
92-
grid.attach (separator, 0, 1, 1, 1);
9370

9471
process_info_cpu_ram = new ProcessInfoCPURAM ();
9572
process_info_cpu_ram.hide ();
96-
grid.attach (process_info_cpu_ram, 0, 2, 1, 1);
9773

98-
grid.attach (process_info_io_stats, 0, 4, 1, 1);
74+
process_info_io_stats = new ProcessInfoIOStats ();
9975

100-
end_process_button = new Gtk.Button.with_label (_("Shut Down…")) {
76+
var end_process_button = new Gtk.Button.with_label (_("Shut Down…")) {
10177
tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>E" })
10278
};
10379

104-
kill_process_button = new Gtk.Button.with_label (_("Force Quit…")) {
80+
var kill_process_button = new Gtk.Button.with_label (_("Force Quit…")) {
10581
tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>K" })
10682
};
10783
kill_process_button.add_css_class (Granite.CssClass.DESTRUCTIVE);
10884

109-
process_action_bar = new Gtk.Box (HORIZONTAL, 12) {
85+
process_action_bar = new Granite.Box (HORIZONTAL) {
11086
halign = END,
11187
valign = END,
11288
homogeneous = true,
@@ -115,9 +91,26 @@ public class Monitor.ProcessInfoView : Gtk.Box {
11591
process_action_bar.append (end_process_button);
11692
process_action_bar.append (kill_process_button);
11793

94+
var box = new Granite.Box (VERTICAL) {
95+
margin_top = 12,
96+
margin_bottom = 12,
97+
margin_start = 12,
98+
margin_end = 12
99+
};
100+
box.append (process_info_header);
101+
box.append (separator);
102+
box.append (process_info_cpu_ram);
103+
box.append (process_info_io_stats);
104+
box.append (process_action_bar);
105+
106+
orientation = VERTICAL;
107+
hexpand = true;
108+
append (permission_error_infobar);
109+
append (box);
110+
118111
kill_process_button.clicked.connect (() => {
119112
var confirmation_dialog = new Granite.MessageDialog (
120-
_("Force “%s” to quit without initiating shutdown tasks?").printf (process_info_header.application_name.label),
113+
_("Force “%s” to quit without initiating shutdown tasks?").printf (process.application_name),
121114
_("This may lead to data loss. Only Force Quit if Shut Down has failed."),
122115
new ThemedIcon ("computer-fail"),
123116
Gtk.ButtonsType.CANCEL
@@ -144,11 +137,11 @@ public class Monitor.ProcessInfoView : Gtk.Box {
144137

145138
end_process_button.clicked.connect (() => {
146139
var confirmation_dialog = new Granite.MessageDialog (
147-
_("Ask “%s” to shut down?").printf (process_info_header.application_name.label),
140+
_("Ask “%s” to shut down?").printf (process.application_name),
148141
_("The process will be asked to initiate shutdown tasks and close. In some cases the process may not quit."),
149142
new ThemedIcon ("system-shutdown"),
150143
Gtk.ButtonsType.CANCEL
151-
) {
144+
) {
152145
badge_icon = new ThemedIcon ("dialog-question"),
153146
modal = true,
154147
transient_for = (Gtk.Window) get_root ()
@@ -168,13 +161,11 @@ public class Monitor.ProcessInfoView : Gtk.Box {
168161

169162
confirmation_dialog.present ();
170163
});
171-
172-
grid.attach (process_action_bar, 0, 5);
173164
}
174165

175166
private void show_permission_error_infobar (string error) {
176167
if (!permission_error_infobar.revealed) {
177-
permission_error_label.set_text (error);
168+
permission_error_label.label = error;
178169
permission_error_infobar.revealed = true;
179170
}
180171
}
@@ -190,5 +181,4 @@ public class Monitor.ProcessInfoView : Gtk.Box {
190181
process_info_io_stats.open_files_tree_view.visible = true;
191182
}
192183
}
193-
194184
}

0 commit comments

Comments
 (0)