Skip to content

Commit efac043

Browse files
authored
Invalid favorities are no longer removed from the sidebar (#8767)
1 parent 852a69b commit efac043

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/Files.Uwp/DataModels/NavigationControlItems/LocationItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public bool IsExpanded
5555
}
5656
}
5757

58+
public bool IsInvalid { get; set; } = false;
59+
5860
public SectionType Section { get; set; }
5961

6062
public int CompareTo(INavigationControlItem other) => Text.CompareTo(other.Text);

src/Files.Uwp/DataModels/SidebarPinnedModel.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,20 @@ public async Task AddItemToSidebarAsync(string path)
259259
{
260260
var item = await FilesystemTasks.Wrap(() => DrivesManager.GetRootFromPathAsync(path));
261261
var res = await FilesystemTasks.Wrap(() => StorageFileExtensions.DangerousGetFolderFromPathAsync(path, item));
262-
if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path))
262+
var lastItem = favoriteSection.ChildItems.LastOrDefault(x => x.ItemType == NavigationControlItemType.Location && !x.Path.Equals(CommonPaths.RecycleBinPath));
263+
int insertIndex = lastItem != null ? favoriteSection.ChildItems.IndexOf(lastItem) + 1 : 0;
264+
var locationItem = new LocationItem
263265
{
264-
var lastItem = favoriteSection.ChildItems.LastOrDefault(x => x.ItemType == NavigationControlItemType.Location && !x.Path.Equals(CommonPaths.RecycleBinPath));
265-
int insertIndex = lastItem != null ? favoriteSection.ChildItems.IndexOf(lastItem) + 1 : 0;
266-
var locationItem = new LocationItem
267-
{
268-
Font = MainViewModel.FontName,
269-
Path = path,
270-
Section = SectionType.Favorites,
271-
IsDefaultLocation = false,
272-
Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'))
273-
};
266+
Font = MainViewModel.FontName,
267+
Path = path,
268+
Section = SectionType.Favorites,
269+
IsDefaultLocation = false,
270+
Text = res.Result?.DisplayName ?? Path.GetFileName(path.TrimEnd('\\'))
271+
};
274272

273+
if (res || (FilesystemResult)FolderHelpers.CheckFolderAccessWithWin32(path))
274+
{
275+
locationItem.IsInvalid = false;
275276
if (res)
276277
{
277278
var iconData = await FileThumbnailHelper.LoadIconFromStorageItemAsync(res.Result, 24u, Windows.Storage.FileProperties.ThumbnailMode.ListView);
@@ -290,16 +291,17 @@ public async Task AddItemToSidebarAsync(string path)
290291
locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => locationItem.IconData.ToBitmapAsync());
291292
}
292293
}
293-
294-
if (!favoriteSection.ChildItems.Any(x => x.Path == locationItem.Path))
295-
{
296-
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => favoriteSection.ChildItems.Insert(insertIndex, locationItem));
297-
}
298294
}
299295
else
300296
{
301-
Debug.WriteLine($"Pinned item was invalid and will be removed from the file lines list soon: {res.ErrorCode}");
302-
RemoveItem(path);
297+
locationItem.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => UIHelpers.GetIconResource(Constants.ImageRes.Folder));
298+
locationItem.IsInvalid = true;
299+
Debug.WriteLine($"Pinned item was invalid {res.ErrorCode}, item: {path}");
300+
}
301+
302+
if (!favoriteSection.ChildItems.Any(x => x.Path == locationItem.Path))
303+
{
304+
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => favoriteSection.ChildItems.Insert(insertIndex, locationItem));
303305
}
304306
}
305307

src/Files.Uwp/UserControls/SidebarControl.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
<muxc:NavigationViewItem.Icon>
6464
<muxc:ImageIcon Source="{x:Bind Icon, Mode=OneWay}" />
6565
</muxc:NavigationViewItem.Icon>
66+
<muxc:NavigationViewItem.InfoBadge>
67+
<muxc:InfoBadge Style="{ThemeResource CautionIconInfoBadgeStyle}" Visibility="{x:Bind IsInvalid, Mode=OneWay}"/>
68+
</muxc:NavigationViewItem.InfoBadge>
6669
</muxc:NavigationViewItem>
6770
</DataTemplate>
6871

0 commit comments

Comments
 (0)