/// <summary>
        /// Initializes a new instance of the <see cref="KeyGestureRecognizer"/> class.
        /// </summary>
        /// <param name="gesture">The gesture to recognized.</param>
        /// <exception cref="System.ArgumentNullException">gesture</exception>
        /// <exception cref="System.ArgumentException">The gesture needs to consist of at least one key or key combination.;gesture</exception>
        public KeyGestureRecognizer(KeyGesture gesture)
        {
            if (gesture == null)
            {
                throw new ArgumentNullException("gesture");
            }

            if (gesture.Count == 0)
            {
                throw new ArgumentException("The gesture needs to consist of at least one key or key combination.", "gesture");
            }

            this.gesture = gesture;
            this.window = Window.Current;
            this.window.CoreWindow.KeyDown += this.CoreWindowOnKeyDown;
        }
        public void HotKeyManager_Should_Register_And_Unregister_Key_Binding()
        {
            using (PerspexLocator.EnterScope())
            {
                var windowImpl = new Mock<IWindowImpl>();
                var styler = new Mock<Styler>();

                PerspexLocator.CurrentMutable
                    .Bind<IWindowImpl>().ToConstant(windowImpl.Object)
                    .Bind<IStyler>().ToConstant(styler.Object);

                var gesture1 = new KeyGesture {Key = Key.A, Modifiers = InputModifiers.Control};
                var gesture2 = new KeyGesture {Key = Key.B, Modifiers = InputModifiers.Control};

                var tl = new Window();
                var button = new Button();
                tl.Content = button;
                tl.Template = CreateWindowTemplate();
                tl.ApplyTemplate();

                HotKeyManager.SetHotKey(button, gesture1);

                Assert.Equal(gesture1, tl.KeyBindings[0].Gesture);

                HotKeyManager.SetHotKey(button, gesture2);
                Assert.Equal(gesture2, tl.KeyBindings[0].Gesture);

                tl.Content = null;
                tl.Presenter.ApplyTemplate();

                Assert.Empty(tl.KeyBindings);

                tl.Content = button;
                tl.Presenter.ApplyTemplate();

                Assert.Equal(gesture2, tl.KeyBindings[0].Gesture);

                HotKeyManager.SetHotKey(button, null);
                Assert.Empty(tl.KeyBindings);

            }
        }
        /// <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();
        }
Beispiel #4
0
 public StandardMenuItem WithGlobalShortcut(ModifierKeys modifier, Key key)
 {
     _keyGesture = new KeyGesture(key, modifier);
     IoC.Get <IInputManager>().SetShortcut(_keyGesture, this);
     return(this);
 }
        public void Dispose()
        {
            if (!this.window.Dispatcher.HasThreadAccess)
            {
                this.window.Dispatcher.RunAsync(
                    CoreDispatcherPriority.High,
                    Dispose);
                return;
            }

            this.window.CoreWindow.KeyDown -= this.CoreWindowOnKeyDown;
            this.window = null;
            this.gesture = null;
        }
Beispiel #6
0
 /// <summary>Registers a given shortcut for a specific view and connect that shortcut with a given action.</summary>
 /// <param name="viewType">The type of the view.</param>
 /// <param name="gesture">The shortcut.</param>
 /// <param name="action">The action.</param>
 /// <param name="canExecute">Delegate that determines wheter the action can be executed.</param>
 public static void RegisterShortcut(Type viewType, KeyGesture gesture, Action action, Func <bool> canExecute = null)
 {
     CommandManager.RegisterClassInputBinding(
         viewType,
         canExecute == null ? new InputBinding(new RelayCommand(action), gesture) : new InputBinding(new RelayCommand(action, canExecute), gesture));
 }
 private void BindHotkey()
 {
     foreach (var child in Toolbar.Children)
     {
         if (child.GetType() == typeof(RibbonButton))
         {
             RibbonButton tlb         = (RibbonButton)child;
             KeyBinding   key         = new KeyBinding();
             string       strTinhNang = tlb.Name.Substring(3, tlb.Name.Length - 3);
             if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.THEM)))
             {
                 KeyGesture keyg = new KeyGesture(Key.N, ModifierKeys.Control);
                 key         = new KeyBinding(AddCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.SUA)))
             {
                 KeyGesture keyg = new KeyGesture(Key.M, ModifierKeys.Control);
                 key         = new KeyBinding(ModifyCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.XOA)))
             {
                 KeyGesture keyg = new KeyGesture(Key.D, ModifierKeys.Control);
                 key         = new KeyBinding(DeleteCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.DUYET)))
             {
                 KeyGesture keyg = new KeyGesture(Key.A, ModifierKeys.Control | ModifierKeys.Shift);
                 key         = new KeyBinding(ApproveCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.TU_CHOI_DUYET)))
             {
                 KeyGesture keyg = new KeyGesture(Key.R, ModifierKeys.Control | ModifierKeys.Shift);
                 key         = new KeyBinding(RefuseCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.THOAI_DUYET)))
             {
                 KeyGesture keyg = new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Shift);
                 key         = new KeyBinding(CancelCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.XEM)))
             {
                 KeyGesture keyg = new KeyGesture(Key.W, ModifierKeys.Control);
                 key         = new KeyBinding(ViewCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.TIM_KIEM)))
             {
                 KeyGesture keyg = new KeyGesture(Key.F, ModifierKeys.Control);
                 key         = new KeyBinding(SearchCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.LAY_LAI)))
             {
                 KeyGesture keyg = new KeyGesture(Key.F5, ModifierKeys.None);
                 key         = new KeyBinding(ReloadCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.XUAT_DU_LIEU)))
             {
                 KeyGesture keyg = new KeyGesture(Key.E, ModifierKeys.Control | ModifierKeys.Shift);
                 key         = new KeyBinding(ExportCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.TRO_GIUP)))
             {
                 KeyGesture keyg = new KeyGesture(Key.F1, ModifierKeys.None);
                 key         = new KeyBinding(HelpCommand, keyg);
                 key.Gesture = keyg;
             }
             if (key != null)
             {
                 InputBindings.Add(key);
             }
         }
     }
 }
