Skip to content

Commit ea175f7

Browse files
authored
Cleaned commands code (#8115)
1 parent 9aca493 commit ea175f7

14 files changed

+288
-244
lines changed

src/Files/Helpers/AdaptiveLayoutHelpers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, Ite
1616

1717
if (userSettingsService.PreferencesSettingsService.AreLayoutPreferencesPerFolder && userSettingsService.PreferencesSettingsService.AdaptiveLayoutEnabled && !folderSettings.LayoutPreference.IsAdaptiveLayoutOverridden)
1818
{
19-
Action layoutDetails = () => folderSettings.ToggleLayoutModeDetailsView.Execute(false);
20-
Action layoutTiles = () => folderSettings.ToggleLayoutModeTiles.Execute(false);
21-
Action layoutGridView = () => folderSettings.ToggleLayoutModeGridView.Execute(folderSettings.GridViewSize);
19+
Action layoutDetails = () => folderSettings.ToggleLayoutModeDetailsView(false);
20+
Action layoutTiles = () => folderSettings.ToggleLayoutModeTiles(false);
21+
Action layoutGridView = () => folderSettings.ToggleLayoutModeGridView(folderSettings.GridViewSize);
2222

2323
bool desktopIniFound = false;
2424

src/Files/Helpers/ContextFlyoutItemHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseLayoutMenuItems(Curren
118118
ShowInSearchPage = true,
119119
ShowInFtpPage = true,
120120
ShowInZipPage = true,
121-
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeDetailsView,
121+
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeDetailsViewCommand,
122122
CommandParameter = true,
123123
KeyboardAcceleratorTextOverride = "BaseLayoutContextFlyoutDetails/KeyboardAcceleratorTextOverride".GetLocalized(),
124124
KeyboardAccelerator = new KeyboardAccelerator{Key = VirtualKey.Number1, Modifiers = VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift, IsEnabled = false}
@@ -132,7 +132,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseLayoutMenuItems(Curren
132132
ShowInSearchPage = true,
133133
ShowInFtpPage = true,
134134
ShowInZipPage = true,
135-
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeTiles,
135+
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeTilesCommand,
136136
CommandParameter = true,
137137
KeyboardAcceleratorTextOverride = "BaseLayoutContextFlyoutTiles/KeyboardAcceleratorTextOverride".GetLocalized(),
138138
KeyboardAccelerator = new KeyboardAccelerator{Key = VirtualKey.Number2, Modifiers = VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift, IsEnabled = false}
@@ -146,7 +146,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseLayoutMenuItems(Curren
146146
ShowInSearchPage = true,
147147
ShowInFtpPage = true,
148148
ShowInZipPage = true,
149-
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeGridViewSmall,
149+
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeGridViewSmallCommand,
150150
CommandParameter = true,
151151
KeyboardAcceleratorTextOverride = "BaseLayoutContextFlyoutSmallIcons/KeyboardAcceleratorTextOverride".GetLocalized(),
152152
KeyboardAccelerator = new KeyboardAccelerator{Key = VirtualKey.Number3, Modifiers = VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift, IsEnabled = false}
@@ -160,7 +160,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseLayoutMenuItems(Curren
160160
ShowInSearchPage = true,
161161
ShowInFtpPage = true,
162162
ShowInZipPage = true,
163-
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeGridViewMedium,
163+
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeGridViewMediumCommand,
164164
CommandParameter = true,
165165
KeyboardAcceleratorTextOverride = "BaseLayoutContextFlyoutMediumIcons/KeyboardAcceleratorTextOverride".GetLocalized(),
166166
KeyboardAccelerator = new KeyboardAccelerator{Key = VirtualKey.Number4, Modifiers = VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift, IsEnabled = false}
@@ -174,7 +174,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseLayoutMenuItems(Curren
174174
ShowInSearchPage = true,
175175
ShowInFtpPage = true,
176176
ShowInZipPage = true,
177-
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeGridViewLarge,
177+
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeGridViewLargeCommand,
178178
CommandParameter = true,
179179
KeyboardAcceleratorTextOverride = "BaseLayoutContextFlyoutLargeIcons/KeyboardAcceleratorTextOverride".GetLocalized(),
180180
KeyboardAccelerator = new KeyboardAccelerator{Key = VirtualKey.Number5, Modifiers = VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift, IsEnabled = false}
@@ -189,7 +189,7 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseLayoutMenuItems(Curren
189189
ShowInSearchPage = true,
190190
ShowInFtpPage = true,
191191
ShowInZipPage = true,
192-
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeColumnView,
192+
Command = currentInstanceViewModel.FolderSettings.ToggleLayoutModeColumnViewCommand,
193193
CommandParameter = true,
194194
KeyboardAcceleratorTextOverride = "BaseLayoutContextFlyoutColumn/KeyboardAcceleratorTextOverride".GetLocalized(),
195195
KeyboardAccelerator = new KeyboardAccelerator{Key = VirtualKey.Number6, Modifiers = VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift, IsEnabled = false}

src/Files/UserControls/InnerNavigationToolbar.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@
586586
HorizontalContentAlignment="Center"
587587
VerticalContentAlignment="Center"
588588
AutomationProperties.Name="{helpers:ResourceString Name=Details}"
589-
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeDetailsView, Mode=OneWay}"
589+
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeDetailsViewCommand, Mode=OneWay}"
590590
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
591591
CornerRadius="{StaticResource ControlCornerRadius}"
592592
IsChecked="{x:Bind ViewModel.InstanceViewModel.FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=DetailsInfo}"
@@ -614,7 +614,7 @@
614614
HorizontalContentAlignment="Center"
615615
VerticalContentAlignment="Center"
616616
AutomationProperties.Name="{helpers:ResourceString Name=Tiles}"
617-
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeTiles, Mode=OneWay}"
617+
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeTilesCommand, Mode=OneWay}"
618618
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
619619
CornerRadius="{StaticResource ControlCornerRadius}"
620620
IsChecked="{x:Bind ViewModel.InstanceViewModel.FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=TilesInfo}"
@@ -642,7 +642,7 @@
642642
HorizontalContentAlignment="Center"
643643
VerticalContentAlignment="Center"
644644
AutomationProperties.Name="Small Icons"
645-
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewSmall, Mode=OneWay}"
645+
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewSmallCommand, Mode=OneWay}"
646646
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
647647
CornerRadius="{StaticResource ControlCornerRadius}"
648648
IsChecked="{x:Bind ViewModel.InstanceViewModel.FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=SmallGridInfo}"
@@ -679,7 +679,7 @@
679679
HorizontalContentAlignment="Center"
680680
VerticalContentAlignment="Center"
681681
AutomationProperties.Name="Medium Icons"
682-
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewMedium, Mode=OneWay}"
682+
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewMediumCommand, Mode=OneWay}"
683683
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
684684
CornerRadius="{StaticResource ControlCornerRadius}"
685685
Foreground="{ThemeResource TextFillColorPrimaryBrush}"
@@ -708,7 +708,7 @@
708708
HorizontalContentAlignment="Center"
709709
VerticalContentAlignment="Center"
710710
AutomationProperties.Name="Large Icons"
711-
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewLarge, Mode=OneWay}"
711+
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewLargeCommand, Mode=OneWay}"
712712
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
713713
CornerRadius="{StaticResource ControlCornerRadius}"
714714
IsChecked="{x:Bind ViewModel.InstanceViewModel.FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=LargeGridInfo}"
@@ -736,7 +736,7 @@
736736
HorizontalContentAlignment="Center"
737737
VerticalContentAlignment="Center"
738738
AutomationProperties.Name="{helpers:ResourceString Name=Columns}"
739-
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeColumnView, Mode=OneWay}"
739+
Command="{x:Bind ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeColumnViewCommand, Mode=OneWay}"
740740
CommandParameter="{xh:SystemTypeToXaml Bool=True}"
741741
CornerRadius="{StaticResource ControlCornerRadius}"
742742
IsChecked="{x:Bind ViewModel.InstanceViewModel.FolderSettings.LayoutModeInformation, Converter={StaticResource LayoutModeConverter}, Mode=OneWay, ConverterParameter=ColumnInfo}"

