Esempio n. 1
0
    private void KeyBindCopy(KeyBindings from, KeyBindings to)
    {
        to.Clear();

        foreach (string key in from.Keys)
        {
            to.Add(key, from[key]);
        }
    }
Esempio n. 2
0
 public bool AddKeyBinding(Keys key, InputType inputType)
 {
     if (KeyBindings.ContainsKey(key))
     {
         return(false);
     }
     KeyBindings.Add(key, inputType);
     return(true);
 }
Esempio n. 3
0
 private void AddBinding(RoutedCommand command, EventHandler <ExecutedRoutedEventArgs> handler, EventHandler <CanExecuteRoutedEventArgs> canExecuteHandler = null)
 {
     CommandBindings.Add(new RoutedCommandBinding(command, handler, canExecuteHandler));
     if (command.Gesture != null)
     {
         KeyBindings.Add(new KeyBinding {
             Command = command, Gesture = command.Gesture
         });
     }
 }
Esempio n. 4
0
 public void AddScoresKeyBinding(ScoresRange scoresRange, GamepadButtons button)
 {
     if (KeyBindings.ContainsKey(button))
     {
         KeyBindings[button] = scoresRange;
     }
     else
     {
         KeyBindings.Add(button, scoresRange);
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes the hotkeys.
 /// </summary>
 protected virtual void InitializeHotKeys()
 {
     KillHotkeys(GetHotKeyGestures());
     foreach (var item in GetHotKeyGestures())
     {
         var vm = ViewModel;
         KeyBindings.Add(new KeyBinding()
         {
             Command          = vm.RegisterHotkeyCommand,
             CommandParameter = item.Key,
             Gesture          = item.Value
         });
     }
 }
Esempio n. 6
0
        private void Initialize(IDictionary <Command, ICollection <KeyBinding> > keyBindings)
        {
            _keyBindings = keyBindings;

            ClearKeyBindings();

            foreach (var value in Enum.GetValues(typeof(Command)))
            {
                var command   = (Command)value;
                var viewModel = new KeyBindingsViewModel(command, _keyBindings[command], _dialogService);
                viewModel.Edited += OnEdited;
                KeyBindings.Add(viewModel);
            }
        }
 public TemplateDbTableEditorView()
 {
     InitializeComponent();
     KeyBindings.Add(new KeyBinding()
     {
         Command = new DelegateCommand(() =>
         {
             TextBox tb = this.FindControl <TextBox>("SearchTextBox") as TextBox;
             tb?.Focus();
         }),
         Gesture = new KeyGesture(Key.F, AvaloniaLocator.Current
                                  .GetService <PlatformHotkeyConfiguration>()?.CommandModifiers ?? KeyModifiers.Control)
     });
 }
Esempio n. 8
0
        public KeyBindingsViewModel(Command command, ICollection <KeyBinding> keyBindings, IDialogService dialogService)
        {
            _command       = command;
            _keyBindings   = keyBindings;
            _dialogService = dialogService;

            foreach (var binding in keyBindings)
            {
                var viewModel = new KeyBindingViewModel(binding, _dialogService);
                viewModel.Deleted += ViewModel_Deleted;
                viewModel.Edited  += ViewModel_Edited;
                KeyBindings.Add(viewModel);
            }
        }
Esempio n. 9
0
        public InputBinding AddBinding(string name, bool shift, bool control, bool alt, Keys key, EventHandler beginHandler, EventHandler endHandler)
        {
            InputBinding binding = new InputBinding(name, shift, control, alt);

            binding.BeginExecution = beginHandler;
            binding.EndExecution   = endHandler;

            key |= shift ? Keys.Shift : Keys.None;
            key |= control ? Keys.Control : Keys.None;
            key |= alt ? Keys.Alt : Keys.None;

            KeyBindings.Add(key, binding);

            return(binding);
        }
Esempio n. 10
0
        protected override void ReloadMappings()
        {
            // load defaults
            base.ReloadMappings();

            var rulesetId = ruleset?.ID;

            // load from database if present.
            if (store != null)
            {
                foreach (var b in store.Query <DatabasedKeyBinding>(b => b.RulesetID == rulesetId && b.Variant == variant))
                {
                    KeyBindings.Add(b);
                }
            }
        }
        public KeyBindingsViewModel(Command command, ICollection <KeyBinding> keyBindings, IDialogService dialogService)
        {
            Command        = command;
            _keyBindings   = keyBindings;
            _dialogService = dialogService;

            CommandName = EnumHelper.GetEnumDescription(command);

            foreach (var binding in keyBindings)
            {
                var viewModel = new KeyBindingViewModel(binding, _dialogService);
                viewModel.Deleted += ViewModel_Deleted;
                viewModel.Edited  += ViewModel_Edited;
                KeyBindings.Add(viewModel);
            }
        }
        private void Initialize(IDictionary <string, ICollection <KeyBinding> > keyBindings)
        {
            ClearKeyBindings();

            foreach (var value in Enum.GetValues(typeof(Command)))
            {
                var command   = (Command)value;
                var viewModel = new KeyBindingsViewModel(command.ToString(), _dialogService, I18N.Translate($"{nameof(Command)}.{command}"), true);
                foreach (var keyBinding in keyBindings[command.ToString()])
                {
                    viewModel.Add(keyBinding);
                }
                viewModel.Edited += OnEdited;
                KeyBindings.Add(viewModel);
            }
        }
Esempio n. 13
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)
                });
            }
        }
