Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/SymbolPane/SymbolOutline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ public class Scratch.Services.SymbolOutline : Gtk.Box {
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 {
search_entry.sensitive = value;
filter_button.sensitive = value;
}
}

public virtual void parse_symbols () {}

Gtk.MenuButton filter_button;
Expand Down
35 changes: 33 additions & 2 deletions src/SymbolPane/Vala/ValaSymbolOutline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline {
public const int PARSE_TIME_MAX_MSEC = 1000;
private Code.Plugins.ValaSymbolResolver resolver;
private Vala.Parser parser;
private GLib.Cancellable cancellable;
Expand Down Expand Up @@ -71,7 +72,9 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
}
}

private uint parse_timeout_id = 0;
public override void parse_symbols () {
tool_box_sensitive = true;
var context = new Vala.CodeContext ();
#if VALA_0_50
context.set_target_profile (Vala.Profile.GOBJECT, false);
Expand All @@ -92,8 +95,20 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
resolver.resolve (context);
Vala.CodeContext.pop ();

bool took_too_long = false;
parse_timeout_id = Timeout.add_full (Priority.LOW, PARSE_TIME_MAX_MSEC, () => {
parse_timeout_id = 0;
took_too_long = true;
cancellable.cancel ();
return Source.REMOVE;
});

var new_root = construct_tree (cancellable);
if (!cancellable.is_cancelled ()) {
if (parse_timeout_id > 0) {
Source.remove (parse_timeout_id);
}

if (!cancellable.is_cancelled () || took_too_long) {
Idle.add (() => {
double adjustment_value = store.vadjustment.value;
var root_children = store.root.children; // Keep reference to children for later destruction
Expand All @@ -102,7 +117,21 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
destroy_all_children ((Code.Widgets.SourceList.ExpandableItem)child);
}

store.root.add (new_root);
if (took_too_long) {
var warning_item = new Code.Widgets.SourceList.Item () {
icon = new ThemedIcon ("dialog-warning"),
markup = "<big>%s</big>".printf (_("Too Many Symbols")),
tooltip = _("%s contains too many Vala symbols.\nParsing and showing them took long").printf (doc.file.get_basename ()),
selectable = false
};

store.root.add (warning_item);
tool_box_sensitive = false;

} else {
store.root.add (new_root);
}

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

Expand All @@ -111,6 +140,7 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline
} else {
destroy_all_children (new_root);
}

return null;
});
}
Expand Down Expand Up @@ -146,6 +176,7 @@ public class Scratch.Services.ValaSymbolOutline : Scratch.Services.SymbolOutline

construct_child (symbol, new_root, cancellable);
}

return new_root;
}

Expand Down