Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValaSymbolOutline: Lose global header #1409

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/SymbolPane/SymbolOutline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public abstract class Scratch.Services.SymbolOutline : Object {

construct {
store = new Granite.Widgets.SourceList ();
root = new Granite.Widgets.SourceList.ExpandableItem (_("Symbols"));
store.root.add (root);

set_up_css ();
}
Expand Down
38 changes: 32 additions & 6 deletions src/SymbolPane/Vala/ValaSymbolOutline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,35 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
var new_root = construct_tree (cancellable);
if (!cancellable.is_cancelled ()) {
Idle.add (() => {
var symbol_header = new Granite.Widgets.SourceList.ExpandableItem (_("Other Symbols"));
double adjustment_value = store.vadjustment.value;
var root_children = store.root.children; // Keep reference to children for later destruction
store.root.clear (); // This does not destroy children but disconnects signals - avoids terminal warnings
foreach (var child in root_children) { // Destroy items after clearing list to avoid memory leak
destroy_all_children ((Granite.Widgets.SourceList.ExpandableItem)child);
}

store.root.add (new_root);

store.root = new_root;
foreach (var item in new_root.children) {
var child = (ValaSymbolItem)item;
if (child == null) {
continue;
}

var new_child = new ValaSymbolItem (child.symbol);
if (child.parent.name == new_root.name && !(child.n_children > 0)) {
var existing = find_existing (new_child.symbol, new_root, cancellable);
if (existing == null || existing.parent == new_root) {
symbol_header.add (new_child);
}
}
}

if (symbol_header.n_children > 0) {
store.root.add (symbol_header);
}

store.root.expand_all ();
store.vadjustment.set_value (adjustment_value);

Expand Down Expand Up @@ -115,27 +136,32 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline

var new_root = new Granite.Widgets.SourceList.ExpandableItem (_("Symbols"));
foreach (var symbol in symbols) {
if (cancellable.is_cancelled ())
if (cancellable.is_cancelled ()) {
break;
}

var exist = find_existing (symbol, new_root, cancellable);
if (exist != null)
if (exist != null) {
continue;
}

if (symbol.name == null)
if (symbol.name == null) {
continue;
}

construct_child (symbol, new_root, cancellable);
}

return new_root;
}

private ValaSymbolItem construct_child (Vala.Symbol symbol, Granite.Widgets.SourceList.ExpandableItem given_parent, GLib.Cancellable cancellable) {
Granite.Widgets.SourceList.ExpandableItem parent;
if (symbol.scope.parent_scope.owner.name == null)
if (symbol.scope.parent_scope.owner.name == null) {
parent = given_parent;
else
} else {
parent = find_existing (symbol.scope.parent_scope.owner, given_parent, cancellable);
}

if (parent == null) {
parent = construct_child (symbol.scope.parent_scope.owner, given_parent, cancellable);
Expand Down