Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 6 additions & 56 deletions src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,16 @@ public class Monitor.ProcessInfoView : Gtk.Box {

process_info_io_stats = new ProcessInfoIOStats ();

var app = (Gtk.Application) GLib.Application.get_default ();

var end_process_button = new Gtk.Button.with_label (_("Shut Down…")) {
tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>E" })
action_name = "process.end",
tooltip_markup = Granite.markup_accel_tooltip (app.get_accels_for_action ("process.end"))
};

var kill_process_button = new Gtk.Button.with_label (_("Force Quit…")) {
tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>K" })
action_name = "process.kill",
tooltip_markup = Granite.markup_accel_tooltip (app.get_accels_for_action ("process.kill"))
};
kill_process_button.add_css_class (Granite.CssClass.DESTRUCTIVE);

Expand Down Expand Up @@ -107,60 +111,6 @@ public class Monitor.ProcessInfoView : Gtk.Box {
hexpand = true;
append (permission_error_infobar);
append (box);

kill_process_button.clicked.connect (() => {
var confirmation_dialog = new Granite.MessageDialog (
_("Force “%s” to quit without initiating shutdown tasks?").printf (process.application_name),
_("This may lead to data loss. Only Force Quit if Shut Down has failed."),
new ThemedIcon ("computer-fail"),
Gtk.ButtonsType.CANCEL
) {
badge_icon = new ThemedIcon ("process-stop"),
modal = true,
transient_for = (Gtk.Window) get_root ()
};

var accept_button = confirmation_dialog.add_button (_("Force Quit"), Gtk.ResponseType.ACCEPT);
accept_button.add_css_class (Granite.CssClass.DESTRUCTIVE);

confirmation_dialog.response.connect ((response) => {
if (response == Gtk.ResponseType.ACCEPT) {
// @TODO: maybe add a toast that process killed
process.kill ();
}

confirmation_dialog.close ();
});

confirmation_dialog.present ();
});

end_process_button.clicked.connect (() => {
var confirmation_dialog = new Granite.MessageDialog (
_("Ask “%s” to shut down?").printf (process.application_name),
_("The process will be asked to initiate shutdown tasks and close. In some cases the process may not quit."),
new ThemedIcon ("system-shutdown"),
Gtk.ButtonsType.CANCEL
) {
badge_icon = new ThemedIcon ("dialog-question"),
modal = true,
transient_for = (Gtk.Window) get_root ()
};

var accept_button = confirmation_dialog.add_button (_("Shut Down"), Gtk.ResponseType.ACCEPT);
accept_button.add_css_class (Granite.CssClass.SUGGESTED);

confirmation_dialog.response.connect ((response) => {
if (response == Gtk.ResponseType.ACCEPT) {
// TODO: maybe add a toast that process killed
process.end ();
}

confirmation_dialog.close ();
});

confirmation_dialog.present ();
});
}

private void show_permission_error_infobar (string error) {
Expand Down
12 changes: 0 additions & 12 deletions src/Views/ProcessView/ProcessTreeView/CPUProcessTreeView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,6 @@ public class Monitor.CPUProcessTreeView : Gtk.TreeView {
cursor_changed.connect (_cursor_changed);
// model.process_manager.updated.connect (_cursor_changed);

var end_process_action = new GLib.SimpleAction ("end", null);
end_process_action.activate.connect (end_process);

var kill_process_action = new GLib.SimpleAction ("kill", null);
kill_process_action.activate.connect (kill_process);

var action_group = new SimpleActionGroup ();
action_group.add_action (end_process_action);
action_group.add_action (kill_process_action);

insert_action_group ("process", action_group);

var key_controller = new Gtk.EventControllerKey ();
add_controller (key_controller);
key_controller.key_released.connect ((keyval, keycode, state) => {
Expand Down
90 changes: 90 additions & 0 deletions src/Views/ProcessView/ProcessView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class Monitor.ProcessView : Granite.Bin {
private ProcessInfoView process_info_view;
private TreeViewModel treeview_model;

private SimpleAction end_action;
private SimpleAction kill_action;

construct {
treeview_model = new TreeViewModel ();

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

notify["needle"].connect (filter_model.refilter);

kill_action = new SimpleAction ("kill", null);
kill_action.activate.connect (action_kill);

end_action = new SimpleAction ("end", null);
end_action.activate.connect (action_end);

var action_group = new SimpleActionGroup ();
action_group.add_action (kill_action);
action_group.add_action (end_action);

insert_action_group ("process", action_group);

var key_controller = new Gtk.EventControllerKey ();
key_controller.key_pressed.connect ((keyval, keycode, state) => {
if ((state & Gdk.ModifierType.CONTROL_MASK) != 0) {
switch (keyval) {
case Gdk.Key.k:
activate_action ("process.kill", null);
return Gdk.EVENT_STOP;
case Gdk.Key.e:
activate_action ("process.end", null);
return Gdk.EVENT_STOP;
}
}

return Gdk.EVENT_PROPAGATE;
});

add_controller (key_controller);
}

private void action_end () {
var confirmation_dialog = new Granite.MessageDialog (
_("Ask “%s” to shut down?").printf (process_info_view.process.application_name),
_("The process will be asked to initiate shutdown tasks and close. In some cases the process may not quit."),
new ThemedIcon ("system-shutdown"),
Gtk.ButtonsType.CANCEL
) {
badge_icon = new ThemedIcon ("dialog-question"),
modal = true,
transient_for = (Gtk.Window) get_root ()
};

var accept_button = confirmation_dialog.add_button (_("Shut Down"), Gtk.ResponseType.ACCEPT);
accept_button.add_css_class (Granite.CssClass.SUGGESTED);

confirmation_dialog.response.connect ((response) => {
if (response == Gtk.ResponseType.ACCEPT) {
// TODO: maybe add a toast that process killed
process_info_view.process.end ();
}

confirmation_dialog.close ();
});

confirmation_dialog.present ();
}

private void action_kill () {
var confirmation_dialog = new Granite.MessageDialog (
_("Force “%s” to quit without initiating shutdown tasks?").printf (process_info_view.process.application_name),
_("This may lead to data loss. Only Force Quit if Shut Down has failed."),
new ThemedIcon ("computer-fail"),
Gtk.ButtonsType.CANCEL
) {
badge_icon = new ThemedIcon ("process-stop"),
modal = true,
transient_for = (Gtk.Window) get_root ()
};

var accept_button = confirmation_dialog.add_button (_("Force Quit"), Gtk.ResponseType.ACCEPT);
accept_button.add_css_class (Granite.CssClass.DESTRUCTIVE);

confirmation_dialog.response.connect ((response) => {
if (response == Gtk.ResponseType.ACCEPT) {
// @TODO: maybe add a toast that process killed
process_info_view.process.kill ();
}

confirmation_dialog.close ();
});

confirmation_dialog.present ();
}

public void on_process_selected (Process process) {
process_info_view.process = process;
process_info_view.visible = true;

end_action.set_enabled (process.uid == Posix.getuid ());
kill_action.set_enabled (process.uid == Posix.getuid ());
}

public void update () {
Expand Down