Skip to content

Commit bb6265c

Browse files
committed
wip: bundles changes
1 parent be75f1a commit bb6265c

File tree

6 files changed

+49
-53
lines changed

6 files changed

+49
-53
lines changed

Files/EventArguments/Bundles/BundlesOpenPathEventArgs.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
using Files.Filesystem;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
using Windows.Storage;
33

44
namespace Files.EventArguments.Bundles
55
{
66
public class BundlesOpenPathEventArgs
77
{
8-
public readonly string path;
9-
10-
public readonly FilesystemItemType itemType;
8+
public readonly IStorageItem item;
119

1210
public readonly bool openSilent;
1311

1412
public readonly bool openViaApplicationPicker;
1513

1614
public readonly IEnumerable<string> selectItems;
1715

18-
public BundlesOpenPathEventArgs(string path, FilesystemItemType itemType, bool openSilent, bool openViaApplicationPicker, IEnumerable<string> selectItems)
16+
public BundlesOpenPathEventArgs(IStorageItem item, bool openSilent, bool openViaApplicationPicker, IEnumerable<string> selectItems)
1917
{
20-
this.path = path;
21-
this.itemType = itemType;
18+
this.item = item;
2219
this.openSilent = openSilent;
2320
this.openViaApplicationPicker = openViaApplicationPicker;
2421
this.selectItems = selectItems;

Files/Helpers/NavigationHelpers.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static async Task<bool> OpenPath(IStorageItem item, IShellPage associated
210210
.OnSuccess(childFolder =>
211211
{
212212
// Add location to MRU List
213-
mostRecentlyUsed.Add(childFolder.Folder, childFolder.Path);
213+
mostRecentlyUsed.Add(childFolder, childFolder.Path);
214214
});
215215
if (!opened)
216216
{
@@ -261,15 +261,15 @@ public static async Task<bool> OpenPath(IStorageItem item, IShellPage associated
261261
.OnSuccess(async childFile =>
262262
{
263263
// Add location to MRU List
264-
mostRecentlyUsed.Add(childFile.File, childFile.Path);
264+
mostRecentlyUsed.Add(childFile, childFile.Path);
265265

266266
if (openViaApplicationPicker)
267267
{
268268
LauncherOptions options = new LauncherOptions
269269
{
270270
DisplayApplicationPicker = true
271271
};
272-
await Launcher.LaunchFileAsync(childFile.File, options);
272+
await Launcher.LaunchFileAsync(childFile, options);
273273
}
274274
else
275275
{
@@ -345,7 +345,7 @@ public static async Task<bool> OpenPath(IStorageItem item, IShellPage associated
345345
};
346346

347347
// Now launch file with options.
348-
launchSuccess = await Launcher.LaunchFileAsync(childFile.File, options);
348+
launchSuccess = await Launcher.LaunchFileAsync(childFile, options);
349349
}
350350

351351
if (!launchSuccess)

Files/Helpers/StorageItemHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public static async Task<IStorageItem> PathToStorageItemAsync(string path, Type
1919

2020
if (type == typeof(StorageFile))
2121
{
22-
return await StorageFile.GetFileFromPathAsync(path).AsTask();
22+
return await StorageFile.GetFileFromPathAsync(path);
2323
}
2424

2525
if (type == typeof(StorageFolder))
2626
{
27-
return await StorageFolder.GetFolderFromPathAsync(path).AsTask();
27+
return await StorageFolder.GetFolderFromPathAsync(path);
2828
}
2929

3030
if (type == typeof(RecycleBinFile))

Files/ViewModels/Widgets/Bundles/BundleContainerViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class BundleContainerViewModel : ObservableObject, IDisposable
4646

4747
public Action<string, string> NotifyBundleItemRemoved { get; set; }
4848

49-
public Action<string, FilesystemItemType, bool, bool, IEnumerable<string>> OpenPath { get; set; }
49+
public Action<IStorageItem, bool, bool, IEnumerable<string>> OpenPath { get; set; }
5050

5151
public Action<string> OpenPathInNewPane { get; set; }
5252

@@ -274,13 +274,13 @@ private async void Drop(DragEventArgs e)
274274
{
275275
if (Contents.Count < Constants.Widgets.Bundles.MaxAmountOfItemsPerBundle)
276276
{
277-
if (!Contents.Any((i) => i.Path == item.Path)) // Don't add existing items!
277+
if (!Contents.Any((i) => i.Item.Path == item.Path)) // Don't add existing items!
278278
{
279-
AddBundleItem(new BundleItemViewModel(item.Path, item.IsOfType(StorageItemTypes.Folder) ? FilesystemItemType.Directory : FilesystemItemType.File)
279+
AddBundleItem(new BundleItemViewModel(item)
280280
{
281281
ParentBundleName = BundleName,
282282
NotifyItemRemoved = NotifyItemRemovedHandle,
283-
OpenPath = OpenPath,
283+
OpenItemDelegate = OpenPath,
284284
OpenPathInNewPane = OpenPathInNewPane,
285285
LoadIconOverlay = LoadIconOverlay
286286
});
@@ -327,7 +327,7 @@ private async void Drop(DragEventArgs e)
327327
{
328328
ParentBundleName = BundleName,
329329
NotifyItemRemoved = NotifyItemRemovedHandle,
330-
OpenPath = OpenPath,
330+
OpenItem = OpenPath,
331331
OpenPathInNewPane = OpenPathInNewPane,
332332
LoadIconOverlay = LoadIconOverlay
333333
});

Files/ViewModels/Widgets/Bundles/BundleItemViewModel.cs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class BundleItemViewModel : ObservableObject, IDisposable
2828

2929
#region Actions
3030

31-
public Action<string, FilesystemItemType, bool, bool, IEnumerable<string>> OpenPath { get; set; }
31+
public Action<IStorageItem, bool, bool, IEnumerable<string>> OpenItemDelegate { get; set; }
3232

3333
public Action<string> OpenPathInNewPane { get; set; }
3434

@@ -45,13 +45,13 @@ public class BundleItemViewModel : ObservableObject, IDisposable
4545
/// </summary>
4646
public string ParentBundleName { get; set; }
4747

48-
public string Path { get; set; }
48+
public IStorageItem Item { get; set; }
4949

5050
public string Name
5151
{
5252
get
5353
{
54-
string fileName = System.IO.Path.GetFileName(this.Path);
54+
string fileName = System.IO.Path.GetFileName(this.Item.Path);
5555

5656
if (fileName.EndsWith(".lnk"))
5757
{
@@ -62,8 +62,6 @@ public string Name
6262
}
6363
}
6464

65-
public FilesystemItemType TargetType { get; set; } = FilesystemItemType.File;
66-
6765
private ImageSource icon;
6866

6967
public ImageSource Icon
@@ -81,12 +79,12 @@ public ImageSource Icon
8179

8280
public Visibility OpenInNewTabVisibility
8381
{
84-
get => TargetType == FilesystemItemType.Directory ? Visibility.Visible : Visibility.Collapsed;
82+
get => Item.IsOfType(StorageItemTypes.Folder) ? Visibility.Visible : Visibility.Collapsed;
8583
}
8684

8785
public Visibility OpenInNewPaneVisibility
8886
{
89-
get => App.AppSettings.IsDualPaneEnabled && TargetType == FilesystemItemType.Directory ? Visibility.Visible : Visibility.Collapsed;
87+
get => App.AppSettings.IsDualPaneEnabled && Item.IsOfType(StorageItemTypes.Folder) ? Visibility.Visible : Visibility.Collapsed;
9088
}
9189

9290
#endregion Public Properties
@@ -105,10 +103,9 @@ public Visibility OpenInNewPaneVisibility
105103

106104
#region Constructor
107105

108-
public BundleItemViewModel(string path, FilesystemItemType targetType)
106+
public BundleItemViewModel(IStorageItem item)
109107
{
110-
this.Path = path;
111-
this.TargetType = targetType;
108+
this.Item = item;
112109

113110
// Create commands
114111
OpenInNewTabCommand = new RelayCommand(OpenInNewTab);
@@ -123,17 +120,17 @@ public BundleItemViewModel(string path, FilesystemItemType targetType)
123120

124121
private async void OpenInNewTab()
125122
{
126-
await MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), Path);
123+
await MainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), Item.Path);
127124
}
128125

129126
private void OpenInNewPane()
130127
{
131-
OpenPathInNewPane(Path);
128+
OpenPathInNewPane(Item.Path);
132129
}
133130

134131
private void OpenItemLocation()
135132
{
136-
OpenPath(System.IO.Path.GetDirectoryName(Path), FilesystemItemType.Directory, false, false, System.IO.Path.GetFileName(Path).CreateEnumerable());
133+
OpenItemDelegate(Item, false, false, System.IO.Path.GetFileName(Item.Path).CreateEnumerable());
137134
}
138135

139136
#endregion Command Implementation
@@ -142,17 +139,17 @@ private void OpenItemLocation()
142139

143140
public async void UpdateIcon()
144141
{
145-
if (TargetType == FilesystemItemType.Directory) // OpenDirectory
142+
if (Item is IStorageFolder)
146143
{
147144
Icon = FolderIcon;
148145
}
149-
else // NotADirectory
146+
else if (Item is IStorageFile file)
150147
{
151148
try
152149
{
153-
if (Path.EndsWith(".lnk"))
150+
if (file.Path.EndsWith(".lnk"))
154151
{
155-
var (IconData, OverlayData, IsCustom) = LoadIconOverlay(Path, 24u);
152+
var (IconData, OverlayData, IsCustom) = LoadIconOverlay(file.Path, 24u);
156153

157154
await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
158155
{
@@ -162,17 +159,14 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
162159
return;
163160
}
164161

165-
StorageFile file = await StorageItemHelpers.ToStorageItem<StorageFile>(Path);
162+
BitmapImage icon = new BitmapImage();
163+
StorageItemThumbnail thumbnail = null;
166164

167-
if (file == null) // No file found
165+
if (file is StorageFile storageFile)
168166
{
169-
Icon = new BitmapImage();
170-
return;
167+
thumbnail = await storageFile.GetThumbnailAsync(ThumbnailMode.ListView, 24u, ThumbnailOptions.UseCurrentScale);
171168
}
172169

173-
BitmapImage icon = new BitmapImage();
174-
StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.ListView, 24u, ThumbnailOptions.UseCurrentScale);
175-
176170
if (thumbnail != null)
177171
{
178172
await icon.SetSourceAsync(thumbnail);
@@ -186,19 +180,24 @@ await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () =>
186180
Icon = new BitmapImage(); // Set here no file image
187181
}
188182
}
183+
else
184+
{
185+
Icon = new BitmapImage();
186+
return;
187+
}
189188
}
190189

191190
public void OpenItem()
192191
{
193-
OpenPath(Path, TargetType, false, false, null);
192+
OpenItemDelegate(Item, false, false, null);
194193
}
195194

196195
public void RemoveItem()
197196
{
198197
if (BundlesSettings.SavedBundles.ContainsKey(ParentBundleName))
199198
{
200199
Dictionary<string, List<string>> allBundles = BundlesSettings.SavedBundles;
201-
allBundles[ParentBundleName].Remove(Path);
200+
allBundles[ParentBundleName].Remove(Item.Path);
202201
BundlesSettings.SavedBundles = allBundles;
203202
NotifyItemRemoved(this);
204203
}
@@ -210,14 +209,14 @@ public void RemoveItem()
210209

211210
public void Dispose()
212211
{
213-
Path = null;
212+
Item = null;
214213
Icon = null;
215214

216215
OpenInNewTabCommand = null;
217216
OpenItemLocationCommand = null;
218217
RemoveItemCommand = null;
219218

220-
OpenPath = null;
219+
OpenItemDelegate = null;
221220
OpenPathInNewPane = null;
222221
LoadIconOverlay = null;
223222
}

Files/ViewModels/Widgets/Bundles/BundlesViewModel.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ private async void ExportBundles()
269269

270270
#region Handlers
271271

272-
private void OpenPathHandle(string path, FilesystemItemType itemType, bool openSilent, bool openViaApplicationPicker, IEnumerable<string> selectItems)
272+
private void OpenPathHandle(IStorageItem item, bool openSilent, bool openViaApplicationPicker, IEnumerable<string> selectItems)
273273
{
274-
OpenPathEvent?.Invoke(this, new BundlesOpenPathEventArgs(path, itemType, openSilent, openViaApplicationPicker, selectItems));
274+
OpenPathEvent?.Invoke(this, new BundlesOpenPathEventArgs(item, openSilent, openViaApplicationPicker, selectItems));
275275
}
276276

277277
private void OpenPathInNewPaneHandle(string path)
@@ -309,7 +309,7 @@ private void NotifyItemRemovedHandle(BundleContainerViewModel item)
309309
/// <param name="bundleItemPath"></param>
310310
private void NotifyBundleItemRemovedHandle(string bundleContainer, string bundleItemPath)
311311
{
312-
BundleItemViewModel itemToRemove = this.Items.Where((item) => item.BundleName == bundleContainer).First().Contents.Where((item) => item.Path == bundleItemPath).First();
312+
BundleItemViewModel itemToRemove = this.Items.Where((item) => item.BundleName == bundleContainer).First().Contents.Where((item) => item.Item.Path == bundleItemPath).First();
313313
itemToRemove.RemoveItem();
314314
}
315315

@@ -364,7 +364,7 @@ public void Save()
364364
{
365365
if (bundleItem != null)
366366
{
367-
bundleItems.Add(bundleItem.Path);
367+
bundleItems.Add(bundleItem.Item.Path);
368368
}
369369
}
370370

@@ -393,11 +393,11 @@ public async Task Load()
393393
{
394394
if (bundleItem != null)
395395
{
396-
bundleItems.Add(new BundleItemViewModel(bundleItem, await StorageItemHelpers.GetTypeFromPath(bundleItem))
396+
bundleItems.Add(new BundleItemViewModel(await StorageItemHelpers.PathToStorageItemAsync<StorageFile>(bundleItem))
397397
{
398398
ParentBundleName = bundle.Key,
399399
NotifyItemRemoved = NotifyBundleItemRemovedHandle,
400-
OpenPath = OpenPathHandle,
400+
OpenItemDelegate = OpenPathHandle,
401401
OpenPathInNewPane = OpenPathInNewPaneHandle,
402402
LoadIconOverlay = LoadIconOverlayHandle
403403
});

0 commit comments

Comments
 (0)