Skip to content

Commit 9617e66

Browse files
authored
ProcessInfoView: handle process actions (#484)
* ProcessInfoView: handle process actions * Put accels back in application * revert case change * move actions to functions * move actions up to ProcessView and add key controller * Disable actions appropriately
1 parent de1812c commit 9617e66

File tree

3 files changed

+96
-68
lines changed

3 files changed

+96
-68
lines changed

src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,16 @@ public class Monitor.ProcessInfoView : Gtk.Box {
7373

7474
process_info_io_stats = new ProcessInfoIOStats ();
7575

76+
var app = (Gtk.Application) GLib.Application.get_default ();
77+
7678
var end_process_button = new Gtk.Button.with_label (_("Shut Down…")) {
77-
tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>E" })
79+
action_name = "process.end",
80+
tooltip_markup = Granite.markup_accel_tooltip (app.get_accels_for_action ("process.end"))
7881
};
7982

8083
var kill_process_button = new Gtk.Button.with_label (_("Force Quit…")) {
81-
tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>K" })
84+
action_name = "process.kill",
85+
tooltip_markup = Granite.markup_accel_tooltip (app.get_accels_for_action ("process.kill"))
8286
};
8387
kill_process_button.add_css_class (Granite.CssClass.DESTRUCTIVE);
8488

@@ -107,60 +111,6 @@ public class Monitor.ProcessInfoView : Gtk.Box {
107111
hexpand = true;
108112
append (permission_error_infobar);
109113
append (box);
110-
111-
kill_process_button.clicked.connect (() => {
112-
var confirmation_dialog = new Granite.MessageDialog (
113-
_("Force “%s” to quit without initiating shutdown tasks?").printf (process.application_name),
114-
_("This may lead to data loss. Only Force Quit if Shut Down has failed."),
115-
new ThemedIcon ("computer-fail"),
116-
Gtk.ButtonsType.CANCEL
117-
) {
118-
badge_icon = new ThemedIcon ("process-stop"),
119-
modal = true,
120-
transient_for = (Gtk.Window) get_root ()
121-
};
122-
123-
var accept_button = confirmation_dialog.add_button (_("Force Quit"), Gtk.ResponseType.ACCEPT);
124-
accept_button.add_css_class (Granite.CssClass.DESTRUCTIVE);
125-
126-
confirmation_dialog.response.connect ((response) => {
127-
if (response == Gtk.ResponseType.ACCEPT) {
128-
// @TODO: maybe add a toast that process killed
129-
process.kill ();
130-
}
131-
132-
confirmation_dialog.close ();
133-
});
134-
135-
confirmation_dialog.present ();
136-
});
137-
138-
end_process_button.clicked.connect (() => {
139-
var confirmation_dialog = new Granite.MessageDialog (
140-
_("Ask “%s” to shut down?").printf (process.application_name),
141-
_("The process will be asked to initiate shutdown tasks and close. In some cases the process may not quit."),
142-
new ThemedIcon ("system-shutdown"),
143-
Gtk.ButtonsType.CANCEL
144-
) {
145-
badge_icon = new ThemedIcon ("dialog-question"),
146-
modal = true,
147-
transient_for = (Gtk.Window) get_root ()
148-
};
149-
150-
var accept_button = confirmation_dialog.add_button (_("Shut Down"), Gtk.ResponseType.ACCEPT);
151-
accept_button.add_css_class (Granite.CssClass.SUGGESTED);
152-
153-
confirmation_dialog.response.connect ((response) => {
154-
if (response == Gtk.ResponseType.ACCEPT) {
155-
// TODO: maybe add a toast that process killed
156-
process.end ();
157-
}
158-
159-
confirmation_dialog.close ();
160-
});
161-
162-
confirmation_dialog.present ();
163-
});
164114
}
165115

166116
private void show_permission_error_infobar (string error) {

src/Views/ProcessView/ProcessTreeView/CPUProcessTreeView.vala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,6 @@ public class Monitor.CPUProcessTreeView : Gtk.TreeView {
8181
cursor_changed.connect (_cursor_changed);
8282
// model.process_manager.updated.connect (_cursor_changed);
8383

84-
var end_process_action = new GLib.SimpleAction ("end", null);
85-
end_process_action.activate.connect (end_process);
86-
87-
var kill_process_action = new GLib.SimpleAction ("kill", null);
88-
kill_process_action.activate.connect (kill_process);
89-
90-
var action_group = new SimpleActionGroup ();
91-
action_group.add_action (end_process_action);
92-
action_group.add_action (kill_process_action);
93-
94-
insert_action_group ("process", action_group);
95-
9684
var key_controller = new Gtk.EventControllerKey ();
9785
add_controller (key_controller);
9886
key_controller.key_released.connect ((keyval, keycode, state) => {

src/Views/ProcessView/ProcessView.vala

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public class Monitor.ProcessView : Granite.Bin {
1111
private ProcessInfoView process_info_view;
1212
private TreeViewModel treeview_model;
1313

14+
private SimpleAction end_action;
15+
private SimpleAction kill_action;
16+
1417
construct {
1518
treeview_model = new TreeViewModel ();
1619

@@ -47,11 +50,98 @@ public class Monitor.ProcessView : Granite.Bin {
4750
child = paned;
4851

4952
notify["needle"].connect (filter_model.refilter);
53+
54+
kill_action = new SimpleAction ("kill", null);
55+
kill_action.activate.connect (action_kill);
56+
57+
end_action = new SimpleAction ("end", null);
58+
end_action.activate.connect (action_end);
59+
60+
var action_group = new SimpleActionGroup ();
61+
action_group.add_action (kill_action);
62+
action_group.add_action (end_action);
63+
64+
insert_action_group ("process", action_group);
65+
66+
var key_controller = new Gtk.EventControllerKey ();
67+
key_controller.key_pressed.connect ((keyval, keycode, state) => {
68+
if ((state & Gdk.ModifierType.CONTROL_MASK) != 0) {
69+
switch (keyval) {
70+
case Gdk.Key.k:
71+
activate_action ("process.kill", null);
72+
return Gdk.EVENT_STOP;
73+
case Gdk.Key.e:
74+
activate_action ("process.end", null);
75+
return Gdk.EVENT_STOP;
76+
}
77+
}
78+
79+
return Gdk.EVENT_PROPAGATE;
80+
});
81+
82+
add_controller (key_controller);
83+
}
84+
85+
private void action_end () {
86+
var confirmation_dialog = new Granite.MessageDialog (
87+
_("Ask “%s” to shut down?").printf (process_info_view.process.application_name),
88+
_("The process will be asked to initiate shutdown tasks and close. In some cases the process may not quit."),
89+
new ThemedIcon ("system-shutdown"),
90+
Gtk.ButtonsType.CANCEL
91+
) {
92+
badge_icon = new ThemedIcon ("dialog-question"),
93+
modal = true,
94+
transient_for = (Gtk.Window) get_root ()
95+
};
96+
97+
var accept_button = confirmation_dialog.add_button (_("Shut Down"), Gtk.ResponseType.ACCEPT);
98+
accept_button.add_css_class (Granite.CssClass.SUGGESTED);
99+
100+
confirmation_dialog.response.connect ((response) => {
101+
if (response == Gtk.ResponseType.ACCEPT) {
102+
// TODO: maybe add a toast that process killed
103+
process_info_view.process.end ();
104+
}
105+
106+
confirmation_dialog.close ();
107+
});
108+
109+
confirmation_dialog.present ();
110+
}
111+
112+
private void action_kill () {
113+
var confirmation_dialog = new Granite.MessageDialog (
114+
_("Force “%s” to quit without initiating shutdown tasks?").printf (process_info_view.process.application_name),
115+
_("This may lead to data loss. Only Force Quit if Shut Down has failed."),
116+
new ThemedIcon ("computer-fail"),
117+
Gtk.ButtonsType.CANCEL
118+
) {
119+
badge_icon = new ThemedIcon ("process-stop"),
120+
modal = true,
121+
transient_for = (Gtk.Window) get_root ()
122+
};
123+
124+
var accept_button = confirmation_dialog.add_button (_("Force Quit"), Gtk.ResponseType.ACCEPT);
125+
accept_button.add_css_class (Granite.CssClass.DESTRUCTIVE);
126+
127+
confirmation_dialog.response.connect ((response) => {
128+
if (response == Gtk.ResponseType.ACCEPT) {
129+
// @TODO: maybe add a toast that process killed
130+
process_info_view.process.kill ();
131+
}
132+
133+
confirmation_dialog.close ();
134+
});
135+
136+
confirmation_dialog.present ();
50137
}
51138

52139
public void on_process_selected (Process process) {
53140
process_info_view.process = process;
54141
process_info_view.visible = true;
142+
143+
end_action.set_enabled (process.uid == Posix.getuid ());
144+
kill_action.set_enabled (process.uid == Posix.getuid ());
55145
}
56146

57147
public void update () {

0 commit comments

Comments
 (0)