Skip to content

Commit 247b1c3

Browse files
authored
SymbolOutline - cleanup (#1797)
* Modernise header (keeping LGPL) * Reorder const/public/protected/private fields/construct/methods * Use add_once where appropriate
1 parent 16a21ac commit 247b1c3

1 file changed

Lines changed: 85 additions & 99 deletions

File tree

‎src/SymbolPane/SymbolOutline.vala‎

Lines changed: 85 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
/*-
2-
* Copyright (c) 2013-2025 elementary LLC. (https://elementary.io)
3-
* Copyright (C) 2013 Tom Beckmann <tomjonabc@gmail.com>
4-
*
5-
* This program is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Lesser General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* This program is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1+
/*
2+
* SPDX-License-Identifier: LGPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2013-2025 elementary Inc. (https://elementary.io)
4+
* 2013 Tom Beckmann <tomjonabc@gmail.com>
175
*/
186

197
public enum Scratch.Services.SymbolType {
@@ -64,21 +52,13 @@ public interface Scratch.Services.SymbolItem : Code.Widgets.SourceList.Expandabl
6452
}
6553

6654
public class Scratch.Services.SymbolOutline : Gtk.Box {
67-
protected static SymbolType[] filters; //Initialized by derived classes
6855
const string ACTION_GROUP = "symbol";
6956
const string ACTION_PREFIX = ACTION_GROUP + ".";
7057
const string ACTION_SELECT = "action-select";
7158
const string ACTION_TOGGLE = "toggle-";
7259
const uint SPINNER_DELAY_MSEC = 300;
73-
SimpleActionGroup symbol_action_group;
7460

7561
public Scratch.Services.Document doc { get; construct; }
76-
77-
protected Gee.HashMap<SymbolType, SimpleAction> checks;
78-
protected Gtk.SearchEntry search_entry;
79-
protected Code.Widgets.SourceList store;
80-
protected Code.Widgets.SourceList.ExpandableItem root;
81-
protected Gtk.CssProvider source_list_style_provider;
8262
public Gtk.Widget get_widget () { return this; }
8363
public bool tool_box_sensitive {
8464
set {
@@ -87,36 +67,21 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
8767
}
8868
}
8969

70+
protected static SymbolType[] filters; //Initialized by derived classes
71+
protected Gee.HashMap<SymbolType, SimpleAction> checks;
72+
protected Gtk.SearchEntry search_entry;
73+
protected Code.Widgets.SourceList store;
74+
protected Code.Widgets.SourceList.ExpandableItem root;
75+
protected Gtk.CssProvider source_list_style_provider;
9076
protected bool took_too_long;
91-
private uint show_spinner_timeout_id = 0;
92-
protected void before_parse () {
93-
tool_box_sensitive = true;
94-
took_too_long = false;
95-
show_spinner_timeout_id = Timeout.add (SPINNER_DELAY_MSEC, () => {
96-
show_spinner_timeout_id = 0;
97-
stack.visible_child = spinner;
98-
spinner.start ();
99-
return Source.REMOVE;
100-
});
101-
}
102-
103-
protected void after_parse () {
104-
if (show_spinner_timeout_id > 0) {
105-
Source.remove (show_spinner_timeout_id);
106-
show_spinner_timeout_id = 0;
107-
}
108-
109-
spinner.stop ();
110-
stack.visible_child = filter_button;
111-
tool_box_sensitive = !took_too_long;
112-
}
113-
114-
public virtual void parse_symbols () {}
115-
public virtual void add_tooltips (Code.Widgets.SourceList.ExpandableItem root) {}
11677

11778
private Gtk.MenuButton filter_button;
79+
private uint refilter_timeout_id = 0;
80+
private bool delay_refilter = false;
11881
private Gtk.Spinner spinner;
82+
private uint show_spinner_timeout_id = 0;
11983
private Gtk.Stack stack;
84+
private SimpleActionGroup symbol_action_group;
12085

12186
construct {
12287
symbol_action_group = new SimpleActionGroup ();
@@ -192,61 +157,30 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
192157
});
193158
}
194159

