Skip to content

Add "Close tabs to the left" and "Close others" to tab context menu #8015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/Files/Helpers/MultitaskingTabsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,41 @@
using Microsoft.Toolkit.Uwp;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Files.Helpers
{
public static class MultitaskingTabsHelpers
{
public static void CloseTabsToTheRight(TabItem clickedTab, IMultitaskingControl multitaskingControl)
public static void CloseTabsToTheLeft(TabItem clickedTab, IMultitaskingControl multitaskingControl)
{
int index = MainPageViewModel.AppInstances.IndexOf(clickedTab);
List<TabItem> tabsToClose = new List<TabItem>();
if (multitaskingControl is not null)
{
var tabs = MainPageViewModel.AppInstances;
var currentIndex = tabs.IndexOf(clickedTab);

tabs.Take(currentIndex).ToList().ForEach(tab => multitaskingControl.CloseTab(tab));
}
}

for (int i = index + 1; i < MainPageViewModel.AppInstances.Count; i++)
public static void CloseTabsToTheRight(TabItem clickedTab, IMultitaskingControl multitaskingControl)
{
if (multitaskingControl is not null)
{
tabsToClose.Add(MainPageViewModel.AppInstances[i]);
var tabs = MainPageViewModel.AppInstances;
var currentIndex = tabs.IndexOf(clickedTab);

tabs.Skip(currentIndex + 1).ToList().ForEach(tab => multitaskingControl.CloseTab(tab));
}
}

foreach (var item in tabsToClose)
public static void CloseOthers(TabItem clickedTab, IMultitaskingControl multitaskingControl)
{
if (multitaskingControl is not null)
{
multitaskingControl?.CloseTab(item);
var tabs = MainPageViewModel.AppInstances;
tabs.Where((t) => t != clickedTab).ToList().ForEach(tab => multitaskingControl.CloseTab(tab));
}
}

Expand Down Expand Up @@ -64,4 +79,4 @@ public static async Task AddNewTab(Type type, object tabViewItemArgs, int atInde
MainPageViewModel.AppInstances.Insert(atIndex == -1 ? MainPageViewModel.AppInstances.Count : atIndex, tabItem);
}
}
}
}
28 changes: 24 additions & 4 deletions src/Files/MultilingualResources/Files.it-IT.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -1771,10 +1771,6 @@
<source>Would you like to continue as administrator?</source>
<target state="translated">Vuoi continuare come amministratore?</target>
</trans-unit>
<trans-unit id="HorizontalMultitaskingControlCloseTabsToTheRight.Text" translate="yes" xml:space="preserve">
<source>Close tabs to the right</source>
<target state="translated">Chiudi schede a destra</target>
</trans-unit>
<trans-unit id="FullTrustStatusTeachingTip.Title" translate="yes" xml:space="preserve">
<source>Administrator</source>
<target state="translated">Amministratore</target>
Expand Down Expand Up @@ -3498,6 +3494,30 @@ Usiamo App Center per tenere traccia dell'utilizzo dell'app, trovare bug e risol
<source>Open in</source>
<target state="new">Open in</target>
</trans-unit>
<trans-unit id="RotateLeft" translate="yes" xml:space="preserve">
<source>Rotate left</source>
<target state="new">Rotate left</target>
</trans-unit>
<trans-unit id="RotateRight" translate="yes" xml:space="preserve">
<source>Rotate right</source>
<target state="new">Rotate right</target>
</trans-unit>
<trans-unit id="Install" translate="yes" xml:space="preserve">
<source>Install</source>
<target state="new">Install</target>
</trans-unit>
<trans-unit id="CloseTabsToTheLeft" translate="yes" xml:space="preserve">
<source>Close tabs to the left</source>
<target state="translated">Chiudi schede a sinistra</target>
</trans-unit>
<trans-unit id="CloseTabsToTheRight" translate="yes" xml:space="preserve">
<source>Close tabs to the right</source>
<target state="translated">Chiudi schede a destra</target>
</trans-unit>
<trans-unit id="CloseOthers" translate="yes" xml:space="preserve">
<source>Close others</source>
<target state="translated">Chiudi le altre schede</target>
</trans-unit>
</group>
</body>
</file>
Expand Down
14 changes: 10 additions & 4 deletions src/Files/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1560,9 +1560,6 @@
<data name="PropertyItemCount" xml:space="preserve">
<value>Item count</value>
</data>
<data name="HorizontalMultitaskingControlCloseTabsToTheRight.Text" xml:space="preserve">
<value>Close tabs to the right</value>
</data>
<data name="StatusDeletionFailed" xml:space="preserve">
<value>Deletion Failed</value>
</data>
Expand Down Expand Up @@ -2738,4 +2735,13 @@ We use App Center to track which settings are being used, find bugs, and fix cra
<data name="Install" xml:space="preserve">
<value>Install</value>
</data>
</root>
<data name="CloseTabsToTheLeft" xml:space="preserve">
<value>Close tabs to the left</value>
</data>
<data name="CloseTabsToTheRight" xml:space="preserve">
<value>Close tabs to the right</value>
</data>
<data name="CloseOthers" xml:space="preserve">
<value>Close others</value>
</data>
</root>
12 changes: 9 additions & 3 deletions src/Files/Strings/it-IT/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1335,9 +1335,6 @@
<data name="ElevateConfirmDialog.Content" xml:space="preserve">
<value>Vuoi continuare come amministratore?</value>
</data>
<data name="HorizontalMultitaskingControlCloseTabsToTheRight.Text" xml:space="preserve">
<value>Chiudi schede a destra</value>
</data>
<data name="FullTrustStatusTeachingTip.Title" xml:space="preserve">
<value>Amministratore</value>
</data>
Expand Down Expand Up @@ -2596,4 +2593,13 @@ Usiamo App Center per tenere traccia dell'utilizzo dell'app, trovare bug e risol
<data name="Bytes" xml:space="preserve">
<value>Byte</value>
</data>
<data name="CloseTabsToTheLeft" xml:space="preserve">
<value>Chiudi schede a sinistra</value>
</data>
<data name="CloseTabsToTheRight" xml:space="preserve">
<value>Chiudi schede a destra</value>
</data>
<data name="CloseOthers" xml:space="preserve">
<value>Chiudi le altre schede</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ public List<ITabItemContent> GetAllTabInstances()
return MainPageViewModel.AppInstances.Select(x => x.Control?.TabItemContent).ToList();
}

