Skip to content

Commit

Permalink
Fix search
Browse files Browse the repository at this point in the history
  • Loading branch information
stsdc committed Nov 25, 2023
1 parent 5b1ddcf commit 3cb548f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public class Monitor.MainWindow : Gtk.ApplicationWindow {
preferences_grid.attach (new PreferencesView (), 0, 0, 1, 1);

// Search entry
var search = new Search () {
valign = Gtk.Align.CENTER
var search = new Search (process_view.process_tree_view) {
valign = Gtk.Align.CENTER,
};

Gtk.Revealer search_revealer = new Gtk.Revealer () {
Expand Down
6 changes: 3 additions & 3 deletions src/Views/ProcessView/ProcessInfoView/Preventor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class Monitor.Preventor : Gtk.Box {
valign = Gtk.Align.END;
halign = Gtk.Align.END;

preventive_action_bar = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0){
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?")){
confirmation_label = new Gtk.Label (_("Are you sure you want to do this?")) {
margin_end = 10
};

Expand All @@ -35,7 +35,7 @@ public class Monitor.Preventor : Gtk.Box {
}

public Preventor (Gtk.Widget child_widget, string name) {
stack = new Gtk.Stack ();
stack = new Gtk.Stack ();
append (stack);
stack.add_named (child_widget, name);
stack.add_named (preventive_action_bar, "preventive_action_bar");
Expand Down
18 changes: 10 additions & 8 deletions src/Widgets/Headerbar/Search.vala
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
public class Monitor.Search : Gtk.Box {
private Gtk.TreeModelFilter filter_model;
private CPUProcessTreeView process_tree_view;
public CPUProcessTreeView process_tree_view;
private Gtk.SearchEntry search_entry;

construct {
public Search (CPUProcessTreeView _process_tree_view) {
this.process_tree_view = _process_tree_view;

search_entry = new Gtk.SearchEntry () {
tooltip_markup = Granite.markup_accel_tooltip ({ "<Ctrl>F" }, _("Type process name or PID to search")),
};
Expand All @@ -15,25 +17,25 @@ public class Monitor.Search : Gtk.Box {
// process_tree_view.set_model (filter_model);

var sort_model = new Gtk.TreeModelSort.with_model (filter_model);
// process_tree_view.set_model (sort_model);
process_tree_view.set_model (sort_model);
append (search_entry);
}

private void connect_signal () {
search_entry.search_changed.connect (() => {
// collapse tree only when search is focused and changed
// if (this.is_focus) {
// process_tree_view.collapse_all ();
// }
if (search_entry.is_focus()) {
process_tree_view.collapse_all ();
}

filter_model.refilter ();

// focus on child row to avoid the app crashes by clicking "Kill/End Process" buttons in headerbar
process_tree_view.focus_on_child_row ();
search_entry.grab_focus ();

// if (this.text != "") {
// this.insert_at_cursor ("");
// if (search_entry.text != "") {
// search_entry.insert_at_cursor ("");
// }
});
}
Expand Down

0 comments on commit 3cb548f

Please sign in to comment.