Skip to content

Commit 6e587bf

Browse files
authored
Fixes an issue for which "close tab to the right" was sometimes improperly enabled (#4198)
1 parent b911357 commit 6e587bf

File tree

6 files changed

+35
-45
lines changed

6 files changed

+35
-45
lines changed

Files/App.xaml.cs

-14
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,6 @@ private void OnLeavingBackground(object sender, LeavingBackgroundEventArgs e)
141141
DrivesManager?.ResumeDeviceWatcher();
142142
}
143143

144-
public static INavigationControlItem RightClickedItem;
145-
146-
public static void UnpinItem_Click(object sender, RoutedEventArgs e)
147-
{
148-
if (RightClickedItem.Path.Equals(AppSettings.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
149-
{
150-
AppSettings.PinRecycleBinToSideBar = false;
151-
}
152-
else if (RightClickedItem.Section == SectionType.Favorites)
153-
{
154-
SidebarPinnedController.Model.RemoveItem(RightClickedItem.Path.ToString());
155-
}
156-
}
157-
158144
public static Windows.UI.Xaml.UnhandledExceptionEventArgs ExceptionInfo { get; set; }
159145
public static string ExceptionStackTrace { get; set; }
160146
public static List<string> pathsToDeleteAfterPaste = new List<string>();

Files/UserControls/MultitaskingControl/HorizontalMultitaskingControl.xaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@
4949
</MenuFlyoutItem.Icon>
5050
</MenuFlyoutItem>
5151
<MenuFlyoutItem
52+
x:Name="MenuItemCloseTabsToTheRight"
5253
x:Uid="HorizontalMultitaskingControlCloseTabsToTheRight"
5354
Click="{x:Bind views:MainPage.CloseTabsToTheRight}"
5455
Text="Close tabs to the right"
55-
IsEnabled="{x:Bind CloseTabsToTheRightEnabled, Mode=OneWay}"/>
56+
DataContextChanged="MenuItemCloseTabsToTheRight_DataContextChanged" />
5657
</MenuFlyout>
5758
</ResourceDictionary>
5859
<ResourceDictionary>

Files/UserControls/MultitaskingControl/HorizontalMultitaskingControl.xaml.cs

+11-22
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ public sealed partial class HorizontalMultitaskingControl : BaseMultitaskingCont
2121

2222
private SettingsViewModel AppSettings => App.AppSettings;
2323

24-
private bool closeTabsToTheRightEnabled = true;
25-
public bool CloseTabsToTheRightEnabled
26-
{
27-
get => closeTabsToTheRightEnabled;
28-
private set
29-
{
30-
if (value != closeTabsToTheRightEnabled)
31-
{
32-
closeTabsToTheRightEnabled = value;
33-
OnPropertyChanged();
34-
}
35-
}
36-
}
37-
3824
public HorizontalMultitaskingControl()
3925
{
4026
InitializeComponent();
@@ -187,24 +173,27 @@ private async void TabStrip_TabDroppedOutside(TabView sender, TabViewTabDroppedO
187173

188174
private void TabItemContextMenu_Opening(object sender, object e)
189175
{
190-
TabItem tabItem = (((MenuFlyout)sender).Items.First()).DataContext as TabItem;
191-
192-
if (MainPage.AppInstances.IndexOf(tabItem) == MainPage.AppInstances.Count - 1)
176+
if (MainPage.MultitaskingControl.Items.Count == 1)
193177
{
194-
CloseTabsToTheRightEnabled = false;
178+
MenuItemMoveTabToNewWindow.IsEnabled = false;
195179
}
196180
else
197181
{
198-
CloseTabsToTheRightEnabled = true;
182+
MenuItemMoveTabToNewWindow.IsEnabled = true;
199183
}
184+
}
200185

201-
if (MainPage.MultitaskingControl.Items.Count == 1)
186+
private void MenuItemCloseTabsToTheRight_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
187+
{
188+
TabItem tabItem = args.NewValue as TabItem;
189+
190+
if (MainPage.AppInstances.IndexOf(tabItem) == MainPage.AppInstances.Count - 1)
202191
{
203-
MenuItemMoveTabToNewWindow.IsEnabled = false;
192+
MenuItemCloseTabsToTheRight.IsEnabled = false;
204193
}
205194
else
206195
{
207-
MenuItemMoveTabToNewWindow.IsEnabled = true;
196+
MenuItemCloseTabsToTheRight.IsEnabled = true;
208197
}
209198
}
210199
}

Files/UserControls/SidebarControl.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
x:Name="UnpinItem"
187187
x:Uid="SideBarUnpinFromSideBar"
188188
x:Load="{x:Bind ShowUnpinItem, Mode=OneWay}"
189-
Click="{x:Bind local1:App.UnpinItem_Click}"
189+
Click="{x:Bind UnpinItem_Click}"
190190
Text="Unpin from Sidebar">
191191
<MenuFlyoutItem.Icon>
192192
<FontIcon Glyph="&#xE77A;" />

Files/UserControls/SidebarControl.xaml.cs

+20-6
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,27 @@ public bool RecycleBinHasItems
194194
}
195195
}
196196

197+
public INavigationControlItem RightClickedItem;
198+
197199
public event PropertyChangedEventHandler PropertyChanged;
198200

199201
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
200202
{
201203
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
202204
}
203205

206+
public void UnpinItem_Click(object sender, RoutedEventArgs e)
207+
{
208+
if (RightClickedItem.Path.Equals(AppSettings.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
209+
{
210+
AppSettings.PinRecycleBinToSideBar = false;
211+
}
212+
else if (RightClickedItem.Section == SectionType.Favorites)
213+
{
214+
App.SidebarPinnedController.Model.RemoveItem(RightClickedItem.Path.ToString());
215+
}
216+
}
217+
204218
private void Sidebar_ItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs args)
205219
{
206220
if (args.InvokedItem == null || args.InvokedItemContainer == null)
@@ -245,8 +259,8 @@ private void NavigationViewLocationItem_RightTapped(object sender, RightTappedRo
245259
}
246260
}
247261

262+
RightClickedItem = item;
248263
SideBarItemContextFlyout.ShowAt(sidebarItem, e.GetPosition(sidebarItem));
249-
App.RightClickedItem = item;
250264
}
251265

252266
e.Handled = true;
@@ -264,7 +278,7 @@ private void NavigationViewDriveItem_RightTapped(object sender, RightTappedRoute
264278

265279
SideBarItemContextFlyout.ShowAt(sidebarItem, e.GetPosition(sidebarItem));
266280

267-
App.RightClickedItem = item;
281+
RightClickedItem = item;
268282

269283
e.Handled = true;
270284
}
@@ -281,19 +295,19 @@ private void NavigationViewWSLItem_RightTapped(object sender, RightTappedRoutedE
281295

282296
SideBarItemContextFlyout.ShowAt(sidebarItem, e.GetPosition(sidebarItem));
283297

284-
App.RightClickedItem = item;
298+
RightClickedItem = item;
285299

286300
e.Handled = true;
287301
}
288302

289303
private void OpenInNewTab_Click(object sender, RoutedEventArgs e)
290304
{
291-
Interaction.OpenPathInNewTab(App.RightClickedItem.Path);
305+
Interaction.OpenPathInNewTab(RightClickedItem.Path);
292306
}
293307

294308
private async void OpenInNewWindow_Click(object sender, RoutedEventArgs e)
295309
{
296-
await Interaction.OpenPathInNewWindowAsync(App.RightClickedItem.Path);
310+
await Interaction.OpenPathInNewWindowAsync(RightClickedItem.Path);
297311
}
298312

299313
private void NavigationViewItem_DragStarting(UIElement sender, DragStartingEventArgs args)
@@ -555,7 +569,7 @@ private void SettingsButton_Tapped(object sender, TappedRoutedEventArgs e)
555569

556570
private async void EjectDevice_Click(object sender, RoutedEventArgs e)
557571
{
558-
await DeviceHelpers.EjectDeviceAsync(App.RightClickedItem.Path);
572+
await DeviceHelpers.EjectDeviceAsync(RightClickedItem.Path);
559573
}
560574

561575
private void SidebarNavView_Loaded(object sender, RoutedEventArgs e)

Files/Views/MainPage.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public static async void DuplicateTabAtIndex(object sender, RoutedEventArgs e)
189189
}
190190
}
191191

192-
public static async void CloseTabsToTheRight(object sender, RoutedEventArgs e)
192+
public static void CloseTabsToTheRight(object sender, RoutedEventArgs e)
193193
{
194194
TabItem tabItem = ((FrameworkElement)sender).DataContext as TabItem;
195195
int index = AppInstances.IndexOf(tabItem);

0 commit comments

Comments
 (0)