@@ -67,6 +67,7 @@ public void InitSharpDevelopCore(SharpDevelopHost.CallbackHelper callback, Start
6767 ResourceService . RegisterNeutralImages ( new ResourceManager ( "Resources.BitmapResources" , exe ) ) ;
6868
6969 MenuCommand . LinkCommandCreator = delegate ( string link ) { return new LinkCommand ( link ) ; } ;
70+ MenuCommand . KnownCommandCreator = CreateICommandForWPFCommand ;
7071 Core . Presentation . MenuService . LinkCommandCreator = MenuCommand . LinkCommandCreator ;
7172 StringParser . RegisterStringTagProvider ( new SharpDevelopStringTagProvider ( ) ) ;
7273
@@ -100,6 +101,41 @@ public void InitSharpDevelopCore(SharpDevelopHost.CallbackHelper callback, Start
100101
101102 LoggingService . Info ( "InitSharpDevelop finished" ) ;
102103 }
104+
105+ static ICommand CreateICommandForWPFCommand ( AddIn addIn , string commandName )
106+ {
107+ var wpfCommand = Core . Presentation . MenuService . GetRegisteredCommand ( addIn , commandName ) ;
108+ if ( wpfCommand != null )
109+ return new WpfCommandWrapper ( wpfCommand ) ;
110+ else
111+ return null ;
112+ }
113+
114+ sealed class WpfCommandWrapper : AbstractCommand
115+ {
116+ readonly System . Windows . Input . ICommand wpfCommand ;
117+
118+ public WpfCommandWrapper ( System . Windows . Input . ICommand wpfCommand )
119+ {
120+ this . wpfCommand = wpfCommand ;
121+ }
122+
123+ public override void Run ( )
124+ {
125+ var routedCommand = wpfCommand as System . Windows . Input . RoutedCommand ;
126+ if ( routedCommand != null ) {
127+ var target = System . Windows . Input . FocusManager . GetFocusedElement ( WorkbenchSingleton . MainWindow ) ;
128+ routedCommand . Execute ( this . Owner , target ) ;
129+ } else {
130+ wpfCommand . Execute ( this . Owner ) ;
131+ }
132+ }
133+
134+ public override string ToString ( )
135+ {
136+ return "[WpfCommandWrapper " + wpfCommand + "]" ;
137+ }
138+ }
103139 #endregion
104140
105141 #region Initialize and run Workbench
0 commit comments