Skip to content

Commit 92fbb65

Browse files
committed
Update
1 parent cfd9e17 commit 92fbb65

File tree

7 files changed

+107
-103
lines changed

7 files changed

+107
-103
lines changed

src/Files.App.Storage/Storables/WindowsStorage/WindowsStorableHelpers.Storage.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,12 @@ public static bool TryShowFormatDriveDialog(HWND hWnd, uint driveLetterIndex, SH
8484
var result = PInvoke.SHFormatDrive(hWnd, driveLetterIndex, id, options);
8585
return result is 0xFFFF;
8686
}
87+
88+
public static bool TryGetDriveInfo(this IWindowsStorable storable)
89+
{
90+
91+
92+
return true;
93+
}
8794
}
8895
}

src/Files.App/Data/Items/WidgetCardItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace Files.App.Data.Items
88
/// </summary>
99
public abstract class WidgetCardItem : ObservableObject
1010
{
11+
public virtual object? Item { get; set; }
12+
1113
public virtual string? Path { get; set; }
1214
}
1315
}

src/Files.App/Data/Items/WidgetDriveCardItem.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@
77

88
namespace Files.App.Data.Items
99
{
10-
public sealed partial class WidgetDriveCardItem : WidgetCardItem, IWidgetCardItem<IWindowsStorable>, IDisposable
10+
public sealed partial class WidgetDriveCardItem : WidgetCardItem, IWidgetCardItem<IFolder>, IDisposable
1111
{
1212
// Properties
1313

14-
public required new IWindowsStorable Item { get; private set; }
14+
public required IFolder Item { get; set; }
1515

16-
public required string Path { get; set; }
16+
public required new string Path { get; set; }
1717

1818
public required string Text { get; set; }
1919

20-
private BitmapImage _Thumbnail;
21-
public BitmapImage Thumbnail { get => _Thumbnail; set => SetProperty(ref _Thumbnail, value); }
20+
public bool ShowStorageSense { get; set; }
21+
22+
public bool ShowDriveUsage { get; set; } = true;
23+
24+
public string? UsageText { get; set; }
25+
26+
public ByteSizeLib.ByteSize TotalSpace { get; set; }
27+
28+
public ByteSizeLib.ByteSize SpaceUsed { get; set; }
29+
30+
private BitmapImage? _Thumbnail;
31+
public BitmapImage? Thumbnail { get => _Thumbnail; set => SetProperty(ref _Thumbnail, value); }
2232

2333
// Constructor
2434

@@ -28,10 +38,10 @@ public WidgetDriveCardItem()
2838

2939
public async Task LoadCardThumbnailAsync()
3040
{
31-
if (string.IsNullOrEmpty(Path))
41+
if (string.IsNullOrEmpty(Path) || Item is not IWindowsStorable windowsStorable)
3242
return;
3343

34-
Item.TryGetThumbnail((int)(Constants.ShellIconSizes.Large * App.AppModel.AppWindowDPI), SIIGBF.SIIGBF_ICONONLY, out var rawThumbnailData);
44+
windowsStorable.TryGetThumbnail((int)(Constants.ShellIconSizes.Large * App.AppModel.AppWindowDPI), SIIGBF.SIIGBF_ICONONLY, out var rawThumbnailData);
3545
if (rawThumbnailData is null)
3646
return;
3747

src/Files.App/UserControls/Widgets/DrivesWidget.xaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
VerticalAlignment="Stretch"
3232
HorizontalContentAlignment="Stretch"
3333
VerticalContentAlignment="Stretch"
34-
AutomationProperties.Name="{x:Bind Item.Text, Mode=OneWay}"
34+
AutomationProperties.Name="{x:Bind Text, Mode=OneWay}"
3535
Click="Button_Click"
3636
CornerRadius="{StaticResource ControlCornerRadius}"
3737
DataContext="{x:Bind}"
3838
PointerPressed="Button_PointerPressed"
3939
RightTapped="Button_RightTapped"
40-
Tag="{x:Bind Item.Path}"
41-
ToolTipService.ToolTip="{x:Bind Item.Text, Mode=OneWay}">
40+
Tag="{x:Bind Path}"
41+
ToolTipService.ToolTip="{x:Bind Text, Mode=OneWay}">
4242
<Grid
4343
Margin="8"
4444
HorizontalAlignment="Stretch"
@@ -75,7 +75,7 @@
7575
VerticalAlignment="Center"
7676
FontSize="14"
7777
FontWeight="Medium"
78-
Text="{x:Bind Item.Text, Mode=OneWay}"
78+
Text="{x:Bind Text, Mode=OneWay}"
7979
TextTrimming="CharacterEllipsis"
8080
TextWrapping="NoWrap" />
8181

@@ -85,10 +85,10 @@
8585
Grid.Column="1"
8686
VerticalAlignment="Stretch"
8787
VerticalContentAlignment="Stretch"
88-
x:Load="{x:Bind Item.ShowDriveDetails, Mode=OneWay}"
88+
x:Load="{x:Bind ShowDriveUsage, Mode=OneWay}"
8989
AutomationProperties.AccessibilityView="Raw"
90-
Maximum="{x:Bind Item.MaxSpace.GigaBytes, Mode=OneWay}"
91-
Value="{x:Bind Item.SpaceUsed.GigaBytes, Mode=OneWay}" />
90+
Maximum="{x:Bind TotalSpace.GigaBytes, Mode=OneWay}"
91+
Value="{x:Bind SpaceUsed.GigaBytes, Mode=OneWay}" />
9292

9393
<Button
9494
x:Name="GoToStorageSense"
@@ -100,12 +100,12 @@
100100
Padding="0"
101101
HorizontalContentAlignment="Center"
102102
VerticalContentAlignment="Center"
103-
x:Load="{x:Bind Item.ShowStorageSense, Mode=OneWay}"
103+
x:Load="{x:Bind ShowStorageSense, Mode=OneWay}"
104104
AutomationProperties.Name="{helpers:ResourceString Name=OpenStorageSense}"
105105
Background="Transparent"
106106
BorderBrush="Transparent"
107107
Click="GoToStorageSense_Click"
108-
Tag="{x:Bind Item.Path}"
108+
Tag="{x:Bind Path}"
109109
ToolTipService.ToolTip="{helpers:ResourceString Name=OpenStorageSense}">
110110
<FontIcon
111111
HorizontalAlignment="Center"
@@ -121,13 +121,13 @@
121121
Grid.ColumnSpan="2"
122122
HorizontalAlignment="Stretch"
123123
VerticalAlignment="Center"
124-
x:Load="{x:Bind Item.ShowDriveDetails, Mode=OneWay}"
124+
x:Load="{x:Bind ShowDriveUsage, Mode=OneWay}"
125125
x:Phase="1"
126126
FontSize="12"
127-
Text="{x:Bind Item.SpaceText, Mode=OneWay}"
127+
Text="{x:Bind UsageText, Mode=OneWay}"
128128
TextTrimming="CharacterEllipsis"
129129
TextWrapping="NoWrap"
130-
ToolTipService.ToolTip="{x:Bind Item.SpaceText, Mode=OneWay}" />
130+
ToolTipService.ToolTip="{x:Bind UsageText, Mode=OneWay}" />
131131
</Grid>
132132
</Button>
133133
</DataTemplate>

src/Files.App/UserControls/Widgets/NetworkLocationsWidget.xaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@
5858
VerticalAlignment="Stretch"
5959
HorizontalContentAlignment="Stretch"
6060
VerticalContentAlignment="Stretch"
61-
AutomationProperties.Name="{x:Bind Item.Text, Mode=OneWay}"
61+
AutomationProperties.Name="{x:Bind Text, Mode=OneWay}"
6262
Click="Button_Click"
6363
CornerRadius="{StaticResource ControlCornerRadius}"
6464
DataContext="{x:Bind}"
6565
PointerPressed="Button_PointerPressed"
6666
RightTapped="Button_RightTapped"
67-
Tag="{x:Bind Item.Path}"
68-
ToolTipService.ToolTip="{x:Bind Item.Text, Mode=OneWay}">
67+
Tag="{x:Bind Path}"
68+
ToolTipService.ToolTip="{x:Bind Text, Mode=OneWay}">
6969
<Grid
7070
Margin="8"
7171
HorizontalAlignment="Stretch"
@@ -101,7 +101,7 @@
101101
VerticalAlignment="Center"
102102
FontSize="14"
103103
FontWeight="Medium"
104-
Text="{x:Bind Item.Text, Mode=OneWay}"
104+
Text="{x:Bind Text, Mode=OneWay}"
105105
TextTrimming="CharacterEllipsis"
106106
TextWrapping="NoWrap" />
107107

@@ -111,24 +111,24 @@
111111
Grid.Column="1"
112112
VerticalAlignment="Stretch"
113113
VerticalContentAlignment="Stretch"
114-
x:Load="{x:Bind Item.ShowDriveDetails, Mode=OneWay}"
114+
x:Load="{x:Bind ShowDriveUsage, Mode=OneWay}"
115115
AutomationProperties.AccessibilityView="Raw"
116-
Maximum="{x:Bind Item.MaxSpace.GigaBytes, Mode=OneWay}"
117-
Value="{x:Bind Item.SpaceUsed.GigaBytes, Mode=OneWay}" />
116+
Maximum="{x:Bind TotalSpace.GigaBytes, Mode=OneWay}"
117+
Value="{x:Bind SpaceUsed.GigaBytes, Mode=OneWay}" />
118118

119119
<TextBlock
120120
x:Name="DriveSpaceTextBlock"
121121
Grid.Row="2"
122122
Grid.Column="1"
123123
HorizontalAlignment="Stretch"
124124
VerticalAlignment="Center"
125-
x:Load="{x:Bind Item.ShowDriveDetails, Mode=OneWay}"
125+
x:Load="{x:Bind ShowDriveUsage, Mode=OneWay}"
126126
x:Phase="1"
127127
FontSize="12"
128-
Text="{x:Bind Item.SpaceText, Mode=OneWay}"
128+
Text="{x:Bind UsageText, Mode=OneWay}"
129129
TextTrimming="CharacterEllipsis"
130130
TextWrapping="NoWrap"
131-
ToolTipService.ToolTip="{x:Bind Item.SpaceText, Mode=OneWay}" />
131+
ToolTipService.ToolTip="{x:Bind UsageText, Mode=OneWay}" />
132132
</Grid>
133133
</Button>
134134
</DataTemplate>

src/Files.App/ViewModels/UserControls/Widgets/DrivesWidgetViewModel.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
using System.Windows.Input;
88
using Windows.System;
99
using Windows.UI.Core;
10+
using Windows.Win32;
11+
using Windows.Win32.Foundation;
12+
using Windows.Win32.System.Com;
13+
using Windows.Win32.System.WinRT;
14+
using Windows.Win32.UI.Shell;
1015

1116
namespace Files.App.ViewModels.UserControls.Widgets
1217
{
@@ -58,6 +63,14 @@ public Task RefreshWidgetAsync()
5863

5964
await foreach (IWindowsStorable folder in HomePageContext.HomeFolder.GetLogicalDrivesAsync(default))
6065
{
66+
Items.Insert(
67+
Items.Count,
68+
new()
69+
{
70+
Item = (IFolder)folder,
71+
Text = folder.GetDisplayName(SIGDN.SIGDN_PARENTRELATIVEFORUI),
72+
Path = folder.GetDisplayName(SIGDN.SIGDN_FILESYSPATH),
73+
});
6174
}
6275
});
6376
}
@@ -92,8 +105,6 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
92105
StringComparison.OrdinalIgnoreCase))
93106
.FirstOrDefault();
94107