Beispiel #8
0
        //Centralizovaná správa akcí, které se spouštějí z menu (klávesové zkratky, enable/disable apod.)
        #region Commands

        /// <summary>
        /// Vytvoření a přiřazení commands tlačítkům, klávesové zkratky
        /// </summary>
        private void akce()
        {
            CommandBinding cb = new CommandBinding(CommandAbout, comAboutExecute, comAboutCanExecute);

            this.CommandBindings.Add(cb);

            toolBtnAbout.Command = CommandAbout;
            MenBtnAbout.Command  = CommandAbout;

            //klávesové zkratky
            KeyGesture   kg = new KeyGesture(Key.F1, ModifierKeys.Control);
            InputBinding ib = new InputBinding(CommandAbout, kg);

            this.InputBindings.Add(ib);

            //I/O
            cb = new CommandBinding(CommandIO, comIOExecute, comIOCanExecute);
            this.CommandBindings.Add(cb);

            menBtnIO.Command  = CommandIO;
            toolBtnIO.Command = CommandIO;

            kg = new KeyGesture(Key.F4);
            ib = new InputBinding(CommandIO, kg);
            this.InputBindings.Add(ib);

            //Nastavení
            cb = new CommandBinding(CommandNastaveni, comNastaveniExecute, comNastaveniCanExecute);
            this.CommandBindings.Add(cb);

            menBtnNastaveni.Command  = CommandNastaveni;
            toolBtnNastaveni.Command = CommandNastaveni;

            kg = new KeyGesture(Key.F3);
            ib = new InputBinding(CommandNastaveni, kg);
            this.InputBindings.Add(ib);

            //Vynulovat
            cb = new CommandBinding(CommandVynulovat, comVynulovatExecute, comVynulovatCanExecute);
            this.CommandBindings.Add(cb);

            menBtnVynulovat.Command  = CommandVynulovat;
            toolBtnVynulovat.Command = CommandVynulovat;

            kg = new KeyGesture(Key.F7);
            ib = new InputBinding(CommandVynulovat, kg);
            this.InputBindings.Add(ib);

            //Receptury
            cb = new CommandBinding(CommandReceptury, comRecepturyExecute, comRecepturyCanExecute);
            this.CommandBindings.Add(cb);

            menBtnReceptury.Command  = CommandReceptury;
            toolBtnReceptury.Command = CommandReceptury;

            kg = new KeyGesture(Key.F10);
            ib = new InputBinding(CommandReceptury, kg);
            this.InputBindings.Add(ib);

            /*  //Vyber receptury
             * cb = new CommandBinding(CommandVyberRcp, comVyberRcpExecute, comVyberRcpCanExecute);
             * this.CommandBindings.Add(cb);
             *
             * menBtnVyberRcp.Command = CommandVyberRcp;
             * toolBtnVyberRcp.Command = CommandVyberRcp;
             * ucVizualizace.btnTypeName.Command = CommandVyberRcp;
             *
             * kg = new KeyGesture(Key.F11);
             * ib = new InputBinding(CommandVyberRcp, kg);
             * this.InputBindings.Add(ib);   */

            //Login
            cb = new CommandBinding(CommandLogin, comLoginExecute, comLoginCanExecute);
            this.CommandBindings.Add(cb);

            menBtnLogin.Command  = CommandLogin;
            toolBtnLogin.Command = CommandLogin;

            kg = new KeyGesture(Key.F5, ModifierKeys.Control);
            ib = new InputBinding(CommandLogin, kg);
            this.InputBindings.Add(ib);

            //Logout
            cb = new CommandBinding(CommandLogout, comLogoutExecute, comLogoutCanExecute);
            this.CommandBindings.Add(cb);

            menBtnLogout.Command  = CommandLogout;
            toolBtnLogout.Command = CommandLogout;

            kg = new KeyGesture(Key.F5);
            ib = new InputBinding(CommandLogout, kg);
            this.InputBindings.Add(ib);

            //ACK
            cb = new CommandBinding(CommandAck, comAckExecute, comAckCanExecute);
            this.CommandBindings.Add(cb);

            menBtnAck.Command  = CommandAck;
            toolBtnAck.Command = CommandAck;

            kg = new KeyGesture(Key.F6, ModifierKeys.Control);
            ib = new InputBinding(CommandAck, kg);
            this.InputBindings.Add(ib);

            /*   //Home
             * cb = new CommandBinding(CommandHome, comHomeExecute, comHomeCanExecute);
             * this.CommandBindings.Add(cb);
             *
             * menBtnHome.Command = CommandHome;
             * toolBtnHome.Command = CommandHome;
             *
             * kg = new KeyGesture(Key.F7, ModifierKeys.Control);
             * ib = new InputBinding(CommandHome, kg);
             * this.InputBindings.Add(ib);
             *
             */
        }
 private void BindShortkey()
 {
     foreach (var child in Toolbar.Children)
     {
         if (child.GetType() == typeof(StackPanel))
         {
             foreach (var subchild in ((StackPanel)child).Children)
             {
                 if (subchild.GetType() == typeof(RibbonButton))
                 {
                     RibbonButton btl = (RibbonButton)subchild;
                     KeyBinding   key = new KeyBinding();
                     if (btl.Name.Equals("tlbAdd"))
                     {
                         KeyGesture keyg = new KeyGesture(Key.N, ModifierKeys.Control);
                         key         = new KeyBinding(TemplateDanhSach.AddCommand, keyg);
                         key.Gesture = keyg;
                     }
                     else if (btl.Name.Equals("tlbModify"))
                     {
                         KeyGesture keyg = new KeyGesture(Key.M, ModifierKeys.Control);
                         key = new KeyBinding(TemplateDanhSach.ModifyCommand, keyg);
                     }
                     else if (btl.Name.Equals("tlbDelete"))
                     {
                         KeyGesture keyg = new KeyGesture(Key.Delete, ModifierKeys.None);
                         key = new KeyBinding(TemplateDanhSach.DeleteCommand, keyg);
                     }
                     else if (btl.Name.Equals("tlbApprove"))
                     {
                         KeyGesture keyg = new KeyGesture(Key.D, ModifierKeys.Control);
                         key = new KeyBinding(TemplateDanhSach.ApproveCommand, keyg);
                     }
                     else if (btl.Name.Equals("tlbRefuse"))
                     {
                         KeyGesture keyg = new KeyGesture(Key.R, ModifierKeys.Control);
                         key = new KeyBinding(TemplateDanhSach.RefuseCommand, keyg);
                     }
                     else if (btl.Name.Equals("tlbCancel"))
                     {
                         KeyGesture keyg = new KeyGesture(Key.I, ModifierKeys.Control);
                         key = new KeyBinding(TemplateDanhSach.CancelCommand, keyg);
                     }
                     else if (btl.Name.Equals("tlbSearch"))
                     {
                         KeyGesture keyg = new KeyGesture(Key.F, ModifierKeys.Control);
                         key = new KeyBinding(TemplateDanhSach.SearchCommand, keyg);
                     }
                     else if (btl.Name.Equals("tlbExport"))
                     {
                         KeyGesture keyg = new KeyGesture(Key.E, ModifierKeys.Control);
                         key = new KeyBinding(TemplateDanhSach.ExportCommand, keyg);
                     }
                     else if (btl.Name.Equals("tlbClose"))
                     {
                         KeyGesture keyg = new KeyGesture(Key.Escape, ModifierKeys.None);
                         key = new KeyBinding(TemplateDanhSach.CloseCommand, keyg);
                     }
                     InputBindings.Add(key);
                 }
             }
         }
         if (child.GetType() == typeof(RibbonButton))
         {
             RibbonButton btl = (RibbonButton)child;
             KeyBinding   key = new KeyBinding();
             if (btl.Name.Equals("tlbAdd"))
             {
                 KeyGesture keyg = new KeyGesture(Key.N, ModifierKeys.Control);
                 key         = new KeyBinding(TemplateDanhSach.AddCommand, keyg);
                 key.Gesture = keyg;
             }
             else if (btl.Name.Equals("tlbModify"))
             {
                 KeyGesture keyg = new KeyGesture(Key.M, ModifierKeys.Control);
                 key = new KeyBinding(TemplateDanhSach.ModifyCommand, keyg);
             }
             else if (btl.Name.Equals("tlbDelete"))
             {
                 KeyGesture keyg = new KeyGesture(Key.Delete, ModifierKeys.None);
                 key = new KeyBinding(TemplateDanhSach.DeleteCommand, keyg);
             }
             else if (btl.Name.Equals("tlbApprove"))
             {
                 KeyGesture keyg = new KeyGesture(Key.D, ModifierKeys.Control);
                 key = new KeyBinding(TemplateDanhSach.ApproveCommand, keyg);
             }
             else if (btl.Name.Equals("tlbRefuse"))
             {
                 KeyGesture keyg = new KeyGesture(Key.R, ModifierKeys.Control);
                 key = new KeyBinding(TemplateDanhSach.RefuseCommand, keyg);
             }
             else if (btl.Name.Equals("tlbCancel"))
             {
                 KeyGesture keyg = new KeyGesture(Key.I, ModifierKeys.Control);
                 key = new KeyBinding(TemplateDanhSach.CancelCommand, keyg);
             }
             else if (btl.Name.Equals("tlbSearch"))
             {
                 KeyGesture keyg = new KeyGesture(Key.F, ModifierKeys.Control);
                 key = new KeyBinding(TemplateDanhSach.SearchCommand, keyg);
             }
             else if (btl.Name.Equals("tlbExport"))
             {
                 KeyGesture keyg = new KeyGesture(Key.E, ModifierKeys.Control);
                 key = new KeyBinding(TemplateDanhSach.ExportCommand, keyg);
             }
             else if (btl.Name.Equals("tlbClose"))
             {
                 KeyGesture keyg = new KeyGesture(Key.Escape, ModifierKeys.None);
                 key = new KeyBinding(TemplateDanhSach.CloseCommand, keyg);
             }
             InputBindings.Add(key);
         }
     }
 }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MenuItemViewModel"/> class.
 /// </summary>
 /// <param name="header">The header.</param>
 /// <param name="priority">The priority.</param>
 /// <param name="icon">The icon.</param>
 /// <param name="command">The command.</param>
 /// <param name="gesture">The gesture.</param>
 /// <param name="isCheckable">if set to <c>true</c> this menu acts as a checkable menu.</param>
 /// <param name="hideDisabled">if set to <c>true</c> this menu is not visible when disabled.</param>
 /// <param name="container">The container.</param>
 public MenuItemViewModel(String header, Int32 priority, ImageSource icon = null, ICommand command = null,
                          KeyGesture gesture = null, Boolean isCheckable = false, Boolean hideDisabled = false)
     : base(header, priority, icon, command, gesture, isCheckable, hideDisabled)
 {
 }
