Skip to content

Commit 6c5ffd3

Browse files
authored
Stack spinner on filterbutton, start after delay (#1599)
1 parent 833f850 commit 6c5ffd3

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

src/SymbolPane/C/CtagsSymbolOutline.vala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class Scratch.Services.CtagsSymbolOutline : Scratch.Services.SymbolOutlin
5555
}
5656

5757
public override void parse_symbols () {
58+
before_parse ();
5859
if (current_subprocess != null)
5960
current_subprocess.force_exit ();
6061

@@ -64,9 +65,12 @@ public class Scratch.Services.CtagsSymbolOutline : Scratch.Services.SymbolOutlin
6465
"ctags", "-f", "-", "--format=2", "--excmd=n", "--fields=nstK", "--extra=", "--sort=no", doc.file.get_path ()
6566
);
6667

67-
parse_output.begin (current_subprocess);
68+
parse_output.begin (current_subprocess, (obj, res) => {
69+
after_parse ();
70+
});
6871
} catch (GLib.Error e) {
6972
critical (e.message);
73+
after_parse ();
7074
}
7175
}
7276

src/SymbolPane/SymbolOutline.vala

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
6969
const string ACTION_PREFIX = ACTION_GROUP + ".";
7070
const string ACTION_SELECT = "action-select";
7171
const string ACTION_TOGGLE = "toggle-";
72+
const uint SPINNER_DELAY_MSEC = 300;
7273
SimpleActionGroup symbol_action_group;
7374

7475
public Scratch.Services.Document doc { get; construct; }
@@ -86,10 +87,36 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
8687
}
8788
}
8889

90+
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+
89114
public virtual void parse_symbols () {}
90115
public virtual void add_tooltips (Code.Widgets.SourceList.ExpandableItem root) {}
91116

92-
Gtk.MenuButton filter_button;
117+
private Gtk.MenuButton filter_button;
118+
private Gtk.Spinner spinner;
119+
private Gtk.Stack stack;
93120

94121
construct {
95122
symbol_action_group = new SimpleActionGroup ();
@@ -145,9 +172,15 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
145172

146173
filter_button.menu_model = top_model;
147174

175+
spinner = new Gtk.Spinner ();
176+
stack = new Gtk.Stack ();
177+
stack.add (filter_button);
178+
stack.add (spinner);
179+
stack.visible_child = filter_button;
180+
148181
var tool_box = new Gtk.Box (HORIZONTAL, 3);
149182
tool_box.add (search_entry);
150-
tool_box.add (filter_button);
183+
tool_box.add (stack);
151184
add (tool_box);
152185
add (store);
153186
set_up_css ();

src/SymbolPane/Vala/ValaSymbolOutline.vala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
7474

7575
private uint parse_timeout_id = 0;
7676
public override void parse_symbols () {
77-
tool_box_sensitive = true;
77+
before_parse ();
7878
var context = new Vala.CodeContext ();
7979
#if VALA_0_50
8080
context.set_target_profile (Vala.Profile.GOBJECT, false);
@@ -95,7 +95,6 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
9595
resolver.resolve (context);
9696
Vala.CodeContext.pop ();
9797

98-
bool took_too_long = false;
9998
parse_timeout_id = Timeout.add_full (Priority.LOW, PARSE_TIME_MAX_MSEC, () => {
10099
parse_timeout_id = 0;
101100
took_too_long = true;
@@ -126,21 +125,20 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
126125
};
127126

128127
store.root.add (warning_item);
129-
tool_box_sensitive = false;
130-
131128
} else {
132129
store.root.add (new_root);
133130
}
134131

135132
store.root.expand_all ();
136133
add_tooltips (store.root);
137134
store.vadjustment.set_value (adjustment_value);
138-
return false;
135+
return Source.REMOVE;
139136
});
140137
} else {
141138
destroy_all_children (new_root);
142139
}
143140

141+
after_parse ();
144142
return null;
145143
});
146144
}

0 commit comments

Comments
 (0)