Browse Source

Implemented custom command routing: if a WPF routed command is not handled by the current focus, re-route it to the logical focus of the active workbench window.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5213 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
4c27af8849
  1. 34
      src/Main/Base/Project/Src/Gui/Workbench/Layouts/AvalonDockLayout.cs

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

@ -109,6 +109,8 @@ namespace ICSharpCode.SharpDevelop.Gui
throw new InvalidOperationException("Can attach only once!"); throw new InvalidOperationException("Can attach only once!");
this.workbench = (WpfWorkbench)workbench; this.workbench = (WpfWorkbench)workbench;
this.workbench.mainContent.Content = dockingManager; this.workbench.mainContent.Content = dockingManager;
CommandManager.AddCanExecuteHandler(this.workbench, OnCanExecuteRoutedCommand);
CommandManager.AddExecutedHandler(this.workbench, OnExecuteRoutedCommand);
Busy = true; Busy = true;
try { try {
foreach (PadDescriptor pd in workbench.PadContentCollection) { foreach (PadDescriptor pd in workbench.PadContentCollection) {
@ -124,6 +126,38 @@ namespace ICSharpCode.SharpDevelop.Gui
{ {
StoreConfiguration(); StoreConfiguration();
this.workbench.mainContent.Content = null; this.workbench.mainContent.Content = null;
CommandManager.RemoveCanExecuteHandler(this.workbench, OnCanExecuteRoutedCommand);
CommandManager.RemoveExecutedHandler(this.workbench, OnExecuteRoutedCommand);
}
// Custom command routing:
// if the command isn't handled on the current focus, try to execute it on the focus inside the active workbench window
void OnCanExecuteRoutedCommand(object sender, CanExecuteRoutedEventArgs e)
{
workbench.VerifyAccess();
RoutedCommand routedCommand = e.Command as RoutedCommand;
AvalonWorkbenchWindow workbenchWindow = ActiveWorkbenchWindow as AvalonWorkbenchWindow;
if (!e.Handled && routedCommand != null && workbenchWindow != null) {
IInputElement target = CustomFocusManager.GetFocusedChild(workbenchWindow);
if (target != null && target != e.OriginalSource) {
e.CanExecute = routedCommand.CanExecute(e.Parameter, target);
e.Handled = true;
}
}
}
void OnExecuteRoutedCommand(object sender, ExecutedRoutedEventArgs e)
{
workbench.VerifyAccess();
RoutedCommand routedCommand = e.Command as RoutedCommand;
AvalonWorkbenchWindow workbenchWindow = ActiveWorkbenchWindow as AvalonWorkbenchWindow;
if (!e.Handled && routedCommand != null && workbenchWindow != null) {
IInputElement target = CustomFocusManager.GetFocusedChild(workbenchWindow);
if (target != null && target != e.OriginalSource) {
routedCommand.Execute(e.Parameter, target);
e.Handled = true;
}
}
} }
Dictionary<PadDescriptor, AvalonPadContent> pads = new Dictionary<PadDescriptor, AvalonPadContent>(); Dictionary<PadDescriptor, AvalonPadContent> pads = new Dictionary<PadDescriptor, AvalonPadContent>();

Loading…
Cancel
Save