Skip to content

Commit ae06d2d

Browse files
committed
CQ: Fix DragRegions
1 parent e7668e4 commit ae06d2d

File tree

5 files changed

+92
-61
lines changed

5 files changed

+92
-61
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace Files.App.Data.Contracts
55
{
66
public interface IRealTimeLayoutService
77
{
8+
9+
FlowDirection FlowDirection { get; }
810
void AddCallback(object target, Action callback);
911

1012
void UpdateContent(FrameworkElement frameworkElement);

src/Files.App/Services/Content/RealTimeLayoutService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace Files.App.Services.Content
1010
internal sealed class RealTimeLayoutService : IRealTimeLayoutService
1111
{
1212
private readonly List<(WeakReference<object> Reference, Action Callback)> _callbacks = [];
13-
public static FlowDirection FlowDirection => CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
13+
14+
public FlowDirection FlowDirection => CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
1415

1516
public void UpdateCulture(CultureInfo culture)
1617
{

src/Files.App/UserControls/AddressToolbar.xaml

Lines changed: 76 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -263,63 +263,68 @@
263263
</AnimatedIcon>
264264
</ToggleButton>
265265

266-
<Button
267-
x:Name="Back"
268-
AccessKey="B"
269-
AccessKeyInvoked="Button_AccessKeyInvoked"
270-
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateBack.Description, Mode=OneWay}"
271-
AutomationProperties.Name="{x:Bind ViewModel.Commands.NavigateBack.Label, Mode=OneWay}"
272-
Command="{x:Bind ViewModel.Commands.NavigateBack, Mode=OneWay}"
273-
IsEnabled="{x:Bind ViewModel.Commands.NavigateBack.IsExecutable, Mode=OneWay}"
274-
Style="{StaticResource AddressToolbarButtonStyle}"
275-
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.NavigateBack.LabelWithHotKey, Mode=OneWay}">
276-
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.Commands.NavigateBack.Glyph.BaseGlyph, Mode=OneWay}" />
277-
<Button.ContextFlyout>
278-
<MenuFlyout
279-
x:Name="BackHistoryFlyout"
280-
Opening="BackHistoryFlyout_Opening"
281-
Placement="BottomEdgeAlignedLeft"
282-
ScrollViewer.VerticalScrollBarVisibility="Auto"
283-
ScrollViewer.VerticalScrollMode="Auto">
284-
<MenuFlyout.MenuFlyoutPresenterStyle>
285-
<Style TargetType="MenuFlyoutPresenter">
286-
<Setter Property="MaxHeight" Value="400" />
287-
<!-- Workaround for https://github.com/files-community/Files/issues/13078 -->
288-
<Setter Target="HighContrastAdjustment" Value="None" />
289-
</Style>
290-
</MenuFlyout.MenuFlyoutPresenterStyle>
291-
</MenuFlyout>
292-
</Button.ContextFlyout>
293-
</Button>
294-
295-
<Button
296-
x:Name="Forward"
297-
AccessKey="F"
298-
AccessKeyInvoked="Button_AccessKeyInvoked"
299-
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateForward.Description, Mode=OneWay}"
300-
AutomationProperties.Name="{x:Bind ViewModel.Commands.NavigateForward.Label, Mode=OneWay}"
301-
Command="{x:Bind ViewModel.Commands.NavigateForward, Mode=OneWay}"
302-
IsEnabled="{x:Bind ViewModel.Commands.NavigateForward.IsExecutable, Mode=OneWay}"
303-
Style="{StaticResource AddressToolbarButtonStyle}"
304-
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.NavigateForward.LabelWithHotKey, Mode=OneWay}">
305-
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.Commands.NavigateForward.Glyph.BaseGlyph, Mode=OneWay}" />
306-
<Button.ContextFlyout>
307-
<MenuFlyout
308-
x:Name="ForwardHistoryFlyout"
309-
Opening="ForwardHistoryFlyout_Opening"
310-
Placement="BottomEdgeAlignedLeft"
311-
ScrollViewer.VerticalScrollBarVisibility="Auto"
312-
ScrollViewer.VerticalScrollMode="Auto">
313-
<MenuFlyout.MenuFlyoutPresenterStyle>
314-
<Style TargetType="MenuFlyoutPresenter">
315-
<Setter Property="MaxHeight" Value="400" />
316-
<!-- Workaround for https://github.com/files-community/Files/issues/13078 -->
317-
<Setter Target="HighContrastAdjustment" Value="None" />
318-
</Style>
319-
</MenuFlyout.MenuFlyoutPresenterStyle>
320-
</MenuFlyout>
321-
</Button.ContextFlyout>
322-
</Button>
266+
<StackPanel
267+
x:Name="NavigationButtons"
268+
FlowDirection="{Binding Path=FlowDirection, ElementName=Root}"
269+
Orientation="Horizontal">
270+
<Button
271+
x:Name="Back"
272+
AccessKey="B"
273+
AccessKeyInvoked="Button_AccessKeyInvoked"
274+
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateBack.Description, Mode=OneWay}"
275+
AutomationProperties.Name="{x:Bind ViewModel.Commands.NavigateBack.Label, Mode=OneWay}"
276+
Command="{x:Bind ViewModel.Commands.NavigateBack, Mode=OneWay}"
277+
IsEnabled="{x:Bind ViewModel.Commands.NavigateBack.IsExecutable, Mode=OneWay}"
278+
Style="{StaticResource AddressToolbarButtonStyle}"
279+
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.NavigateBack.LabelWithHotKey, Mode=OneWay}">
280+
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.Commands.NavigateBack.Glyph.BaseGlyph, Mode=OneWay}" />
281+
<Button.ContextFlyout>
282+
<MenuFlyout
283+
x:Name="BackHistoryFlyout"
284+
Opening="BackHistoryFlyout_Opening"
285+
Placement="BottomEdgeAlignedLeft"
286+
ScrollViewer.VerticalScrollBarVisibility="Auto"
287+
ScrollViewer.VerticalScrollMode="Auto">
288+
<MenuFlyout.MenuFlyoutPresenterStyle>
289+
<Style TargetType="MenuFlyoutPresenter">
290+
<Setter Property="MaxHeight" Value="400" />
291+
<!-- Workaround for https://github.com/files-community/Files/issues/13078 -->
292+
<Setter Target="HighContrastAdjustment" Value="None" />
293+
</Style>
294+
</MenuFlyout.MenuFlyoutPresenterStyle>
295+
</MenuFlyout>
296+
</Button.ContextFlyout>
297+
</Button>
298+
299+
<Button
300+
x:Name="Forward"
301+
AccessKey="F"
302+
AccessKeyInvoked="Button_AccessKeyInvoked"
303+
AutomationProperties.FullDescription="{x:Bind ViewModel.Commands.NavigateForward.Description, Mode=OneWay}"
304+
AutomationProperties.Name="{x:Bind ViewModel.Commands.NavigateForward.Label, Mode=OneWay}"
305+
Command="{x:Bind ViewModel.Commands.NavigateForward, Mode=OneWay}"
306+
IsEnabled="{x:Bind ViewModel.Commands.NavigateForward.IsExecutable, Mode=OneWay}"
307+
Style="{StaticResource AddressToolbarButtonStyle}"
308+
ToolTipService.ToolTip="{x:Bind ViewModel.Commands.NavigateForward.LabelWithHotKey, Mode=OneWay}">
309+
<FontIcon FontSize="14" Glyph="{x:Bind ViewModel.Commands.NavigateForward.Glyph.BaseGlyph, Mode=OneWay}" />
310+
<Button.ContextFlyout>
311+
<MenuFlyout
312+
x:Name="ForwardHistoryFlyout"
313+
Opening="ForwardHistoryFlyout_Opening"
314+
Placement="BottomEdgeAlignedLeft"
315+
ScrollViewer.VerticalScrollBarVisibility="Auto"
316+
ScrollViewer.VerticalScrollMode="Auto">
317+
<MenuFlyout.MenuFlyoutPresenterStyle>
318+
<Style TargetType="MenuFlyoutPresenter">
319+
<Setter Property="MaxHeight" Value="400" />
320+
<!-- Workaround for https://github.com/files-community/Files/issues/13078 -->
321+
<Setter Target="HighContrastAdjustment" Value="None" />
322+
</Style>
323+
</MenuFlyout.MenuFlyoutPresenterStyle>
324+
</MenuFlyout>
325+
</Button.ContextFlyout>
326+
</Button>
327+
</StackPanel>
323328

