Browse Source
The new shortcut handling has moved to branches/shortcuts/ git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4181 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts^2
52 changed files with 576 additions and 3109 deletions
@ -1,75 +0,0 @@
@@ -1,75 +0,0 @@
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
/// <summary>
|
||||
/// Stores information about command binding loaded from add-in tree
|
||||
/// </summary>
|
||||
public class CommandBindingDescriptor |
||||
{ |
||||
/// <summary>
|
||||
/// Codon used to create this descriptor
|
||||
/// </summary>
|
||||
public Codon Codon { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Full name of the command class which will be executed when this
|
||||
/// binding is triggered
|
||||
/// </summary>
|
||||
public string Class { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Full name of routed UI command which will trigger this binding
|
||||
/// </summary>
|
||||
public string Command { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Full name of context class.
|
||||
///
|
||||
/// UI element in which this binding will be valid
|
||||
/// </summary>
|
||||
public string Context { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gestures.
|
||||
///
|
||||
/// Optional, if provided input bindings in the same context will be created
|
||||
/// </summary>
|
||||
public string Gestures { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Lazy loading
|
||||
///
|
||||
/// If true add-in referenced assemblies are loaded when command is invoked.
|
||||
/// Otherwise command can't be invoked until addin is loaded
|
||||
/// </summary>
|
||||
public bool Lazy { |
||||
get { |
||||
return Codon.Properties["lazy"] == "1" || Codon.Properties["lazy"] == "true"; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="codon">Reference to codon used to create this descriptor</param>
|
||||
public CommandBindingDescriptor(Codon codon) |
||||
{ |
||||
Codon = codon; |
||||
Class = Codon.Properties["class"]; |
||||
Command = Codon.Properties["command"]; |
||||
Context = Codon.Properties["context"]; |
||||
Gestures = Codon.Properties["gestures"]; |
||||
} |
||||
} |
||||
} |
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
/// <attribute name="command" use="required">
|
||||
/// Name of routed UI command which triggers this binding.
|
||||
///
|
||||
/// Routed UI command details are specified in path '/SharpDevelop/Workbench/RoutedUICommands'
|
||||
/// </attribute>
|
||||
/// <attribute name="class" use="required">
|
||||
/// Class implementing System.Window.Input.ICommand or
|
||||
/// ICSharpCode.Core class. CanExecute and Executed methods
|
||||
/// are used to handle raised event
|
||||
/// </attribute>
|
||||
/// <attribute name="context" use="optional">
|
||||
/// Specified binding owner
|
||||
///
|
||||
/// If context is not specified binding is applied to default context
|
||||
/// </attribute>
|
||||
/// <attribute name="lazy" use="optional" enum="1;0;true;false">
|
||||
/// Use lazy loading. If addin containing binded command is
|
||||
/// not loaded yet, load asseblies referenced in add-in and then
|
||||
/// invoke command
|
||||
/// </attribute>
|
||||
/// <attribute name="gestures" use="optional">
|
||||
/// Create input bindings in the same context which will trigger specified routed UI command
|
||||
/// </attribute>
|
||||
/// <usage>Only in /SharpDevelop/Workbench/CommandBindings</usage>
|
||||
/// <returns>
|
||||
/// CommandBindingDescriptor object
|
||||
/// </returns>
|
||||
/// <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); |
||||
} |
||||
} |
||||
} |
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
public class GesturesPlaceHolderDescriptor |
||||
{ |
||||
public string Name { |
||||
get; private set; |
||||
} |
||||
|
||||
public string Text { |
||||
get; private set; |
||||
} |
||||
|
||||
public string Gestures { |
||||
get; private set; |
||||
} |
||||
|
||||
public GesturesPlaceHolderDescriptor(Codon codon) |
||||
{ |
||||
Name = codon.Properties["name"]; |
||||
Text = codon.Properties["text"]; |
||||
Gestures = codon.Properties["gestures"]; |
||||
} |
||||
} |
||||
} |
@ -1,43 +0,0 @@
@@ -1,43 +0,0 @@
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
/// <attribute name="name" use="required">
|
||||
/// Place holder name. This name should be unique application wide
|
||||
/// </attribute>
|
||||
/// <attribute name="text" use="required">
|
||||
/// Text displayed to use
|
||||
/// </attribute>
|
||||
/// <attribute name="lazy" use="optional" enum="1;0;true;false">
|
||||
/// Use lazy loading. If addin containing binded command is
|
||||
/// not loaded yet, load asseblies referenced in add-in and then
|
||||
/// invoke command
|
||||
/// </attribute>
|
||||
/// <attribute name="gestures" use="optional">
|
||||
/// Keys which will invoke command
|
||||
/// </attribute>
|
||||
/// <usage>Only in /SharpDevelop/Workbench/CommandBindings</usage>
|
||||
/// <returns>
|
||||
/// GesturesPlaceHolder object
|
||||
/// </returns>
|
||||
/// <summary>
|
||||
/// Creates descriptor containing information about command binding
|
||||
/// </summary>
|
||||
public class GesturesPlaceHolderDoozer : IDoozer |
||||
{ |
||||
/// <see cref="IDoozer.HandleConditions" />
|
||||
public bool HandleConditions { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/// <see cref="IDoozer.BuildItem(object, Codon, System.Collections.ArrayList)">
|
||||
/// Builds GesturesPlaceHolderDoozer
|
||||
/// </see>
|
||||
public object BuildItem(object caller, Codon codon, System.Collections.ArrayList subItems) |
||||
{ |
||||
return new GesturesPlaceHolderDescriptor(codon); |
||||
} |
||||
} |
||||
} |
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
/// <summary>
|
||||
/// Stores information about input binding loaded from add-in tree
|
||||
/// </summary>
|
||||
public class InputBindingDescriptor |
||||
{ |
||||
/// <summary>
|
||||
/// Full name of routed UI command which will be invoked when this binding is triggered
|
||||
/// </summary>
|
||||
public string Command { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Full name of context class.
|
||||
///
|
||||
/// UI element in which this binding will be valid
|
||||
/// </summary>
|
||||
public string Context { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Description of gesture which will trigger this bindin
|
||||
/// </summary>
|
||||
public string Gesture { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="codon">Reference to codon used to create this descriptor</param>
|
||||
public InputBindingDescriptor(Codon codon) |
||||
{ |
||||
Command = codon.Properties["command"]; |
||||
Context = codon.Properties["context"]; |
||||
Gesture = codon.Properties["gesture"]; |
||||
} |
||||
} |
||||
} |
@ -1,35 +0,0 @@
@@ -1,35 +0,0 @@
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
/// <attribute name="command" use="required">
|
||||
/// Name of routed UI command which is triggered by this binding
|
||||
/// </attribute>
|
||||
/// <attribute name="gesture" use="required">
|
||||
/// Gesture which triggers this binding
|
||||
/// </attribute>
|
||||
/// <usage>Only in /SharpDevelop/Workbench/InputBindings</usage>
|
||||
/// <returns>
|
||||
/// InputBindingDescriptor object
|
||||
/// </returns>
|
||||
/// <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); |
||||
} |
||||
} |
||||
} |
@ -1,39 +0,0 @@
@@ -1,39 +0,0 @@
|
||||
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["name"]; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="codon">Reference to codon used to create this descriptor</param>
|
||||
public RoutedUICommandDescriptor(Codon codon) |
||||
{ |
||||
this.codon = codon; |
||||
} |
||||
} |
||||
} |
@ -1,35 +0,0 @@
@@ -1,35 +0,0 @@
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
/// <attribute name="name" use="required">
|
||||
/// Routed UI command name
|
||||
/// </attribute>
|
||||
/// <attribute name="text" use="required">
|
||||
/// Routed UI command displayed name
|
||||
/// </attribute>
|
||||
/// <usage>Only in /SharpDevelop/Workbench/CommandBindings</usage>
|
||||
/// <returns>
|
||||
/// RoutedUICommandDescriptor object
|
||||
/// </returns>
|
||||
/// <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); |
||||
} |
||||
} |
||||
} |
@ -1,174 +0,0 @@
@@ -1,174 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
public delegate void GesturesPlaceHolderUpdate(); |
||||
|
||||
/// <summary>
|
||||
/// Stores gestures place holders
|
||||
///
|
||||
/// Through this class one can register a handler which which would be
|
||||
/// called when gestures associated with place holder name are updated
|
||||
/// </summary>
|
||||
public static class BaseGesturesPlaceHolderRegistry |
||||
{ |
||||
private static Dictionary<string, GesturesPlaceHolderInfo> gesturePlaceHolders = new Dictionary<string, GesturesPlaceHolderInfo>(); |
||||
|
||||
private static Dictionary<string, string> commandTexts = new Dictionary<string, string>(); |
||||
private static Dictionary<string, List<string>> registeredKeys = new Dictionary<string, List<string>>(); |
||||
private static Dictionary<string, List<WeakReference>> commandKeysUpdateHandlers = new Dictionary<string, List<WeakReference>>(); |
||||
|
||||
/// <summary>
|
||||
/// Register a place holder
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name. Unique application wide</param>
|
||||
/// <param name="placeHolderText">Place holder text visible to user</param>
|
||||
public static void RegisterPlaceHolder(string placeHolderName, string placeHolderText) { |
||||
gesturePlaceHolders.Add(placeHolderName, new GesturesPlaceHolderInfo(placeHolderName, placeHolderText)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Get gestures assigned to place holder
|
||||
///
|
||||
/// Use KeysCollectionConverter or InputGestureCollectionConverter
|
||||
/// to convert returned value representation to required format
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <returns>Array of gestures</returns>
|
||||
public static string[] GetGestures(string placeHolderName) { |
||||
if(!gesturePlaceHolders.ContainsKey(placeHolderName) || gesturePlaceHolders[placeHolderName].Gestures.Count == 0) { |
||||
return new string[] { }; |
||||
} |
||||
|
||||
return gesturePlaceHolders[placeHolderName].Gestures.ToArray(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Add gestures to place holder
|
||||
///
|
||||
/// Use KeysCollectionConverter or InputGestureCollectionConverter
|
||||
/// to convert gestures to string representation
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <param name="gestures">Added gestures</param>
|
||||
public static void AddGestures(string placeHolderName, IEnumerable<string> gestures) { |
||||
if(!gesturePlaceHolders.ContainsKey(placeHolderName)) { |
||||
throw new ApplicationException("No gestures place holder with name '" + placeHolderName + "' is registered"); |
||||
} |
||||
|
||||
foreach(string gesture in gestures) { |
||||
if(!gesturePlaceHolders[placeHolderName].Gestures.Contains(gesture)) { |
||||
gesturePlaceHolders[placeHolderName].Gestures.Add(gesture); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove gestures from place holder
|
||||
///
|
||||
/// Use KeysCollectionConverter or InputGestureCollectionConverter
|
||||
/// to convert gestures to string representation
|
||||
///
|
||||
/// Null argumens are igonred and all gestures which specify
|
||||
/// provided parameters are removed
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName"></param>
|
||||
/// <param name="gestures"></param>
|
||||
public static void RemoveGestures(string placeHolderName, IEnumerable<string> gestures) { |
||||
if(gesturePlaceHolders.ContainsKey(placeHolderName)) { |
||||
if(gestures == null) { |
||||
gesturePlaceHolders[placeHolderName].Gestures.Clear(); |
||||
} else { |
||||
for(int i = gesturePlaceHolders[placeHolderName].Gestures.Count - 1; i >= 0; i--) { |
||||
foreach(string gesture in gestures) { |
||||
if(gesturePlaceHolders[placeHolderName].Gestures[i] == gesture) { |
||||
gesturePlaceHolders[placeHolderName].Gestures.RemoveAt(i); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register update handler which will trigger when gestures in
|
||||
/// place holder are updated
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <param name="handler">Handler which handles place holder gestures update</param>
|
||||
public static void RegisterUpdateHandler(string placeHolderName, GesturesPlaceHolderUpdate handler) { |
||||
if(!commandKeysUpdateHandlers.ContainsKey(placeHolderName)) { |
||||
commandKeysUpdateHandlers.Add(placeHolderName, new List<WeakReference>()); |
||||
} |
||||
|
||||
commandKeysUpdateHandlers[placeHolderName].Add(new WeakReference(handler)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Invoke delegates which handle gestures update in place holder
|
||||
///
|
||||
/// If place holder is not provided all registered handlers are invoked
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName"></param>
|
||||
public static void InvokeUpdateHandlers(string placeHolderName) { |
||||
if(placeHolderName == null) { |
||||
foreach(var handlers in commandKeysUpdateHandlers) { |
||||
foreach(var handler in handlers.Value) { |
||||
if(handler != null && handler.Target != null) { |
||||
((GesturesPlaceHolderUpdate)handler.Target).Invoke(); |
||||
} |
||||
} |
||||
} |
||||
} else { |
||||
if(commandKeysUpdateHandlers.ContainsKey(placeHolderName)) { |
||||
foreach(var handler in commandKeysUpdateHandlers[placeHolderName]) { |
||||
if(handler != null && handler.Target != null) { |
||||
((GesturesPlaceHolderUpdate)handler.Target).Invoke(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Intername representation of place holders
|
||||
/// </summary>
|
||||
class GesturesPlaceHolderInfo |
||||
{ |
||||
/// <summary>
|
||||
/// Place hollder name
|
||||
/// </summary>
|
||||
public string Name { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Place holder text visible to user
|
||||
/// </summary>
|
||||
public string Text { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Collection of gestures assigned to this place holder
|
||||
/// </summary>
|
||||
public List<string> Gestures { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="name">Place holder name</param>
|
||||
/// <param name="text">Place holder text visible to user</param>
|
||||
public GesturesPlaceHolderInfo(string name, string text) { |
||||
Name = name; |
||||
Text = text; |
||||
Gestures = new List<string>(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
@ -1,185 +0,0 @@
@@ -1,185 +0,0 @@
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Input; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
/// Stores details about command binding
|
||||
/// </summary>
|
||||
public class CommandBindingInfo |
||||
{ |
||||
private UIElement contextInstance; |
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context full name</param>
|
||||
/// <param name="routedCommandName">Name of routed UI command which triggers this binding</param>
|
||||
/// <param name="className">Command full name</param>
|
||||
/// <param name="addIn">Add-in where command is registered</param>
|
||||
/// <param name="isLazy">Lazy load command</param>
|
||||
public CommandBindingInfo(string contextName, string routedCommandName, string className, AddIn addIn, bool isLazy) { |
||||
RoutedCommandName = routedCommandName; |
||||
ContextName = contextName; |
||||
ClassName = className; |
||||
IsLazy = isLazy; |
||||
AddIn = addIn; |
||||
} |
||||
|
||||
public CommandBindingInfo(string contextName, UIElement contextInstance, string routedCommandName, string className, AddIn addIn, bool isLazy) { |
||||
RoutedCommandName = routedCommandName; |
||||
ContextName = contextName; |
||||
ClassName = className; |
||||
IsLazy = isLazy; |
||||
AddIn = addIn; |
||||
this.contextInstance = contextInstance; |
||||
} |
||||
|
||||
public CommandBindingInfo(string contextName, string routedCommandName, ExecutedRoutedEventHandler executedHandler, CanExecuteRoutedEventHandler canExecuteHandler) { |
||||
RoutedCommandName = routedCommandName; |
||||
ContextName = contextName; |
||||
this.executedEventHandler = executedHandler; |
||||
this.canExecutedEventHandler = canExecuteHandler; |
||||
} |
||||
|
||||
public CommandBindingInfo(string contextName, UIElement contextInstance, string routedCommandName, ExecutedRoutedEventHandler executedHandler, CanExecuteRoutedEventHandler canExecuteHandler) { |
||||
RoutedCommandName = routedCommandName; |
||||
ContextName = contextName; |
||||
this.executedEventHandler = executedHandler; |
||||
this.canExecutedEventHandler = canExecuteHandler; |
||||
this.contextInstance = contextInstance; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Routed command name
|
||||
///
|
||||
/// Described binding is triggered by this routed command
|
||||
/// </summary>
|
||||
/// <seealso cref="RoutedCommand"></seealso>
|
||||
public string RoutedCommandName { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Routed command instance
|
||||
///
|
||||
/// Described binding is triggered by this routed command
|
||||
/// </summary>
|
||||
/// <seealso cref="RoutedCommandName"></seealso>
|
||||
public RoutedUICommand RoutedCommand { |
||||
get { |
||||
return CommandsRegistry.GetRoutedUICommand(RoutedCommandName); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Add-in to which binded command belongs
|
||||
/// </summary>
|
||||
public AddIn AddIn { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Binded command full name
|
||||
///
|
||||
/// This command is invoke when this binding is triggered
|
||||
/// </summary>
|
||||
/// <seealso cref="Class"></seealso>
|
||||
public string ClassName { |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Binded command instance
|
||||
///
|
||||
/// This command is invoke when this binding is triggered. If this value is equal
|
||||
/// to null then add-in is not loaded yet, see <see cref="IsLazy">IsLazy</see> attribute
|
||||
/// for details
|
||||
/// </summary>
|
||||
/// <seealso cref="ClassName"></seealso>
|
||||
public System.Windows.Input.ICommand Class { |
||||
get { |
||||
if(AddIn != null && (AddIn.DependenciesLoaded || IsLazy)) { |
||||
CommandsRegistry.LoadAddinCommands(AddIn); |
||||
} |
||||
|
||||
System.Windows.Input.ICommand command; |
||||
CommandsRegistry.commands.TryGetValue(ClassName, out command); |
||||
|
||||
return command; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Context class full name
|
||||
///
|
||||
/// Described binding will be valid in this context
|
||||
/// </summary>
|
||||
public string ContextName{ |
||||
get; private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Context class instance
|
||||
///
|
||||
/// Described binding will be valid in this context
|
||||
/// </summary>
|
||||
public UIElement Context { |
||||
get { |
||||
if(contextInstance != null) { |
||||
return contextInstance; |
||||
} else { |
||||
UIElement context; |
||||
CommandsRegistry.contexts.TryGetValue(ContextName, out context); |
||||
|
||||
return context; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Lazy load
|
||||
///
|
||||
/// If lazy load is enabled then all add-in references are loaded when this
|
||||
/// command is invoked. Otherwice if add-in is not loaded and IsLazy is set
|
||||
/// to false then this binding can't be triggered until add-in is loaded.
|
||||
/// </summary>
|
||||
public bool IsLazy{ |
||||
get; private set; |
||||
} |
||||
|
||||
private ExecutedRoutedEventHandler executedEventHandler; |
||||
public void ExecutedEventHandler(object sender, ExecutedRoutedEventArgs e) { |
||||
if(executedEventHandler != null) { |
||||
executedEventHandler.Invoke(sender, e); |
||||
} else { |
||||
if(IsLazy && Class == null) { |
||||
AddIn.LoadRuntimeAssemblies(); |
||||
|
||||
var command = (ICommand)AddIn.CreateObject(ClassName); |
||||
CommandsRegistry.LoadCommand(ClassName, command); |
||||
} |
||||
|
||||
if(Class != null) { |
||||
Class.Execute(e.Parameter); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private CanExecuteRoutedEventHandler canExecutedEventHandler; |
||||
public void CanExecuteEventHandler(object sender, CanExecuteRoutedEventArgs e) { |
||||
if(canExecutedEventHandler != null) { |
||||
canExecutedEventHandler.Invoke(sender, e); |
||||
} else { |
||||
if(IsLazy && Class == null) { |
||||
e.CanExecute = true; |
||||
} else if(Class == null) { |
||||
e.CanExecute = false; |
||||
} else { |
||||
e.CanExecute = Class.CanExecute(e.Parameter); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,568 +0,0 @@
@@ -1,568 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Windows.Input; |
||||
using System.Windows; |
||||
using ICSharpCode.Core; |
||||
using System.Threading; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
public delegate void BindingsUpdatedHandler(); |
||||
|
||||
/// <summary>
|
||||
/// Global registry to store and access commands, command bindings and input bindings
|
||||
/// </summary>
|
||||
public static class CommandsRegistry |
||||
{ |
||||
/// <summary>
|
||||
/// This element is used to represent null key in dictionary
|
||||
/// </summary>
|
||||
private static UIElement NullUIElement = new UIElement(); |
||||
|
||||
/// <summary>
|
||||
/// Default application context.
|
||||
///
|
||||
/// This should be set to the root UI element
|
||||
/// </summary>
|
||||
public static string DefaultContext { |
||||
get; set; |
||||
} |
||||
|
||||
private static List<CommandBindingInfo> commandBindings = new List<CommandBindingInfo>(); |
||||
private static List<InputBindingInfo> inputBidnings = new List<InputBindingInfo>(); |
||||
|
||||
private static Dictionary<string, RoutedUICommand> routedCommands = new Dictionary<string, RoutedUICommand>(); |
||||
internal static Dictionary<string, System.Windows.Input.ICommand> commands = new Dictionary<string, System.Windows.Input.ICommand>(); |
||||
internal static Dictionary<string, UIElement> contexts = new Dictionary<string, UIElement>(); |
||||
|
||||
private static Dictionary<string, Dictionary<UIElement, List<BindingsUpdatedHandler>>> commandBindingsUpdateHandlers = new Dictionary<string, Dictionary<UIElement, List<BindingsUpdatedHandler>>>(); |
||||
private static Dictionary<string, Dictionary<UIElement, List<BindingsUpdatedHandler>>> inputBindingsUpdateHandlers = new Dictionary<string, Dictionary<UIElement, List<BindingsUpdatedHandler>>>(); |
||||
|
||||
/// <summary>
|
||||
/// Get reference to routed UI command by name
|
||||
/// </summary>
|
||||
/// <param name="routedCommandName">Routed command name</param>
|
||||
/// <returns>Routed command instance</returns>
|
||||
public static RoutedUICommand GetRoutedUICommand(string routedCommandName) { |
||||
if(routedCommands.ContainsKey(routedCommandName)) { |
||||
return routedCommands[routedCommandName]; |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks whether routed UI command registered
|
||||
/// </summary>
|
||||
/// <param name="routedCommandName">Routed command name</param>
|
||||
/// <returns>Returns value specifting whether routed UI command is registered</returns>
|
||||
public static bool IsRoutedUICommandRegistered(string routedCommandName) { |
||||
return GetRoutedUICommand(routedCommandName) != null; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register new routed command in the global registry
|
||||
///
|
||||
/// Routed command name should be unique in SharpDevelop scope.
|
||||
/// Use "." to organize commands into groups
|
||||
/// </summary>
|
||||
/// <param name="routedCommandName">Routed command name</param>
|
||||
/// <param name="text">Short text describing command functionality</param>
|
||||
public static void RegisterRoutedUICommand(string routedCommandName, string text) { |
||||
var routedCommand = new RoutedUICommand(text, routedCommandName, typeof(CommandsRegistry)); |
||||
|
||||
if(!routedCommands.ContainsKey(routedCommandName)) { |
||||
routedCommands.Add(routedCommandName, routedCommand); |
||||
} else { |
||||
var test = routedCommands[routedCommandName]; |
||||
throw new IndexOutOfRangeException("Routed UI command with name " + routedCommandName + " is already registered"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register existing routed command in the global registry
|
||||
///
|
||||
/// Routed command then can be accessed
|
||||
/// Routed command name should be uniq in SharpDevelop scope.
|
||||
/// Use "." to organize commands into groups
|
||||
/// </summary>
|
||||
/// <param name="routedCommandName">Existing routed command</param>
|
||||
public static void RegisterRoutedUICommand(RoutedUICommand existingRoutedUICommand) { |
||||
string routedCommandName = existingRoutedUICommand.OwnerType.Name + "." + existingRoutedUICommand.Name; |
||||
|
||||
if(!routedCommands.ContainsKey(routedCommandName)) { |
||||
routedCommands.Add(existingRoutedUICommand.OwnerType.Name + "." + existingRoutedUICommand.Name, existingRoutedUICommand); |
||||
} else { |
||||
throw new IndexOutOfRangeException("Routed UI command with name " + routedCommandName + " is already registered"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove routed command from global registry
|
||||
/// </summary>
|
||||
/// <param name="routedCommandName">Routed command name</param>
|
||||
public static void UnregisterRoutedUICommand(string routedCommandName) { |
||||
if(routedCommands.ContainsKey(routedCommandName)) { |
||||
routedCommands.Remove(routedCommandName); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register input binding in context
|
||||
///
|
||||
/// Registering input binding means that when specified gesture is met in specified
|
||||
/// context routed command is invoked
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Context class instance. If instance is provided this input binding only applies to provided UI element</param>
|
||||
/// <param name="routedCommandName">Routed UI command invoked on gesture run</param>
|
||||
/// <param name="gesture">Gesture</param>
|
||||
public static void RegisterInputBinding(string contextName, UIElement contextInstance, string routedCommandName, InputGesture gesture) { |
||||
var inputBindingInfo = new InputBindingInfo(contextName, contextInstance, routedCommandName, gesture); |
||||
inputBidnings.Add(inputBindingInfo); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove input bindings which satisfy provided arguments
|
||||
///
|
||||
/// Null arguments are ignored
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Unregister binding assigned to specific context instance</param>
|
||||
/// <param name="routedCommandName">Routed UI command name</param>
|
||||
/// <param name="gesture">Gesture</param>
|
||||
public static void UnregisterInputBindings(string contextName, UIElement contextInstance, string routedCommandName, InputGesture gesture) { |
||||
for(int i = inputBidnings.Count - 1; i >= 0; i--) { |
||||
if((contextName == null || inputBidnings[i].ContextName == contextName) |
||||
&& (contextInstance == null || inputBidnings[i].Context == null || inputBidnings[i].Context == contextInstance) |
||||
&& (routedCommandName == null || inputBidnings[i].RoutedCommandName == routedCommandName) |
||||
&& (gesture == null || inputBidnings[i].Gesture == gesture)) { |
||||
inputBidnings.RemoveAt(i); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register delegate which will be invoked on change in input bindings in specified context
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Register update handler which will trigger only if input bindings registered for this object where triggered</param>
|
||||
/// <param name="handler">Update handler delegate</param>
|
||||
public static void RegisterInputBindingUpdateHandler(string contextName, UIElement contextInstance, BindingsUpdatedHandler handler) { |
||||
if(contextInstance == null) { |
||||
contextInstance = NullUIElement; |
||||
} |
||||
|
||||
if(!inputBindingsUpdateHandlers.ContainsKey(contextName)) { |
||||
inputBindingsUpdateHandlers.Add(contextName, new Dictionary<UIElement, List<BindingsUpdatedHandler>>()); |
||||
} |
||||
|
||||
if(!inputBindingsUpdateHandlers[contextName].ContainsKey(contextInstance)) { |
||||
inputBindingsUpdateHandlers[contextName].Add(contextInstance, new List<BindingsUpdatedHandler>()); |
||||
} |
||||
|
||||
inputBindingsUpdateHandlers[contextName][contextInstance].Add(handler); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove input bindings update handler
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Unregister update handler which was triggered only if input bindings registered for specific instance where updated</param>
|
||||
/// <param name="handler">Update handler delegate</param>
|
||||
public static void UnregisterInputBindingUpdateHandler(string contextName, UIElement contextInstance, BindingsUpdatedHandler handler) { |
||||
if(contextInstance == null) { |
||||
contextInstance = NullUIElement; |
||||
} |
||||
if(!inputBindingsUpdateHandlers.ContainsKey(contextName)) { |
||||
if(!inputBindingsUpdateHandlers[contextName].ContainsKey(contextInstance)) { |
||||
for(int i = inputBindingsUpdateHandlers[contextName][contextInstance].Count - 1; i >= 0; i++) { |
||||
if(inputBindingsUpdateHandlers[contextName][contextInstance][i] == handler) { |
||||
inputBindingsUpdateHandlers[contextName][contextInstance].RemoveAt(i); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
/// <summary>
|
||||
/// Invoke registered input bindings update handlers registered in specified context
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
public static void InvokeInputBindingUpdateHandlers(string contextName, UIElement contextInstance) { |
||||
if(contextInstance == null) { |
||||
contextInstance = NullUIElement; |
||||
} |
||||
|
||||
if(contextName != null) { |
||||
if(inputBindingsUpdateHandlers.ContainsKey(contextName)) { |
||||
if(contextInstance == NullUIElement) { |
||||
foreach(var instanceHandlers in inputBindingsUpdateHandlers[contextName]) { |
||||
foreach(var handler in instanceHandlers.Value) { |
||||
if(handler != null) { |
||||
((BindingsUpdatedHandler)handler).Invoke(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} else if(inputBindingsUpdateHandlers[contextName].ContainsKey(contextInstance)) { |
||||
foreach(var handler in inputBindingsUpdateHandlers[contextName][contextInstance]) { |
||||
if(handler != null) { |
||||
((BindingsUpdatedHandler)handler).Invoke(); |
||||
} |
||||
} |
||||
} |
||||
} else { |
||||
foreach(var contextHandlers in inputBindingsUpdateHandlers) { |
||||
foreach(var instanceHandlers in contextHandlers.Value) { |
||||
foreach(var handler in instanceHandlers.Value) { |
||||
if(handler != null) { |
||||
((BindingsUpdatedHandler)handler).Invoke(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove all managed input bindings from input bindings collection
|
||||
/// </summary>
|
||||
/// <param name="inputBindingCollection"></param>
|
||||
public static void RemoveManagedInputBindings(InputBindingCollection inputBindingCollection) { |
||||
for(int i = inputBindingCollection.Count - 1; i >= 0; i--) { |
||||
if(inputBindingCollection[i] is ManagedInputBinding) { |
||||
inputBindingCollection.RemoveAt(i); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register command binding
|
||||
///
|
||||
/// Registering command binding means that when provided routed command is invoked
|
||||
/// in specified context event is routed to specified command (implementing ICommand class)
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Register update handler which is triggered only if input bindings registered for specific instance are updated</param>
|
||||
/// <param name="routedCommandName">Routed UI command name</param>
|
||||
/// <param name="className">Command full name to which invokation event is routed</param>
|
||||
/// <param name="addIn">Add-in in which hosts the command</param>
|
||||
/// <param name="isLazy">Load add-in referenced assemblies on command invocation</param>
|
||||
public static void RegisterCommandBinding(string contextName, UIElement contextInstance, string routedCommandName, string className, AddIn addIn, bool isLazy) { |
||||
var commandBindingInfo = new CommandBindingInfo(contextName, contextInstance, routedCommandName, className, addIn, isLazy); |
||||
commandBindings.Add(commandBindingInfo); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register command binding which when triggered provided delegates are invoked
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Register update handler which is triggered only if input bindings registered for specific instance are updated</param>
|
||||
/// <param name="routedCommandName">Routed UI command name</param>
|
||||
/// <param name="executedEventHandler">Delegate which is called when binding is triggered</param>
|
||||
/// <param name="canExecuteEventHandler">Delegate which is called to check whether executedEventHandler can be invoked</param>
|
||||
public static void RegisterCommandBinding(string contextName, UIElement contextInstance, string routedCommandName, ExecutedRoutedEventHandler executedEventHandler, CanExecuteRoutedEventHandler canExecuteEventHandler) { |
||||
var commandBindingInfo = new CommandBindingInfo(contextName, contextInstance, routedCommandName, executedEventHandler, canExecuteEventHandler); |
||||
commandBindings.Add(commandBindingInfo); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove all command bindings which satisfy provided parameters
|
||||
///
|
||||
/// Null arguments are ignored
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Unregister update handler which was triggered only if command bindings registered for specific instance where updated</param>
|
||||
/// <param name="routedCommandName">Routed UI command name</param>
|
||||
/// <param name="className">Command full name to which invokation event is routed</param>
|
||||
public static void UnregisterCommandBindings(string contextName, UIElement contextInstance, string routedCommandName, string className) { |
||||
for(int i = commandBindings.Count - 1; i >= 0; i--) { |
||||
if((contextName == null || commandBindings[i].ContextName == contextName) |
||||
&& (contextInstance == null || commandBindings[i].Context == null || commandBindings[i].Context == contextInstance) |
||||
&& (routedCommandName == null || commandBindings[i].RoutedCommandName == routedCommandName) |
||||
&& (className == null || commandBindings[i].ClassName == className)) { |
||||
inputBidnings.RemoveAt(i); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register delegate which will be invoked on any chage in command bindings of specified context
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Register update handler which is triggered only if input bindings registered for specific instance are updated</param>
|
||||
/// <param name="handler">Update handler delegate</param>
|
||||
public static void RegisterCommandBindingsUpdateHandler(string contextName, UIElement contextInstance, BindingsUpdatedHandler handler) { |
||||
if(contextInstance == null) { |
||||
contextInstance = NullUIElement; |
||||
} |
||||
if(!commandBindingsUpdateHandlers.ContainsKey(contextName)) { |
||||
commandBindingsUpdateHandlers.Add(contextName, new Dictionary<UIElement, List<BindingsUpdatedHandler>>()); |
||||
} |
||||
|
||||
if(!commandBindingsUpdateHandlers[contextName].ContainsKey(contextInstance)) { |
||||
commandBindingsUpdateHandlers[contextName].Add(contextInstance, new List<BindingsUpdatedHandler>()); |
||||
} |
||||
|
||||
commandBindingsUpdateHandlers[contextName][contextInstance].Add(handler); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove handler command bindings update handler
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Unregister update handler which was triggered only if input bindings registered for specific instance were updated</param>
|
||||
/// <param name="handler">Update handler delegate</param>
|
||||
public static void UnregisterCommandBindingsUpdateHandler(string contextName, UIElement contextInstance, BindingsUpdatedHandler handler) { |
||||
if(contextInstance == null) { |
||||
contextInstance = NullUIElement; |
||||
} |
||||
if(commandBindingsUpdateHandlers.ContainsKey(contextName)) { |
||||
if(commandBindingsUpdateHandlers[contextName].ContainsKey(contextInstance)) { |
||||
for(int i = commandBindingsUpdateHandlers[contextName][contextInstance].Count - 1; i >= 0; i--) { |
||||
if(commandBindingsUpdateHandlers[contextName][contextInstance][i] == handler) { |
||||
commandBindingsUpdateHandlers[contextName][contextInstance].RemoveAt(i); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Invoke registered command bindings update handlers registered in specified context
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Invoke update handlers which handle update only in specifyc context</param>
|
||||
public static void InvokeCommandBindingUpdateHandlers(string contextName, UIElement contextInstance) { |
||||
if(contextInstance == null) { |
||||
contextInstance = NullUIElement; |
||||
} |
||||
|
||||
if(contextName != null) { |
||||
if(commandBindingsUpdateHandlers.ContainsKey(contextName)) { |
||||
if(contextInstance == NullUIElement) { |
||||
foreach(var instanceHandlers in commandBindingsUpdateHandlers[contextName]) { |
||||
foreach(var handler in instanceHandlers.Value) { |
||||
if(handler != null) { |
||||
((BindingsUpdatedHandler)handler).Invoke(); |
||||
} |
||||
} |
||||
} |
||||
} else if(commandBindingsUpdateHandlers[contextName].ContainsKey(contextInstance)) { |
||||
foreach(var handler in commandBindingsUpdateHandlers[contextName][contextInstance]) { |
||||
if(handler != null) { |
||||
((BindingsUpdatedHandler)handler).Invoke(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} else { |
||||
foreach(var contextHandlers in commandBindingsUpdateHandlers) { |
||||
foreach(var instanceHandlers in contextHandlers.Value) { |
||||
foreach(var handler in instanceHandlers.Value) { |
||||
if(handler != null) { |
||||
((BindingsUpdatedHandler)handler).Invoke(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove all managed command bindungs from command bindings collection
|
||||
/// </summary>
|
||||
/// <param name="commandBindingsCollection"></param>
|
||||
public static void RemoveManagedCommandBindings(CommandBindingCollection commandBindingsCollection) { |
||||
for(int i = commandBindingsCollection.Count - 1; i >= 0; i--) { |
||||
if(commandBindingsCollection[i] is ManagedCommandBinding) { |
||||
commandBindingsCollection.RemoveAt(i); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Load all registered commands in addin
|
||||
/// </summary>
|
||||
/// <param name="addIn">Addin</param>
|
||||
public static void LoadAddinCommands(AddIn addIn) { |
||||
foreach(var binding in commandBindings) { |
||||
if(binding.AddIn != addIn) continue; |
||||
|
||||
if(!commands.ContainsKey(binding.ClassName)){ |
||||
var command = addIn.CreateObject(binding.ClassName); |
||||
var wpfCommand = command as System.Windows.Input.ICommand; |
||||
if(wpfCommand == null) { |
||||
wpfCommand = new WpfCommandWrapper((ICSharpCode.Core.ICommand)command); |
||||
} |
||||
|
||||
commands.Add(binding.ClassName, wpfCommand); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Load command
|
||||
/// </summary>
|
||||
/// <param name="commandName">Command name</param>
|
||||
/// <param name="command">Command instance</param>
|
||||
public static void LoadCommand(string commandName, object command) { |
||||
var wpfCommand = command as System.Windows.Input.ICommand; |
||||
if(wpfCommand == null) { |
||||
wpfCommand = new WpfCommandWrapper((ICSharpCode.Core.ICommand)command); |
||||
} |
||||
|
||||
if(!commands.ContainsKey(commandName)) { |
||||
commands.Add(commandName, wpfCommand); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Load context
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="context">Context class instance</param>
|
||||
public static void LoadContext(string contextName, UIElement context) { |
||||
contexts[contextName] = context; |
||||
} |
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get list of all command bindings which satisfy provided parameters
|
||||
///
|
||||
/// Null arguments are ignored
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Get command bindings assigned only to specific context</param>
|
||||
/// <param name="routedCommandName">Context class full name</param>
|
||||
/// <param name="className">Context class full name</param>
|
||||
/// <returns>Collection of managed command bindings</returns>
|
||||
public static CommandBindingCollection GetCommandBindings(string contextName, UIElement contextInstance, string routedCommandName, string className) { |
||||
var bindings = new CommandBindingCollection(); |
||||
|
||||
foreach(var binding in commandBindings) { |
||||
if((contextName == null || binding.ContextName == contextName) |
||||
&& (contextInstance == null || binding.Context == null || binding.Context == contextInstance) |
||||
&& (routedCommandName == null || binding.RoutedCommandName == routedCommandName) |
||||
&& (className == null || binding.ClassName == className)) { |
||||
|
||||
var managedCommandBinding = new ManagedCommandBinding(binding.RoutedCommand); |
||||
managedCommandBinding.CanExecute += binding.CanExecuteEventHandler; |
||||
managedCommandBinding.Executed += binding.ExecutedEventHandler; |
||||
|
||||
bindings.Add(managedCommandBinding); |
||||
} |
||||
} |
||||
|
||||
return bindings; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Get list of all input bindings which satisfy provided parameters
|
||||
///
|
||||
/// Null arguments are ignored
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Get input bindings assigned only to specific context</param>
|
||||
/// <param name="routedCommandName">Routed UI command name</param>
|
||||
/// <param name="gesture">Gesture</param>
|
||||
public static InputBindingCollection GetInputBindings(string contextName, UIElement contextInstance, string routedCommandName, InputGesture gesture) { |
||||
var bindings = new InputBindingCollection(); |
||||
|
||||
foreach(var binding in inputBidnings) { |
||||
if((contextName == null || binding.ContextName == contextName) |
||||
&& (contextInstance == null || binding.Context == null || binding.Context == contextInstance) |
||||
&& (routedCommandName == null || binding.RoutedCommandName == routedCommandName) |
||||
&& (gesture == null || binding.Gesture == gesture)) { |
||||
|
||||
bindings.Add(new ManagedInputBinding(binding.RoutedCommand, binding.Gesture)); |
||||
} |
||||
} |
||||
|
||||
return bindings; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Get list of input gestures from all input bindings which satisfy provided parameters
|
||||
///
|
||||
/// Null arguments are ignored
|
||||
/// </summary>
|
||||
/// <param name="contextName">Context class full name</param>
|
||||
/// <param name="contextInstance">Get gestures assigned only to specific context</param>
|
||||
/// <param name="routedCommandName">Routed UI command name</param>
|
||||
/// <param name="gesture">Gesture</param>
|
||||
public static InputGestureCollection GetInputGestures(string contextName, UIElement contextInstance, string routedCommandName, InputGesture gesture) { |
||||
var bindings = GetInputBindings(contextName, contextInstance, routedCommandName, gesture); |
||||
var gestures = new InputGestureCollection(); |
||||
|
||||
foreach(InputBinding binding in bindings) { |
||||
gestures.Add(binding.Gesture); |
||||
} |
||||
|
||||
return gestures; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Create default BindingUpdateHandler which will update command bindings in specified context
|
||||
/// </summary>
|
||||
/// <param name="bindingsCollection">Collection which should be updated with latest bindings</param>
|
||||
/// <param name="contextName">Context name which was used to register command bindings</param>
|
||||
/// <param name="contextInstance">Reference to instance which is used to find command bindings registered in specific context instance</param>
|
||||
/// <returns>Bindings updated handler</returns>
|
||||
public static BindingsUpdatedHandler CreateCommandBindingUpdateHandler(CommandBindingCollection bindingsCollection, string contextName, UIElement contextInstance) { |
||||
return new CommonCommandBindingUpdateDelegate(bindingsCollection, contextName, contextInstance).UpdateCommandBinding; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Create default BindingUpdateHandler which will update input bindings in specified context
|
||||
/// </summary>
|
||||
/// <param name="bindingsCollection">Collection which should be updated with latest bindings</param>
|
||||
/// <param name="contextName">Context name which was used to register input bindings</param>
|
||||
/// <param name="contextInstance">Reference to instance which is used to find command bindings registered in specific context instance</param>
|
||||
/// <returns>Bindings updated handler</returns>
|
||||
public static BindingsUpdatedHandler CreateInputBindingUpdateHandler(InputBindingCollection bindingsCollection, string contextName, UIElement contextInstance) { |
||||
return new CommonInputBindingUpdateDelegate(bindingsCollection, contextName, contextInstance).UpdateInputBinding; |
||||
} |
||||
|
||||
class CommonCommandBindingUpdateDelegate |
||||
{ |
||||
CommandBindingCollection bindingsCollection; |
||||
string contextName; |
||||
UIElement contextInstance; |
||||
|
||||
public CommonCommandBindingUpdateDelegate(CommandBindingCollection bindingsCollection, string contextName, UIElement contextInstance) { |
||||
this.bindingsCollection = bindingsCollection; |
||||
this.contextName = contextName; |
||||
this.contextInstance = contextInstance; |
||||
} |
||||
|
||||
public void UpdateCommandBinding() { |
||||
var newBindings = CommandsRegistry.GetCommandBindings(contextName, contextInstance, null, null); |
||||
CommandsRegistry.RemoveManagedCommandBindings(bindingsCollection); |
||||
bindingsCollection.AddRange(newBindings); |
||||
} |
||||
} |
||||
|
||||
|
||||
class CommonInputBindingUpdateDelegate |
||||
{ |
||||
InputBindingCollection bindingsCollection; |
||||
string contextName; |
||||
UIElement contextInstance; |
||||
|
||||
public CommonInputBindingUpdateDelegate(InputBindingCollection bindingsCollection, string contextName, UIElement contextInstance) { |
||||
this.bindingsCollection = bindingsCollection; |
||||
this.contextName = contextName; |
||||
this.contextInstance = contextInstance; |
||||
} |
||||
|
||||
public void UpdateInputBinding() { |
||||
var newBindings = CommandsRegistry.GetInputBindings(contextName, contextInstance, null, null); |
||||
CommandsRegistry.RemoveManagedInputBindings(bindingsCollection); |
||||
bindingsCollection.AddRange(newBindings); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,72 +0,0 @@
@@ -1,72 +0,0 @@
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Windows.Input; |
||||
using System.Windows.Documents; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
/// Description of CommandsService.
|
||||
/// </summary>
|
||||
public static class CommandsService |
||||
{ |
||||
public static void RegisterRoutedCommands(Type type) { |
||||
var typeProperties = type.GetProperties(BindingFlags.Static | BindingFlags.Public); |
||||
foreach(var property in typeProperties) { |
||||
var command = (RoutedUICommand)property.GetValue(null, null); |
||||
CommandsRegistry.RegisterRoutedUICommand(command); |
||||
} |
||||
} |
||||
|
||||
public static void RegisterBuiltInRoutedUICommands() { |
||||
RegisterRoutedCommands(typeof(ApplicationCommands)); |
||||
RegisterRoutedCommands(typeof(ComponentCommands)); |
||||
RegisterRoutedCommands(typeof(MediaCommands)); |
||||
RegisterRoutedCommands(typeof(NavigationCommands)); |
||||
RegisterRoutedCommands(typeof(EditingCommands)); |
||||
} |
||||
|
||||
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; |
||||
|
||||
// If routed with such name is not registered register routed command with text same as name
|
||||
if(CommandsRegistry.GetRoutedUICommand(desc.Command) == null) { |
||||
CommandsRegistry.RegisterRoutedUICommand(desc.Command, desc.Command); |
||||
} |
||||
|
||||
CommandsRegistry.RegisterCommandBinding(contextName, null, desc.Command, desc.Class, desc.Codon.AddIn, desc.Lazy); |
||||
|
||||
// If gestures are provided register input binding in the same context
|
||||
if(!string.IsNullOrEmpty(desc.Gestures)) { |
||||
var gestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFromString(desc.Gestures); |
||||
foreach(InputGesture gesture in gestures) { |
||||
CommandsRegistry.RegisterInputBinding(contextName, null, desc.Command, gesture); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
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, null, desc.Command, gesture); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,82 +0,0 @@
@@ -1,82 +0,0 @@
|
||||
using System; |
||||
using System.Windows.Input; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
/// Stores gestures place holders
|
||||
///
|
||||
/// Through this class one can register a handler which which would be
|
||||
/// called when gestures associated with place holder name are updated
|
||||
/// </summary>
|
||||
public static class GesturePlaceHolderRegistry |
||||
{ |
||||
/// <summary>
|
||||
/// Register a place holder
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name. Unique application wide</param>
|
||||
/// <param name="placeHolderText">Place holder text visible to user</param>
|
||||
public static void RegisterPlaceHolder(string placeHolderName, string placeHolderText) { |
||||
BaseGesturesPlaceHolderRegistry.RegisterPlaceHolder(placeHolderName, placeHolderText); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Get gestures assigned to place holder
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <returns>Collection of gestures</returns>
|
||||
public static InputGestureCollection GetGestures(string placeHolderName) { |
||||
var serializesGesturesColection = BaseGesturesPlaceHolderRegistry.GetGestures(placeHolderName); |
||||
var gestures = (InputGestureCollection)new InputGestureCollectionConverter().ConvertFrom(serializesGesturesColection); |
||||
|
||||
return gestures; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Add gestures to place holder
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <param name="gestures">Added gestures</param>
|
||||
public static void AddGestures(string placeHolderName, InputGestureCollection gestures) { |
||||
var serializedGestures = (string[])new InputGestureCollectionConverter().ConvertTo(gestures, typeof(string[])); |
||||
|
||||
BaseGesturesPlaceHolderRegistry.AddGestures(placeHolderName, serializedGestures); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove gestures from place holder
|
||||
///
|
||||
/// Null argumens are igonred and all gestures which specify
|
||||
/// provided parameters are removed
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <param name="gestures">Removed gestures</param>
|
||||
public static void RemoveGestures(string placeHolderName, InputGestureCollection gestures) { |
||||
var serializedGestures = (string[])new InputGestureCollectionConverter().ConvertTo(gestures, typeof(string[])); |
||||
|
||||
BaseGesturesPlaceHolderRegistry.RemoveGestures(placeHolderName, serializedGestures); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register update handler which will trigger when gestures in
|
||||
/// place holder are updated
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <param name="handler">Handler which handles place holder gestures update</param>
|
||||
public static void RegisterUpdateHandler(string placeHolderName, GesturesPlaceHolderUpdate handler) { |
||||
BaseGesturesPlaceHolderRegistry.RegisterUpdateHandler(placeHolderName, handler); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Invoke delegates which handle gestures update in place holder
|
||||
///
|
||||
/// If place holder is not provided all registered handlers are invoked
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName"></param>
|
||||
public static void InvokeUpdateHandler(string placeHolderName) { |
||||
BaseGesturesPlaceHolderRegistry.InvokeUpdateHandlers(placeHolderName); |
||||
} |
||||
} |
||||
} |
@ -1,90 +0,0 @@
@@ -1,90 +0,0 @@
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Input; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
/// Stores details about input binding
|
||||
/// </summary>
|
||||
public class InputBindingInfo |
||||
{ |
||||
private UIElement contextInstance; |
||||
|
||||
/// <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, InputGesture gesture) { |
||||
ContextName = contextName; |
||||
RoutedCommandName = routedCommandName; |
||||
Gesture = gesture; |
||||
} |
||||
|
||||
public InputBindingInfo(string contextName, UIElement contextInstance, string routedCommandName, InputGesture gesture) { |
||||
ContextName = contextName; |
||||
RoutedCommandName = routedCommandName; |
||||
Gesture = gesture; |
||||
this.contextInstance = contextInstance; |
||||
} |
||||
|
||||
|
||||
/// <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 { |
||||
if(contextInstance != null) { |
||||
return contextInstance; |
||||
} else { |
||||
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 InputGesture Gesture { |
||||
get; set; |
||||
} |
||||
} |
||||
} |
@ -1,103 +0,0 @@
@@ -1,103 +0,0 @@
|
||||
using System; |
||||
using System.Windows.Input; |
||||
using System.ComponentModel; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
using System.Text.RegularExpressions; |
||||
using System.Globalization; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
/// Converts input gesture from text representation to object and vice versa
|
||||
///
|
||||
/// Will be able to convert mouse and key gestures and handle gestures collections
|
||||
/// </summary>
|
||||
public class InputGestureCollectionConverter : TypeConverter |
||||
{ |
||||
/// <summary>
|
||||
/// Returns a value indicating whether this converter can convert an object in the
|
||||
/// specified source type to the native type of the converter.
|
||||
/// </summary>
|
||||
/// <param name="context">Type descriptor context</param>
|
||||
/// <param name="sourceType">Source type</param>
|
||||
/// <returns>Array of keys</returns>
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { |
||||
if (sourceType == typeof(string)) { |
||||
return true; |
||||
} |
||||
|
||||
return base.CanConvertFrom(context, sourceType); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether this converter can convert a
|
||||
/// specified object to the specified destination type.
|
||||
/// </summary>
|
||||
/// <param name="context">An ITypeDescriptorContext that provides a format context, which can be used to extract additional information about the environment this converter is being invoked from. This parameter or properties of this parameter can be a null reference</param>
|
||||
/// <param name="destinationType">Convertion destination type</param>
|
||||
/// <returns>Destination object</returns>
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { |
||||
if (destinationType == typeof(string)) { |
||||
return true; |
||||
} |
||||
|
||||
return base.CanConvertTo(context, destinationType); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Convert from object to input gesture collection
|
||||
/// </summary>
|
||||
/// <param name="context">An ITypeDescriptorContext that provides a format context, which can be used to extract additional information about the environment this converter is being invoked from. This parameter or properties of this parameter can be a null reference </param>
|
||||
/// <param name="culture">Locale information which can influence convertion</param>
|
||||
/// <param name="value">Input gesture collection</param>
|
||||
/// <returns></returns>
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { |
||||
if (value is string) { |
||||
var gestures = new InputGestureCollection(); |
||||
var serializedGestures = Regex.Split((string)value, @"\s*\|\s*"); |
||||
|
||||
foreach(var serializedGesture in serializedGestures) { |
||||
if(string.IsNullOrEmpty(serializedGesture)) continue; |
||||
|
||||
gestures.Add((InputGesture)new KeyGestureConverter().ConvertFromString(context, culture, serializedGesture)); |
||||
} |
||||
|
||||
return gestures; |
||||
} |
||||
|
||||
return base.ConvertFrom(context, culture, value); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Converts the input gesture collection to the specified destination type
|
||||
/// </summary>
|
||||
/// <param name="context">An ITypeDescriptorContext that provides a format context, which can be used to extract additional information about the environment this converter is being invoked from. This parameter or properties of this parameter can be a null reference </param>
|
||||
/// <param name="culture">Locale information which can influence convertion</param>
|
||||
/// <param name="value">Input gesture collection</param>
|
||||
/// <param name="destinationType">Convertion destination type</param>
|
||||
/// <returns></returns>
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { |
||||
if(destinationType == typeof(string)) { |
||||
var sb = new StringBuilder(); |
||||
var gesturesCollection = (InputGestureCollection)value; |
||||
foreach(var gesture in gesturesCollection) { |
||||
string serializedGesture; |
||||
if (gesture is KeyGesture) { |
||||
serializedGesture = (string)new KeyGestureConverter().ConvertTo(context, culture, gesture, typeof(string)); |
||||
} else if (gesture is MouseGesture) { |
||||
serializedGesture = (string)new KeyGestureConverter().ConvertTo(context, culture, gesture, typeof(string)); |
||||
} else { |
||||
continue; |
||||
} |
||||
|
||||
sb.AppendFormat("{0} | ", serializedGesture); |
||||
} |
||||
|
||||
return sb.Length >= 3 ? sb.ToString(0, sb.Length - 3) : sb.ToString(); |
||||
} |
||||
|
||||
return base.ConvertTo(context, culture, value, destinationType); |
||||
} |
||||
} |
||||
} |
@ -1,35 +0,0 @@
@@ -1,35 +0,0 @@
|
||||
using System; |
||||
using System.Windows.Input; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
/// ManagedCommandBinding is used to distinguish command bindings managed
|
||||
/// by CommandsRegistry from other command bindings not managed by CommandsRegistry
|
||||
///
|
||||
/// If command binding is not managed then CommandsRegistry ignores it when
|
||||
/// performing any action
|
||||
/// </summary>
|
||||
public class ManagedCommandBinding : System.Windows.Input.CommandBinding |
||||
{ |
||||
/// <see cref="System.Windows.Input.CommandBinding()" />
|
||||
public ManagedCommandBinding() |
||||
: base() |
||||
{ } |
||||
|
||||
/// <see cref="System.Windows.Input.CommandBinding(System.Windows.Input.ICommand)" />
|
||||
public ManagedCommandBinding(System.Windows.Input.ICommand command) |
||||
: base(command) |
||||
{ } |
||||
|
||||
/// <see cref="System.Windows.Input.CommandBinding(System.Windows.Input.ICommand, System.Windows.Input.ExecutedRoutedEventHandler)" />
|
||||
public ManagedCommandBinding(System.Windows.Input.ICommand command, System.Windows.Input.ExecutedRoutedEventHandler executed) |
||||
: base(command, executed) |
||||
{ } |
||||
|
||||
/// <see cref="System.Windows.Input.CommandBinding(System.Windows.Input.ICommand, System.Windows.Input.ExecutedRoutedEventHandler, System.Windows.Input.CanExecuteRoutedEventHandler)" />
|
||||
public ManagedCommandBinding(System.Windows.Input.ICommand command, System.Windows.Input.ExecutedRoutedEventHandler executed, System.Windows.Input.CanExecuteRoutedEventHandler canExecute) |
||||
: base(command, executed, canExecute) |
||||
{ } |
||||
} |
||||
} |
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
using System; |
||||
using System.Windows.Input; |
||||
|
||||
namespace ICSharpCode.Core.Presentation |
||||
{ |
||||
/// <summary>
|
||||
/// ManagedKeyBinding is used to distinguish input bindings managed
|
||||
/// by CommandsRegistry from other input bindings not managed by CommandsRegistry.
|
||||
///
|
||||
/// If input binding is not managed then CommansRegistry ignores it when
|
||||
/// performing any action
|
||||
/// </summary>
|
||||
public class ManagedInputBinding : System.Windows.Input.InputBinding |
||||
{ |
||||
/// <see cref="System.Windows.Input.InputBinding()"></see>
|
||||
public ManagedInputBinding() : base() |
||||
{ } |
||||
|
||||
/// <see cref="System.Windows.Input.InputBinding(System.Windows.Input.ICommand, System.Windows.Input.InputGesture)"></see>
|
||||
public ManagedInputBinding(System.Windows.Input.ICommand command, System.Windows.Input.InputGesture gesture) |
||||
: base(command, gesture) |
||||
{ } |
||||
} |
||||
} |
@ -1,44 +0,0 @@
@@ -1,44 +0,0 @@
|
||||
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 { |
||||
add { } |
||||
remove { } |
||||
} |
||||
|
||||
/// <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; |
||||
} |
||||
} |
||||
} |
@ -1,82 +0,0 @@
@@ -1,82 +0,0 @@
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.Core.WinForms |
||||
{ |
||||
/// <summary>
|
||||
/// Stores gestures place holders
|
||||
///
|
||||
/// Through this class one can register a handler which which would be
|
||||
/// called when gestures associated with place holder name are updated
|
||||
/// </summary>
|
||||
public static class GesturePlaceHolderRegistry |
||||
{ |
||||
/// <summary>
|
||||
/// Register a place holder
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name. Unique application wide</param>
|
||||
/// <param name="placeHolderText">Place holder text visible to user</param>
|
||||
public static void RegisterPlaceHolder(string placeHolderName, string placeHolderText) { |
||||
BaseGesturesPlaceHolderRegistry.RegisterPlaceHolder(placeHolderName, placeHolderText); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Get gestures assigned to place holder
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <returns>Array of keys</returns>
|
||||
public static Keys[] GetGestures(string placeHolderName) { |
||||
var serializesGesturesColection = BaseGesturesPlaceHolderRegistry.GetGestures(placeHolderName); |
||||
var gestures = (Keys[])new KeysCollectionConverter().ConvertFrom(serializesGesturesColection); |
||||
|
||||
return gestures; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Add gestures to place holder
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <param name="gestures">Added gestures</param>
|
||||
public static void AddGestures(string placeHolderName, IEnumerable<Keys> gestures) { |
||||
var serializedGestures = (string[])new KeysCollectionConverter().ConvertTo(gestures, typeof(string[])); |
||||
|
||||
BaseGesturesPlaceHolderRegistry.AddGestures(placeHolderName, serializedGestures); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Remove gestures from place holder
|
||||
///
|
||||
/// Null argumens are igonred and all gestures which specify
|
||||
/// provided parameters are removed
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <param name="gestures">Gestures</param>
|
||||
public static void RemoveGestures(string placeHolderName, IEnumerable<Keys> gestures) { |
||||
var serializedGestures = (string[])new KeysCollectionConverter().ConvertTo(gestures, typeof(string[])); |
||||
|
||||
BaseGesturesPlaceHolderRegistry.RemoveGestures(placeHolderName, serializedGestures); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Register update handler which will trigger when gestures in
|
||||
/// place holder are updated
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName">Place holder name</param>
|
||||
/// <param name="handler">Handler which handles place holder gestures update</param>
|
||||
public static void RegisterUpdateHandler(string placeHolderName, GesturesPlaceHolderUpdate handler) { |
||||
BaseGesturesPlaceHolderRegistry.RegisterUpdateHandler(placeHolderName, handler); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Invoke delegates which handle gestures update in place holder
|
||||
///
|
||||
/// If place holder is not provided all registered handlers are invoked
|
||||
/// </summary>
|
||||
/// <param name="placeHolderName"></param>
|
||||
public static void InvokeUpdateHandlers(string placeHolderName) { |
||||
BaseGesturesPlaceHolderRegistry.InvokeUpdateHandlers(placeHolderName); |
||||
} |
||||
} |
||||
} |
@ -1,114 +0,0 @@
@@ -1,114 +0,0 @@
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
using System.ComponentModel; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
using System.Text.RegularExpressions; |
||||
using System.Globalization; |
||||
|
||||
namespace ICSharpCode.Core.WinForms |
||||
{ |
||||
/// <summary>
|
||||
/// Converts objects of different types to array of keys and
|
||||
/// convert enumerable back to objects of different type
|
||||
/// </summary>
|
||||
public class KeysCollectionConverter : TypeConverter |
||||
{ |
||||
/// <summary>
|
||||
/// Returns a value indicating whether this converter can convert an object in the
|
||||
/// specified source type to the native type of the converter.
|
||||
/// </summary>
|
||||
/// <param name="context">Type descriptor context</param>
|
||||
/// <param name="sourceType">Source type</param>
|
||||
/// <returns>Array of keys</returns>
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { |
||||
if (sourceType == typeof(string)) { |
||||
return true; |
||||
} if (sourceType == typeof(string[])) { |
||||
return true; |
||||
} |
||||
|
||||
return base.CanConvertFrom(context, sourceType); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether this converter can convert a
|
||||
/// specified object to the specified destination type.
|
||||
/// </summary>
|
||||
/// <param name="context">An ITypeDescriptorContext that provides a format context, which can be used to extract additional information about the environment this converter is being invoked from. This parameter or properties of this parameter can be a null reference</param>
|
||||
/// <param name="destinationType">Convertion destination type</param>
|
||||
/// <returns>Destination object</returns>
|
||||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { |
||||
if (destinationType == typeof(string) || destinationType == typeof(string[])) { |
||||
return true; |
||||
} |
||||
|
||||
return base.CanConvertTo(context, destinationType); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Convert from source object to array of keys
|
||||
/// </summary>
|
||||
/// <param name="context">An ITypeDescriptorContext that provides a format context, which can be used to extract additional information about the environment this converter is being invoked from. This parameter or properties of this parameter can be a null reference </param>
|
||||
/// <param name="culture">Locale information which can influence convertion</param>
|
||||
/// <param name="value">Array of Keys</param>
|
||||
/// <returns></returns>
|
||||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { |
||||
if(value is string || value is string[]) { |
||||
var gestures = new List<Keys>(); |
||||
|
||||
string[] serializedGestures; |
||||
if(value is string) { |
||||
serializedGestures = Regex.Split((string)value, @"\s*\|\s*"); |
||||
} else { |
||||
serializedGestures = (string[])value; |
||||
} |
||||
|
||||
foreach(var serializedGesture in serializedGestures) { |
||||
if(string.IsNullOrEmpty(serializedGesture)) continue; |
||||
|
||||
gestures.Add((Keys)new KeysConverter().ConvertFromInvariantString(serializedGesture)); |
||||
} |
||||
|
||||
return gestures.ToArray(); |
||||
} |
||||
|
||||
return base.ConvertFrom(context, culture, value); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Converts array of keys to the specified destination type
|
||||
/// </summary>
|
||||
/// <param name="context">An ITypeDescriptorContext that provides a format context, which can be used to extract additional information about the environment this converter is being invoked from. This parameter or properties of this parameter can be a null reference </param>
|
||||
/// <param name="culture">Locale information which can influence convertion</param>
|
||||
/// <param name="value">Array of keys</param>
|
||||
/// <param name="destinationType">Convertion destination type</param>
|
||||
/// <returns></returns>
|
||||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { |
||||
if(destinationType == typeof(string) || destinationType == typeof(string[])) |
||||
{ |
||||
if(value == null) return null; |
||||
|
||||
var keysCollection = (IEnumerable<Keys>)value; |
||||
var serializedKeysCollection = new List<string>(); |
||||
|
||||
foreach(var gesture in keysCollection) { |
||||
var serializedGesture = new KeysConverter().ConvertToInvariantString(gesture); |
||||
serializedKeysCollection.Add(serializedGesture); |
||||
} |
||||
|
||||
if(destinationType == typeof(string[])) { |
||||
return serializedKeysCollection.ToArray(); |
||||
} else if(destinationType == typeof(string)) { |
||||
var sb = new StringBuilder(); |
||||
foreach(var serializedGesture in serializedKeysCollection) { |
||||
sb.AppendFormat("{0} | ", serializedGesture); |
||||
} |
||||
|
||||
return sb.Length >= 3 ? sb.ToString(0, sb.Length - 3) : sb.ToString(); |
||||
} |
||||
} |
||||
return base.ConvertTo(context, culture, value, destinationType); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue