示例#1
0
        public void KeyGesture_Parse()
        {
            // TODO: Modify the code so that the Ctrl/Shift/Alt+ modifiers apply to a gesture rather than key command.
            var cordGesture = KeyGesture.Parse("Ctrl+D");

            Assert.AreEqual(cordGesture.Count, 1);
            Assert.AreEqual(cordGesture[0].Count, 2);
            Assert.AreEqual(cordGesture[0][0], VirtualKey.Control);
            Assert.AreEqual(cordGesture[0][1], VirtualKey.D);

            var threeKeyCordGesture = KeyGesture.Parse("Ctrl+Shift+D");

            Assert.AreEqual(threeKeyCordGesture.Count, 1);
            Assert.AreEqual(threeKeyCordGesture[0].Count, 3);
            Assert.AreEqual(threeKeyCordGesture[0][0], VirtualKey.Control);
            Assert.AreEqual(threeKeyCordGesture[0][1], VirtualKey.Shift);
            Assert.AreEqual(threeKeyCordGesture[0][2], VirtualKey.D);

            var doubleCordGesture = KeyGesture.Parse("Ctrl+S,D");

            Assert.AreEqual(doubleCordGesture.Count, 2);
            Assert.AreEqual(doubleCordGesture[0].Count, 2);
            Assert.AreEqual(doubleCordGesture[0][0], VirtualKey.Control);
            Assert.AreEqual(doubleCordGesture[0][1], VirtualKey.S);
            Assert.AreEqual(doubleCordGesture[1].Count, 1);
            Assert.AreEqual(doubleCordGesture[1][0], VirtualKey.D);
        }
示例#2
0
 public void Key_Gesture_Is_Able_To_Parse_Sample_Data()
 {
     foreach (var d in SampleData)
     {
         Assert.Equal(d.Value, KeyGesture.Parse(d.Key));
     }
 }
示例#3
0
        public Window1()
        {
            this.InitializeComponent();
#if DEBUG
            this.AttachDevTools(KeyGesture.Parse("F1"));
#endif
        }
        private IList <NativeMenuItemBase> GetNativeItems(IEnumerable <MenuItemModel> items, NativeMenu menu = null)
        {
            var result = new List <NativeMenuItemBase>();

            foreach (var item in items)
            {
                if (item is MenuItemSeparatorModel)
                {
                    if (menu != null)
                    {
                        menu.Add(new NativeMenuItemSeperator());
                    }
                    else
                    {
                        result.Add(new NativeMenuItemSeperator());
                    }
                }
                else
                {
                    var gesture = item.Gesture;

                    var nativeItem = new NativeMenuItem
                    {
                        Header  = item.Label,
                        Command = item.Command,
                    };

                    if (gesture != null)
                    {
                        nativeItem.Gesture = KeyGesture.Parse(gesture);
                    }

                    if (nativeItem.Header == null)
                    {
                        nativeItem.Header = "";
                    }

                    if (item.Children != null && item.Children.Any())
                    {
                        var nativeMenu = new NativeMenu();
                        GetNativeItems(item.Children, nativeMenu);

                        nativeItem.Menu = nativeMenu;
                    }

                    if (menu != null)
                    {
                        menu.Add(nativeItem);
                    }
                    else
                    {
                        result.Add(nativeItem);
                    }
                }
            }

            return(result);
        }
示例#5
0
        public MainWindow()
        {
            this.WhenActivated(disposables => { });
            AvaloniaXamlLoader.Load(this);
            Instance = this;


#if DEBUG
            this.AttachDevTools(KeyGesture.Parse("CTRL+R"));
#endif
        }
        public void Initialise(IDockFactory layoutFactory = null)
        {
            if (layoutFactory == null)
            {
                Factory = new DefaultLayoutFactory();
            }
            else
            {
                Factory = layoutFactory;
            }

            LoadLayout();

            foreach (var extension in _extensions)
            {
                if (extension.Value is IActivatableExtension activatable)
                {
                    activatable.BeforeActivation();
                }
            }

            _layout.WhenAnyValue(l => l.FocusedView).Subscribe(focused =>
            {
                if (focused?.Context is IDocumentTabViewModel doc)
                {
                    SelectedDocument = doc;
                }
                else
                {
                    SelectedDocument = null;
                }
            });

            foreach (var extension in _extensions)
            {
                if (extension.Value is IActivatableExtension activatable)
                {
                    activatable.Activation();
                }
            }

            foreach (var command in _commandService.GetKeyGestures())
            {
                foreach (var keyGesture in command.Value)
                {
                    _keyBindings.Add(new KeyBinding {
                        Command = command.Key.Command, Gesture = KeyGesture.Parse(keyGesture)
                    });
                }
            }

            IoC.Get <IStatusBar>().ClearText();
        }
