Beispiel #1
0
 /// <summary>
 /// Constructs an instance of <c>CommandBinding</c> using the specified details.
 /// </summary>
 /// <param name="command">The command object.</param>
 /// <param name="source">The source object.</param>
 /// <param name="sourceEvent">The source event.</param>
 public CommandBinding(IBoundCommand command, object source, string sourceEvent)
     :this()
 {
     Command = command;
     SourceObject = source;
     SourceEvent = sourceEvent;
 }
Beispiel #2
0
 /// <summary>
 /// Constructs an instance of <c>CommandBinding</c> using the specified details.
 /// </summary>
 /// <param name="command">The command object.</param>
 /// <param name="source">The source object.</param>
 /// <param name="sourceEvent">The source event.</param>
 public CommandBinding(IBoundCommand command, object source, string sourceEvent)
     : this()
 {
     Command      = command;
     SourceObject = source;
     SourceEvent  = sourceEvent;
 }
Beispiel #3
0
        public void Dettach(IBoundCommand command, object source, string sourceEvent)
        {
            var toolStripItem = source as ToolStripItem;

            if (toolStripItem == null)
            {
                throw new NullReferenceException();
            }

            toolStripItem.Enabled = false;
            var detached     = true;
            var triggerEvent = TypeDescriptor.GetEvents(toolStripItem).Find(sourceEvent, false);

            if (triggerEvent != null)
            {
                if (triggerEvent.EventType == typeof(EventHandler))
                {
                    triggerEvent.RemoveEventHandler(toolStripItem, (EventHandler)((s, e) => command.Execute(null)));
                }
                else if (triggerEvent.EventType == typeof(MouseEventHandler))
                {
                    triggerEvent.RemoveEventHandler(toolStripItem, (MouseEventHandler)((s, e) => command.Execute(null)));
                }
                else if (triggerEvent.EventType == typeof(DragEventHandler))
                {
                    triggerEvent.RemoveEventHandler(toolStripItem, (DragEventHandler)((s, e) => command.Execute(null)));
                }
#if !WEBGUI
                else if (triggerEvent.EventType == typeof(GiveFeedbackEventHandler))
                {
                    triggerEvent.RemoveEventHandler(toolStripItem, (GiveFeedbackEventHandler)((s, e) => command.Execute(null)));
                }
                else if (triggerEvent.EventType == typeof(QueryContinueDragEventHandler))
                {
                    triggerEvent.RemoveEventHandler(toolStripItem, (QueryContinueDragEventHandler)((s, e) => command.Execute(null)));
                }
                else if (triggerEvent.EventType == typeof(QueryAccessibilityHelpEventHandler))
                {
                    triggerEvent.RemoveEventHandler(toolStripItem, (QueryAccessibilityHelpEventHandler)((s, e) => command.Execute(null)));
                }
#endif
                else
                {
                    detached = false;
                }
            }

            if (!detached)
            {
                toolStripItem.Click -= (s, e) => command.Execute(null);
            }

            command.CanExecuteChanged -= (s, e) => toolStripItem.Enabled = command.CanExecute(null);
        }
Beispiel #4
0
        public void Dettach(IBoundCommand command, object source, string sourceEvent)
        {
            var menuItem = source as MenuItem;

            if (menuItem == null)
            {
                throw new NullReferenceException();
            }

            menuItem.Enabled = false;
            var triggerEvent = TypeDescriptor.GetEvents(menuItem).Find(sourceEvent, false);

            if (triggerEvent != null && triggerEvent.EventType == typeof(EventHandler))
            {
                triggerEvent.RemoveEventHandler(menuItem, (EventHandler)((s, e) => command.Execute(null)));
            }
            else
            {
                menuItem.Click -= (s, e) => command.Execute(null);
            }

            command.CanExecuteChanged -= (s, e) => menuItem.Enabled = command.CanExecute(null);
        }
