Skip to content

Commit c67f241

Browse files
authored
Added a toolbar button to empty recycle bin (#6693)
1 parent 223b7eb commit c67f241

File tree

6 files changed

+89
-31
lines changed

6 files changed

+89
-31
lines changed

Files/BaseLayout.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using Windows.ApplicationModel.DataTransfer;
2727
using Windows.ApplicationModel.DataTransfer.DragDrop;
2828
using Windows.Foundation;
29+
using Windows.Foundation.Collections;
2930
using Windows.Storage;
3031
using Windows.System;
3132
using Windows.UI.Core;
@@ -108,10 +109,19 @@ public CollectionViewSource CollectionViewSource
108109
get => collectionViewSource;
109110
set
110111
{
111-
if (collectionViewSource != value)
112+
if (collectionViewSource == value)
112113
{
113-
collectionViewSource = value;
114-
NotifyPropertyChanged(nameof(CollectionViewSource));
114+
return;
115+
}
116+
if (collectionViewSource?.View is not null)
117+
{
118+
collectionViewSource.View.VectorChanged -= View_VectorChanged;
119+
}
120+
collectionViewSource = value;
121+
NotifyPropertyChanged(nameof(CollectionViewSource));
122+
if (collectionViewSource?.View is not null)
123+
{
124+
collectionViewSource.View.VectorChanged += View_VectorChanged;
115125
}
116126
}
117127
}
@@ -1098,6 +1108,11 @@ private void ItemManipulationModel_RefreshItemsOpacityInvoked(object sender, Eve
10981108
}
10991109
}
11001110

1111+
private void View_VectorChanged(IObservableVector<object> sender, IVectorChangedEventArgs @event)
1112+
{
1113+
ParentShellPageInstance.NavToolbarViewModel.HasItem = CollectionViewSource.View.Any();
1114+
}
1115+
11011116
virtual public void StartRenameItem() { }
11021117

11031118
private ListedItem preRenamingItem = null;

Files/Strings/en-US/Resources.resw

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<root>
3-
<!--
4-
Microsoft ResX Schema
5-
3+
<!--
4+
Microsoft ResX Schema
5+
66
Version 2.0
7-
8-
The primary goals of this format is to allow a simple XML format
9-
that is mostly human readable. The generation and parsing of the
10-
various data types are done through the TypeConverter classes
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
1111
associated with the data types.
12-
12+
1313
Example:
14-
14+
1515
... ado.net/XML headers & schema ...
1616
<resheader name="resmimetype">text/microsoft-resx</resheader>
1717
<resheader name="version">2.0</resheader>
@@ -26,36 +26,36 @@
2626
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
2727
<comment>This is a comment</comment>
2828
</data>
29-
30-
There are any number of "resheader" rows that contain simple
29+
30+
There are any number of "resheader" rows that contain simple
3131
name/value pairs.
32-
33-
Each data row contains a name, and value. The row also contains a
34-
type or mimetype. Type corresponds to a .NET class that support
35-
text/value conversion through the TypeConverter architecture.
36-
Classes that don't support this are serialized and stored with the
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
3737
mimetype set.
38-
39-
The mimetype is used for serialized objects, and tells the
40-
ResXResourceReader how to depersist the object. This is currently not
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
4141
extensible. For a given mimetype the value must be set accordingly:
42-
43-
Note - application/x-microsoft.net.object.binary.base64 is the format
44-
that the ResXResourceWriter will generate, however the reader can
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
4545
read any of the formats listed below.
46-
46+
4747
mimetype: application/x-microsoft.net.object.binary.base64
48-
value : The object must be serialized with
48+
value : The object must be serialized with
4949
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
5050
: and then encoded with base64 encoding.
51-
51+
5252
mimetype: application/x-microsoft.net.object.soap.base64
53-
value : The object must be serialized with
53+
value : The object must be serialized with
5454
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
5555
: and then encoded with base64 encoding.
5656
5757
mimetype: application/x-microsoft.net.object.bytearray.base64
58-
value : The object must be serialized into a byte array
58+
value : The object must be serialized into a byte array
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
@@ -2779,7 +2779,10 @@ We use App Center to keep track of app usage, find bugs, and fix crashes. All in
27792779
<data name="SettingsImportErrorTitle" xml:space="preserve">
27802780
<value>Error importing settings</value>
27812781
</data>
2782-
<data name="Sidebar" xml:space="preserve">
2782+
<data name="EmptyRecycleBin" xml:space="preserve">
2783+
<value>Empty Recycle Bin</value>
2784+
</data>
2785+
<data name="Sidebar" xml:space="preserve">
27832786
<value>Sidebar</value>
27842787
</data>
27852788
<data name="ChooseCustomIcon" xml:space="preserve">

Files/UserControls/InnerNavigationToolbar.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@
180180
<local:ColoredIcon BaseLayerGlyph="&#xF035;" OverlayLayerGlyph="&#xF036;" />
181181
</AppBarButton.Content>
182182
</AppBarButton>
183+
<AppBarSeparator x:Name="AdditionalActionSeparator" x:Load="{x:Bind ViewModel.HasAdditionnalAction, Mode=OneWay}" />
184+
<AppBarButton
185+
x:Name="EmptyRecycleBinButton"
186+
Label="{helpers:ResourceString Name=EmptyRecycleBin}"
187+
ToolTipService.ToolTip="{helpers:ResourceString Name=EmptyRecycleBin}"
188+
IsEnabled="{x:Bind ViewModel.CanEmptyRecycleBin, Mode=OneWay}"
189+
Command="{x:Bind ViewModel.EmptyRecycleBinCommand, Mode=OneWay}"
190+
Visibility="{x:Bind ViewModel.InstanceViewModel.IsPageTypeRecycleBin, Mode=OneWay}">
191+
<AppBarButton.Icon>
192+
<FontIcon Glyph="&#xEF88;" FontFamily="{StaticResource RecycleBinIcons}" />
193+
</AppBarButton.Icon>
194+
</AppBarButton>
183195
</CommandBar.PrimaryCommands>
184196
</CommandBar>
185197
<CommandBar

