예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool LoadKeyBindings(string filename = null)
        {
            if (filename == null)
            {
                filename = KeyBindingsFilename;
            }

            List <AppKeyBinding> keyBindings;

            keyBindings = JsonSerializationUtils.DeserializeFromFile(filename, typeof(List <AppKeyBinding>))
                          as List <AppKeyBinding>;

            if (keyBindings == null || keyBindings.Count < 1)
            {
                return(false);
            }

            // TODO: Fix bug with multiple keybindings to the same Command - need Unique Identifier
            foreach (var kb in keyBindings)
            {
                var keyBinding = KeyBindings.FirstOrDefault(binding => binding.Id == kb.Id);
                if (keyBinding == null)
                {
                    continue;
                }

                keyBinding.Key = kb.Key;
                if (keyBinding.Command != null)
                {
                    keyBinding.Command.KeyboardShortcut = kb.Key;
                }
            }

            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool LoadKeyBindings(string filename = null)
        {
            if (filename == null)
            {
                filename = KeyBindingsFilename;
            }

            List <AppKeyBinding> keyBindings;

            keyBindings = JsonSerializationUtils.DeserializeFromFile(filename, typeof(List <AppKeyBinding>))
                          as List <AppKeyBinding>;

            if (keyBindings == null || keyBindings.Count < 1)
            {
                return(false);
            }

            foreach (var kb in keyBindings)
            {
                var keyBinding = KeyBindings.FirstOrDefault(binding => binding.CommandName == kb.CommandName);
                if (keyBinding == null)
                {
                    continue;
                }

                keyBinding.Key = kb.Key;
                if (keyBinding.Command != null)
                {
                    keyBinding.Command.KeyboardShortcut = kb.Key;
                }
            }

            return(true);
        }
예제 #3
0
        private void keyboardListener_KeyDown(object sender, RawKeyEventArgs e)
        {
            _lastKeys.Add(TranslateKey(e.Key));

            var kb = KeyBindings.FirstOrDefault(k => k.Gesture.SetEquals(_lastKeys));

            if (kb != default(KeyBinding))
            {
                _lastBindings.Add(kb);
                kb.Command.OnKeyDown();
            }
        }
예제 #4
0
        private void NewBinding(KeyBinding oldBinding, KeyBinding newBinding)
        {
            KeyBindings.FirstOrDefault(x => x.Keys.Value.SetEquals(newBinding.Keys))?.ClearBinding(); //clear conflicted bindings
            ArgsAndSettings.KeyBindings.SetBinding(newBinding);

            var newBindingVm = new KeyBindingViewModel(newBinding, EditBinding, DeleteBinding);

            KeyBindings.Add(newBindingVm);

            var oldEmptyBinding = EmptyBinding.Value;

            EmptyBinding.Value = null; //have to null this first or the content template bindings don't update
            EmptyBinding.Value = MakeEmptyBinding();

            if (oldEmptyBinding.PathOrLiteralIsFocused.Value)
            {
                newBindingVm.PathOrLiteralIsFocused.Value = true;
            }
        }
예제 #5
0
 private async Task Add(string command)
 {
     var keyBinding = KeyBindings.FirstOrDefault(k => k.Command == command);
     await keyBinding?.ShowAddKeyBindingDialog();
 }
 /// <summary>
 /// Returns the keyboard shortcut for a given command. This is the mapped
 /// command if extended via keyboard bindings.
 /// </summary>
 /// <param name="commandName"></param>
 /// <returns></returns>
 public string GetInputGestureForCommand(string commandName)
 {
     return(KeyBindings.FirstOrDefault(kb => kb.CommandName == commandName)?.Key);
 }
예제 #7
0
 private async Task Add(Command command)
 {
     var keyBinding = KeyBindings.FirstOrDefault(k => k.Command == command);
     await keyBinding?.Add();
 }