Beispiel #5
0
        public void Attach(IBoundCommand command, object source, string sourceEvent)
        {
            var control = source as Control;

            if (control == null)
            {
                throw new NullReferenceException();
            }

            control.Enabled = command.CanExecute(null);
            var attached     = true;
            var triggerEvent = TypeDescriptor.GetEvents(control).Find(sourceEvent, false);

            if (triggerEvent != null)
            {
                if (triggerEvent.EventType == typeof(EventHandler))
                {
                    triggerEvent.AddEventHandler(control, (EventHandler)((s, e) => command.Execute(null)));
                }
                else if (triggerEvent.EventType == typeof(MouseEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (MouseEventHandler)((s, e) => command.Execute(null)));
                }
                else if (triggerEvent.EventType == typeof(DragEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (DragEventHandler)((s, e) => command.Execute(null)));
                }
#if !WEBGUI
                else if (triggerEvent.EventType == typeof(QueryContinueDragEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (QueryContinueDragEventHandler)((s, e) => command.Execute(null)));
                }
#endif
                else if (triggerEvent.EventType == typeof(KeyEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (KeyEventHandler)((s, e) => command.Execute(null)));
                }
                else if (triggerEvent.EventType == typeof(KeyPressEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (KeyPressEventHandler)((s, e) => command.Execute(null)));
                }
#if !WEBGUI
                else if (triggerEvent.EventType == typeof(PreviewKeyDownEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (PreviewKeyDownEventHandler)((s, e) => command.Execute(null)));
                }
#if !WISEJ
                else if (triggerEvent.EventType == typeof(UICuesEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (UICuesEventHandler)((s, e) => command.Execute(null)));
                }
#endif
#endif
#if !WISEJ
                else if (triggerEvent.EventType == typeof(HelpEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (HelpEventHandler)((s, e) => command.Execute(null)));
                }
#if !WEBGUI
                else if (triggerEvent.EventType == typeof(QueryAccessibilityHelpEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (QueryAccessibilityHelpEventHandler)((s, e) => command.Execute(null)));
                }
                else if (triggerEvent.EventType == typeof(GiveFeedbackEventHandler))
                {
                    triggerEvent.AddEventHandler(control, (GiveFeedbackEventHandler)((s, e) => command.Execute(null)));
                }
#endif
#endif
                else
                {
                    attached = false;
                }
            }

            if (!attached)
            {
                control.Click += (s, e) => command.Execute(null);
            }

            command.CanExecuteChanged += (s, e) => control.Enabled = command.CanExecute(null);
        }
Beispiel #6
0
        public void Attach(IBoundCommand command, object source, string sourceEvent)
        {
            var control = source as Control;
            if (control == null)
                throw new NullReferenceException();

            control.Enabled = command.CanExecute(null);
            var attached = true;
            var triggerEvent = TypeDescriptor.GetEvents(control).Find(sourceEvent, false);
            if (triggerEvent != null)
            {
                if (triggerEvent.EventType == typeof(EventHandler))
                    triggerEvent.AddEventHandler(control, (EventHandler)((s, e) => command.Execute(null)));
                else if (triggerEvent.EventType == typeof(MouseEventHandler))
                    triggerEvent.AddEventHandler(control, (MouseEventHandler)((s, e) => command.Execute(null)));
                else if (triggerEvent.EventType == typeof(DragEventHandler))
                    triggerEvent.AddEventHandler(control, (DragEventHandler)((s, e) => command.Execute(null)));
#if !WEBGUI
                else if (triggerEvent.EventType == typeof(QueryContinueDragEventHandler))
                    triggerEvent.AddEventHandler(control, (QueryContinueDragEventHandler)((s, e) => command.Execute(null)));
#endif
                else if (triggerEvent.EventType == typeof(KeyEventHandler))
                    triggerEvent.AddEventHandler(control, (KeyEventHandler)((s, e) => command.Execute(null)));
                else if (triggerEvent.EventType == typeof(KeyPressEventHandler))
                    triggerEvent.AddEventHandler(control, (KeyPressEventHandler)((s, e) => command.Execute(null)));
#if !WEBGUI
                else if (triggerEvent.EventType == typeof(PreviewKeyDownEventHandler))
                    triggerEvent.AddEventHandler(control, (PreviewKeyDownEventHandler)((s, e) => command.Execute(null)));
                else if (triggerEvent.EventType == typeof(UICuesEventHandler))
                    triggerEvent.AddEventHandler(control, (UICuesEventHandler)((s, e) => command.Execute(null)));
#endif
                else if (triggerEvent.EventType == typeof(HelpEventHandler))
                    triggerEvent.AddEventHandler(control, (HelpEventHandler)((s, e) => command.Execute(null)));
#if !WEBGUI
                else if (triggerEvent.EventType == typeof(QueryAccessibilityHelpEventHandler))
                    triggerEvent.AddEventHandler(control, (QueryAccessibilityHelpEventHandler)((s, e) => command.Execute(null)));
                else if (triggerEvent.EventType == typeof(GiveFeedbackEventHandler))
                    triggerEvent.AddEventHandler(control, (GiveFeedbackEventHandler)((s, e) => command.Execute(null)));
#endif
                else attached = false;
            }

            if (!attached)
                control.Click += (s, e) => command.Execute(null);

            command.CanExecuteChanged += (s, e) => control.Enabled = command.CanExecute(null);
        }
