Skip to content

Commit e4e12aa

Browse files
committed
Small refactor
1 parent 4162d19 commit e4e12aa

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

Files/DataModels/SidebarPinnedModel.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public async Task ShowHideRecycleBinItemAsync(bool show)
113113
{
114114
Text = ApplicationData.Current.LocalSettings.Values.Get("RecycleBin_Title", "Recycle Bin"),
115115
IsDefaultLocation = true,
116-
Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => new BitmapImage()),
117116
Path = CommonPaths.RecycleBinPath
118117
};
119118
// Add recycle bin to sidebar, title is read from LocalSettings (provided by the fulltrust process)
@@ -123,7 +122,7 @@ public async Task ShowHideRecycleBinItemAsync(bool show)
123122
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() =>
124123
{
125124
favoriteSection.ChildItems.Add(recycleBinItem);
126-
UIHelpers.LoadIconResource(recycleBinItem.Icon, Constants.ImageRes.RecycleBin);
125+
UIHelpers.LoadIconResource(recycleBinItem, Constants.ImageRes.RecycleBin);
127126
});
128127
}
129128
}
@@ -341,7 +340,6 @@ public async Task AddAllItemsToSidebar()
341340
Text = "SidebarFavorites".GetLocalized(),
342341
Section = SectionType.Favorites,
343342
SelectsOnInvoked = false,
344-
Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => new BitmapImage()),
345343
Font = MainViewModel.FontName,
346344
ChildItems = new ObservableCollection<INavigationControlItem>()
347345
};
@@ -359,7 +357,7 @@ public async Task AddAllItemsToSidebar()
359357
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() =>
360358
{
361359
SidebarControl.SideBarItems.EndBulkOperation();
362-
UIHelpers.LoadIconResource(favoriteSection.Icon, Constants.Shell32.QuickAccess);
360+
UIHelpers.LoadIconResource(favoriteSection, Constants.Shell32.QuickAccess);
363361
});
364362
}
365363
}

Files/Filesystem/Drives.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
142142
Text = "SidebarDrives".GetLocalized(),
143143
Section = SectionType.Drives,
144144
SelectsOnInvoked = false,
145-
Icon = new BitmapImage(),
146145
ChildItems = new ObservableCollection<INavigationControlItem>()
147146
};
148147
var index = (SidebarControl.SideBarItems.Any(item => item.Section == SectionType.Favorites) ? 1 : 0) +
149148
(SidebarControl.SideBarItems.Any(item => item.Section == SectionType.Library) ? 1 : 0); // After libraries section
150149
SidebarControl.SideBarItems.BeginBulkOperation();
151150
SidebarControl.SideBarItems.Insert(Math.Min(index, SidebarControl.SideBarItems.Count), section);
152151
SidebarControl.SideBarItems.EndBulkOperation();
153-
UIHelpers.LoadIconResource(section.Icon, Constants.ImageRes.ThisPC);
152+
153+
UIHelpers.LoadIconResource(section, Constants.ImageRes.ThisPC);
154154
}
155155

156156
// Sync drives to sidebar

Files/Filesystem/LibraryManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
202202
Text = "SidebarLibraries".GetLocalized(),
203203
Section = SectionType.Library,
204204
SelectsOnInvoked = false,
205-
Icon = new BitmapImage(),
206205
ChildItems = new ObservableCollection<INavigationControlItem>()
207206
};
208207
var index = (SidebarControl.SideBarItems.Any(item => item.Section == SectionType.Favorites) ? 1 : 0); // After favorites section
209208
SidebarControl.SideBarItems.BeginBulkOperation();
210209
SidebarControl.SideBarItems.Insert(Math.Min(index, SidebarControl.SideBarItems.Count), librarySection);
211210
SidebarControl.SideBarItems.EndBulkOperation();
212-
UIHelpers.LoadIconResource(section.Icon, Constants.ImageRes.Libraries);
211+
212+
UIHelpers.LoadIconResource(section, Constants.ImageRes.Libraries);
213213
}
214214
}
215215
finally

Files/Filesystem/NetworkDrivesManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
130130
Text = "SidebarNetworkDrives".GetLocalized(),
131131
Section = SectionType.Network,
132132
SelectsOnInvoked = false,
133-
Icon = new BitmapImage(),
134133
ChildItems = new ObservableCollection<INavigationControlItem>()
135134
};
136135
var index = (SidebarControl.SideBarItems.Any(item => item.Section == SectionType.Favorites) ? 1 : 0) +
@@ -140,7 +139,8 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio
140139
SidebarControl.SideBarItems.BeginBulkOperation();
141140
SidebarControl.SideBarItems.Insert(Math.Min(index, SidebarControl.SideBarItems.Count), section);
142141
SidebarControl.SideBarItems.EndBulkOperation();
143-
UIHelpers.LoadIconResource(section.Icon, Constants.ImageRes.NetworkDrives);
142+
143+
UIHelpers.LoadIconResource(section, Constants.ImageRes.NetworkDrives);
144144
}
145145

146146
if (section != null)

Files/Helpers/UIHelpers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Files.Common;
2+
using Files.DataModels.NavigationControlItems;
23
using Newtonsoft.Json;
34
using System;
45
using System.Collections.Generic;
@@ -83,15 +84,14 @@ public static async Task<IconFileInfo> GetIconResourceInfo(int index)
8384
return null;
8485
}
8586

86-
public static async void LoadIconResource(BitmapImage image, int index)
87+
public static async void LoadIconResource(LocationItem item, int index)
8788
{
8889
await Common.Extensions.IgnoreExceptions(async () =>
8990
{
9091
var iconInfo = await GetIconResourceInfo(index);
91-
if (iconInfo?.IconDataBytes is byte[] data)
92+
if (iconInfo != null)
9293
{
93-
using var ms = new MemoryStream(data);
94-
await image.SetSourceAsync(ms.AsRandomAccessStream());
94+
item.Icon = await iconInfo.IconDataBytes.ToBitmapAsync();
9595
}
9696
}, App.Logger);
9797
}

0 commit comments

Comments
 (0)