Skip to content

Commit b40c658

Browse files
committed
Add Properties to Fully-Loaded Items When Ready
1 parent 8b837fb commit b40c658

File tree

3 files changed

+152
-37
lines changed

3 files changed

+152
-37
lines changed

Files/Filesystem/ItemViewModel.cs

Lines changed: 75 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class ItemViewModel : INotifyPropertyChanged
4040
public ListedItem currentFolder { get => _rootFolderItem; }
4141
public CollectionViewSource viewSource;
4242
public UniversalPath Universal { get; } = new UniversalPath();
43-
private ObservableCollection<ListedItem> _filesAndFolders;
43+
public ObservableCollection<ListedItem> _filesAndFolders;
4444
private StorageFolderQueryResult _folderQueryResult;
4545
public StorageFileQueryResult _fileQueryResult;
4646
private CancellationTokenSource _cancellationTokenSource;
@@ -578,31 +578,38 @@ public async void RapidAddItemsToCollectionAsync(string path)
578578
Universal.path = App.OneDrivePath;
579579
break;
580580
}
581-
582-
_rootFolder = await StorageFolder.GetFolderFromPathAsync(path);
583-
QueryOptions options = new QueryOptions()
584-
{
585-
IndexerOption = IndexerOption.OnlyUseIndexerAndOptimizeForIndexedProperties,
586-
FolderDepth = FolderDepth.Shallow
587-
};
588-
var query = _rootFolder.CreateFileQueryWithOptions(options);
589-
options.SetPropertyPrefetch(PropertyPrefetchOptions.None, null);
590-
options.SetThumbnailPrefetch(ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached);
591-
FileInformationFactory thumbnailFactory = new FileInformationFactory(query, ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached, false);
592-
593-
var singlePurposedFiles = await thumbnailFactory.GetFilesAsync();
594-
ObservableCollection<PartialStorageItem> partialFiles = new System.Collections.ObjectModel.ObservableCollection<PartialStorageItem>();
595-
foreach(FileInformation info in singlePurposedFiles)
581+
ObservableCollection<PartialStorageItem> partialFiles = null;
582+
ObservableCollection<PartialStorageItem> partialFolders = null;
583+
var fetchOperation = Task.Run(async () =>
596584
{
597-
partialFiles.Add(new PartialStorageItem() { RelativeId = info.FolderRelativeId, Thumbnail = info.Thumbnail, ItemName = info.Name, ContentType = info.DisplayType });
598-
}
585+
_rootFolder = await StorageFolder.GetFolderFromPathAsync(path);
586+
QueryOptions options = new QueryOptions()
587+
{
588+
IndexerOption = IndexerOption.OnlyUseIndexerAndOptimizeForIndexedProperties,
589+
FolderDepth = FolderDepth.Shallow
590+
};
591+
var query = _rootFolder.CreateItemQueryWithOptions(options);
592+
options.SetPropertyPrefetch(PropertyPrefetchOptions.None, null);
593+
options.SetThumbnailPrefetch(ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached);
594+
FileInformationFactory thumbnailFactory = new FileInformationFactory(query, ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached, false);
595+
596+
var singlePurposedFiles = await thumbnailFactory.GetFilesAsync();
597+
partialFiles = new System.Collections.ObjectModel.ObservableCollection<PartialStorageItem>();
598+
foreach (FileInformation info in singlePurposedFiles)
599+
{
600+
partialFiles.Add(new PartialStorageItem() { RelativeId = info.FolderRelativeId, Thumbnail = await info.GetThumbnailAsync(ThumbnailMode.ListView, 40, ThumbnailOptions.ReturnOnlyIfCached), ItemName = info.Name, ContentType = info.DisplayType });
601+
}
602+
603+
var singlePurposedFolders = await thumbnailFactory.GetFoldersAsync();
604+
partialFolders = new System.Collections.ObjectModel.ObservableCollection<PartialStorageItem>();
605+
foreach (FolderInformation info in singlePurposedFolders)
606+
{
607+
partialFolders.Add(new PartialStorageItem() { RelativeId = info.FolderRelativeId, ItemName = info.Name, ContentType = null, Thumbnail = null });
608+
}
609+
610+
611+
});
599612

600-
var singlePurposedFolders = await thumbnailFactory.GetFoldersAsync();
601-
ObservableCollection<PartialStorageItem> partialFolders = new System.Collections.ObjectModel.ObservableCollection<PartialStorageItem>();
602-
foreach(FolderInformation info in singlePurposedFolders)
603-
{
604-
partialFolders.Add(new PartialStorageItem() { RelativeId = info.FolderRelativeId, ItemName = info.Name, ContentType = null, Thumbnail = null });
605-
}
606613