95-
var options = drive?.Item.MenuOptions;
96-
97108
return new List<ContextMenuFlyoutItemViewModel>()
98109
{
99110
new ContextMenuFlyoutItemViewModelBuilder(CommandManager.OpenInNewTabFromHomeAction)
@@ -129,7 +140,7 @@ public override List<ContextMenuFlyoutItemViewModel> GetItemMenuItems(WidgetCard
129140
Text = Strings.Eject.GetLocalizedResource(),
130141
Command = EjectDeviceCommand,
131142
CommandParameter = item,
132-
ShowItem = options?.ShowEjectDevice ?? false
143+
ShowItem = false
133144
},
134145
new()
135146
{
@@ -184,7 +195,7 @@ private void ExecuteEjectDeviceCommand(WidgetDriveCardItem? item)
184195
if (item is null)
185196
return;
186197

187-
DriveHelpers.EjectDeviceAsync(item.Item.Path);
198+
DriveHelpers.EjectDeviceAsync(item.Path);
188199
}
189200

190201
private void ExecuteOpenPropertiesCommand(WidgetDriveCardItem? item)
@@ -214,33 +225,19 @@ private void ExecuteDisconnectNetworkDriveCommand(WidgetDriveCardItem? item)
214225

215226
// Event methods
216227

217-
private async void UserSettingsService_OnSettingChangedEvent(object? sender, SettingChangedEventArgs e)
228+
private async void Items_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
218229
{
219-
if (e.SettingName == nameof(UserSettingsService.FoldersSettingsService.SizeUnitFormat))
220-
await RefreshWidgetAsync();
230+
if (e.Action is NotifyCollectionChangedAction.Add)
231+
{
232+
foreach (WidgetDriveCardItem cardItem in e.NewItems!)
233+
await cardItem.LoadCardThumbnailAsync();
234+
}
221235
}
222236

223-
private async void Drives_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
237+
private async void UserSettingsService_OnSettingChangedEvent(object? sender, SettingChangedEventArgs e)
224238
{
225-
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
226-
{
227-
foreach (DriveItem drive in DrivesViewModel.Drives.ToList().Cast<DriveItem>())
228-
{
229-
if (!Items.Any(x => x.Item == drive) && drive.Type is not DriveType.VirtualDrive and not DriveType.Network)
230-
{
231-
var cardItem = new WidgetDriveCardItem(drive);
232-
Items.AddSorted(cardItem);
233-
234-
await cardItem.LoadCardThumbnailAsync();
235-
}
236-
}
237-
238-
foreach (WidgetDriveCardItem driveCard in Items.ToList())
239-
{
240-
if (!DrivesViewModel.Drives.Contains(driveCard.Item))
241-
Items.Remove(driveCard);
242-
}
243-
});
239+
if (e.SettingName == nameof(UserSettingsService.FoldersSettingsService.SizeUnitFormat))
240+
await RefreshWidgetAsync();
244241
}
245242

246243
// Disposer

0 commit comments

Comments
 (0)