From 5db16a87a95f9a178ce0e904cf9b817adc2c3185 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 14 Aug 2026 11:58:16 +0100 Subject: [PATCH 1/3] Modernise header (keeping LGPL) --- src/SymbolPane/SymbolOutline.vala | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/SymbolPane/SymbolOutline.vala b/src/SymbolPane/SymbolOutline.vala index 1e5fcce80b..f915842f39 100644 --- a/src/SymbolPane/SymbolOutline.vala +++ b/src/SymbolPane/SymbolOutline.vala @@ -1,19 +1,7 @@ -/*- - * Copyright (c) 2013-2025 elementary LLC. (https://elementary.io) - * Copyright (C) 2013 Tom Beckmann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . +/* + * SPDX-License-Identifier: LGPL-3.0-or-later + * SPDX-FileCopyrightText: 2013-2025 elementary Inc. (https://elementary.io) + * 2013 Tom Beckmann */ public enum Scratch.Services.SymbolType { From a9004534b45d64c8cfec4d67223e40a38ab0c052 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 14 Aug 2026 12:23:32 +0100 Subject: [PATCH 2/3] Reorder const/public/protected/private fields/construct/methods --- src/SymbolPane/SymbolOutline.vala | 162 +++++++++++++++--------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/src/SymbolPane/SymbolOutline.vala b/src/SymbolPane/SymbolOutline.vala index f915842f39..abb954989e 100644 --- a/src/SymbolPane/SymbolOutline.vala +++ b/src/SymbolPane/SymbolOutline.vala @@ -52,21 +52,13 @@ public interface Scratch.Services.SymbolItem : Code.Widgets.SourceList.Expandabl } public class Scratch.Services.SymbolOutline : Gtk.Box { - protected static SymbolType[] filters; //Initialized by derived classes const string ACTION_GROUP = "symbol"; const string ACTION_PREFIX = ACTION_GROUP + "."; const string ACTION_SELECT = "action-select"; const string ACTION_TOGGLE = "toggle-"; const uint SPINNER_DELAY_MSEC = 300; - SimpleActionGroup symbol_action_group; public Scratch.Services.Document doc { get; construct; } - - protected Gee.HashMap checks; - protected Gtk.SearchEntry search_entry; - protected Code.Widgets.SourceList store; - protected Code.Widgets.SourceList.ExpandableItem root; - protected Gtk.CssProvider source_list_style_provider; public Gtk.Widget get_widget () { return this; } public bool tool_box_sensitive { set { @@ -75,36 +67,21 @@ public class Scratch.Services.SymbolOutline : Gtk.Box { } } + protected static SymbolType[] filters; //Initialized by derived classes + protected Gee.HashMap checks; + protected Gtk.SearchEntry search_entry; + protected Code.Widgets.SourceList store; + protected Code.Widgets.SourceList.ExpandableItem root; + protected Gtk.CssProvider source_list_style_provider; protected bool took_too_long; - private uint show_spinner_timeout_id = 0; - protected void before_parse () { - tool_box_sensitive = true; - took_too_long = false; - show_spinner_timeout_id = Timeout.add (SPINNER_DELAY_MSEC, () => { - show_spinner_timeout_id = 0; - stack.visible_child = spinner; - spinner.start (); - return Source.REMOVE; - }); - } - - protected void after_parse () { - if (show_spinner_timeout_id > 0) { - Source.remove (show_spinner_timeout_id); - show_spinner_timeout_id = 0; - } - - spinner.stop (); - stack.visible_child = filter_button; - tool_box_sensitive = !took_too_long; - } - - public virtual void parse_symbols () {} - public virtual void add_tooltips (Code.Widgets.SourceList.ExpandableItem root) {} private Gtk.MenuButton filter_button; + private uint refilter_timeout_id = 0; + private bool delay_refilter = false; private Gtk.Spinner spinner; + private uint show_spinner_timeout_id = 0; private Gtk.Stack stack; + private SimpleActionGroup symbol_action_group; construct { symbol_action_group = new SimpleActionGroup (); @@ -180,61 +157,31 @@ public class Scratch.Services.SymbolOutline : Gtk.Box { }); } - private void add_filter_menuitem (Menu menu, SymbolType filter) { - var filter_action = new SimpleAction.stateful ( - ACTION_TOGGLE + ((uint)filter).to_string (), - null, - new Variant.boolean (true) - ); - - checks[filter] = filter_action; - filter_action.activate.connect (action_toggle_filter); - symbol_action_group.add_action (filter_action); - - var filter_item = new MenuItem ( - filter.to_string (), - ACTION_PREFIX + filter_action.get_name () - ); + public virtual void parse_symbols () {} + public virtual void add_tooltips (Code.Widgets.SourceList.ExpandableItem root) {} - menu.append_item (filter_item); + protected void before_parse () { + tool_box_sensitive = true; + took_too_long = false; + show_spinner_timeout_id = Timeout.add (SPINNER_DELAY_MSEC, () => { + show_spinner_timeout_id = 0; + stack.visible_child = spinner; + spinner.start (); + return Source.REMOVE; + }); } - protected bool filter_func (Object item) { - if (!(item is SymbolItem)) { - return true; - } - - var symbol_type = ((SymbolItem)item).symbol_type; - if (symbol_type == SymbolType.NAMESPACE) { - return true; - } - - if (checks[symbol_type] == null) { - symbol_type = SymbolType.OTHER; - } - - var filter_action = checks[symbol_type]; - - if (!filter_action.get_state ().get_boolean ()) { - return false; - } - - // Do not exclude text search misses on Item with children as may - // hide hits on its children - if (item is Code.Widgets.SourceList.ExpandableItem) { - var expandable = (Code.Widgets.SourceList.ExpandableItem)item; - if (expandable.n_children > 0) { - return true; - } - - return ((SymbolItem)item).name.contains (search_entry.text); + protected void after_parse () { + if (show_spinner_timeout_id > 0) { + Source.remove (show_spinner_timeout_id); + show_spinner_timeout_id = 0; } - return true; + spinner.stop (); + stack.visible_child = filter_button; + tool_box_sensitive = !took_too_long; } - uint refilter_timeout_id = 0; - bool delay_refilter = false; protected void schedule_refilter () { // Ensure a refilter happens at least 500mS later if not already // delayed. @@ -288,6 +235,59 @@ public class Scratch.Services.SymbolOutline : Gtk.Box { } } + protected bool filter_func (Object item) { + if (!(item is SymbolItem)) { + return true; + } + + var symbol_type = ((SymbolItem)item).symbol_type; + if (symbol_type == SymbolType.NAMESPACE) { + return true; + } + + if (checks[symbol_type] == null) { + symbol_type = SymbolType.OTHER; + } + + var filter_action = checks[symbol_type]; + + if (!filter_action.get_state ().get_boolean ()) { + return false; + } + + // Do not exclude text search misses on Item with children as may + // hide hits on its children + if (item is Code.Widgets.SourceList.ExpandableItem) { + var expandable = (Code.Widgets.SourceList.ExpandableItem)item; + if (expandable.n_children > 0) { + return true; + } + + return ((SymbolItem)item).name.contains (search_entry.text); + } + + return true; + } + + private void add_filter_menuitem (Menu menu, SymbolType filter) { + var filter_action = new SimpleAction.stateful ( + ACTION_TOGGLE + ((uint)filter).to_string (), + null, + new Variant.boolean (true) + ); + + checks[filter] = filter_action; + filter_action.activate.connect (action_toggle_filter); + symbol_action_group.add_action (filter_action); + + var filter_item = new MenuItem ( + filter.to_string (), + ACTION_PREFIX + filter_action.get_name () + ); + + menu.append_item (filter_item); + } + private void action_select_filters (SimpleAction action, Variant? param) { foreach (var filter_action in checks.values) { filter_action.set_state (new Variant ("b", param.get_boolean ())); From 008a5f544e6c2d853b279069372af4a033a2a37f Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 14 Aug 2026 12:54:06 +0100 Subject: [PATCH 3/3] Use add_once where appropriate --- src/SymbolPane/SymbolOutline.vala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/SymbolPane/SymbolOutline.vala b/src/SymbolPane/SymbolOutline.vala index abb954989e..963803249b 100644 --- a/src/SymbolPane/SymbolOutline.vala +++ b/src/SymbolPane/SymbolOutline.vala @@ -163,11 +163,10 @@ public class Scratch.Services.SymbolOutline : Gtk.Box { protected void before_parse () { tool_box_sensitive = true; took_too_long = false; - show_spinner_timeout_id = Timeout.add (SPINNER_DELAY_MSEC, () => { + show_spinner_timeout_id = Timeout.add_once (SPINNER_DELAY_MSEC, () => { show_spinner_timeout_id = 0; stack.visible_child = spinner; spinner.start (); - return Source.REMOVE; }); } @@ -294,9 +293,8 @@ public class Scratch.Services.SymbolOutline : Gtk.Box { } schedule_refilter (); // Keep menu open - Idle.add (() => { + Idle.add_once (() => { filter_button.set_active (true); - return Source.REMOVE; }); }