324329
<Button
325330
x:Name="Up"
@@ -691,6 +696,20 @@
691696
<Setter Target="StatusInfoBadge.Style" Value="{StaticResource CriticalIconInfoBadgeStyle}" />
692697
</VisualState.Setters>
693698
</VisualState>
699+
<!-- FlowDirection LeftToRight -->
700+
<VisualState x:Name="LTR">
701+
<VisualState.Setters>
702+
<Setter Target="NavigationButtons.Children[0]" Value="Back" />
703+
<Setter Target="NavigationButtons.Children[1]" Value="Forward" />
704+
</VisualState.Setters>
705+
</VisualState>
706+
<!-- FlowDirection RightToLeft -->
707+
<VisualState x:Name="RTL">
708+
<VisualState.Setters>
709+
<Setter Target="NavigationButtons.Children[0]" Value="Forward" />
710+
<Setter Target="NavigationButtons.Children[1]" Value="Back" />
711+
</VisualState.Setters>
712+
</VisualState>
694713
</VisualStateGroup>
695714
</VisualStateManager.VisualStateGroups>
696715
</Grid>

src/Files.App/UserControls/Sidebar/SidebarView.xaml.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ private void SidebarResizer_ManipulationStarted(object sender, ManipulationStart
130130

131131
private void SidebarResizer_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
132132
{
133-
var newWidth = preManipulationSidebarWidth + e.Cumulative.Translation.X;
133+
var rtls = Ioc.Default.GetRequiredService<IRealTimeLayoutService>();
134+
var rePos = rtls.FlowDirection == FlowDirection.LeftToRight ? 1 : -1;
135+
var newWidth = preManipulationSidebarWidth + (e.Cumulative.Translation.X * rePos);
136+
134137
UpdateDisplayModeForPaneWidth(newWidth);
135138
e.Handled = true;
136139
}
@@ -156,14 +159,16 @@ private void SidebarResizerControl_KeyDown(object sender, KeyRoutedEventArgs e)
156159
return;
157160
}
158161