Beispiel #11
0
        public Shell()
        {
            InitializeComponent();


            ////////////////////////
            //LastStartedFiles target = new LastStartedFiles(); // TODO: инициализация подходящего значения

            //LastStartedFile lf = new LastStartedFile("C:\\1.txt");
            //LastStartedFile lf2 = new LastStartedFile("C:\\2.txt");
            //LastStartedFile lf3 = new LastStartedFile("C:\\3.txt");
            //target.Add(lf);
            //target.Add(lf2);
            //target.Add(lf3);

            //target.Save();
            //LastStartedFiles target2 = LastStartedFiles.Load();
            ////////////////////////////

            //Создание команды и сочетания клавиш для удаления
            CommandBinding cbDelete = new CommandBinding(DeleteFilesCommand, ExecutedDeleteFilesCommand);

            this.CommandBindings.Add(cbDelete);

            KeyGesture kgDel = new KeyGesture(Key.Delete);
            KeyBinding kbDel = new KeyBinding(DeleteFilesCommand, kgDel);

            this.InputBindings.Add(kbDel);

            KeyGesture kgF8 = new KeyGesture(Key.F8);
            KeyBinding kbF8 = new KeyBinding(DeleteFilesCommand, kgF8);

            this.InputBindings.Add(kbF8);

            //Создание команды и сочетания клавиш для создания директории
            CommandBinding cbMakeDir = new CommandBinding(MakeDirCommand, ExecutedMakeDirCommand);

            this.CommandBindings.Add(cbMakeDir);
            KeyGesture kgMakeDir = new KeyGesture(Key.F7);
            KeyBinding kbMakeDir = new KeyBinding(MakeDirCommand, kgMakeDir);

            this.InputBindings.Add(kbMakeDir);

            //////////////////////////////////////////////////
            CommandBinding cbCopy = new CommandBinding(CopyCommand, ExecutedCopyCommand);

            this.CommandBindings.Add(cbCopy);

            KeyGesture kgCopyF5 = new KeyGesture(Key.F5);
            KeyBinding kbCopyF5 = new KeyBinding(CopyCommand, kgCopyF5);

            KeyGesture kgCopyF6 = new KeyGesture(Key.F6);
            KeyBinding kbCopyF6 = new KeyBinding(CopyCommand, kgCopyF6);

            this.InputBindings.Add(kbCopyF5);
            this.InputBindings.Add(kbCopyF6);

            //////////////////////////////////////////////////
            CommandBinding cbRename = new CommandBinding(RenameCommand, ExecutedRenameCommand);

            this.CommandBindings.Add(cbRename);

            KeyGesture kgRename = new KeyGesture(Key.F2);
            KeyBinding kbRename = new KeyBinding(RenameCommand, kgRename);

            this.InputBindings.Add(kbRename);

            LoadWindowPos();
            //testing
            //ExplorerNet.Languages.LanguagesManager lm = new Languages.LanguagesManager();
            //var lst = lm.GetAllLanguages();

            lbLastStartedFiles.ItemsSource = Properties.Settings.Default.LastStartedFiles;
            //cmLastStartedFiles.Items.Clear();
            //cmLastStartedFiles.ItemsSource = Properties.Settings.Default.LastStartedFiles;
            lbLastStartedFilesContextMenu.ItemsSource = Properties.Settings.Default.LastStartedFiles;


            /////////////////////////
            // ExplorerNet.Tools.Wallpapers.WallpaperManager wm = new Tools.Wallpapers.WallpaperManager();
            //wm.ChangePicture(@"h:\pic\otBuh\CG Artwork Wallpapers Collection-3 02.jpg", imgFon);
            //this.imgFon.Visibility = System.Windows.Visibility.Hidden;
            //wm.ChangeWindowFon(this, Brushes.Black.Color);


            // WallpaperManager wm = new WallpaperManager();


            //wm.ApplyWallpaper(imgFon, this);
        }