src/Files/UserControls/InnerNavigationToolbar.xaml.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ private void NewEmptySpace_Opening(object sender, object e)
192192
}
193193

194194
private void NavToolbarDetailsHeader_Tapped(object sender, TappedRoutedEventArgs e)
195-
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeDetailsView.Execute(true);
195+
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeDetailsView(true);
196196
private void NavToolbarTilesHeader_Tapped(object sender, TappedRoutedEventArgs e)
197-
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeTiles.Execute(true);
197+
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeTiles(true);
198198
private void NavToolbarSmallIconsHeader_Tapped(object sender, TappedRoutedEventArgs e)
199-
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewSmall.Execute(true);
199+
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewSmall(true);
200200
private void NavToolbarMediumIconsHeader_Tapped(object sender, TappedRoutedEventArgs e)
201-
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewMedium.Execute(true);
201+
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewMedium(true);
202202
private void NavToolbarLargeIconsHeader_Tapped(object sender, TappedRoutedEventArgs e)
203-
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewLarge.Execute(true);
203+
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeGridViewLarge(true);
204204
private void NavToolbarColumnsHeader_Tapped(object sender, TappedRoutedEventArgs e)
205-
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeColumnView.Execute(true);
205+
=> ViewModel.InstanceViewModel.FolderSettings.ToggleLayoutModeColumnView(true);
206206
}
207207
}

