Skip to content

Commit 3e488b0

Browse files
jeremypwdanirabbitleonardo-lemos
authored
Fix global search - load children synchronously when expanding sidebar to path (#1571)
* Load children synchronously when expanding to path * FolderItem: Ensure children not loaded more than once --------- Co-authored-by: Danielle Foré <[email protected]> Co-authored-by: Leonardo Lemos <[email protected]>
1 parent 9c7a5e3 commit 3e488b0

File tree

2 files changed

+62
-38
lines changed

2 files changed

+62
-38
lines changed

src/FolderManager/FileView.vala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,11 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
209209
}
210210
}
211211

212-
private unowned Code.Widgets.SourceList.Item? find_path (Code.Widgets.SourceList.ExpandableItem list,
213-
string path,
214-
bool expand = false) {
212+
private unowned Code.Widgets.SourceList.Item? find_path (
213+
Code.Widgets.SourceList.ExpandableItem list,
214+
string path,
215+
bool expand = false) {
216+
215217
foreach (var item in list.children) {
216218
if (item is Item) {
217219
var code_item = (Item)item;
@@ -227,6 +229,7 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
227229

228230
if (!expander.expanded) {
229231
if (expand) {
232+
((FolderItem)expander).load_children (); //Synchronous
230233
expander.expanded = true;
231234
} else {
232235
continue;

src/FolderManager/FolderItem.vala

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ namespace Scratch.FolderManager {
2929
private bool has_dummy;
3030
private Code.Widgets.SourceList.Item dummy; /* Blank item for expanded empty folders */
3131

32+
public bool loading_required {
33+
get {
34+
return !children_loaded && n_children <= 1 && file.children.size > 0;
35+
}
36+
}
37+
3238
public FolderItem (File file, FileView view) {
3339
Object (file: file, view: view);
3440
}
@@ -55,50 +61,65 @@ namespace Scratch.FolderManager {
5561
}
5662
}
5763

58-
private async void load_children () {
59-
var root = get_root_folder ();
60-
foreach (var child in file.children) {
61-
Idle.add (() => {
62-
Code.Widgets.SourceList.Item item = null;
63-
if (child.is_valid_directory) {
64-
item = new FolderItem (child, view);
65-
} else if (child.is_valid_textfile) {
66-
item = new FileItem (child, view);
67-
}
68-
69-
if (item != null) {
70-
add (item);
71-
}
72-
73-
load_children.callback ();
74-
return Source.REMOVE;
75-
});
76-
77-
yield;
64+
65+
public void load_children () {
66+
if (loading_required) {
67+
foreach (var child in file.children) {
68+
add_child (child);
69+
}
70+
71+
after_children_loaded ();
7872
}
73+
}
7974

80-
children_loaded = true;
81-
if (root != null) {
82-
root.child_folder_loaded (this);
75+
private async void load_children_async () {
76+
if (loading_required) {
77+
foreach (var child in file.children) {
78+
Idle.add (() => {
79+
add_child (child);
80+
load_children_async.callback ();
81+
return Source.REMOVE;
82+
});
83+
84+
yield;
85+
}
8386
}
87+
88+
after_children_loaded ();
8489
}
8590

86-
private void on_toggled () {
87-
if (!children_loaded &&
88-
expanded &&
89-
n_children <= 1 &&
90-
file.children.size > 0) {
91+
private void add_child (File child) {
92+
Code.Widgets.SourceList.Item item = null;
93+
if (child.is_valid_directory) {
94+
item = new FolderItem (child, view);
95+
} else if (child.is_valid_textfile) {
96+
item = new FileItem (child, view);
97+
}
9198

92-
load_children.begin ();
93-
return;
99+
if (item != null) {
100+
add (item);
94101
}
102+
}
95103

104+
private void after_children_loaded () {
105+
children_loaded = true;
96106
var root = get_root_folder ();
97-
if (!expanded &&
98-
root != null &&
99-
root.monitored_repo != null) {
100-
//When toggled closed, update status to reflect hidden contents
101-
root.update_item_status (this);
107+
if (root != null) {
108+
root.child_folder_loaded (this); //Updates child status emblens
109+
}
110+
}
111+
112+
private void on_toggled () {
113+
if (expanded) {
114+
load_children_async.begin ();
115+
return;
116+
} else {
117+
var root = get_root_folder ();
118+
if (root != null &&
119+
root.monitored_repo != null) {
120+
//When toggled closed, update status to reflect hidden contents
121+
root.update_item_status (this);
122+
}
102123
}
103124
}
104125

0 commit comments

Comments
 (0)