Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4127 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts^2
16 changed files with 393 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.Core |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Creates descriptor containing information about command binding
|
||||||
|
/// </summary>
|
||||||
|
public class CommandBindingDoozer : IDoozer |
||||||
|
{ |
||||||
|
/// <see cref="IDoozer.HandleConditions" />
|
||||||
|
public bool HandleConditions { |
||||||
|
get { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <see cref="IDoozer.BuildItem(object, Codon, System.Collections.ArrayList)">
|
||||||
|
/// Builds CommandBindingDescriptor
|
||||||
|
/// </see>
|
||||||
|
public object BuildItem(object caller, Codon codon, System.Collections.ArrayList subItems) |
||||||
|
{ |
||||||
|
return new CommandBindingDescriptor(codon); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.Core |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Creates descriptor containing information about input binding
|
||||||
|
/// </summary>
|
||||||
|
public class InputBindingDoozer : IDoozer |
||||||
|
{ |
||||||
|
/// <see cref="IDoozer.HandleConditions" />
|
||||||
|
public bool HandleConditions { |
||||||
|
get { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <see cref="IDoozer.BuildItem(object, Codon, System.Collections.ArrayList)">
|
||||||
|
/// Builds InputBindingDescriptor
|
||||||
|
/// </see>
|
||||||
|
public object BuildItem(object caller, Codon codon, System.Collections.ArrayList subItems) |
||||||
|
{ |
||||||
|
return new InputBindingDescriptor(codon); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.Core |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Stores information about routed UI command loaded from add-in tree
|
||||||
|
/// </summary>
|
||||||
|
public class RoutedUICommandDescriptor |
||||||
|
{ |
||||||
|
private Codon codon; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Text presented to user
|
||||||
|
/// </summary>
|
||||||
|
public string Text { |
||||||
|
get { |
||||||
|
return codon.Properties["text"]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Routed command name
|
||||||
|
/// </summary>
|
||||||
|
public string Name { |
||||||
|
get { |
||||||
|
return codon.Properties["id"]; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="codon">Reference to codon used to create this descriptor</param>
|
||||||
|
public RoutedUICommandDescriptor(Codon codon) |
||||||
|
{ |
||||||
|
this.codon = codon; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
using System; |
||||||
|
|
||||||
|
namespace ICSharpCode.Core |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Creates descriptor containing information about routed UI command
|
||||||
|
/// </summary>
|
||||||
|
public class RoutedUICommandDoozer : IDoozer |
||||||
|
{ |
||||||
|
/// <see cref="IDoozer.HandleConditions" />
|
||||||
|
public bool HandleConditions { |
||||||
|
get { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <see cref="IDoozer.BuildItem(object, Codon, System.Collections.ArrayList)">
|
||||||
|
/// Builds RoutedUICommandDescriptor
|
||||||
|
/// </see>
|
||||||
|
public object BuildItem(object caller, Codon codon, System.Collections.ArrayList subItems) |
||||||
|
{ |
||||||
|
return new RoutedUICommandDescriptor(codon); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
using System; |
||||||
|
using System.Reflection; |
||||||
|
using System.Windows.Input; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.Core.Presentation |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Description of CommandsService.
|
||||||
|
/// </summary>
|
||||||
|
public static class CommandsService |
||||||
|
{ |
||||||
|
public static void RegisterRoutedUICommands(object caller, string path) |
||||||
|
{ |
||||||
|
var descriptors = AddInTree.BuildItems<RoutedUICommandDescriptor>(path, caller, false); |
||||||
|
foreach(var desc in descriptors) { |
||||||
|
CommandsRegistry.RegisterRoutedUICommand(desc.Name, desc.Text); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void RegisterCommandBindings(object caller, string path) |
||||||
|
{ |
||||||
|
var descriptors = AddInTree.BuildItems<CommandBindingDescriptor>(path, caller, false); |
||||||
|
foreach(var desc in descriptors) { |
||||||
|
var contextName = !string.IsNullOrEmpty(desc.Context) ? desc.Context : CommandsRegistry.DefaultContext; |
||||||
|
|
||||||
|
CommandsRegistry.RegisterCommandBinding(contextName, desc.Command, desc.Class, desc.Codon.AddIn, desc.Lazy); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static void RegisterInputBindings(object caller, string path) |
||||||
|
{ |
||||||
|
var descriptors = AddInTree.BuildItems<InputBindingDescriptor>(path, caller, false); |
||||||
|
foreach(var desc in descriptors) { |
||||||
|
var contextName = !string.IsNullOrEmpty(desc.Context) ? desc.Context : CommandsRegistry.DefaultContext; |
||||||
|
|
||||||
|
var gesture = (KeyGesture)new KeyGestureConverter().ConvertFromInvariantString(desc.Gesture); |
||||||
|
CommandsRegistry.RegisterInputBinding(contextName, desc.Command, gesture); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,76 @@ |
|||||||
|
using System; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Input; |
||||||
|
|
||||||
|
namespace ICSharpCode.Core.Presentation |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Stores details about input binding
|
||||||
|
/// </summary>
|
||||||
|
public class InputBindingInfo |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="contextName">Context full name</param>
|
||||||
|
/// <param name="routedCommandName">Name of routed UI command which is triggered by this binding</param>
|
||||||
|
/// <param name="gesture">Gesture which triggers this binding</param>
|
||||||
|
public InputBindingInfo(string contextName, string routedCommandName, KeyGesture gesture) { |
||||||
|
ContextName = contextName; |
||||||
|
RoutedCommandName = routedCommandName; |
||||||
|
Gesture = gesture; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Context class full name
|
||||||
|
///
|
||||||
|
/// Described binding will be valid in this context
|
||||||
|
/// </summary>
|
||||||
|
public string ContextName { |
||||||
|
get; set; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Context class instance
|
||||||
|
///
|
||||||
|
/// Described binding will be valid in this context
|
||||||
|
/// </summary>
|
||||||
|
public UIElement Context { |
||||||
|
get { |
||||||
|
UIElement context; |
||||||
|
CommandsRegistry.contexts.TryGetValue(ContextName, out context); |
||||||
|
|
||||||
|
return context; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Routed command name
|
||||||
|
///
|
||||||
|
/// Described binding triggers this routed command
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="RoutedCommand"></seealso>
|
||||||
|
public string RoutedCommandName { |
||||||
|
get; set; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Routed command instance
|
||||||
|
///
|
||||||
|
/// Described binding triggers this routed command
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="RoutedCommandName"></seealso>
|
||||||
|
public RoutedUICommand RoutedCommand { |
||||||
|
get { |
||||||
|
return CommandsRegistry.GetRoutedUICommand(RoutedCommandName); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gesture which triggers this binding
|
||||||
|
/// </summary>
|
||||||
|
public KeyGesture Gesture { |
||||||
|
get; set; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
using System; |
||||||
|
using System.Windows.Input; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.Core.Presentation |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Wraps SharpDevelop's native command inside WPF command
|
||||||
|
/// </summary>
|
||||||
|
public class WpfCommandWrapper : System.Windows.Input.ICommand |
||||||
|
{ |
||||||
|
ICommand command; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">SharpDevelop native command</param>
|
||||||
|
public WpfCommandWrapper(ICommand command) |
||||||
|
{ |
||||||
|
this.command = command; |
||||||
|
} |
||||||
|
|
||||||
|
/// <see cref="System.Windows.Input.ICommand.CanExecuteChanged">
|
||||||
|
/// Not used because SharpDevelop's native command implementation
|
||||||
|
/// doesn't support it
|
||||||
|
/// </see>
|
||||||
|
public event EventHandler CanExecuteChanged; |
||||||
|
|
||||||
|
/// <see cref="System.Windows.Input.ICommand.Execute(object)" />
|
||||||
|
public void Execute(object parameter) |
||||||
|
{ |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
/// <see cref="System.Windows.Input.ICommand.CanExecute(object)" />
|
||||||
|
public bool CanExecute(object parameter) |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue