@@ -17,7 +17,12 @@ public class MainWindowViewModel : ViewModelBase
1717 public AvaloniaList < FileNodeBase > Files { get ; } = new AvaloniaList < FileNodeBase > ( ) ;
1818
1919 // TODO: Temporary workaround to avoid converting the FileTree logic to use FileGridItem.
20- public AvaloniaList < FileGridItem > Items { get ; } = new AvaloniaList < FileGridItem > ( ) ;
20+ public AvaloniaList < FileGridItem > Items
21+ {
22+ get => items ;
23+ set => this . RaiseAndSetIfChanged ( ref items , value ) ;
24+ }
25+ private AvaloniaList < FileGridItem > items = new AvaloniaList < FileGridItem > ( ) ;
2126
2227 public static Dictionary < Region , string > DescriptionByRegion { get ; } = new Dictionary < Region , string >
2328 {
@@ -81,7 +86,7 @@ public string? CurrentDirectoryPath
8186 {
8287 get => currentDirectoryPath ;
8388 set
84- {
89+ {
8590 if ( arcFile != null && value != currentDirectoryPath )
8691 {
8792 this . RaiseAndSetIfChanged ( ref currentDirectoryPath , value ) ;
@@ -96,8 +101,8 @@ public string? CurrentDirectoryPath
96101 }
97102 private string ? currentDirectoryPath ;
98103
99- public FolderNode ? CurrentDirectory
100- {
104+ public FolderNode ? CurrentDirectory
105+ {
101106 get => currentDirectory ;
102107 set
103108 {
@@ -186,15 +191,18 @@ public MainWindowViewModel()
186191 // HACK: DataGrid doesn't seem to support multiple types, so use a wrapper type.
187192 Files . CollectionChanged += ( s , e ) =>
188193 {
189- Items . Clear ( ) ;
194+ var newItems = new List < FileGridItem > ( ) ;
190195 foreach ( var node in Files )
191196 {
192197 if ( node is FileNode file )
193- Items . Add ( new FileGridItem ( file ) ) ;
198+ newItems . Add ( new FileGridItem ( file ) ) ;
194199 else if ( node is FolderNode folder )
195- Items . Add ( new FileGridItem ( folder ) ) ;
200+ newItems . Add ( new FileGridItem ( folder ) ) ;
196201 }
197202
203+ // Recreating the list is faster than adding items individually.
204+ Items = new AvaloniaList < FileGridItem > ( newItems ) ;
205+
198206 // HACK: Adding files to the file list increments selected index?
199207 SelectedFileIndex = 0 ;
200208 } ;
@@ -251,7 +259,7 @@ private void InitializeArcFile(string arcPathText)
251259 ArcVersion = arcFile . Version . ToString ( ) ;
252260
253261 Files . Clear ( ) ;
254- var newFiles = FileTree . CreateRootLevelNodes ( arcFile ,
262+ var newFiles = FileTree . CreateRootLevelNodes ( arcFile ,
255263 BackgroundTaskStart , BackgroundTaskReportProgress , BackgroundTaskEnd , ApplicationSettings . Instance . MergeTrailingSlash ) ;
256264 Files . AddRange ( newFiles ) ;
257265 }
@@ -291,7 +299,7 @@ public void ExitFolder()
291299 return ;
292300 }
293301
294- // Go up one level in the file tree.
302+ // Go up one level in the file tree.
295303 var parent = FileTree . CreateFolderNode ( arcFile , parentPath ) ;
296304 if ( parent == null )
297305 LoadRootNodes ( arcFile ) ;
@@ -360,7 +368,7 @@ public void ExtractAllFiles()
360368 if ( arcFile == null )
361369 return ;
362370
363- FileTree . ExtractAllFiles ( arcFile ,
371+ FileTree . ExtractAllFiles ( arcFile ,
364372 BackgroundTaskStart , BackgroundTaskReportProgress , BackgroundTaskEnd ,
365373 ApplicationSettings . Instance . MergeTrailingSlash ) ;
366374 }
0 commit comments