Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public bool IsExpanded
}
}

public bool IsInvalid { get; set; } = false;

public SectionType Section { get; set; }

public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text);
Expand Down
38 changes: 20 additions & 18 deletions src/Files.Uwp/DataModels/SidebarPinnedModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,20 @@ public async Task AddItemToSidebarAsync(string path)
{
var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path));
var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item));
if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path))
var lastItem = favoriteSection.ChildItems.LastOrDefault(x => x.ItemType == NavigationControlItemType.Location && !x.Path.Equals(CommonPaths.RecycleBinPath));
int insertIndex = lastItem != null ? favoriteSection.ChildItems.IndexOf(lastItem) + 1 : 0;
var locationItem = new LocationItem
{
var lastItem = favoriteSection.ChildItems.LastOrDefault(x => x.ItemType == NavigationControlItemType.Location && !x.Path.Equals(CommonPaths.RecycleBinPath));
int insertIndex = lastItem != null ? favoriteSection.ChildItems.IndexOf(lastItem) + 1 : 0;
var locationItem = new LocationItem
{
Font = MainViewModel.FontName,
Path = path,
Section = SectionType.Favorites,
IsDefaultLocation = false,
Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'))
};
Font = MainViewModel.FontName,
Path = path,
Section = SectionType.Favorites,
IsDefaultLocation = false,
Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'))
};

if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path))
{
locationItem.IsInvalid = false;
if (res)
{
var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 24u, Windows.Storage.FileProperties.ThumbnailMode.ListView);
Expand All @@ -290,16 +291,17 @@ public async Task AddItemToSidebarAsync(string path)
locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync());
}
}

if (!favoriteSection.ChildItems.Any(x => x.Path == locationItem.Path))
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => favoriteSection.ChildItems.Insert(insertIndex, locationItem));
}
}
else
{
Debug.WriteLine($"Pinned item was invalid and will be removed from the file lines list soon: {res.ErrorCode}");
RemoveItem(path);
locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.ImageRes.Folder));
locationItem.IsInvalid = true;
Debug.WriteLine($"Pinned item was invalid {res.ErrorCode}, item: {path}");
}

if (!favoriteSection.ChildItems.Any(x => x.Path == locationItem.Path))
{
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => favoriteSection.ChildItems.Insert(insertIndex, locationItem));
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Files.Uwp/UserControls/SidebarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
<muxc:NavigationViewItem.Icon>
<muxc:ImageIcon Source="{x:Bind Icon, Mode=OneWay}" />
</muxc:NavigationViewItem.Icon>
<muxc:NavigationViewItem.InfoBadge>
<muxc:InfoBadge Style="{ThemeResource CautionIconInfoBadgeStyle}" Visibility="{x:Bind IsInvalid, Mode=OneWay}"/>
</muxc:NavigationViewItem.InfoBadge>
</muxc:NavigationViewItem>
</DataTemplate>

Expand Down