@@ -132,20 +132,14 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {
132132 dbusserver.indicator_state (MonitorApp .settings .get_boolean ("indicator -state "));
133133 stack. visible_child_name = MonitorApp.settings.get_string ("opened -view ");
134134
135- var filter_model = new Gtk .TreeModelFilter (process_view. treeview_model, null );
136- filter_model.set_visible_func (filter_func );
137-
138- var sort_model = new Gtk .TreeModelSort .with_model (filter_model);
139-
140- process_view.process_tree_view.set_model (sort_model );
141-
142135 search_entry.search_changed.connect (() => {
143136 // collapse tree only when search is focused and changed
144137 if (search_entry. is_focus) {
145138 process_view. process_tree_view. collapse_all ();
146139 }
147140
148- filter_model. refilter ();
141+ process_view. needle = search_entry. text;
142+ process_view. filter_model. refilter ();
149143
150144 // focus on child row to avoid the app crashes by clicking "Kill/End Process" buttons in headerbar
151145 process_view. process_tree_view. focus_on_child_row ();
@@ -178,47 +172,4 @@ public class Monitor.MainWindow : Hdy.ApplicationWindow {
178172 this . maximize ();
179173 }
180174 }
181-
182- private bool filter_func (Gtk .TreeModel model , Gtk .TreeIter iter ) {
183- string name_haystack;
184- int pid_haystack;
185- string cmd_haystack;
186- bool found = false ;
187- var needle = search_entry. text;
188-
189- // should help with assertion errors, donno
190- // if (needle == null) return true;
191-
192- if (needle. length == 0 ) {
193- return true ;
194- }
195-
196- model. get (iter, Column . NAME , out name_haystack, - 1 );
197- model. get (iter, Column . PID , out pid_haystack, - 1 );
198- model. get (iter, Column . CMD , out cmd_haystack, - 1 );
199-
200- // sometimes name_haystack is null
201- if (name_haystack != null ) {
202- bool name_found = name_haystack. casefold (). contains (needle. casefold ()) || false ;
203- bool pid_found = pid_haystack. to_string (). casefold (). contains (needle. casefold ()) || false ;
204- bool cmd_found = cmd_haystack. casefold (). contains (needle. casefold ()) || false ;
205- found = name_found || pid_found || cmd_found;
206- }
207-
208-
209- Gtk . TreeIter child_iter;
210- bool child_found = false ;
211-
212- if (model. iter_children (out child_iter, iter)) {
213- do {
214- child_found = filter_func (model, child_iter);
215- } while (model. iter_next (ref child_iter) && ! child_found);
216- }
217-
218- if (child_found && needle. length > 0 ) {
219- process_view. process_tree_view. expand_all ();
220- }
221-
222- return found || child_found;
223- }
224175}
0 commit comments