162+
var rtls = Ioc.Default.GetRequiredService<IRealTimeLayoutService>();
159163
var ctrl = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control);
160164
var increment = ctrl.HasFlag(CoreVirtualKeyStates.Down) ? 5 : 1;
165+
var rePos = rtls.FlowDirection == FlowDirection.LeftToRight ? 1 : -1;
161166

162167
// Left makes the pane smaller so we invert the increment
163168
if (e.Key == VirtualKey.Left)
164169
increment = -increment;
165170

166-
var newWidth = OpenPaneLength + increment;
171+
var newWidth = OpenPaneLength + (increment * rePos);
167172
UpdateDisplayModeForPaneWidth(newWidth);
168173
e.Handled = true;
169174
return;

src/Files.App/Views/MainPage.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,12 @@ private void HorizontalMultitaskingControl_Loaded(object sender, RoutedEventArgs
137137

138138
private int SetTitleBarDragRegion(InputNonClientPointerSource source, SizeInt32 size, double scaleFactor, Func<UIElement, RectInt32?, RectInt32> getScaledRect)
139139
{
140+
var rtls = Ioc.Default.GetRequiredService<IRealTimeLayoutService>();
140141
var height = (int)TabControl.ActualHeight;
141-
source.SetRegionRects(NonClientRegionKind.Passthrough, [getScaledRect(this, new RectInt32(0, 0, (int)(TabControl.ActualWidth + TabControl.Margin.Left - TabControl.DragArea.ActualWidth), height))]);
142+
var x = rtls.FlowDirection == FlowDirection.LeftToRight ? 0 : (int)TabControl.ActualWidth;
143+
var width = (int)(TabControl.ActualWidth + TabControl.Margin.Left - TabControl.DragArea.ActualWidth);
144+
145+
source.SetRegionRects(NonClientRegionKind.Passthrough, [getScaledRect(this, new RectInt32(x, 0, width, height))]);
142146
return height;
143147
}
144148

0 commit comments

Comments
 (0)