Skip to content

Commit 9107f40

Browse files
authored
Add tooltips after tree finished constructing (#1591)
1 parent a1aa031 commit 9107f40

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/SymbolPane/SymbolOutline.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
8787
}
8888

8989
public virtual void parse_symbols () {}
90+
public virtual void add_tooltips (Code.Widgets.SourceList.ExpandableItem root) {}
9091

9192
Gtk.MenuButton filter_button;
9293

src/SymbolPane/Vala/ValaSymbolOutline.vala

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
133133
}
134134

135135
store.root.expand_all ();
136+
add_tooltips (store.root);
136137
store.vadjustment.set_value (adjustment_value);
137-
138138
return false;
139139
});
140140
} else {
@@ -145,6 +145,30 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
145145
});
146146
}
147147

148+
protected override void add_tooltips (Code.Widgets.SourceList.ExpandableItem root) {
149+
foreach (var parent in root.children) {
150+
add_tooltip ((Code.Widgets.SourceList.ExpandableItem) parent);
151+
}
152+
}
153+
154+
private void add_tooltip (Code.Widgets.SourceList.ExpandableItem parent) {
155+
if (parent is ValaSymbolItem) {
156+
var item = ((ValaSymbolItem)parent);
157+
var symbol = item.symbol;
158+
item.tooltip = "%s%s".printf (
159+
doc.get_slice (
160+
symbol.source_reference.begin.line,
161+
symbol.source_reference.begin.column,
162+
symbol.source_reference.end.line,
163+
symbol.source_reference.end.column
164+
),
165+
symbol.comment != null ? "\n" + symbol.comment.content : ""
166+
);
167+
}
168+
169+
add_tooltips (parent);
170+
}
171+
148172
private void destroy_all_children (Code.Widgets.SourceList.ExpandableItem parent) {
149173
foreach (var child in parent.children) {
150174
remove (child, parent);
@@ -177,7 +201,9 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
177201
continue;
178202

179203
construct_child (symbol, new_root, cancellable);
180-
Thread.yield ();
204+
if (!cancellable.is_cancelled ()) {
205+
Thread.yield ();
206+
}
181207
}
182208

183209
return new_root;
@@ -199,19 +225,10 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
199225
parent = construct_child (symbol.scope.parent_scope.owner, given_parent, cancellable);
200226
}
201227

202-
var tooltip = "%s%s".printf (
203-
doc.get_slice (
204-
symbol.source_reference.begin.line,
205-
symbol.source_reference.begin.column,
206-
symbol.source_reference.end.line,
207-
symbol.source_reference.end.column
208-
),
209-
symbol.comment != null ? "\n" + symbol.comment.content : ""
210-
);
211228

212229
var tree_child = new ValaSymbolItem (
213230
symbol,
214-
tooltip
231+
""
215232
);
216233
parent.add (tree_child);
217234
return tree_child;

0 commit comments

Comments
 (0)