607614
WIN32_FIND_DATA findData;
608615
FINDEX_INFO_LEVELS findInfoLevel = FINDEX_INFO_LEVELS.FindExInfoStandard;
@@ -619,19 +626,60 @@ public async void RapidAddItemsToCollectionAsync(string path)
619626
{
620627
if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) != FileAttributes.Directory)
621628
{
622-
AddFile(findData, path, partialFiles.FirstOrDefault(x => x.ItemName == findData.cFileName));
629+
AddFile(findData, path, null);
623630
++count;
624631
}
625632
else if(((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
626633
{
627-
AddFolder(findData, path, partialFolders.FirstOrDefault(x => x.ItemName == findData.cFileName));
634+
AddFolder(findData, path, null);
628635
++count;
629636
}
630637
} while (FindNextFile(hFile, out findData));
631638

632639
FindClose(hFile);
633640
}
634-
641+
var populateFetchedProperties = await fetchOperation.ContinueWith(async (i) =>
642+
{
643+
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
644+
{
645+
BitmapImage icon = null;
646+
var itemsCopy = FilesAndFolders.ToList();
647+
foreach (ListedItem item in itemsCopy)
648+
{
649+
if (item.FileType != "Folder")
650+
{
651+
icon = new BitmapImage();
652+
var matchingItem = _filesAndFolders.FirstOrDefault(x => x == item);
653+
var matchingStorageItem = partialFiles.FirstOrDefault(x => x.ItemName == matchingItem.FileName);
654+
if (matchingItem != null && matchingStorageItem != null)
655+
{
656+
matchingItem.FileType = matchingStorageItem.ContentType;
657+
matchingItem.FolderRelativeId = matchingStorageItem.RelativeId;
658+
if (matchingStorageItem.Thumbnail != null)
659+
{
660+
icon.DecodePixelWidth = 40;
661+
icon.DecodePixelHeight = 40;
662+
await icon.SetSourceAsync(matchingStorageItem.Thumbnail.CloneStream());
663+
matchingItem.FileImg = icon;
664+
matchingItem.EmptyImgVis = Visibility.Collapsed;
665+
matchingItem.FileIconVis = Visibility.Visible;
666+
}
667+
}
668+
}
669+
else
670+
{
671+
var matchingItem = _filesAndFolders.FirstOrDefault(x => x == item);
672+
var matchingStorageItem = partialFolders.FirstOrDefault(x => x.ItemName == matchingItem.FileName);
673+
if (matchingItem != null && matchingStorageItem != null)
674+
{
675+
matchingItem.FolderRelativeId = matchingStorageItem.RelativeId;
676+
}
677+
}
678+
}
679+
});
680+
681+
});
682+
635683