Esempio n. 14
0
        public MainWindow()
        {
            const double spacing_about = 50;

            InitializeComponent();

            this.menu = this.FindControl <Menu>("menu");

            KeyBindings.Add(new KeyBinding()
            {
                Command = ReactiveCommand.Create(ToggleFullScreen),
                Gesture = new KeyGesture(Key.F11),
            });
            WandConfig cfg;

            try
            {
                using (var file = File.OpenText(WandConfig.CFG_NAME))
                {
                    cfg = JsonConvert.DeserializeObject <WandConfig>(file.ReadToEnd());
                }
            }
            catch (Exception e)
            {
                cfg = new WandConfig()
                {
                    LedShape        = LedShape.Eck,
                    LedCols         = 8,
                    LedRows         = 12,
                    Protocol        = LedProto.TPM2,
                    ListenInterface = "localhost",
                    ListenPort      = 65506,
                    StartFullScreen = false,
                };
                var win = new Window();
                win.Content = e.Message;
            }
            MainWindowViewModel viewModel = new MainWindowViewModel(this, cfg);

            this.DataContext = viewModel;
            this.Width       = spacing_about * viewModel.LedVm.Cols;
            this.Height      = spacing_about * viewModel.LedVm.Rows;
            //this.AttachDevTools();
            Renderer.DrawFps = true;
            //Renderer.DrawDirtyRects = Renderer.DrawFps = true;
        }
Esempio n. 15
0
        private void InitializeViewModelProperties(ShellProfile shellProfile)
        {
            SelectedTerminalTheme = TerminalThemes.FirstOrDefault(t => t.Id == shellProfile.TerminalThemeId);
            Id               = shellProfile.Id;
            Name             = shellProfile.Name;
            Arguments        = shellProfile.Arguments;
            Location         = shellProfile.Location;
            WorkingDirectory = shellProfile.WorkingDirectory;
            SelectedTabTheme = TabThemes.FirstOrDefault(t => t.Id == shellProfile.TabThemeId);
            PreInstalled     = shellProfile.PreInstalled;

            KeyBindings.Clear();
            foreach (var keyBinding in shellProfile.KeyBindings.Select(x => new KeyBinding(x)).ToList())
            {
                KeyBindings.Add(keyBinding);
            }
        }
Esempio n. 16
0
        private void Initialize(IDictionary <string, ICollection <KeyBinding> > keyBindings)
        {
            _keyBindings = keyBindings;

            ClearKeyBindings();

            foreach (var value in Enum.GetValues(typeof(Command)))
            {
                var command   = (Command)value;
                var viewModel = new KeyBindingsViewModel(command.ToString(), _dialogService, EnumHelper.GetEnumDescription(command), true);
                foreach (var keyBinding in _keyBindings[command.ToString()])
                {
                    viewModel.Add(keyBinding);
                }
                viewModel.Edited += OnEdited;
                KeyBindings.Add(viewModel);
            }
        }
Esempio n. 17
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;
            }
        }
        /// <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)
                {
                    if (kb.CommandName == "EditorCommand")
                    {
                        keyBinding = kb;
                        keyBinding.HasJavaScriptHandler = true;
                        KeyBindings.Add(keyBinding);
                    }
                    continue;
                }

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

            return(true);
        }
Esempio n. 19
0
        private void InitializeComponent()
        {
            this.WhenActivated(disposable => {
                // Bind connect button text to connect command execution
                ConnectButton.Bind(Button.ContentProperty, ViewModel.ConnectCommand.IsExecuting.Select(executing => executing ? "Connecting..." : "Connect"))
                .DisposeWith(disposable);

                // Handle authentication requests
                ViewModel.InteractiveAuthenticationHandler.EnterPasswordInteraction.RegisterHandler(async context => {
                    string?password = await new EnterPasswordDialog().ShowDialog <string?>(this).ConfigureAwait(true);
                    context.SetOutput(password);
                }).DisposeWith(disposable);
            });

            // Register keybinding for exiting fullscreen
            KeyBindings.Add(new KeyBinding {
                Gesture = new KeyGesture(Key.Escape, KeyModifiers.Control),
                Command = ReactiveCommand.Create(() => SetFullscreenMode(false))
            });

            AvaloniaXamlLoader.Load(this);
        }
 //private void KeyBinding_Added(KeyBinding keyBinding)
 //{
 //    if (IsAttached)
 //        TextArea.KeyBindings.Add(keyBinding);
 //}
 //private void KeyBinding_Removed(KeyBinding keyBinding)
 //{
 //    if (IsAttached)
 //        TextArea.KeyBindings.Remove(keyBinding);
 //}
 /// <summary>
 /// Adds a command and input binding.
 /// </summary>
 /// <param name="command">The command ID.</param>
 /// <param name="modifiers">The modifiers of the keyboard shortcut.</param>
 /// <param name="key">The key of the keyboard shortcut.</param>
 /// <param name="handler">The event handler to run when the command is executed.</param>
 public void AddBinding(RoutedCommand command, InputModifiers modifiers, Key key, EventHandler<ExecutedRoutedEventArgs> handler)
 {
     CommandBindings.Add(new RoutedCommandBinding(command, handler));
     KeyBindings.Add(new KeyBinding { Command = command, Gesture = new KeyGesture { Key = key, Modifiers = modifiers } });
 }
Esempio n. 21
0
 public void SetKey(KeyType keyType, KeyCode newKey)
 {
     KeyBindings.Remove(keyType);
     KeyBindings.Add(keyType, newKey);
 }