Ejemplo n.º 1
0
        private void AddHotkeyCommandExecute([NotNull] object obj)
        {
            Assert.ArgumentNotNull(obj, "obj");

            var oldHotkey = new Hotkey();

            oldHotkey.Actions.Add(new SendTextAction());
            var hotKeyToAdd      = new GlobalHotkeyViewModel(oldHotkey, _actionDescriptions);
            var hotKeyEditDialog = new GlobalHotkeyEditDialog {
                DataContext = hotKeyToAdd, Owner = (Window)obj
            };

            var dialogResult = hotKeyEditDialog.ShowDialog();

            if (dialogResult.HasValue && dialogResult.Value)
            {
                var hotkeyViewModel = Hotkeys.FirstOrDefault(hotk => hotk.Key == hotKeyToAdd.Key && hotk.ModifierKeys == hotKeyToAdd.ModifierKeys);
                if (hotkeyViewModel != null)
                {
                    Hotkeys.Remove(hotkeyViewModel);
                }

                var hotkey = _hotkeys.FirstOrDefault(hotk => hotk.Key == hotKeyToAdd.Key && hotk.ModifierKeys == hotKeyToAdd.ModifierKeys);
                if (hotkey != null)
                {
                    _hotkeys.Remove(hotkey);
                }

                Hotkeys.Add(hotKeyToAdd);
                _hotkeys.Add(hotKeyToAdd.Hotkey);
            }
        }
Ejemplo n.º 2
0
        private void EditHotkeyCommandExecute([NotNull] object obj)
        {
            Assert.ArgumentNotNull(obj, "obj");

            if (SelectedHotkey == null)
            {
                return;
            }

            var hotkeyViewModel = SelectedHotkey.Clone();

            var hotKeyEditDialog = new GlobalHotkeyEditDialog {
                DataContext = hotkeyViewModel, Owner = (Window)obj
            };
            var dialogResult = hotKeyEditDialog.ShowDialog();

            if (dialogResult.HasValue && dialogResult.Value)
            {
                var hotkeyViewModelToRemove = Hotkeys.FirstOrDefault(hotk => hotk.Key == hotkeyViewModel.Key && hotk.ModifierKeys == hotkeyViewModel.ModifierKeys);
                if (hotkeyViewModelToRemove != null)
                {
                    Hotkeys.Remove(hotkeyViewModelToRemove);
                }

                var hotkey = _hotkeys.FirstOrDefault(hotk => hotk.Key == hotkeyViewModel.Key && hotk.ModifierKeys == hotkeyViewModel.ModifierKeys);
                if (hotkey != null)
                {
                    _hotkeys.Remove(hotkey);
                }

                Hotkeys.Add(hotkeyViewModel);
                _hotkeys.Add(hotkeyViewModel.Hotkey);

                SelectedHotkey = hotkeyViewModel;
            }
        }