Skip to content

Commit 562424f

Browse files
author
Yair Aichenbaum
committed
Merge branch 'develop' of https://github.com/duke7553/files-uwp into develop
2 parents ed9be2d + ef87bdc commit 562424f

File tree

5 files changed

+329
-46
lines changed

5 files changed

+329
-46
lines changed

Files/Filesystem/ItemViewModel.cs

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,43 @@ class PartialStorageItem
537537
public string RelativeId { get; set; }
538538
}
539539

540+
public async void LoadExtendedItemProperties(ListedItem item)
541+
{
542+
if (!item.ItemPropertiesInitialized)
543+
{
544+
if (item.FileType != "Folder")
545+
{
546+
BitmapImage icon = new BitmapImage();
547+
var matchingItem = _filesAndFolders.FirstOrDefault(x => x == item);
548+
var matchingStorageItem = await StorageFile.GetFileFromPathAsync(item.FilePath);
549+
if (matchingItem != null && matchingStorageItem != null)
550+
{
551+
matchingItem.FileType = matchingStorageItem.DisplayType;
552+
matchingItem.FolderRelativeId = matchingStorageItem.FolderRelativeId;
553+
var Thumbnail = await matchingStorageItem.GetThumbnailAsync(ThumbnailMode.ListView, 20, ThumbnailOptions.UseCurrentScale);
554+
if (Thumbnail != null)
555+
{
556+
matchingItem.FileImg = icon;
557+
await icon.SetSourceAsync(Thumbnail);
558+
matchingItem.EmptyImgVis = Visibility.Collapsed;
559+
matchingItem.FileIconVis = Visibility.Visible;
560+
}
561+
}
562+
}
563+
else
564+
{
565+
var matchingItem = _filesAndFolders.FirstOrDefault(x => x == item);
566+
var matchingStorageItem = await StorageFolder.GetFolderFromPathAsync(item.FilePath);
567+
if (matchingItem != null && matchingStorageItem != null)
568+
{
569+
matchingItem.FolderRelativeId = matchingStorageItem.FolderRelativeId;
570+
}
571+
}
572+
573+
item.ItemPropertiesInitialized = true;
574+
}
575+
}
576+
540577
public async void RapidAddItemsToCollectionAsync(string path)
541578
{
542579
App.CurrentInstance.CanRefresh = false;
@@ -672,56 +709,31 @@ public async void RapidAddItemsToCollectionAsync(string path)
672709
}
673710
else if (((FileAttributes)findData.dwFileAttributes & FileAttributes.Directory) == FileAttributes.Directory)
674711
{
675-
AddFolder(findData, path, null);
676-
++count;
712+
if (findData.cFileName != "." && findData.cFileName != "..")
713+
{
714+
AddFolder(findData, path, null);
715+
++count;
716+
}
677717
}
678718
}
679719

680720
} while (FindNextFile(hFile, out findData));
681721

682722
FindClose(hFile);
683723
}
684-
var populateFetchedProperties = await fetchOperation.ContinueWith(async (i) =>
685-
{
686-
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
687-
{
688-
BitmapImage icon = null;
689-
var itemsCopy = FilesAndFolders.ToList();
690-
foreach (ListedItem item in itemsCopy)
691-
{
692-
if (item.FileType != "Folder")
693-
{
694-
icon = new BitmapImage();
695-
var matchingItem = _filesAndFolders.FirstOrDefault(x => x == item);
696-
var matchingStorageItem = partialFiles.FirstOrDefault(x => x.ItemName == matchingItem.FileName);
697-
if (matchingItem != null && matchingStorageItem != null)
698-
{
699-
matchingItem.FileType = matchingStorageItem.ContentType;
700-
matchingItem.FolderRelativeId = matchingStorageItem.RelativeId;
701-
if (matchingStorageItem.Thumbnail != null)
702-
{
703-
icon.DecodePixelWidth = 40;
704-
icon.DecodePixelHeight = 40;
705-
await icon.SetSourceAsync(matchingStorageItem.Thumbnail.CloneStream());
706-
matchingItem.FileImg = icon;
707-
matchingItem.EmptyImgVis = Visibility.Collapsed;
708-
matchingItem.FileIconVis = Visibility.Visible;
709-
}
710-
}
711-
}
712-
else
713-
{
714-
var matchingItem = _filesAndFolders.FirstOrDefault(x => x == item);
715-
var matchingStorageItem = partialFolders.FirstOrDefault(x => x.ItemName == matchingItem.FileName);
716-
if (matchingItem != null && matchingStorageItem != null)
717-
{
718-
matchingItem.FolderRelativeId = matchingStorageItem.RelativeId;
719-
}
720-
}
721-
}
722-
});
724+
//var populateFetchedProperties = await fetchOperation.ContinueWith(async (i) =>
725+
//{
726+
// await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
727+
// {
728+
// BitmapImage icon = null;
729+
// var itemsCopy = FilesAndFolders.ToList();
730+
// foreach (ListedItem item in itemsCopy)
731+
// {
732+
733+
// }
734+
// });
723735

724-
});
736+
//});
725737