636684
if (FilesAndFolders.Count == 0)
637685
{

Files/Filesystem/ListedItem.cs

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,82 @@
11
using Files.Enums;
22
using System;
3+
using System.ComponentModel;
34
using Windows.UI.Xaml;
45
using Windows.UI.Xaml.Media.Imaging;
56

67
namespace Files.Filesystem
78
{
8-
public class ListedItem
9+
public class ListedItem : INotifyPropertyChanged
910
{
1011
public string FolderTooltipText { get; set; }
11-
public string FolderRelativeId { get; }
12+
public string FolderRelativeId { get; set; }
1213
public Visibility FolderImg { get; set; }
13-
public Visibility FileIconVis { get; set; }
14-
public Visibility EmptyImgVis { get; set; }
15-
public BitmapImage FileImg { get; set; }
14+
private Visibility _FileIconVis;
15+
public Visibility FileIconVis
16+
{
17+
get
18+
{
19+
return _FileIconVis;
20+
}
21+
set
22+
{
23+
if(_FileIconVis != value)
24+
{
25+
_FileIconVis = value;
26+
NotifyPropertyChanged("FileIconVis");
27+
}
28+
}
29+
}
30+
private Visibility _EmptyImgVis;
31+
public Visibility EmptyImgVis
32+
{
33+
get
34+
{
35+
return _EmptyImgVis;
36+
}
37+
set
38+
{
39+
if (_EmptyImgVis != value)
40+
{
41+
_EmptyImgVis = value;
42+
NotifyPropertyChanged("EmptyImgVis");
43+
}
44+
}
45+
}
46+
private BitmapImage _FileImg;
47+
public BitmapImage FileImg
48+
{
49+
get
50+
{
51+
return _FileImg;
52+
}
53+
set
54+
{
55+
if(_FileImg != value && value != null)
56+
{
57+
_FileImg = value;
58+
NotifyPropertyChanged("FileImg");
59+
}
60+
}
61+
}
1662
public string FileName { get; set; }
1763
public string FileDate { get; private set; }
18-
public string FileType { get; set; }
64+
private string _FileType;
65+
public string FileType
66+
{
67+
get
68+
{
69+
return _FileType;
70+
}
71+
set
72+
{
73+
if(_FileType != value && value != null)
74+
{
75+
_FileType = value;
76+
NotifyPropertyChanged("FileType");
77+
}
78+
}
79+
}
1980
public string DotFileExtension { get; set; }
2081
public string FilePath { get; set; }
2182
public string FileSize { get; set; }
@@ -33,6 +94,12 @@ public DateTimeOffset FileDateReal
3394

3495
private DateTimeOffset _fileDataReal;
3596

97+
public event PropertyChangedEventHandler PropertyChanged;
98+
private void NotifyPropertyChanged(string info)
99+
{
100+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
101+
}
102+
36103
public ListedItem(string folderRelativeId)
37104
{
38105
FolderRelativeId = folderRelativeId;

Files/GenericFileBrowser.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
<Rectangle x:Load="{x:Bind IsSelectionRectangleDisplayed, Mode=OneWay}" x:Name="SelectionRectangle" Fill="Blue" Stroke="DarkBlue" Opacity="0.7"/>
142142
<ProgressBar Visibility="{x:Bind AssociatedViewModel.LoadIndicator.isVisible,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" x:Name="progBar" Height="10" VerticalAlignment="Top" IsIndeterminate="True"/>
143143
<TextBlock Visibility="{x:Bind AssociatedViewModel.EmptyTextState.isVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name="EmptyText" HorizontalAlignment="Center" Text="This folder is empty." TextWrapping="Wrap" VerticalAlignment="Top" Margin="0,125,0,0"/>
144-
<controls:DataGrid DoubleTapped="{x:Bind local:App.OccupiedInstance.instanceInteraction.List_ItemClick}" RightTapped="{x:Bind local:App.OccupiedInstance.instanceInteraction.AllView_RightTapped}" ItemsSource="{x:Bind AssociatedViewModel.FilesAndFolders}" PreviewKeyDown="AllView_PreviewKeyDown" ScrollViewer.IsScrollInertiaEnabled="True" ClipboardCopyMode="None" RowDetailsVisibilityMode="Collapsed" AllowDrop="True" Drop="AllView_DropAsync" DragStarting="AllView_DragStarting" SelectionChanged="AllView_SelectionChanged" Margin="24,24,0,0" Grid.Row="3" PreparingCellForEdit="AllView_PreparingCellForEdit" CellEditEnding="AllView_CellEditEnding" CellEditEnded="AllView_CellEditEnded" FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" AutoGenerateColumns="False" CanDrag="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" CanUserSortColumns="True" Sorting="AllView_Sorting" HorizontalAlignment="Left">
144+
<controls:DataGrid DoubleTapped="{x:Bind local:App.OccupiedInstance.instanceInteraction.List_ItemClick}" RightTapped="{x:Bind local:App.OccupiedInstance.instanceInteraction.AllView_RightTapped}" ItemsSource="{x:Bind AssociatedViewModel._filesAndFolders, Mode=OneWay}" PreviewKeyDown="AllView_PreviewKeyDown" ScrollViewer.IsScrollInertiaEnabled="True" ClipboardCopyMode="None" RowDetailsVisibilityMode="Collapsed" AllowDrop="True" Drop="AllView_DropAsync" DragStarting="AllView_DragStarting" SelectionChanged="AllView_SelectionChanged" Margin="24,24,0,0" Grid.Row="3" PreparingCellForEdit="AllView_PreparingCellForEdit" CellEditEnding="AllView_CellEditEnding" CellEditEnded="AllView_CellEditEnded" FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" AutoGenerateColumns="False" CanDrag="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" CanUserSortColumns="True" Sorting="AllView_Sorting" HorizontalAlignment="Left">
145145
<controls:DataGrid.Resources>
146146
<SolidColorBrush x:Key="DataGridCellFocusVisualPrimaryBrush" Color="Transparent"/>
147147
<SolidColorBrush x:Key="DataGridCellFocusVisualSecondaryBrush" Color="Transparent"/>
@@ -193,8 +193,8 @@
193193
<SvgImageSource RasterizePixelWidth="128" RasterizePixelHeight="128" UriSource="/Assets/FolderIcon.svg" />
194194
</Image.Source>
195195
</Image>
196-
<FontIcon Visibility="{x:Bind EmptyImgVis}" Glyph="&#xE7C3;" FontFamily="Segoe MDL2 Assets"/>
197-
<Image Visibility="{x:Bind FileIconVis}" Height="20" Width="20" Source="{x:Bind FileImg}" Stretch="UniformToFill" />
196+
<FontIcon Visibility="{x:Bind EmptyImgVis, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Glyph="&#xE7C3;" FontFamily="Segoe MDL2 Assets"/>
197+
<Image Visibility="{x:Bind FileIconVis, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="20" Width="20" Source="{x:Bind FileImg, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Stretch="UniformToFill" />
198198
</Grid>
199199
</DataTemplate>
200200
</controls:DataGridTemplateColumn.CellTemplate>
@@ -210,7 +210,7 @@
210210
<ToolTip Content="{Binding FolderTooltipText}"/>
211211
</ToolTipService.ToolTip>
212212
</controls:DataGridTextColumn>
213-
<controls:DataGridTextColumn DisplayIndex="3" x:Name="typeColumn" IsReadOnly="True" Header="Type" Width="150" Binding="{Binding FileType}" Tag="Type">
213+
<controls:DataGridTextColumn DisplayIndex="3" x:Name="typeColumn" IsReadOnly="True" Header="Type" Width="150" Binding="{Binding FileType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Tag="Type">
214214
<ToolTipService.ToolTip>
215215
<ToolTip Content="{Binding FolderTooltipText}"/>
216216
</ToolTipService.ToolTip>

0 commit comments

Comments
 (0)