Skip to content

Commit 40af234

Browse files
authored
Code Quality: Toolbar toggle button for Shelf (#16678)
1 parent 6798de2 commit 40af234

File tree

9 files changed

+107
-34
lines changed

9 files changed

+107
-34
lines changed

src/Files.App/Data/Contracts/IAppearanceSettingsService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,10 @@ public interface IAppearanceSettingsService : IBaseSettingsService, INotifyPrope
111111
/// Gets or sets a value whether the home button should be displayed.
112112
/// </summary>
113113
bool ShowHomeButton { get; set; }
114+
115+
/// <summary>
116+
/// Gets or sets a value whether the shelf pane toggle button should be displayed.
117+
/// </summary>
118+
bool ShowShelfPaneToggleButton{ get; set; }
114119
}
115120
}

src/Files.App/Services/Settings/AppearanceSettingsService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ public bool ShowHomeButton
152152
set => Set(value);
153153
}
154154

155+
/// <inheritdoc/>
156+
public bool ShowShelfPaneToggleButton
157+
{
158+
get => Get(false);
159+
set => Set(value);
160+
}
161+
155162
protected override void RaiseOnSettingChangedEvent(object sender, SettingChangedEventArgs e)
156163
{
157164
base.RaiseOnSettingChangedEvent(sender, e);

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,7 +3969,7 @@
39693969
<value>Navigate to the home page</value>
39703970
</data>
39713971
<data name="ShowHomeButton" xml:space="preserve">
3972-
<value>Show Home in address bar</value>
3972+
<value>Show home button in address bar</value>
39733973
</data>
39743974
<data name="Toolbars" xml:space="preserve">
39753975
<value>Toolbars</value>
@@ -4019,8 +4019,11 @@
40194019
<data name="AlwaysSwitchToNewlyOpenedTab" xml:space="preserve">
40204020
<value>Always switch focus to newly created tab</value>
40214021
</data>
4022-
<data name="ShowShelfPane" xml:space="preserve">
4023-
<value>Show Shelf Pane</value>
4022+
<data name="ToggleShelfPane" xml:space="preserve">
4023+
<value>Toggle the shelf pane</value>
4024+
</data>
4025+
<data name="ShowShelfPaneButtonInAddressBar" xml:space="preserve">
4026+
<value>Show shelf pane toggle in address bar</value>
40244027
</data>
40254028
<data name="Shelf" xml:space="preserve">
40264029
<value>Shelf</value>
@@ -4033,7 +4036,7 @@
40334036
<value>Remove from shelf</value>
40344037
</data>
40354038
<data name="AddToShelf" xml:space="preserve">
4036-
<value>Add to Shelf</value>
4039+
<value>Add to shelf</value>
40374040
<comment>Tooltip that displays when dragging items to the Shelf Pane</comment>
40384041
</data>
40394042
</root>

src/Files.App/UserControls/AddressToolbar.xaml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
66
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
77
xmlns:contract8Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,8)"
8+
xmlns:controls="using:Files.App.Controls"
89
xmlns:converters="using:Files.App.Converters"
910
xmlns:converters1="using:CommunityToolkit.WinUI.UI.Converters"
1011
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -469,7 +470,10 @@
469470
Visibility="{x:Bind converters:MultiBooleanConverter.OrConvertToVisibility(ShowSearchBox, ViewModel.IsSearchBoxVisible), Mode=OneWay}" />
470471

471472
<!-- Right Side Action Buttons -->
472-
<StackPanel Grid.Column="3" Orientation="Horizontal">
473+
<StackPanel
474+
Grid.Column="3"
475+
Orientation="Horizontal"
476+
Spacing="4">
473477

474478
<!-- Mini Search Button -->
475479
<Button
@@ -485,6 +489,27 @@
485489
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.SearchButtonGlyph, Mode=OneWay}" />
486490
</Button>
487491

492+
<!-- Shelf Pane -->
493+
<ToggleButton
494+
x:Name="OpenShelfPaneButton"
495+
Width="36"
496+
Height="32"
497+
Padding="0"
498+
x:Load="{x:Bind ViewModel.ShowShelfPaneToggleButton, Mode=OneWay}"
499+
AccessKeyInvoked="Button_AccessKeyInvoked"
500+
AutomationProperties.Name="{helpers:ResourceString Name=ToggleShelfPane}"
501+
Background="Transparent"
502+
BorderBrush="Transparent"
503+
IsChecked="{x:Bind ViewModel.ShowShelfPane, Mode=TwoWay}"
504+
ToolTipService.ToolTip="{helpers:ResourceString Name=ToggleShelfPane}">
505+
<controls:ThemedIcon
506+
Width="20"
507+
Height="20"
508+
HorizontalAlignment="Center"
509+
VerticalAlignment="Center"
510+
Style="{StaticResource App.ThemedIcons.Shelf}" />
511+
</ToggleButton>
512+
488513
<!-- Status Center -->
489514
<Button
490515
x:Name="ShowStatusCenterButton"

src/Files.App/ViewModels/Settings/AdvancedViewModel.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,20 +366,6 @@ public bool ShowFlattenOptions
366366
OnPropertyChanged();
367367
}
368368
}
369-
370-
// TODO remove when feature is marked as stable
371-
public bool ShowShelfPane
372-
{
373-
get => UserSettingsService.GeneralSettingsService.ShowShelfPane;
374-
set
375-
{
376-
if (value == UserSettingsService.GeneralSettingsService.ShowShelfPane)
377-
return;
378-
379-
UserSettingsService.GeneralSettingsService.ShowShelfPane = value;
380-
OnPropertyChanged();
381-
}
382-
}
383369