Beispiel #12
0
 public RoutedCommand(string name, KeyGesture keyGesture = null)
 {
     Name    = name;
     Gesture = keyGesture;
 }
Beispiel #13
0
 public static void AttachDevTools(Window window)
 {
     DevTools.Attach(window, KeyGesture.Parse("CTRL+F12"));
 }
Beispiel #14
0
 public ShortCutData(KeyGesture kg)
 {
     skey = kg.Key; mKey = kg.Modifiers;
 }
 protected CommandKeyboardShortcut(KeyGesture keyGesture, int sortOrder, Func <CommandDefinitionBase> commandDefinition)
 {
     _commandDefinition = commandDefinition;
     KeyGesture         = keyGesture;
     SortOrder          = sortOrder;
 }
 internal static void RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler,
                                             CanExecuteRoutedEventHandler canExecuteRoutedEventHandler, string srid1, string srid2)
 {
     PrivateRegisterCommandHandler(controlType, command, executedRoutedEventHandler, canExecuteRoutedEventHandler,
                                   KeyGesture.CreateFromResourceStrings(SR.Get(srid1), SR.Get(srid2)));
 }
Beispiel #17
0
        private void AddGesture(Key key, ModifierKeys modifier)
        {
            KeyGesture keyGesture = new KeyGesture(key, modifier);

            this.InputGestures.Add(keyGesture);
        }
        public void HotKeyManager_Should_Release_Reference_When_Control_In_Item_Template_Detached()
        {
            using (UnitTestApplication.Start(TestServices.StyledWindow))
            {
                var styler = new Mock <Styler>();

                AvaloniaLocator.CurrentMutable
                .Bind <IWindowingPlatform>().ToConstant(new WindowingPlatformMock())
                .Bind <IStyler>().ToConstant(styler.Object);

                var gesture1 = new KeyGesture(Key.A, KeyModifiers.Control);

                var weakReferences = new List <WeakReference>();
                var tl             = new Window {
                    SizeToContent = SizeToContent.WidthAndHeight, IsVisible = true
                };
                var lm = tl.LayoutManager;

                var keyGestures = new AvaloniaList <KeyGesture> {
                    gesture1
                };
                var listBox = new ListBox
                {
                    Width              = 100,
                    Height             = 100,
                    VirtualizationMode = ItemVirtualizationMode.None,
                    // Create a button with binding to the KeyGesture in the template and add it to references list
                    ItemTemplate = new FuncDataTemplate(typeof(KeyGesture), (o, scope) =>
                    {
                        var keyGesture = o as KeyGesture;
                        var button     = new Button
                        {
                            DataContext = keyGesture, [!Button.HotKeyProperty] = new Binding("")
                        };
                        weakReferences.Add(new WeakReference(button, true));
                        return(button);
                    })
                };
                // Add the listbox and render it
                tl.Content = listBox;
                lm.ExecuteInitialLayoutPass();
                listBox.Items = keyGestures;
                lm.ExecuteLayoutPass();

                // Let the button detach when clearing the source items
                keyGestures.Clear();
                lm.ExecuteLayoutPass();

                // Add it again to double check,and render
                keyGestures.Add(gesture1);
                lm.ExecuteLayoutPass();

                keyGestures.Clear();
                lm.ExecuteLayoutPass();

                // The button should be collected since it's detached from the listbox
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();

                Assert.True(weakReferences.Count > 0);
                foreach (var weakReference in weakReferences)
                {
                    Assert.Null(weakReference.Target);
                }
            }
        }
