Browse Source

Allow routing WPF commands to SDWindowsFormsHost without setting focus on a WinForms control

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/reports@6094 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
b410bcd465
  1. 4
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs
  2. 18
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs

4
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs

@ -137,7 +137,7 @@ namespace ICSharpCode.SharpDevelop.Gui
RoutedCommand routedCommand = e.Command as RoutedCommand; RoutedCommand routedCommand = e.Command as RoutedCommand;
AvalonWorkbenchWindow workbenchWindow = ActiveWorkbenchWindow as AvalonWorkbenchWindow; AvalonWorkbenchWindow workbenchWindow = ActiveWorkbenchWindow as AvalonWorkbenchWindow;
if (!e.Handled && routedCommand != null && workbenchWindow != null && !isInNestedCanExecute) { if (!e.Handled && routedCommand != null && workbenchWindow != null && !isInNestedCanExecute) {
IInputElement target = CustomFocusManager.GetFocusedChild(workbenchWindow); IInputElement target = workbenchWindow.GetCommandTarget();
if (target != null && target != e.OriginalSource) { if (target != null && target != e.OriginalSource) {
isInNestedCanExecute = true; isInNestedCanExecute = true;
try { try {
@ -158,7 +158,7 @@ namespace ICSharpCode.SharpDevelop.Gui
RoutedCommand routedCommand = e.Command as RoutedCommand; RoutedCommand routedCommand = e.Command as RoutedCommand;
AvalonWorkbenchWindow workbenchWindow = ActiveWorkbenchWindow as AvalonWorkbenchWindow; AvalonWorkbenchWindow workbenchWindow = ActiveWorkbenchWindow as AvalonWorkbenchWindow;
if (!e.Handled && routedCommand != null && workbenchWindow != null && !isInNestedExecute) { if (!e.Handled && routedCommand != null && workbenchWindow != null && !isInNestedExecute) {
IInputElement target = CustomFocusManager.GetFocusedChild(workbenchWindow); IInputElement target = workbenchWindow.GetCommandTarget();
if (target != null && target != e.OriginalSource) { if (target != null && target != e.OriginalSource) {
isInNestedExecute = true; isInNestedExecute = true;
try { try {

18
src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonWorkbenchWindow.cs

@ -123,6 +123,16 @@ namespace ICSharpCode.SharpDevelop.Gui
} }
} }
SDWindowsFormsHost GetActiveWinFormsHost()
{
if (viewTabControl != null && viewTabControl.SelectedIndex >= 0 && viewTabControl.SelectedIndex < ViewContents.Count) {
TabItem page = (TabItem)viewTabControl.Items[viewTabControl.SelectedIndex];
return page.Content as SDWindowsFormsHost;
} else {
return this.Content as SDWindowsFormsHost;
}
}
public event EventHandler ActiveViewContentChanged; public event EventHandler ActiveViewContentChanged;
IViewContent oldActiveViewContent; IViewContent oldActiveViewContent;
@ -443,5 +453,13 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
return "[AvalonWorkbenchWindow: " + this.Title + "]"; return "[AvalonWorkbenchWindow: " + this.Title + "]";
} }
/// <summary>
/// Gets the target for re-routing commands to this window.
/// </summary>
internal IInputElement GetCommandTarget()
{
return CustomFocusManager.GetFocusedChild(this) ?? GetActiveWinFormsHost();
}
} }
} }

Loading…
Cancel
Save