示例#7
0
 /// <summary>
 /// Gets the enter key gestures.
 /// </summary>
 /// <returns>Dictionary&lt;System.String, KeyGesture&gt;.</returns>
 protected virtual Dictionary <string, KeyGesture> GetEnterKeyGestures()
 {
     if (enterKeyGestures == null)
     {
         enterKeyGestures = new Dictionary <string, KeyGesture>();
         var manager = DIResolver.Get <IHotkeyManager>();
         foreach (var item in manager.GetEnterKeys())
         {
             enterKeyGestures.Add(item, KeyGesture.Parse(item));
         }
     }
     return(enterKeyGestures);
 }
示例#8
0
        public MainWindow()
        {
            AvaloniaXamlLoader.Load(this);
            this.AttachDevTools(KeyGesture.Parse("Ctrl+Shift+D"));

            this.WhenActivated(disposables =>
            {
                ViewModel?.ExitCommand?.SubscribeWithLog(_ =>
                {
                    Close();
                });
            });
        }
示例#9
0
 public ConfirmDialogView()
     : base(false)
 {
     AvaloniaXamlLoader.Load(this);
     this.AttachDevTools(KeyGesture.Parse("Ctrl+Shift+D"));
     this.WhenActivated(disposables =>
     {
         ViewModel.GetResult()
         .SubscribeWithLog(_ =>
         {
             _resultWasSet = true;
             Close();
         });
     });
 }
示例#10
0
        /// <summary>
        /// Initializes the hotkeys.
        /// </summary>
        protected virtual void InitializeHotkeys()
        {
            var manager = DIResolver.Get <IHotkeyManager>();

            KillHotkeys();
            foreach (var item in manager.GetKeys())
            {
                var vm = ViewModel;
                KeyBindings.Add(new KeyBinding()
                {
                    Command          = vm.RegisterHotkeyCommand,
                    CommandParameter = item,
                    Gesture          = KeyGesture.Parse(item)
                });
            }
        }
示例#11
0
    public RegisteredCommandBase()
    {
        var thisType = GetType();

        Name  = thisType.FullName !;
        label = thisType.Name;

        if (thisType.GetCustomAttribute <CommandDefinitionAttribute>() is CommandDefinitionAttribute attribute)
        {
            if (attribute.DefaultInputGesture is string gesture)
            {
                keyGesture = KeyGesture.Parse(gesture);
            }

            Name     = attribute.Name ?? Name;
            Label    = attribute.Label;
            IconName = attribute.IconName;
        }
        Command = CreateCommand();
    }
示例#12
0
        public void Initialise(IFactory layoutFactory = null)
        {
            if (layoutFactory == null)
            {
                Factory = new DefaultLayoutFactory();
            }
            else
            {
                Factory = layoutFactory;
            }

            LoadLayout();

            foreach (var extension in _extensions)
            {
                if (extension.Value is IActivatableExtension activatable)
                {
                    activatable.BeforeActivation();
                }
            }

            foreach (var extension in _extensions)
            {
                if (extension.Value is IActivatableExtension activatable)
                {
                    activatable.Activation();
                }
            }

            foreach (var command in _commandService.GetKeyGesture())
            {
                if (command.Value != null)
                {
                    _keyBindings.Add(new KeyBinding {
                        Command = command.Key.Command, Gesture = KeyGesture.Parse(command.Value)
                    });
                }
            }

            IoC.Get <IStatusBar>().ClearText();
        }
        /// <summary>
        /// Provides derived classes an opportunity to handle changes
        /// to the Shortcut property.
        /// </summary>
        /// <param name="oldShortcut">The old Shortcut value</param>
        /// <param name="newShortcut">The new Shortcut value</param>
        private void OnShortcutChanged(
            string oldShortcut, string newShortcut)
        {
            AutomationProperties.SetAcceleratorKey(this, newShortcut);

            if (this.keyGestureRecognizer != null)
            {
                this.keyGestureRecognizer.GestureRecognized -= this.OnKeyGestureRecognized;
                this.keyGestureRecognizer.Dispose();
            }

            this.keyGesture = string.IsNullOrEmpty(newShortcut) ? null : KeyGesture.Parse(newShortcut);

            if (this.keyGesture != null)
            {
                this.keyGestureRecognizer = new KeyGestureRecognizer(this.keyGesture);
                this.keyGestureRecognizer.GestureRecognized += this.OnKeyGestureRecognized;
            }

            this.UpdateToolTip();
        }
