Skip to content

Commit

Permalink
Preventor ported
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Nov 24, 2023
1 parent 3783fd3 commit 1546c4e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
46 changes: 25 additions & 21 deletions src/Views/ProcessView/ProcessInfoView/Preventor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ public class Monitor.Preventor : Gtk.Box {
private Gtk.Button confirm_button;
private Gtk.Button deny_button;

private Gtk.Widget child_widget;
private Gtk.Stack stack;

public signal void confirmed (bool is_confirmed);

construct {
valign = Gtk.Align.END;
halign = Gtk.Align.END;

preventive_action_bar = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
preventive_action_bar.valign = Gtk.Align.START;
preventive_action_bar.halign = Gtk.Align.END;
preventive_action_bar.margin_top = 10;
preventive_action_bar = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0){
valign = Gtk.Align.START,
halign = Gtk.Align.END,
margin_top = 10
};

confirmation_label = new Gtk.Label (_("Are you sure you want to do this?")){
margin_end = 10
};

confirmation_label = new Gtk.Label (_("Are you sure you want to do this?"));
confirmation_label.margin_end = 10;

confirm_button = new Gtk.Button.with_label (_("Yes"));
confirm_button.margin_end = 10;
// confirm_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
confirm_button = new Gtk.Button.with_label (_("Yes")) {
margin_end = 10
};
confirm_button.add_css_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION);

deny_button = new Gtk.Button.with_label (_("No"));

Expand All @@ -31,28 +34,29 @@ public class Monitor.Preventor : Gtk.Box {
preventive_action_bar.append (deny_button);
}

public Preventor (Gtk.Widget _child, string name) {
child_widget = _child;
append (child_widget);
append (preventive_action_bar);
public Preventor (Gtk.Widget child_widget, string name) {
stack = new Gtk.Stack ();
append (stack);
stack.add_named (child_widget, name);
stack.add_named (preventive_action_bar, "preventive_action_bar");

deny_button.clicked.connect (() => {
// set_transition_type (Gtk.StackTransitionType.SLIDE_UP);
// set_visible_child (child_widget);
stack.set_transition_type (Gtk.StackTransitionType.SLIDE_UP);
stack.set_visible_child (child_widget);
confirmed (false);
});

confirm_button.clicked.connect (() => {
// set_transition_type (Gtk.StackTransitionType.SLIDE_UP);
// set_visible_child (child_widget);
stack.set_transition_type (Gtk.StackTransitionType.SLIDE_UP);
stack.set_visible_child (child_widget);
confirmed (true);
});
}

public void set_prevention (string confirmation_text) {
// set_transition_type (Gtk.StackTransitionType.SLIDE_DOWN);
stack.set_transition_type (Gtk.StackTransitionType.SLIDE_DOWN);
confirmation_label.set_text (_(confirmation_text));
// set_visible_child (preventive_action_bar);
stack.set_visible_child (preventive_action_bar);
preventive_action_bar.visible = true;
}

Expand Down
18 changes: 15 additions & 3 deletions src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
public class Monitor.ProcessInfoView : Gtk.Box {
private Preventor preventor;
private ProcessInfoIOStats process_info_io_stats = new ProcessInfoIOStats ();

private Process _process;
Expand All @@ -21,6 +22,7 @@ public class Monitor.ProcessInfoView : Gtk.Box {
process_info_io_stats.hide ();
end_process_button.hide ();
kill_process_button.hide ();
preventor.hide ();
} else {
_process.fd_permission_error.connect (show_permission_error_infobar);

Expand All @@ -37,6 +39,7 @@ public class Monitor.ProcessInfoView : Gtk.Box {
process_info_io_stats.set_visible (true);
end_process_button.show ();
kill_process_button.show ();
preventor.show();
}
}
}
Expand Down Expand Up @@ -114,15 +117,24 @@ public class Monitor.ProcessInfoView : Gtk.Box {
process_action_bar.append (kill_process_button);

append (grid);
append (process_action_bar);

preventor = new Preventor (process_action_bar, "process_action_bar");
grid.attach (preventor, 0, 5, 1, 1);
preventor.hide ();


kill_process_button.clicked.connect (() => {
process.kill (); // maybe add a toast that process killed
preventor.set_prevention (_("Confirm kill of the process?"));
preventor.confirmed.connect ((is_confirmed) => {
if (is_confirmed) process.kill (); // maybe add a toast that process killed
});
});

end_process_button.clicked.connect (() => {
process.end (); // maybe add a toast that process ended
preventor.set_prevention (_("Confirm end of the process?"));
preventor.confirmed.connect ((is_confirmed) => {
if (is_confirmed) process.end (); // maybe add a toast that process ended
});
});

}
Expand Down

0 comments on commit 1546c4e

Please sign in to comment.