195-
private void add_filter_menuitem (Menu menu, SymbolType filter) {
196-
var filter_action = new SimpleAction.stateful (
197-
ACTION_TOGGLE + ((uint)filter).to_string (),
198-
null,
199-
new Variant.boolean (true)
200-
);
201-
202-
checks[filter] = filter_action;
203-
filter_action.activate.connect (action_toggle_filter);
204-
symbol_action_group.add_action (filter_action);
205-
206-
var filter_item = new MenuItem (
207-
filter.to_string (),
208-
ACTION_PREFIX + filter_action.get_name ()
209-
);
160+
public virtual void parse_symbols () {}
161+
public virtual void add_tooltips (Code.Widgets.SourceList.ExpandableItem root) {}
210162

211-
menu.append_item (filter_item);
163+
protected void before_parse () {
164+
tool_box_sensitive = true;
165+
took_too_long = false;
166+
show_spinner_timeout_id = Timeout.add_once (SPINNER_DELAY_MSEC, () => {
167+
show_spinner_timeout_id = 0;
168+
stack.visible_child = spinner;
169+
spinner.start ();
170+
});
212171
}
213172

214-
protected bool filter_func (Object item) {
215-
if (!(item is SymbolItem)) {
216-
return true;
217-
}
218-
219-
var symbol_type = ((SymbolItem)item).symbol_type;
220-
if (symbol_type == SymbolType.NAMESPACE) {
221-
return true;
222-
}
223-
224-
if (checks[symbol_type] == null) {
225-
symbol_type = SymbolType.OTHER;
226-
}
227-
228-
var filter_action = checks[symbol_type];
229-
230-
if (!filter_action.get_state ().get_boolean ()) {
231-
return false;
232-
}
233-
234-
// Do not exclude text search misses on Item with children as may
235-
// hide hits on its children
236-
if (item is Code.Widgets.SourceList.ExpandableItem) {
237-
var expandable = (Code.Widgets.SourceList.ExpandableItem)item;
238-
if (expandable.n_children > 0) {
239-
return true;
240-
}
241-
242-
return ((SymbolItem)item).name.contains (search_entry.text);
173+
protected void after_parse () {
174+
if (show_spinner_timeout_id > 0) {
175+
Source.remove (show_spinner_timeout_id);
176+
show_spinner_timeout_id = 0;
243177
}
244178

245-
return true;
179+
spinner.stop ();
180+
stack.visible_child = filter_button;
181+
tool_box_sensitive = !took_too_long;
246182
}
247183

248-
uint refilter_timeout_id = 0;
249-
bool delay_refilter = false;
250184
protected void schedule_refilter () {
251185
// Ensure a refilter happens at least 500mS later if not already
252186
// delayed.
@@ -300,15 +234,67 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
300234
}
301235
}
302236

237+
protected bool filter_func (Object item) {
238+
if (!(item is SymbolItem)) {
239+
return true;
240+
}
241+
242+
var symbol_type = ((SymbolItem)item).symbol_type;
243+
if (symbol_type == SymbolType.NAMESPACE) {
244+
return true;
245+
}
246+
247+
if (checks[symbol_type] == null) {
248+
symbol_type = SymbolType.OTHER;
249+
}
250+
251+
var filter_action = checks[symbol_type];
252+
253+
if (!filter_action.get_state ().get_boolean ()) {
254+
return false;
255+
}
256+
257+
// Do not exclude text search misses on Item with children as may
258+
// hide hits on its children
259+
if (item is Code.Widgets.SourceList.ExpandableItem) {
260+
var expandable = (Code.Widgets.SourceList.ExpandableItem)item;
261+
if (expandable.n_children > 0) {
262+
return true;
263+
}
264+
265+
return ((SymbolItem)item).name.contains (search_entry.text);
266+
}
267+
268+
return true;
269+
}
270+
271+
private void add_filter_menuitem (Menu menu, SymbolType filter) {
272+
var filter_action = new SimpleAction.stateful (
273+
ACTION_TOGGLE + ((uint)filter).to_string (),
274+
null,
275+
new Variant.boolean (true)
276+
);
277+
278+
checks[filter] = filter_action;
279+
filter_action.activate.connect (action_toggle_filter);
280+
symbol_action_group.add_action (filter_action);
281+
282+
var filter_item = new MenuItem (
283+
filter.to_string (),
284+
ACTION_PREFIX + filter_action.get_name ()
285+
);
286+
287+
menu.append_item (filter_item);
288+
}
289+
303290
private void action_select_filters (SimpleAction action, Variant? param) {
304291
foreach (var filter_action in checks.values) {
305292
filter_action.set_state (new Variant ("b", param.get_boolean ()));
306293
}
307294
schedule_refilter ();
308295
// Keep menu open
309-
Idle.add (() => {
296+
Idle.add_once (() => {
310297
filter_button.set_active (true);
311-
return Source.REMOVE;
312298
});
313299
}
314300

0 commit comments

Comments
 (0)