diff --git a/src/FolderManager/FileView.vala b/src/FolderManager/FileView.vala index 61ea03789..2bb5035b3 100644 --- a/src/FolderManager/FileView.vala +++ b/src/FolderManager/FileView.vala @@ -209,9 +209,11 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane } } - private unowned Code.Widgets.SourceList.Item? find_path (Code.Widgets.SourceList.ExpandableItem list, - string path, - bool expand = false) { + private unowned Code.Widgets.SourceList.Item? find_path ( + Code.Widgets.SourceList.ExpandableItem list, + string path, + bool expand = false) { + foreach (var item in list.children) { if (item is Item) { var code_item = (Item)item; @@ -227,6 +229,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane if (!expander.expanded) { if (expand) { + ((FolderItem)expander).load_children (); //Synchronous expander.expanded = true; } else { continue; diff --git a/src/FolderManager/FolderItem.vala b/src/FolderManager/FolderItem.vala index f00ce4c1e..3f55c77c2 100644 --- a/src/FolderManager/FolderItem.vala +++ b/src/FolderManager/FolderItem.vala @@ -29,6 +29,12 @@ namespace Scratch.FolderManager { private bool has_dummy; private Code.Widgets.SourceList.Item dummy; /* Blank item for expanded empty folders */ + public bool loading_required { + get { + return !children_loaded && n_children <= 1 && file.children.size > 0; + } + } + public FolderItem (File file, FileView view) { Object (file: file, view: view); } @@ -55,50 +61,65 @@ namespace Scratch.FolderManager { } } - private async void load_children () { - var root = get_root_folder (); - foreach (var child in file.children) { - Idle.add (() => { - Code.Widgets.SourceList.Item item = null; - if (child.is_valid_directory) { - item = new FolderItem (child, view); - } else if (child.is_valid_textfile) { - item = new FileItem (child, view); - } - - if (item != null) { - add (item); - } - - load_children.callback (); - return Source.REMOVE; - }); - - yield; + + public void load_children () { + if (loading_required) { + foreach (var child in file.children) { + add_child (child); + } + + after_children_loaded (); } + } - children_loaded = true; - if (root != null) { - root.child_folder_loaded (this); + private async void load_children_async () { + if (loading_required) { + foreach (var child in file.children) { + Idle.add (() => { + add_child (child); + load_children_async.callback (); + return Source.REMOVE; + }); + + yield; + } } + + after_children_loaded (); } - private void on_toggled () { - if (!children_loaded && - expanded && - n_children <= 1 && - file.children.size > 0) { + private void add_child (File child) { + Code.Widgets.SourceList.Item item = null; + if (child.is_valid_directory) { + item = new FolderItem (child, view); + } else if (child.is_valid_textfile) { + item = new FileItem (child, view); + } - load_children.begin (); - return; + if (item != null) { + add (item); } + } + private void after_children_loaded () { + children_loaded = true; var root = get_root_folder (); - if (!expanded && - root != null && - root.monitored_repo != null) { - //When toggled closed, update status to reflect hidden contents - root.update_item_status (this); + if (root != null) { + root.child_folder_loaded (this); //Updates child status emblens + } + } + + private void on_toggled () { + if (expanded) { + load_children_async.begin (); + return; + } else { + var root = get_root_folder (); + if (root != null && + root.monitored_repo != null) { + //When toggled closed, update status to reflect hidden contents + root.update_item_status (this); + } } }