726738

727739
if (FilesAndFolders.Count == 0)
@@ -810,7 +822,7 @@ private async void AddFile(WIN32_FIND_DATA findData, string pathRoot, PartialSto
810822
try
811823
{
812824

813-
var itemThumbnailImg = partialStorageFile != null ? partialStorageFile.Thumbnail.CloneStream() : null;
825+
var itemThumbnailImg = partialStorageFile != null ? partialStorageFile.Thumbnail : null;
814826
if (itemThumbnailImg != null)
815827
{
816828
itemEmptyImgVis = Visibility.Collapsed;

Files/Filesystem/ListedItem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Files.Filesystem
88
{
99
public class ListedItem : INotifyPropertyChanged
1010
{
11+
public bool ItemPropertiesInitialized { get; set; } = false;
1112
public string FolderTooltipText { get; set; }
1213
public string FolderRelativeId { get; set; }
1314
public Visibility FolderImg { get; set; }

Files/GenericFileBrowser.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
xmlns:local="using:Files"
99
xmlns:local2="using:Files.Filesystem"
1010
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
11-
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
11+
xmlns:muxc="using:Microsoft.UI.Xaml.Controls" xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors"
1212
Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
1313
NavigationCacheMode="Required"
1414
PointerReleased="GenericItemView_PointerReleased"
@@ -336,7 +336,7 @@
336336
ToolTipService.ToolTip="{Binding FolderTooltipText}">
337337
<controls:DataGridTemplateColumn.CellTemplate>
338338
<DataTemplate x:DataType="local2:ListedItem">
339-
<Grid x:Name="Icon" Margin="0,0,0,0">
339+
<Grid x:Name="Icon" Margin="0,0,0,0" EffectiveViewportChanged="Icon_EffectiveViewportChanged">
340340
<Rectangle
341341
x:Name="CutIndicator"
342342
Fill="LightGray"
@@ -360,7 +360,7 @@
360360
<Image
361361
Width="20"
362362
Height="20"
363-
Source="{x:Bind FileImg, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
363+
Source="{x:Bind FileImg,Mode=OneWay}"
364364
Stretch="UniformToFill"
365365
Visibility="{x:Bind FileIconVis, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
366366
</Grid>

Files/GenericFileBrowser.xaml.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
using Windows.UI.Core;
1414
using Windows.UI.Input;
1515
using Files.Controls;
16+
using Microsoft.Xaml.Interactivity;
17+
using System.Linq;
18+
using Microsoft.Toolkit.Uwp.UI.Behaviors;
19+
using Windows.Foundation;
1620

1721
namespace Files
1822
{
@@ -249,5 +253,19 @@ private void BaseLayout_PointerMoved(object sender, PointerRoutedEventArgs e)
249253
SelectionRectangle.Width += (e.GetCurrentPoint(this).Position.X - startingPoint.Position.X);
250254
}
251255
}
256+
257+
private async void Icon_EffectiveViewportChanged(FrameworkElement sender, EffectiveViewportChangedEventArgs args)
258+
{
259+
var parentRow = Interacts.Interaction.FindParent<DataGridRow>(sender);
260+
if((!(parentRow.DataContext as ListedItem).ItemPropertiesInitialized) && (args.BringIntoViewDistanceX < sender.ActualHeight))
261+
{
262+
await Window.Current.CoreWindow.Dispatcher.RunIdleAsync((e) =>
263+
{
264+
App.CurrentInstance.ViewModel.LoadExtendedItemProperties(parentRow.DataContext as ListedItem);
265+
(parentRow.DataContext as ListedItem).ItemPropertiesInitialized = true;
266+
//sender.EffectiveViewportChanged -= Icon_EffectiveViewportChanged;
267+
});
268+
}
269+
}
252270
}
253271
}

0 commit comments

Comments
 (0)