Beispiel #7
0
        public void Dettach(IBoundCommand command, object source, string sourceEvent)
        {
            var menuItem = source as MenuItem;
            if (menuItem == null)
                throw new NullReferenceException();

            menuItem.Enabled = false;
            var triggerEvent = TypeDescriptor.GetEvents(menuItem).Find(sourceEvent, false);

            if (triggerEvent != null && triggerEvent.EventType == typeof(EventHandler))
                triggerEvent.RemoveEventHandler(menuItem, (EventHandler)((s, e) => command.Execute(null)));
            else
                menuItem.Click -= (s, e) => command.Execute(null);

            command.CanExecuteChanged -= (s, e) => menuItem.Enabled = command.CanExecute(null);
        }
Beispiel #8
0
        public void Dettach(IBoundCommand command, object source, string sourceEvent)
        {
            var toolStripItem = source as ToolStripItem;
            if (toolStripItem == null)
                throw new NullReferenceException();

            toolStripItem.Enabled = false;
            var detached = true;
            var triggerEvent = TypeDescriptor.GetEvents(toolStripItem).Find(sourceEvent, false);
            if (triggerEvent != null)
            {
                if (triggerEvent.EventType == typeof(EventHandler))
                    triggerEvent.RemoveEventHandler(toolStripItem, (EventHandler)((s, e) => command.Execute(null)));
                else if (triggerEvent.EventType == typeof(MouseEventHandler))
                    triggerEvent.RemoveEventHandler(toolStripItem, (MouseEventHandler)((s, e) => command.Execute(null)));
                else if (triggerEvent.EventType == typeof(DragEventHandler))
                    triggerEvent.RemoveEventHandler(toolStripItem, (DragEventHandler)((s, e) => command.Execute(null)));
#if !WEBGUI
                else if (triggerEvent.EventType == typeof(GiveFeedbackEventHandler))
                    triggerEvent.RemoveEventHandler(toolStripItem, (GiveFeedbackEventHandler)((s, e) => command.Execute(null)));
                else if (triggerEvent.EventType == typeof(QueryContinueDragEventHandler))
                    triggerEvent.RemoveEventHandler(toolStripItem, (QueryContinueDragEventHandler)((s, e) => command.Execute(null)));
                else if (triggerEvent.EventType == typeof(QueryAccessibilityHelpEventHandler))
                    triggerEvent.RemoveEventHandler(toolStripItem, (QueryAccessibilityHelpEventHandler)((s, e) => command.Execute(null)));
#endif
                else detached = false;
            }

            if (!detached)
                toolStripItem.Click -= (s, e) => command.Execute(null);

            command.CanExecuteChanged -= (s, e) => toolStripItem.Enabled = command.CanExecute(null);
        }