src/Files/UserControls/Widgets/FolderWidget.xaml.cs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Linq;
1212
using System.Runtime.CompilerServices;
1313
using System.Threading.Tasks;
14+
using System.Windows.Input;
1415
using Windows.ApplicationModel.Core;
1516
using Windows.Storage;
1617
using Windows.System;
@@ -50,7 +51,7 @@ public BitmapImage Icon
5051
public bool IsUserCreatedLibrary => Library != null && !LibraryHelper.IsDefaultLibrary(Library.Path);
5152
public LibraryLocationItem Library { get; set; }
5253
public string Path { get; set; }
53-
public RelayCommand<LibraryCardItem> SelectCommand { get; set; }
54+
public ICommand SelectCommand { get; set; }
5455
public string Text { get; set; }
5556
}
5657

@@ -65,6 +66,8 @@ public FolderWidget()
6566
{
6667
InitializeComponent();
6768

69+
LibraryCardCommand = new AsyncRelayCommand<LibraryCardItem>(OpenLibraryCard);
70+
6871
Loaded += FolderWidget_Loaded;
6972
Unloaded += FolderWidget_Unloaded;
7073
}
@@ -87,31 +90,11 @@ public FolderWidget()
8790

8891
public bool IsWidgetSettingEnabled => UserSettingsService.WidgetsSettingsService.ShowFoldersWidget;
8992

90-
public RelayCommand<LibraryCardItem> LibraryCardClicked => new RelayCommand<LibraryCardItem>(async (item) =>
91-
{
92-
if (string.IsNullOrEmpty(item.Path))
93-
{
94-
return;
95-
}
96-
if (item.IsLibrary && item.Library.IsEmpty)
97-
{
98-
// TODO: show message?
99-
return;
100-
}
93+
public ICommand LibraryCardCommand { get; }
10194

102-
var ctrlPressed = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
103-
if (ctrlPressed)
104-
{
105-
await NavigationHelpers.OpenPathInNewTab(item.Path);
106-
return;
107-
}
108-
109-
LibraryCardInvoked?.Invoke(this, new LibraryCardInvokedEventArgs { Path = item.Path });
110-
});
95+
public ICommand ShowCreateNewLibraryDialogCommand { get; } = new RelayCommand(LibraryHelper.ShowCreateNewLibraryDialog);
11196

112-
public RelayCommand ShowCreateNewLibraryDialogCommand => new RelayCommand(LibraryHelper.ShowCreateNewLibraryDialog);
113-
114-
public readonly RelayCommand ShowRestoreLibrariesDialogCommand = new RelayCommand(LibraryHelper.ShowRestoreDefaultLibrariesDialog);
97+
public readonly ICommand ShowRestoreLibrariesDialogCommand = new RelayCommand(LibraryHelper.ShowRestoreDefaultLibrariesDialog);
11598

11699
public bool ShowMultiPaneControls
117100
{
@@ -145,7 +128,7 @@ private async Task GetItemsAddedIcon()
145128
{
146129
foreach (var item in ItemsAdded.ToList()) // ToList() is necessary
147130
{
148-
item.SelectCommand = LibraryCardClicked;
131+
item.SelectCommand = LibraryCardCommand;
149132
item.AutomationProperties = item.Text;
150133
await this.LoadLibraryIcon(item);
151134
}
@@ -256,5 +239,27 @@ private async Task LoadLibraryIcon(LibraryCardItem item)
256239
item.Icon = await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => item.IconData.ToBitmapAsync());
257240
}
258241
}
242+
243+
private async Task OpenLibraryCard(LibraryCardItem item)
244+
{
245+
if (string.IsNullOrEmpty(item.Path))
246+
{
247+
return;
248+
}
249+
if (item.IsLibrary && item.Library.IsEmpty)
250+
{
251+
// TODO: show message?
252+
return;
253+
}
254+
255+
var ctrlPressed = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
256+
if (ctrlPressed)
257+
{
258+
await NavigationHelpers.OpenPathInNewTab(item.Path);
259+
return;
260+
}
261+
262+
LibraryCardInvoked?.Invoke(this, new LibraryCardInvokedEventArgs { Path = item.Path });
263+
}
259264
}
260265
}

0 commit comments

Comments
 (0)