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
9 changes: 6 additions & 3 deletions src/FolderManager/FileView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
91 changes: 56 additions & 35 deletions src/FolderManager/FolderItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
}
}

Expand Down