Skip to content

Commit 93ee5d3

Browse files
Feature: Reflect current layout in the Toolbar (#12915)
1 parent 66aa14b commit 93ee5d3

File tree

3 files changed

+91
-53
lines changed

3 files changed

+91
-53
lines changed

src/Files.App/ResourceDictionaries/PathIcons.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@
16071607
<VisualState x:Name="Selected">
16081608
<VisualState.Setters>
16091609
<Setter Target="Path1.Fill" Value="Transparent" />
1610-
<Setter Target="Path2.Fill" Value="{ThemeResource TextOnAccentFillColorPrimaryBrush}" />
1610+
<Setter Target="Path2.Fill" Value="Transparent" />
16111611
<Setter Target="Path3.Fill" Value="{ThemeResource TextOnAccentFillColorPrimaryBrush}" />
16121612
<Setter Target="Path4.Fill" Value="{ThemeResource TextOnAccentFillColorPrimaryBrush}" />
16131613
<Setter Target="Path5.Fill" Value="{ThemeResource TextOnAccentFillColorPrimaryBrush}" />

src/Files.App/UserControls/InnerNavigationToolbar.xaml

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,7 @@
604604
Style="{StaticResource ToolBarAppBarButtonFlyoutStyle}"
605605
ToolTipService.ToolTip="{helpers:ResourceString Name=Layout}">
606606

607-
<AppBarButton.Icon>
608-
<FontIcon Glyph="&#xE152;" />
609-
</AppBarButton.Icon>
607+
<local:OpacityIcon Style="{x:Bind ViewModel.LayoutOpacityIcon, Mode=OneWay}" />
610608

611609
<AppBarButton.Flyout>
612610
<Flyout contract8Present:ShouldConstrainToRootBounds="False" Placement="Bottom">
@@ -662,7 +660,7 @@
662660
Tapped="{x:Bind Commands.LayoutDetails.ExecuteTapped}"
663661
Text="{x:Bind Commands.LayoutDetails.Label}" />
664662

665-
<!-- Tiles Layout -->
663+
<!-- Columns Layout -->
666664
<RadioButton
667665
Grid.Row="1"
668666
Grid.Column="0"
@@ -672,6 +670,38 @@
672670
Padding="0"
673671
HorizontalContentAlignment="Center"
674672
VerticalContentAlignment="Center"
673+
AutomationProperties.Name="{x:Bind Commands.LayoutColumns.AutomationName}"
674+
Command="{x:Bind Commands.LayoutColumns}"
675+
CornerRadius="{StaticResource ControlCornerRadius}"
676+
GroupName="LayoutRadio"
677+
IsChecked="{x:Bind Commands.LayoutColumns.IsOn, Mode=OneWay}"
678+
Style="{StaticResource DefaultToggleButtonStyle}"
679+
ToolTipService.ToolTip="{x:Bind Commands.LayoutColumns.LabelWithHotKey, Mode=OneWay}">
680+
<local:OpacityIcon
681+
Width="20"
682+
Height="20"
683+
IsSelected="{x:Bind Commands.LayoutColumns.IsOn, Mode=OneWay}"
684+
Style="{x:Bind Commands.LayoutColumns.OpacityStyle}" />
685+
</RadioButton>
686+
687+
<TextBlock
688+
x:Name="NavToolbarColumnsHeader"
689+
Grid.Row="1"
690+
Grid.Column="1"
691+
VerticalAlignment="Center"
692+
Tapped="{x:Bind Commands.LayoutColumns.ExecuteTapped}"
693+
Text="{x:Bind Commands.LayoutColumns.Label}" />
694+
695+
<!-- Tiles Layout -->
696+
<RadioButton
697+
Grid.Row="2"
698+
Grid.Column="0"
699+
Width="36"
700+
Height="32"
701+
MinWidth="0"
702+
Padding="0"
703+
HorizontalContentAlignment="Center"
704+
VerticalContentAlignment="Center"
675705
AutomationProperties.Name="{x:Bind Commands.LayoutTiles.AutomationName}"
676706
Command="{x:Bind Commands.LayoutTiles}"
677707
CornerRadius="{StaticResource ControlCornerRadius}"
@@ -688,16 +718,16 @@
688718

689719
<TextBlock
690720
x:Name="NavToolbarTilesHeader"
691-
Grid.Row="1"
721+
Grid.Row="2"
692722
Grid.Column="1"
693723
VerticalAlignment="Center"
694724
Tapped="{x:Bind Commands.LayoutTiles.ExecuteTapped}"
695725
Text="{x:Bind Commands.LayoutTiles.Label}" />
696726

697727
<!-- Grid Small Layout -->
698728
<RadioButton
699-
Grid.Row="2"
700-
Grid.Column="0"
729+
Grid.Row="0"
730+
Grid.Column="3"
701731
Width="36"
702732
Height="32"
703733
MinWidth="0"
@@ -720,15 +750,15 @@
720750

721751
<TextBlock
722752
x:Name="NavToolbarSmallIconsHeader"
723-
Grid.Row="2"
724-
Grid.Column="1"
753+
Grid.Row="0"
754+
Grid.Column="4"
725755
VerticalAlignment="Center"
726756
Tapped="{x:Bind Commands.LayoutGridSmall.ExecuteTapped}"
727757
Text="{x:Bind Commands.LayoutGridSmall.Label}" />
728758

729759
<!-- Grid Medium Layout -->
730760
<RadioButton
731-
Grid.Row="0"
761+
Grid.Row="1"
732762
Grid.Column="3"
733763
Width="36"
734764
Height="32"
@@ -752,7 +782,7 @@
752782

753783
<TextBlock
754784
x:Name="NavToolbarMediumIconsHeader"
755-
Grid.Row="0"
785+
Grid.Row="1"
756786
Grid.Column="4"
757787
VerticalAlignment="Center"
758788
Tapped="{x:Bind Commands.LayoutGridMedium.ExecuteTapped}"
@@ -770,7 +800,7 @@
770800

771801
<!-- Grid Large Layout -->
772802
<RadioButton
773-
Grid.Row="1"
803+
Grid.Row="2"
774804
Grid.Column="3"
775805
Width="36"
776806
Height="32"
@@ -794,44 +824,12 @@
794824

795825
<TextBlock
796826
x:Name="NavToolbarLargeIconsHeader"
797-
Grid.Row="1"
827+
Grid.Row="2"
798828
Grid.Column="4"
799829
VerticalAlignment="Center"
800830
Tapped="{x:Bind Commands.LayoutGridLarge.ExecuteTapped}"
801831
Text="{x:Bind Commands.LayoutGridLarge.Label}" />
802832

803-
<!-- Columns Layout -->
804-
<RadioButton
805-
Grid.Row="2"
806-
Grid.Column="3"
807-
Width="36"
808-
Height="32"
809-
MinWidth="0"
810-
Padding="0"
811-
HorizontalContentAlignment="Center"
812-
VerticalContentAlignment="Center"
813-
AutomationProperties.Name="{x:Bind Commands.LayoutColumns.AutomationName}"
814-
Command="{x:Bind Commands.LayoutColumns}"
815-
CornerRadius="{StaticResource ControlCornerRadius}"
816-
GroupName="LayoutRadio"
817-
IsChecked="{x:Bind Commands.LayoutColumns.IsOn, Mode=OneWay}"
818-
Style="{StaticResource DefaultToggleButtonStyle}"
819-
ToolTipService.ToolTip="{x:Bind Commands.LayoutColumns.LabelWithHotKey, Mode=OneWay}">
820-
<local:OpacityIcon
821-
Width="20"
822-
Height="20"
823-
IsSelected="{x:Bind Commands.LayoutColumns.IsOn, Mode=OneWay}"
824-
Style="{x:Bind Commands.LayoutColumns.OpacityStyle}" />
825-
</RadioButton>
826-
827-
<TextBlock
828-
x:Name="NavToolbarColumnsHeader"
829-
Grid.Row="2"
830-
Grid.Column="4"
831-
VerticalAlignment="Center"
832-
Tapped="{x:Bind Commands.LayoutColumns.ExecuteTapped}"
833-
Text="{x:Bind Commands.LayoutColumns.Label}" />
834-
835833
</Grid>
836834

837835
<!-- (Divider) -->

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

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using CommunityToolkit.WinUI.UI;
5-
using Files.App.Commands;
6-
using Files.App.Contexts;
7-
using Files.App.Utils.StorageItems;
8-
using Files.App.Utils.Shell;
9-
using Files.Core.Helpers;
10-
using Files.Core.Services;
115
using Files.Shared.EventArguments;
126
using Microsoft.UI.Dispatching;
137
using Microsoft.UI.Xaml;
@@ -178,7 +172,29 @@ public string? PathText
178172
public CurrentInstanceViewModel InstanceViewModel
179173
{
180174
get => instanceViewModel;
181-
set => SetProperty(ref instanceViewModel, value);
175+
set
176+
{
177+
if (instanceViewModel?.FolderSettings is not null)
178+
instanceViewModel.FolderSettings.PropertyChanged -= FolderSettings_PropertyChanged;
179+
180+
if (SetProperty(ref instanceViewModel, value) && instanceViewModel?.FolderSettings is not null)
181+
{
182+
FolderSettings_PropertyChanged(this, new PropertyChangedEventArgs(nameof(FolderSettingsViewModel.LayoutMode)));
183+
instanceViewModel.FolderSettings.PropertyChanged += FolderSettings_PropertyChanged;
184+
}
185+
}
186+
}
187+
188+
private Style _LayoutOpacityIcon;
189+
public Style LayoutOpacityIcon
190+
{
191+
get => _LayoutOpacityIcon;
192+
set
193+
{
194+
if (SetProperty(ref _LayoutOpacityIcon, value))
195+
{
196+
}
197+
}
182198
}
183199

184200
private PointerRoutedEventArgs? pointerRoutedEventArgs;
@@ -819,6 +835,30 @@ public async Task SetAddressBarSuggestions(AutoSuggestBox sender, IShellPage she
819835
}
820836
}
821837

838+
private void FolderSettings_PropertyChanged(object? sender, PropertyChangedEventArgs e)
839+
{
840+
switch (e.PropertyName)
841+
{
842+
case nameof(FolderSettingsViewModel.GridViewSize):
843+
case nameof(FolderSettingsViewModel.LayoutMode):
844+
{
845+
LayoutOpacityIcon = instanceViewModel.FolderSettings.LayoutMode switch
846+
{
847+
FolderLayoutModes.TilesView => Commands.LayoutTiles.OpacityStyle!,
848+
FolderLayoutModes.ColumnView => Commands.LayoutColumns.OpacityStyle!,
849+
FolderLayoutModes.GridView =>
850+
instanceViewModel.FolderSettings.GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeSmall
851+
? Commands.LayoutGridSmall.OpacityStyle!
852+
: instanceViewModel.FolderSettings.GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeMedium
853+
? Commands.LayoutGridMedium.OpacityStyle!
854+
: Commands.LayoutGridLarge.OpacityStyle!,
855+
_ => Commands.LayoutDetails.OpacityStyle!
856+
};
857+
}
858+
break;
859+
}
860+
}
861+
822862
private bool hasItem = false;
823863
public bool HasItem
824864
{

0 commit comments

Comments
 (0)