public void TrySwitchModifierKeyBehavior(KeyEventArgs args)
        {
            if (this.eventRouter.ActiveBehavior == null || this.eventRouter.IsDragging || (this.eventRouter.IsButtonDown || !this.eventRouter.ActiveBehavior.ToolBehaviorContext.View.Artboard.IsMouseOver) || this.eventRouter.IsEditingText)
            {
                return;
            }
            if (this.activeModifierKeyBehavior != null && !this.eventRouter.ContainsBehavior(this.activeModifierKeyBehavior))
            {
                this.activeModifierKeyBehavior        = (ToolBehavior)null;
                this.activeModifierKeyBehaviorFactory = (IModifierKeyBehaviorFactory)null;
            }
            ExtendedModifierKeys extendedModifierKeys = this.ComputeExtendedModifierKeys();

            if (this.activeModifierKeyBehaviorFactory != null && !this.activeModifierKeyBehaviorFactory.ShouldActivate(extendedModifierKeys))
            {
                this.RemoveActiveModifierKeyBehavior();
            }
            if (args != null && !this.eventRouter.IsDragging)
            {
                Key key = args.Key == Key.System ? args.SystemKey : args.Key;
                if (extendedModifierKeys == ExtendedModifierKeys.None)
                {
                    this.suspendingMode = false;
                    return;
                }
                if (!this.modifierKeys.Contains(key) && key != Key.ImeProcessed)
                {
                    this.RemoveActiveModifierKeyBehavior();
                    this.suspendingMode = true;
                }
                if (this.suspendingMode)
                {
                    return;
                }
            }
            if (this.activeModifierKeyBehaviorFactory != null)
            {
                return;
            }
            foreach (IModifierKeyBehaviorFactory keyBehaviorFactory in this.behaviorFactories)
            {
                if (keyBehaviorFactory.ShouldActivate(extendedModifierKeys))
                {
                    ToolBehavior instance = keyBehaviorFactory.CreateInstance(this.eventRouter.ActiveBehavior.ToolBehaviorContext);
                    if (instance != null)
                    {
                        this.activeModifierKeyBehavior        = instance;
                        this.activeModifierKeyBehaviorFactory = keyBehaviorFactory;
                        this.eventRouter.PushBehavior(this.activeModifierKeyBehavior);
                        break;
                    }
                }
            }
        }
 private void RemoveActiveModifierKeyBehavior()
 {
     if (this.activeModifierKeyBehaviorFactory == null)
     {
         return;
     }
     for (ToolBehavior activeBehavior = this.eventRouter.ActiveBehavior; activeBehavior != this.activeModifierKeyBehavior; activeBehavior = this.eventRouter.ActiveBehavior)
     {
         this.eventRouter.PopBehavior();
     }
     this.eventRouter.PopBehavior();
     this.eventRouter.ActiveBehavior.ToolBehaviorContext.ToolManager.OverrideTool = (Tool)null;
     this.activeModifierKeyBehavior        = (ToolBehavior)null;
     this.activeModifierKeyBehaviorFactory = (IModifierKeyBehaviorFactory)null;
 }
 public void Unregister(IModifierKeyBehaviorFactory behaviorFactory)
 {
     this.behaviorFactories.Remove(behaviorFactory);
 }
 public void Register(IModifierKeyBehaviorFactory behaviorFactory)
 {
     this.behaviorFactories.Add(behaviorFactory);
 }