public void CloseTabsToTheLeft(object sender, RoutedEventArgs e)
=> MultitaskingTabsHelpers.CloseTabsToTheLeft(((FrameworkElement)sender).DataContext as TabItem, this);

public void CloseTabsToTheRight(object sender, RoutedEventArgs e)
{
MultitaskingTabsHelpers.CloseTabsToTheRight(((FrameworkElement)sender).DataContext as TabItem, this);
}
=> MultitaskingTabsHelpers.CloseTabsToTheRight(((FrameworkElement)sender).DataContext as TabItem, this);

public void CloseOthers(object sender, RoutedEventArgs e)
=> MultitaskingTabsHelpers.CloseOthers(((FrameworkElement)sender).DataContext as TabItem, this);

public async void ReopenClosedTab(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -165,4 +169,4 @@ public void SetLoadingIndicatorStatus(ITabItem item, bool loading)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:local1="using:Files"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:helpers="using:Files.Helpers"
xmlns:vm="using:Files.ViewModels"
d:DesignHeight="300"
d:DesignWidth="400"
Expand Down Expand Up @@ -52,12 +53,21 @@
<FontIcon Glyph="&#xE8A7;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutItem
x:Name="MenuItemCloseTabsToTheLeft"
Click="CloseTabsToTheLeft"
DataContextChanged="MenuItemCloseTabsToTheLeft_DataContextChanged"
Text="{helpers:ResourceString Name=CloseTabsToTheLeft}" />
<MenuFlyoutItem
x:Name="MenuItemCloseTabsToTheRight"
x:Uid="HorizontalMultitaskingControlCloseTabsToTheRight"
Click="CloseTabsToTheRight"
DataContextChanged="MenuItemCloseTabsToTheRight_DataContextChanged"
Text="Close tabs to the right" />
Text="{helpers:ResourceString Name=CloseTabsToTheRight}" />
<MenuFlyoutItem
x:Name="MenuItemCloseOthers"
Click="CloseOthers"
DataContextChanged="MenuItemCloseOthers_DataContextChanged"
Text="{helpers:ResourceString Name=CloseOthers}" />
<MenuFlyoutItem
x:Name="MenuItemReopenClosedTab"
x:Uid="HorizontalMultitaskingControlReopenClosedTab"
Expand Down Expand Up @@ -129,4 +139,4 @@
HorizontalAlignment="Left"
Child="{x:Bind ActionsControl, Mode=OneWay}" />
</Grid>
</local:BaseMultitaskingControl>
</local:BaseMultitaskingControl>
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,22 @@ private void TabItemContextMenu_Opening(object sender, object e)
MenuItemReopenClosedTab.IsEnabled = RecentlyClosedTabs.Any();
}

private void MenuItemCloseTabsToTheLeft_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
{
TabItem tabItem = args.NewValue as TabItem;
MenuItemCloseTabsToTheLeft.IsEnabled = MainPageViewModel.AppInstances.IndexOf(tabItem) > 0;
}

private void MenuItemCloseTabsToTheRight_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
{
TabItem tabItem = args.NewValue as TabItem;
MenuItemCloseTabsToTheRight.IsEnabled = MainPageViewModel.AppInstances.IndexOf(tabItem) < MainPageViewModel.AppInstances.Count - 1;
}

if (MainPageViewModel.AppInstances.IndexOf(tabItem) == MainPageViewModel.AppInstances.Count - 1)
{
MenuItemCloseTabsToTheRight.IsEnabled = false;
}
else
{
MenuItemCloseTabsToTheRight.IsEnabled = true;
}
private void MenuItemCloseOthers_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
{
TabItem tabItem = args.NewValue as TabItem;
MenuItemCloseOthers.IsEnabled = MainPageViewModel.AppInstances.Count > 1;
}

public override DependencyObject ContainerFromItem(ITabItem item) => HorizontalTabView.ContainerFromItem(item);
Expand All @@ -225,4 +229,4 @@ public Visibility TabStripVisibility
public static readonly DependencyProperty TabStripVisibilityProperty =
DependencyProperty.Register("TabStripVisibility", typeof(Visibility), typeof(HorizontalMultitaskingControl), new PropertyMetadata(Visibility.Visible));
}
}
}