384370
public async Task OpenFilesOnWindowsStartupAsync()
385371
{

src/Files.App/ViewModels/Settings/AppearanceViewModel.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,5 +315,24 @@ public bool ShowHomeButton
315315
}
316316
}
317317
}
318+
319+
public bool ShowShelfPaneToggleButton
320+
{
321+
get => UserSettingsService.AppearanceSettingsService.ShowShelfPaneToggleButton;
322+
set
323+
{
324+
if (value != UserSettingsService.AppearanceSettingsService.ShowShelfPaneToggleButton)
325+
{
326+
UserSettingsService.AppearanceSettingsService.ShowShelfPaneToggleButton = value;
327+
328+
OnPropertyChanged();
329+
}
330+
}
331+
}
332+
333+
public bool IsAppEnvironmentDev
334+
{
335+
get => AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev;
336+
}
318337
}
319338
}

src/Files.App/ViewModels/UserControls/AddressToolbarViewModel.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public sealed class AddressToolbarViewModel : ObservableObject, IAddressToolbarV
2222

2323
private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService<IUserSettingsService>();
2424
private IAppearanceSettingsService AppearanceSettingsService { get; } = Ioc.Default.GetRequiredService<IAppearanceSettingsService>();
25+
private IGeneralSettingsService GeneralSettingsService { get; } = Ioc.Default.GetRequiredService<IGeneralSettingsService>();
2526

2627
private readonly IDialogService _dialogService = Ioc.Default.GetRequiredService<IDialogService>();
2728

@@ -162,6 +163,23 @@ public string? PathText
162163
public bool ShowHomeButton
163164
=> AppearanceSettingsService.ShowHomeButton;
164165

166+
public bool ShowShelfPaneToggleButton
167+
=> AppearanceSettingsService.ShowShelfPaneToggleButton && AppLifecycleHelper.AppEnvironment is AppEnvironment.Dev;
168+
169+
170+
// TODO replace with action when feature is marked as stable
171+
public bool ShowShelfPane
172+
{
173+
get => GeneralSettingsService.ShowShelfPane;
174+
set
175+
{
176+
if (value == GeneralSettingsService.ShowShelfPane)
177+
return;
178+
179+
GeneralSettingsService.ShowShelfPane = value;
180+
}
181+
}
182+
165183
public ObservableCollection<NavigationBarSuggestionItem> NavigationBarSuggestions = [];
166184

167185
private CurrentInstanceViewModel instanceViewModel;
@@ -213,6 +231,19 @@ public AddressToolbarViewModel()
213231
case nameof(AppearanceSettingsService.ShowHomeButton):
214232
OnPropertyChanged(nameof(ShowHomeButton));
215233
break;
234+
case nameof(AppearanceSettingsService.ShowShelfPaneToggleButton):
235+
OnPropertyChanged(nameof(ShowShelfPaneToggleButton));
236+
break;
237+
}
238+
};
239+
240+
GeneralSettingsService.PropertyChanged += (s, e) =>
241+
{
242+
switch (e.PropertyName)
243+
{
244+
case nameof(GeneralSettingsService.ShowShelfPane):
245+
OnPropertyChanged(nameof(ShowShelfPane));
246+
break;
216247
}
217248
};
218249
}

src/Files.App/Views/Settings/AdvancedPage.xaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,6 @@
185185
</ToggleSwitch>
186186
</local:SettingsBlockControl>
187187

188-
<!-- Show Shelf Pane -->
189-
<local:SettingsBlockControl
190-
x:Name="ShowShelfPane"
191-
Title="{helpers:ResourceString Name=ShowShelfPane}"
192-
HorizontalAlignment="Stretch"
193-
x:Load="{x:Bind ViewModel.IsAppEnvironmentDev}">
194-
<local:SettingsBlockControl.Icon>
195-
<FontIcon Glyph="&#xE90D;" />
196-
</local:SettingsBlockControl.Icon>
197-
<ToggleSwitch
198-
AutomationProperties.Name="{helpers:ResourceString Name=ShowShelfPane}"
199-
IsOn="{x:Bind ViewModel.ShowShelfPane, Mode=TwoWay}"
200-
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
201-
</local:SettingsBlockControl>
202-
203188
<!-- Flatten options -->
204189
<local:SettingsBlockControl
205190
Title="{helpers:ResourceString Name=ShowFlattenOptions}"

src/Files.App/Views/Settings/AppearancePage.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,18 @@
270270
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
271271
</local:SettingsBlockControl>
272272

273+
<!-- Show shelf pane toggle button -->
274+
<local:SettingsBlockControl
275+
x:Name="ShowShelfPaneSetting"
276+
Title="{helpers:ResourceString Name=ShowShelfPaneButtonInAddressBar}"
277+
HorizontalAlignment="Stretch"
278+
x:Load="{x:Bind ViewModel.IsAppEnvironmentDev}">
279+
<ToggleSwitch
280+
AutomationProperties.Name="{helpers:ResourceString Name=ShowShelfPaneButtonInAddressBar}"
281+
IsOn="{x:Bind ViewModel.ShowShelfPaneToggleButton, Mode=TwoWay}"
282+
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
283+
</local:SettingsBlockControl>
284+
273285
<!-- Show toolbar -->
274286
<local:SettingsBlockControl Title="{helpers:ResourceString Name=ShowToolbar}" HorizontalAlignment="Stretch">
275287
<ToggleSwitch

0 commit comments

Comments
 (0)