Beispiel #19
0
 public static InputBinding IB(ICommand command, KeyGesture key)
 {
     return(new InputBinding(command, key));
 }
        public void LoadFromTest_wasNotEmpty()
        {
            var gestureInitial = new KeyGesture(Key.T, ModifierKeys.Control);
            var gestureAfter   = new MultiKeyGesture(new[] { new Gesture(Key.None, ModifierKeys.Control), new Gesture(Key.T) });
            var m   = new Manager();
            var key = "Test";
            var c   = new Configs()
            {
                new Config()
                {
                    Name    = "Test.Help",
                    Gesture = new KeyGesture(Key.F1)
                },
                new Config()
                {
                    Name    = "Test.Fullscreen",
                    Gesture = new KeyGesture(Key.F11)
                },
                new Config()
                {
                    Name    = key,
                    Gesture = gestureInitial
                }
            };

            m.LoadFrom(c, ManagerUpdateMode.Full);

            int pc = 0;

            m.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "Item[]")
                {
                    ++pc;
                }
            };

            var c1 = new Configs()
            {
                new Config()
                {
                    Name    = "Test.NotExisting",
                    Gesture = new KeyGesture(Key.F12)
                },
                new Config()
                {
                    Name    = key,
                    Gesture = gestureAfter
                }
            };

            m.LoadFrom(c1, ManagerUpdateMode.OnlyUpdateExisting);
            Assert.IsNull(m["Test.NotExisting"]);
            Assert.AreEqual(3, m.Configs.Count);
            Assert.AreEqual(1, pc);
            Assert.AreEqual(m[key], gestureAfter);

            foreach (var config in m.Configs)
            {
                Assert.IsTrue(config.IsLocked);
            }
        }
        /// <summary>
        /// Dang ky hot key, shortcut key
        /// </summary>
        #region Dang ky hot key, shortcut key
        /// <summary>
        /// Binding HotKey
        /// </summary>
        private void BindHotkey()
        {
            foreach (var child in Toolbar.Children)
            {
                if (child.GetType() == typeof(RibbonButton))
                {
                    RibbonButton tlb         = (RibbonButton)child;
                    KeyBinding   key         = new KeyBinding();
                    string       strTinhNang = tlb.Name.Substring(3, tlb.Name.Length - 3);
                    if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.NHAP_DU_LIEU)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.I, ModifierKeys.Shift);
                        key         = new KeyBinding(ImportCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.SUA)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.M, ModifierKeys.Control);
                        key         = new KeyBinding(ModifyCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.XOA)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.Delete, ModifierKeys.Shift);
                        key         = new KeyBinding(DeleteCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.NHAN_BAN)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.V, ModifierKeys.Control | ModifierKeys.Shift);
                        key         = new KeyBinding(CloneCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.LUU_TAM)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.H, ModifierKeys.Control);
                        key         = new KeyBinding(HoldCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.LUU)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.S, ModifierKeys.Control);
                        key         = new KeyBinding(SubmitCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.BANG_KE)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.S, ModifierKeys.Shift);
                        key         = new KeyBinding(CashStmtCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.DUYET)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.A, ModifierKeys.Control | ModifierKeys.Shift);
                        key         = new KeyBinding(ApproveCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.TU_CHOI_DUYET)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.R, ModifierKeys.Control | ModifierKeys.Shift);
                        key         = new KeyBinding(RefuseCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.THOAI_DUYET)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.C, ModifierKeys.Control | ModifierKeys.Shift);
                        key         = new KeyBinding(CancelCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.XEM_TRUOC)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.W, ModifierKeys.Control | ModifierKeys.Shift);
                        key         = new KeyBinding(PreviewCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.XEM)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.W, ModifierKeys.Control);
                        key         = new KeyBinding(ViewCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.XUAT_DU_LIEU)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.E, ModifierKeys.Shift);
                        key         = new KeyBinding(ExportCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.TIM_KIEM)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.S, ModifierKeys.Control | ModifierKeys.Shift);
                        key         = new KeyBinding(SearchCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.TRO_GIUP)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.F1, ModifierKeys.None);
                        key         = new KeyBinding(HelpCommand, keyg);
                        key.Gesture = keyg;
                    }
                    else if (strTinhNang.Equals(DatabaseConstant.getValue(DatabaseConstant.Action.DONG)))
                    {
                        KeyGesture keyg = new KeyGesture(Key.Escape, ModifierKeys.None);
                        key         = new KeyBinding(CloseCommand, keyg);
                        key.Gesture = keyg;
                    }

                    InputBindings.Add(key);
                }
            }
        }
 protected bool ContainsGesture(RoutedCommand cmd, KeyGesture gesture)
 {
     return(cmd.InputGestures.OfType <KeyGesture>().Any(p => string.Equals(p.DisplayString, gesture.DisplayString)));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProcessShortcutCommand"/> class.
 /// </summary>
 /// <param name="gesture">
 /// The gesture.
 /// </param>
 public ProcessShortcutCommand(KeyGesture gesture)
 {
     this.gesture = gesture;
 }
Beispiel #24
0
 static public void AddKeyBinding(this Control item, System.Windows.Input.ICommand command, KeyGesture gesture)
 {
     item.KeyBindings.Add(new KeyBinding()
     {
         Command = command,
         Gesture = gesture
     });
 }
		protected CommandKeyboardShortcut(KeyGesture keyGesture, int sortOrder, Func<CommandDefinitionBase> commandDefinition)
		{
			_commandDefinition = commandDefinition;
			KeyGesture = keyGesture;
			SortOrder = sortOrder;
		}
Beispiel #26
0
 static public void AddKeyBinding(this Control item, FunctionSyncro function_syncro, KeyGesture gesture)
 {
     item.AddKeyBinding(function_syncro.GetCommand(), gesture);
 }
        public void Dispose()
        {
            if (!this.window.Dispatcher.HasThreadAccess)
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                this.window.Dispatcher.RunAsync(
                    CoreDispatcherPriority.High,
                    Dispose);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

                return;
            }

            this.window.CoreWindow.KeyDown -= this.CoreWindowOnKeyDown;
            this.window = null;
            this.gesture = null;
        }
        private void refreshMenu()
        {
            reader = new AppSettingsReader();
            try
            {
                readConfig = (string)reader.GetValue("newFile", typeof(string));
                newButton.InputGestureText = readConfig;
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString(readConfig);
                KeyBinding newFileHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    newButton.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
                }, o => true), hotkey);
                InputBindings.Add(newFileHotkey);

                readConfig = (string)reader.GetValue("openFile", typeof(string));
                openButton.InputGestureText = readConfig;
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString(readConfig);
                KeyBinding openFileHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    openButton.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
                }, o => true), hotkey);
                InputBindings.Add(openFileHotkey);

                readConfig = (string)reader.GetValue("saveFile", typeof(string));
                saveButton.InputGestureText = readConfig;
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString(readConfig);
                KeyBinding saveFileHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    saveButton.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
                }, o => true), hotkey);
                InputBindings.Add(saveFileHotkey);

                readConfig = (string)reader.GetValue("closeWindow", typeof(string));
                exitButton.InputGestureText = readConfig;
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString(readConfig);
                KeyBinding closeWindowHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Buffer"))
                    {
                        Directory.Delete(Directory.GetCurrentDirectory() + @"\Buffer", true);
                    }
                    Environment.Exit(1);
                }, o => true), hotkey);
                InputBindings.Add(closeWindowHotkey);

                readConfig = (string)reader.GetValue("pluginsMenu", typeof(string));
                openPlMenuButton.InputGestureText = readConfig;
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString(readConfig);
                KeyBinding pluginsMenuHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    Plugins pluginsWindow = new Plugins(this);
                    pluginsWindow.ShowDialog();
                }, o => true), hotkey);
                InputBindings.Add(pluginsMenuHotkey);

                readConfig = (string)reader.GetValue("runPlugins", typeof(string));
                runButton.InputGestureText = readConfig;
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString(readConfig);
                KeyBinding runPluginsHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    Plugins pluginsWindow = new Plugins(this);
                    pluginsWindow.JustRun();
                }, o => true), hotkey);
                InputBindings.Add(runPluginsHotkey);

                readConfig = (string)reader.GetValue("settings", typeof(string));
                settingsButton.InputGestureText = readConfig;
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString(readConfig);
                KeyBinding settingsHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    settingsButton.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
                }, o => true), hotkey);
                InputBindings.Add(settingsHotkey);
            }
            catch (Exception)
            {
                MessageBox.Show("Config file not loaded, loaded standart settings", "Warning", MessageBoxButton.OK, MessageBoxImage.Error);
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString("Ctrl+N");
                newButton.InputGestureText = "Ctrl+N";
                KeyBinding newFileHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    newButton.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
                }, o => true), hotkey);
                InputBindings.Add(newFileHotkey);
                openButton.InputGestureText = "Ctrl+L";
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString("Ctrl+L");
                KeyBinding openFileHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    openButton.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
                }, o => true), hotkey);
                InputBindings.Add(openFileHotkey);
                saveButton.InputGestureText = "Ctrl+S";
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString("Ctrl+S");
                KeyBinding saveFileHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    saveButton.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
                }, o => true), hotkey);
                InputBindings.Add(saveFileHotkey);
                exitButton.InputGestureText = "Esc";
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString("Esc");
                KeyBinding closeWindowHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Buffer"))
                    {
                        Directory.Delete(Directory.GetCurrentDirectory() + @"\Buffer", true);
                    }
                    Environment.Exit(1);
                }, o => true), hotkey);
                InputBindings.Add(closeWindowHotkey);
                openPlMenuButton.InputGestureText = "F2";
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString("F2");
                KeyBinding pluginsMenuHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    Plugins pluginsWindow = new Plugins(this);
                    pluginsWindow.ShowDialog();
                }, o => true), hotkey);
                InputBindings.Add(pluginsMenuHotkey);
                runButton.InputGestureText = "F1";
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString("F1");
                KeyBinding runPluginsHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    Plugins pluginsWindow = new Plugins(this);
                    pluginsWindow.JustRun();
                }, o => true), hotkey);
                InputBindings.Add(runPluginsHotkey);
                settingsButton.InputGestureText = "F9";
                hotkey = (KeyGesture) new KeyGestureConverter().ConvertFromString("F9");
                KeyBinding settingsHotkey = new KeyBinding(new RelayCommand(o =>
                {
                    settingsButton.RaiseEvent(new RoutedEventArgs(MenuItem.ClickEvent));
                }, o => true), hotkey);
                InputBindings.Add(settingsHotkey);
            }
        }
