@@ -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