Browse Source

Fix focus when active tab page is changed via the Window menu

pull/3297/head
tom-englert 7 months ago
parent
commit
d989085a58
  1. 9
      ILSpy/Commands/ShowPane.cs
  2. 3
      ILSpy/Util/MenuService.cs
  3. 17
      ILSpy/ViewModels/TabPageModel.cs

9
ILSpy/Commands/ShowPane.cs

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
using ICSharpCode.ILSpy.Docking;
using ICSharpCode.ILSpy.Properties;
using ICSharpCode.ILSpy.ViewModels;
namespace ICSharpCode.ILSpy.Commands
@ -30,7 +29,13 @@ namespace ICSharpCode.ILSpy.Commands @@ -30,7 +29,13 @@ namespace ICSharpCode.ILSpy.Commands
public override void Execute(object parameter)
{
DockWorkspace.Instance.ActiveTabPage = model;
var workspace = DockWorkspace.Instance;
// ensure the tab control is focused before setting the active tab page, else the tab will not be focused
workspace.ActiveTabPage?.Focus();
// reset first, else clicking on the already active tab will not focus the tab and the menu checkmark will not be updated
workspace.ActiveTabPage = null;
workspace.ActiveTabPage = model;
}
}
}

3
ILSpy/Util/MenuService.cs

@ -207,7 +207,8 @@ namespace ICSharpCode.ILSpy.Util @@ -207,7 +207,8 @@ namespace ICSharpCode.ILSpy.Util
menuItem.SetBinding(MenuItem.IsCheckedProperty, new Binding(nameof(dock.ActiveTabPage)) {
Source = dock,
ConverterParameter = pane,
Converter = BinaryOperationConverter.Equality
Converter = BinaryOperationConverter.Equality,
Mode = BindingMode.OneWay
});
return menuItem;

17
ILSpy/ViewModels/TabPageModel.cs

@ -17,10 +17,14 @@ @@ -17,10 +17,14 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using ICSharpCode.ILSpy.TextView;
using TomsToolbox.Wpf;
namespace ICSharpCode.ILSpy.ViewModels
{
public class TabPageModel : PaneModel
@ -96,6 +100,19 @@ namespace ICSharpCode.ILSpy.ViewModels @@ -96,6 +100,19 @@ namespace ICSharpCode.ILSpy.ViewModels
tabPage.Title = Properties.Resources.Decompiling;
action(textView);
}
public static void Focus(this TabPageModel tabPage)
{
if (tabPage.Content is not FrameworkElement content)
return;
var focusable = content
.VisualDescendantsAndSelf()
.OfType<FrameworkElement>()
.FirstOrDefault(item => item.Focusable);
focusable?.Focus();
}
}
public interface IHaveState

Loading…
Cancel
Save