Files/ViewModels/NavToolbarViewModel.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,12 @@ public void SwitchSearchBoxVisibility()
632632
}
633633
}
634634

635+
public void UpdateAdditionnalActions()
636+
{
637+
OnPropertyChanged(nameof(HasAdditionnalAction));
638+
OnPropertyChanged(nameof(CanEmptyRecycleBin));
639+
}
640+
635641
private NavigationToolbar NavToolbar => (Window.Current.Content as Frame).FindDescendant<NavigationToolbar>();
636642

637643
#region WidgetsPage Widgets
@@ -745,6 +751,8 @@ public void SearchRegion_LostFocus(object sender, RoutedEventArgs e)
745751

746752
public ICommand CutCommand { get; set; }
747753

754+
public ICommand EmptyRecycleBinCommand { get; set; }
755+
748756
public async Task SetPathBoxDropDownFlyoutAsync(MenuFlyout flyout, PathBoxItem pathItem, IShellPage shellPage)
749757
{
750758
var nextPathItemTitle = PathComponents[PathComponents.IndexOf(pathItem) + 1].Title;
@@ -1001,6 +1009,20 @@ public async void SetAddressBarSuggestions(AutoSuggestBox sender, IShellPage she
10011009
}
10021010
}
10031011

1012+
private bool hasItem = true;
1013+
public bool HasItem
1014+
{
1015+
get => hasItem;
1016+
set
1017+
{
1018+
if (SetProperty(ref hasItem, value))
1019+
{
1020+
OnPropertyChanged(nameof(CanEmptyRecycleBin));
1021+
}
1022+
}
1023+
1024+
}
1025+
10041026
private List<ListedItem> selectedItems;
10051027

10061028
public List<ListedItem> SelectedItems
@@ -1017,9 +1039,12 @@ public List<ListedItem> SelectedItems
10171039
}
10181040
}
10191041

1042+
public bool HasAdditionnalAction => InstanceViewModel.IsPageTypeRecycleBin;
1043+
10201044
public bool CanCopy => SelectedItems is not null && SelectedItems.Any();
10211045
public bool CanShare => SelectedItems is not null && SelectedItems.Any() && DataTransferManager.IsSupported() && !SelectedItems.Any(x => (x.IsShortcutItem && !x.IsLinkItem) || x.IsHiddenItem || (x.PrimaryItemAttribute == StorageItemTypes.Folder && !x.IsZipItem));
10221046
public bool CanRename => SelectedItems is not null && SelectedItems.Count == 1;
1047+
public bool CanEmptyRecycleBin => InstanceViewModel.IsPageTypeRecycleBin && HasItem;
10231048

10241049
public void Dispose()
10251050
{

Files/Views/ColumnShellPage.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ private void InitToolbarCommands()
220220
NavToolbarViewModel.Share = new RelayCommand(() => SlimContentPage?.CommandsViewModel.ShareItemCommand.Execute(null));
221221
NavToolbarViewModel.DeleteCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DeleteItemCommand.Execute(null));
222222
NavToolbarViewModel.CutCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.CutItemCommand.Execute(null));
223+
NavToolbarViewModel.EmptyRecycleBinCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.EmptyRecycleBinCommand.Execute(null));
223224
}
224225

225226
private void FolderSettings_LayoutPreferencesUpdateRequired(object sender, LayoutPreferenceEventArgs e)

Files/Views/ModernShellPage.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ private void InitToolbarCommands()
206206
NavToolbarViewModel.Share = new RelayCommand(() => SlimContentPage?.CommandsViewModel.ShareItemCommand.Execute(null));
207207
NavToolbarViewModel.DeleteCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.DeleteItemCommand.Execute(null));
208208
NavToolbarViewModel.CutCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.CutItemCommand.Execute(null));
209+
NavToolbarViewModel.EmptyRecycleBinCommand = new RelayCommand(() => SlimContentPage?.CommandsViewModel.EmptyRecycleBinCommand.Execute(null));
209210
}
210211

211212
private void ModernShellPage_RefreshWidgetsRequested(object sender, EventArgs e)
@@ -616,6 +617,7 @@ private async void ItemDisplayFrame_Navigated(object sender, NavigationEventArgs
616617
ContentPage = await GetContentOrNullAsync();
617618
NavToolbarViewModel.SearchBox.Query = string.Empty;
618619
NavToolbarViewModel.IsSearchBoxVisible = false;
620+
NavToolbarViewModel.UpdateAdditionnalActions();
619621
if (ItemDisplayFrame.CurrentSourcePageType == (typeof(DetailsLayoutBrowser))
620622
|| ItemDisplayFrame.CurrentSourcePageType == typeof(GridViewBrowser))
621623
{

0 commit comments

Comments
 (0)