示例#14
0
 private void InitializeComponent()
 {
     AvaloniaXamlLoader.Load(this);
     DevTools.Attach(this, KeyGesture.Parse("F12"));
 }
示例#15
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     return(KeyGesture.Parse((string)value));
 }
示例#16
0
        public void Initialise(IDockFactory layoutFactory = null)
        {
            foreach (var extension in _extensions)
            {
                if (extension.Value is IActivatableExtension activatable)
                {
                    activatable.BeforeActivation();
                }
            }

            if (layoutFactory == null)
            {
                Factory = new DefaultLayoutFactory();
            }
            else
            {
                Factory = layoutFactory;
            }

            LoadLayout();

            Layout.WhenAnyValue(l => l.FocusedView).Subscribe(focused =>
            {
                if (focused is IDocumentTabViewModel doc)
                {
                    SelectedDocument = doc;
                }
                else
                {
                    SelectedDocument = null;
                }
            });

            if (Layout.Factory.ViewLocator.ContainsKey("LeftDock"))
            {
                _leftPane = Layout.Factory.ViewLocator["LeftDock"]() as ToolDock;
            }

            if (Layout.Factory.ViewLocator.ContainsKey("DocumentDock"))
            {
                _documentDock = Layout.Factory.ViewLocator["DocumentDock"]() as DocumentDock;
            }

            if (Layout.Factory.ViewLocator.ContainsKey("RightDock"))
            {
                _rightPane = Layout.Factory.ViewLocator["RightDock"]() as ToolDock;
            }

            if (Layout.Factory.ViewLocator.ContainsKey("BottomDock"))
            {
                _bottomPane = Layout.Factory.ViewLocator["BottomDock"]() as ToolDock;
            }

            foreach (var extension in _extensions)
            {
                if (extension.Value is IActivatableExtension activatable)
                {
                    activatable.Activation();
                }
            }

            foreach (var command in _commandService.GetKeyGestures())
            {
                foreach (var keyGesture in command.Value)
                {
                    _keyBindings.Add(new KeyBinding {
                        Command = command.Key.Command, Gesture = KeyGesture.Parse(keyGesture)
                    });
                }
            }

            foreach (var tool in _toolControls)
            {
                switch (tool.Value.DefaultLocation)
                {
                case Location.Bottom:
                    DockView(_bottomPane, tool.Value);
                    break;

                //case Location.BottomRight:
                //    BottomRightTabs.Tools.Add(tool);
                //    break;

                //case Location.RightBottom:
                //    RightBottomTabs.Tools.Add(tool);
                //    break;

                //case Location.RightMiddle:
                //    RightMiddleTabs.Tools.Add(tool);
                //    break;

                //case Location.RightTop:
                //    RightTopTabs.Tools.Add(tool);
                //    break;

                //case Location.MiddleTop:
                //    MiddleTopTabs.Tools.Add(tool);
                //    break;

                case Location.Left:
                    DockView(_leftPane, tool.Value);
                    break;

                case Location.Right:
                    DockView(_rightPane, tool.Value);
                    break;
                }
            }

            IoC.Get <IStatusBar>().ClearText();
        }
示例#17
0
 public void Key_Gesture_Is_Able_To_Parse_Sample_Data(string text, KeyGesture gesture)
 {
     Assert.Equal(gesture, KeyGesture.Parse(text));
 }
 public MainWindow()
 {
     InitializeComponent();
     this.AttachDevTools(KeyGesture.Parse("Shift+F12"));
 }
示例#19
0
 public object ConvertFrom(IValueContext context, CultureInfo culture, object value)
 {
     return(KeyGesture.Parse((string)value));
 }
示例#20
0
 public static void AttachDevTools(Window window)
 {
     DevTools.Attach(window, KeyGesture.Parse("CTRL+F12"));
 }