Beispiel #29
0
        //</SnippetCommandingOverviewCommandDefinition>


        public Window1()
        {
            InitializeComponent();

            //<SnippetCommandingOverviewKeyBinding>
            KeyGesture OpenKeyGesture = new KeyGesture(
                Key.B,
                ModifierKeys.Control);

            KeyBinding OpenCmdKeybinding = new KeyBinding(
                ApplicationCommands.Open,
                OpenKeyGesture);

            this.InputBindings.Add(OpenCmdKeybinding);
            //</SnippetCommandingOverviewKeyBinding>

            //<SnippetCommandingOverviewKeyGestureOnCmd>
            KeyGesture OpenCmdKeyGesture = new KeyGesture(
                Key.B,
                ModifierKeys.Control);

            ApplicationCommands.Open.InputGestures.Add(OpenCmdKeyGesture);
            //</SnippetCommandingOverviewKeyGestureOnCmd>

            //<SnippetCommandingOverviewCommandTargetCodeBehind>
            // Creating the UI objects
            StackPanel mainStackPanel = new StackPanel();
            TextBox    pasteTextBox   = new TextBox();
            Menu       stackPanelMenu = new Menu();
            MenuItem   pasteMenuItem  = new MenuItem();

            // Adding objects to the panel and the menu
            stackPanelMenu.Items.Add(pasteMenuItem);
            mainStackPanel.Children.Add(stackPanelMenu);
            mainStackPanel.Children.Add(pasteTextBox);

            // Setting the command to the Paste command
            pasteMenuItem.Command = ApplicationCommands.Paste;

            // Setting the command target to the TextBox
            pasteMenuItem.CommandTarget = pasteTextBox;
            //</SnippetCommandingOverviewCommandTargetCodeBehind>

            //<SnippetCommandingOverviewCustomCommandSourceCodeBehind>
            // create the ui
            StackPanel CustomCommandStackPanel = new StackPanel();
            Button     CustomCommandButton     = new Button();

            CustomCommandStackPanel.Children.Add(CustomCommandButton);

            CustomCommandButton.Command = CustomRoutedCommand;
            //</SnippetCommandingOverviewCustomCommandSourceCodeBehind>

            //<SnippetCommandingOverviewCustomCommandBindingCodeBehind>
            CommandBinding customCommandBinding = new CommandBinding(
                CustomRoutedCommand, ExecutedCustomCommand, CanExecuteCustomCommand);

            // attach CommandBinding to root window
            this.CommandBindings.Add(customCommandBinding);
            //</SnippetCommandingOverviewCustomCommandBindingCodeBehind>

            sp.Children.Add(mainStackPanel);
            pasteTextBox.Background = Brushes.Bisque;

            sp.Children.Add(CustomCommandStackPanel);

            //<SnippetCommandingOverviewCmdSource>
            StackPanel  cmdSourcePanel       = new StackPanel();
            ContextMenu cmdSourceContextMenu = new ContextMenu();
            MenuItem    cmdSourceMenuItem    = new MenuItem();

            // Add ContextMenu to the StackPanel.
            cmdSourcePanel.ContextMenu = cmdSourceContextMenu;
            cmdSourcePanel.ContextMenu.Items.Add(cmdSourceMenuItem);

            // Associate Command with MenuItem.
            cmdSourceMenuItem.Command = ApplicationCommands.Properties;
            //</SnippetCommandingOverviewCmdSource>

            cmdSourcePanel.Background = Brushes.Black;
            cmdSourcePanel.Height     = 100;
            cmdSourcePanel.Width      = 100;
            mainStackPanel.Children.Add(cmdSourcePanel);
        }
Beispiel #30
0
 /// <summary>Sets the value of <see cref="P:DevZest.Windows.Docking.Primitives..WindowSwitcher.Hotkey" /> attached property
 /// for a given <see cref="DockControl" />.</summary>
 /// <param name="dockControl">The <see cref="DockControl"/> on which to set the property value.</param>
 /// <param name="value">The property value to set.</param>
 public static void SetHotkey(DockControl dockControl, KeyGesture value)
 {
     dockControl.SetValue(HotkeyProperty, value);
 }