Skip to content

Commit 18e7398

Browse files
0x5bfayaira2hishitetsu
authored
Feature: Added support for closing the left pane (#15614)
Co-authored-by: Yair <39923744+yaira2@users.noreply.github.com> Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com>
1 parent 9ee8447 commit 18e7398

File tree

8 files changed

+67
-48
lines changed

8 files changed

+67
-48
lines changed

src/Files.App/Actions/Navigation/ClosePaneAction.cs renamed to src/Files.App/Actions/Navigation/CloseActivePaneAction.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
namespace Files.App.Actions
55
{
6-
internal sealed class ClosePaneAction : ObservableObject, IAction
6+
internal sealed class CloseActivePaneAction : ObservableObject, IAction
77
{
8-
private readonly IContentPageContext context;
8+
private IContentPageContext ContentPageContext { get; } = Ioc.Default.GetRequiredService<IContentPageContext>();
99

1010
public string Label
11-
=> "NavigationToolbarClosePane/Label".GetLocalizedResource();
11+
=> "CloseActivePane".GetLocalizedResource();
1212

1313
public string Description
14-
=> "ClosePaneDescription".GetLocalizedResource();
14+
=> "CloseActivePaneDescription".GetLocalizedResource();
1515

1616
public HotKey HotKey
1717
=> new(Keys.W, KeyModifiers.CtrlShift);
@@ -20,23 +20,20 @@ public RichGlyph Glyph
2020
=> new("\uE89F");
2121

2222
public bool IsExecutable
23-
=> context.IsMultiPaneActive;
23+
=> ContentPageContext.IsMultiPaneActive;
2424

25-
public ClosePaneAction()
25+
public CloseActivePaneAction()
2626
{
27-
context = Ioc.Default.GetRequiredService<IContentPageContext>();
28-
29-
context.PropertyChanged += Context_PropertyChanged;
27+
ContentPageContext.PropertyChanged += ContentPageContext_PropertyChanged;
3028
}
3129

3230
public Task ExecuteAsync(object? parameter = null)
3331
{
34-
context.ShellPage!.PaneHolder.CloseSecondaryPane();
35-
32+
ContentPageContext.ShellPage?.PaneHolder.CloseActivePane();
3633
return Task.CompletedTask;
3734
}
3835

39-
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
36+
private void ContentPageContext_PropertyChanged(object? sender, PropertyChangedEventArgs e)
4037
{
4138
switch (e.PropertyName)
4239
{

src/Files.App/Data/Commands/Manager/CommandCodes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public enum CommandCodes
186186
NextTab,
187187
CloseSelectedTab,
188188
OpenNewPane,
189-
ClosePane,
189+
CloseActivePane,
190190
FocusLeftPane,
191191
FocusRightPane,
192192

src/Files.App/Data/Commands/Manager/CommandManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public IRichCommand this[HotKey hotKey]
191191
public IRichCommand NextTab => commands[CommandCodes.NextTab];
192192
public IRichCommand CloseSelectedTab => commands[CommandCodes.CloseSelectedTab];
193193
public IRichCommand OpenNewPane => commands[CommandCodes.OpenNewPane];
194-
public IRichCommand ClosePane => commands[CommandCodes.ClosePane];
194+
public IRichCommand CloseActivePane => commands[CommandCodes.CloseActivePane];
195195
public IRichCommand FocusLeftPane => commands[CommandCodes.FocusLeftPane];
196196
public IRichCommand FocusRightPane => commands[CommandCodes.FocusRightPane];
197197
public IRichCommand OpenFileLocation => commands[CommandCodes.OpenFileLocation];
@@ -374,7 +374,7 @@ public IEnumerator<IRichCommand> GetEnumerator() =>
374374
[CommandCodes.NextTab] = new NextTabAction(),
375375
[CommandCodes.CloseSelectedTab] = new CloseSelectedTabAction(),
376376
[CommandCodes.OpenNewPane] = new OpenNewPaneAction(),
377-
[CommandCodes.ClosePane] = new ClosePaneAction(),
377+
[CommandCodes.CloseActivePane] = new CloseActivePaneAction(),
378378
[CommandCodes.FocusLeftPane] = new FocusLeftPaneAction(),
379379
[CommandCodes.FocusRightPane] = new FocusRightPaneAction(),
380380
[CommandCodes.OpenFileLocation] = new OpenFileLocationAction(),

src/Files.App/Data/Commands/Manager/ICommandManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public interface ICommandManager : IEnumerable<IRichCommand>
171171
IRichCommand NextTab { get; }
172172
IRichCommand CloseSelectedTab { get; }
173173
IRichCommand OpenNewPane { get; }
174-
IRichCommand ClosePane { get; }
174+
IRichCommand CloseActivePane { get; }
175175
IRichCommand FocusLeftPane { get; }
176176
IRichCommand FocusRightPane { get; }
177177

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface IShellPanesPage : IDisposable, INotifyPropertyChanged
1616

1717
public void OpenSecondaryPane(string path);
1818

19-
public void CloseSecondaryPane();
19+
public void CloseActivePane();
2020

2121
public void FocusLeftPane();
2222

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,8 +1583,8 @@
15831583
<data name="SecurityAdvancedReplaceChildPermissions2.ToolTipService.ToolTip" xml:space="preserve">
15841584
<value>Replace all child object permissions entries with inheritable permission entries from this object</value>
15851585
</data>
1586-
<data name="NavigationToolbarClosePane.Label" xml:space="preserve">
1587-
<value>Close pane</value>
1586+
<data name="CloseActivePane" xml:space="preserve">
1587+
<value>Close active pane</value>
15881588
</data>
15891589
<data name="EnterCompactOverlay" xml:space="preserve">
15901590
<value>Enter compact overlay</value>
@@ -2672,8 +2672,8 @@
26722672
<data name="OpenNewPaneDescription" xml:space="preserve">
26732673
<value>Open new pane</value>
26742674
</data>
2675-
<data name="ClosePaneDescription" xml:space="preserve">
2676-
<value>Close right pane</value>
2675+
<data name="CloseActivePaneDescription" xml:space="preserve">
2676+
<value>Close active pane</value>
26772677
</data>
26782678
<data name="FocusLeftPane" xml:space="preserve">
26792679
<value>Focus left pane</value>

src/Files.App/UserControls/InnerNavigationToolbar.xaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@
12261226
</AppBarButton.Icon>
12271227
</AppBarButton>
12281228

1229-
<!-- Open Pane -->
1229+
<!-- Open New Pane -->
12301230
<AppBarButton
12311231
x:Name="NavToolbarNewPane"
12321232
x:Load="{x:Bind Commands.OpenNewPane.IsExecutable, Mode=OneWay}"
@@ -1236,15 +1236,15 @@
12361236
<local:OpacityIcon Style="{x:Bind Commands.OpenNewPane.OpacityStyle}" />
12371237
</AppBarButton>
12381238

1239-
<!-- Close Pane -->
1239+
<!-- Close Active Pane -->
12401240
<AppBarButton
1241-
x:Name="NavToolbarClosePane"
1242-
x:Load="{x:Bind Commands.ClosePane.IsExecutable, Mode=OneWay}"
1243-
Command="{x:Bind Commands.ClosePane, Mode=OneWay}"
1244-
Label="{x:Bind Commands.ClosePane.Label}"
1245-
ToolTipService.ToolTip="{x:Bind Commands.ClosePane.LabelWithHotKey, Mode=OneWay}">
1241+
x:Name="NavToolbarCloseActivePane"
1242+
x:Load="{x:Bind Commands.CloseActivePane.IsExecutable, Mode=OneWay}"
1243+
Command="{x:Bind Commands.CloseActivePane, Mode=OneWay}"
1244+
Label="{x:Bind Commands.CloseActivePane.Label}"
1245+
ToolTipService.ToolTip="{x:Bind Commands.CloseActivePane.LabelWithHotKey, Mode=OneWay}">
12461246
<AppBarButton.Icon>
1247-
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.ClosePane.Glyph.BaseGlyph}" />
1247+
<FontIcon Foreground="{ThemeResource App.Theme.IconBaseBrush}" Glyph="{x:Bind Commands.CloseActivePane.Glyph.BaseGlyph}" />
12481248
</AppBarButton.Icon>
12491249
</AppBarButton>
12501250

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

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,23 @@ public bool IsRightPaneVisible
188188
if (value != _IsRightPaneVisible)
189189
{
190190
_IsRightPaneVisible = value;
191-
if (!_IsRightPaneVisible)
192-
{
193-
ActivePane = GetPane(0);
194-
Pane_ContentChanged(null!, null!);
195-
}
196-
197-
NotifyPropertyChanged(nameof(IsRightPaneVisible));
198-
NotifyPropertyChanged(nameof(IsMultiPaneActive));
199191

200192
if (value)
201193
{
202194
AddPane();
203195
}
204196
else
205197
{
206-
RemovePane((RootGrid.Children.Count - 1) / 2);
198+
if (GetPaneCount() != 1)
199+
{
200+
ActivePane = GetPane(0);
201+
Pane_ContentChanged(null!, null!);
202+
RemovePane((RootGrid.Children.Count - 1) / 2);
203+
}
207204
}
205+
206+
NotifyPropertyChanged(nameof(IsRightPaneVisible));
207+
NotifyPropertyChanged(nameof(IsMultiPaneActive));
208208
}
209209
}
210210
}
@@ -272,10 +272,12 @@ public void OpenSecondaryPane(string path)
272272
ActivePane = GetPane(1);
273273
}
274274

275-
public void CloseSecondaryPane()
275+
public void CloseActivePane()
276276
{
277-
// Remove right pane within this property's setter
278-
IsRightPaneVisible = false;
277+
if (ActivePane == (IShellPage)GetPane(0))
278+
RemovePane(0);
279+
else
280+
IsRightPaneVisible = false;
279281

280282
GetPane(0)?.Focus(FocusState.Programmatic);
281283
SetShadow();
@@ -346,7 +348,6 @@ private void AddPane()
346348
NotifyPropertyChanged(nameof(IsMultiPaneActive));
347349
}
348350

349-
// TODO: Shift column index for when to close left pane
350351
private void RemovePane(int index = -1)
351352
{
352353
if (index is -1)
@@ -355,14 +356,35 @@ private void RemovePane(int index = -1)
355356
// Get proper position of sizer that resides with the pane that is wanted to be removed
356357
var childIndex = index * 2 - 1;
357358
childIndex = childIndex >= 0 ? childIndex : 0;
359+
if (childIndex >= RootGrid.Children.Count)
360+
return;
361+
362+
if (childIndex == 0)
363+
{
364+
var wasMultiPaneActive = IsMultiPaneActive;
358365

359-
// Remove sizer and pane from children
360-
RootGrid.Children.RemoveAt(childIndex);
361-
RootGrid.Children.RemoveAt(childIndex);
366+
// Remove sizer and pane
367+
RootGrid.Children.RemoveAt(0);
368+
RootGrid.ColumnDefinitions.RemoveAt(0);
362369

363-
// Remove sizer and pane from column definitions
364-
RootGrid.ColumnDefinitions.RemoveAt(childIndex);
365-
RootGrid.ColumnDefinitions.RemoveAt(childIndex);
370+
if (wasMultiPaneActive)
371+
{
372+
RootGrid.Children.RemoveAt(0);
373+
RootGrid.ColumnDefinitions.RemoveAt(0);
374+
RootGrid.Children[0].SetValue(Grid.ColumnProperty, 0);
375+
_NavParamsLeft = new() { NavPath = GetPane(0)?.TabBarItemParameter?.NavigationParameter as string ?? string.Empty };
376+
IsRightPaneVisible = false;
377+
ActivePane = GetPane(0);
378+
}
379+
}
380+
else
381+
{
382+
// Remove sizer and pane
383+
RootGrid.Children.RemoveAt(childIndex);
384+
RootGrid.Children.RemoveAt(childIndex);
385+
RootGrid.ColumnDefinitions.RemoveAt(childIndex);
386+
RootGrid.ColumnDefinitions.RemoveAt(childIndex);
387+
}
366388

367389
NotifyPropertyChanged(nameof(IsMultiPaneActive));
368390
}

0 commit comments

Comments
 (0)