Exemple #1
0
        /// <summary>
        /// Initializes all hot key of the application
        /// </summary>
        private void CreateKeyBindings()
        {
            KeyGestureConverter converter = new KeyGestureConverter();

            KeyBindings = new InputBindingCollection()
            {
                new KeyBinding(NewCommand, converter.ConvertFromString(Settings.Keymap.New) as KeyGesture),
                new KeyBinding(OpenCommand, converter.ConvertFromString(Settings.Keymap.Open) as KeyGesture),
                new KeyBinding(OpenFolderCommand, converter.ConvertFromString(Settings.Keymap.OpenFolder) as KeyGesture),
                new KeyBinding(SaveCommand, converter.ConvertFromString(Settings.Keymap.Save) as KeyGesture),
                new KeyBinding(SaveAsCommand, converter.ConvertFromString(Settings.Keymap.SaveAs) as KeyGesture),
                new KeyBinding(SaveAllCommand, converter.ConvertFromString(Settings.Keymap.SaveAll) as KeyGesture),
                new KeyBinding(CloseCommand, converter.ConvertFromString(Settings.Keymap.Close) as KeyGesture),
                new KeyBinding(CloseFolderCommand, converter.ConvertFromString(Settings.Keymap.CloseFolder) as KeyGesture),
                new KeyBinding(ExitCommand, converter.ConvertFromString(Settings.Keymap.Exit) as KeyGesture),
                new KeyBinding(UndoCommand, converter.ConvertFromString(Settings.Keymap.Undo) as KeyGesture),
                new KeyBinding(RedoCommand, converter.ConvertFromString(Settings.Keymap.Redo) as KeyGesture),
                new KeyBinding(CutCommand, converter.ConvertFromString(Settings.Keymap.Cut) as KeyGesture),
                new KeyBinding(CopyCommand, converter.ConvertFromString(Settings.Keymap.Copy) as KeyGesture),
                new KeyBinding(PasteCommand, converter.ConvertFromString(Settings.Keymap.Paste) as KeyGesture),
                new KeyBinding(DeleteCommand, converter.ConvertFromString(Settings.Keymap.Delete) as KeyGesture),
                new KeyBinding(SelectAllCommand, converter.ConvertFromString(Settings.Keymap.SelectAll) as KeyGesture),
                new KeyBinding(FindCommand, converter.ConvertFromString(Settings.Keymap.Find) as KeyGesture),
                new KeyBinding(ReplaceCommand, converter.ConvertFromString(Settings.Keymap.Replace) as KeyGesture),
                new KeyBinding(CompileCommand, converter.ConvertFromString(Settings.Keymap.Compile) as KeyGesture),
                new KeyBinding(RunCommand, converter.ConvertFromString(Settings.Keymap.Run) as KeyGesture),
                new KeyBinding(TerminalCommand, converter.ConvertFromString(Settings.Keymap.Terminal) as KeyGesture),
                new KeyBinding(CalculatorCommand, converter.ConvertFromString(Settings.Keymap.Calculator) as KeyGesture),
                new KeyBinding(SettingsCommand, converter.ConvertFromString(Settings.Keymap.Settings) as KeyGesture),
                new KeyBinding(HelpCommand, converter.ConvertFromString(Settings.Keymap.Help) as KeyGesture),
                new KeyBinding(AboutCommand, converter.ConvertFromString(Settings.Keymap.About) as KeyGesture)
            };
        }
Exemple #2
0
        private void EditInputBinding(MenuItem menu, ModifierKeys modifier)
        {
            KeyConverter           k   = new KeyConverter();
            Key                    key = (Key)k.ConvertFromString(menu.InputGestureText);
            InputBindingCollection InputBindingsCopy = new InputBindingCollection(InputBindings);

            foreach (KeyBinding item in InputBindingsCopy)
            {
                if (item.Key == key)
                {
                    if (modifier == ModifierKeys.None)
                    {
                        InputBindings.Remove(item);
                    }
                    else
                    {
                        item.Modifiers = modifier;
                        if (modifier == ModifierKeys.Control)
                        {
                            menu.InputGestureText = "CTRL+" + menu.InputGestureText;
                        }
                    }
                    break;
                }
            }
        }
    public static void Add <T>(this InputBindingCollection list, Action <T> callback)
        where T : UIElement
    {
        T owner = (T)_ownerField.GetValue(list);

        callback(owner);
    }
    public static void Add(this InputBindingCollection list, String eventName, Delegate handler)
    {
        UIElement owner     = (UIElement)_ownerField.GetValue(list);
        EventInfo eventInfo = owner.GetType().GetEvent(eventName, BindingFlags.Instance | BindingFlags.Public);

        eventInfo.AddEventHandler(owner, handler);
    }
    static void textBox_GotKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
    {
        var window = GetParentWindow(sender as DependencyObject);

        windowBindings = new InputBindingCollection(window.InputBindings);
        window.InputBindings.Clear();
    }
 private static void UnRegisterBindings(Window window, InputBindingCollection inputBindingCollection)
 {
     foreach (var keyBinding in inputBindingCollection.OfType <KeyBinding>())
     {
         window.InputBindings.Remove(keyBinding);
     }
 }
 /// <inheritdoc />
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     inputBindings = null;
     command       = null;
     mapping       = null;
 }
Exemple #8
0
        //static InputBindings()
        //{
        //}

        //public InputBindings(InputBindingCollection bindingsOwner)
        //{
        //	_inputBindings = bindingsOwner;
        //	_stash = new Stack<KeyBinding>();
        //}

        public static void Initialize(InputBindingCollection inputBindings, ActionBinding[] entries)
        {
            _inputBindings = inputBindings;
            _entriesAll    = entries;

            _stash = new Stack <KeyBinding>();
        }
Exemple #9
0
        public ShellViewModel(
            //TODO: one panel at the moment
            [Import] IPanel panel,
            [ImportMany] IEnumerable <Lazy <IActionItem, IActionItemMetadata> > actions,
            IWindowManager windowManager) : this(windowManager, null, false)
        {
            LeftPanel = panel;

            IList <Lazy <IActionItem, IActionItemMetadata> > enumeratedActions =
                actions as IList <Lazy <IActionItem, IActionItemMetadata> > ?? actions.ToList();

            MenuItems = enumeratedActions.Where(action => action.Metadata.Menu == "Root")
                        .OrderBy(action => action.Metadata.Order)
                        .Select(action => action.Value);

            StringToKeyBinding converter = new StringToKeyBinding();

            InputBindingCollection inputBindings = new InputBindingCollection();

            foreach (var action in enumeratedActions)
            {
                if (!string.IsNullOrEmpty(action.Value.Shortcut))
                {
                    KeyGestureConverter keyConv = new KeyGestureConverter();
                    KeyGesture          gesture = (KeyGesture)keyConv.ConvertFromString(action.Value.Shortcut);
                    InputBinding        binding = new InputBinding(action.Value, gesture);

                    inputBindings.Add(binding);
                }
            }

            GlobalInputBindings = inputBindings;
        }
Exemple #10
0
 public void UnregisterShortcuts(InputBindingCollection InputBindings)
 {
     foreach (var menu in Menus)
     {
         menu.UnregisterInputBinding(InputBindings);
     }
 }
        public static void SetInputBinding(InputBindingCollection inputCollection, ICommand command, InputGesture gesture)
        {
            var binding = new InputBinding(command, gesture);

            inputCollection.Remove(binding);
            inputCollection.Add(binding);
        }
Exemple #12
0
        public void ReplaceBinding(ViewModelBase model, InputBinding old_binding, InputBinding new_binding)
        {
            FrameworkElement element = model.ViewElement as FrameworkElement;

            if (element == null)
            {
                return;
            }

            InputBindingCollection elementBindings = element.InputBindings;
            List <InputBinding>    viewBindingList = this.GetBindingList(model);

            for (int i = elementBindings.Count - 1; i >= 0; i--)
            {
                InputBinding b = elementBindings[i];

                if (!BindingsEqual(b, old_binding))
                {
                    continue;
                }

                Console.WriteLine("OVERWRITING BINDING");
                // NOTE: b is being removed because 'old_binding' is just logically equivalent,
                // not necessarily the same object.
                // TODO: replace with Predicate remove.
                viewBindingList.Remove(b);

                viewBindingList.Add(new_binding);

                //elementBindings.RemoveAt( i );
                elementBindings[i] = new_binding;

                return;
            }             // for-loop.
        }
        /// <summary>
        ///     Регистрируе привязку
        /// </summary>
        /// <param name="inputBindings"></param>
        /// <param name="commandTarget"></param>
        private static void RegisterBindings(InputBindingCollection inputBindings, FrameworkElement commandTarget)
        {
            Debug.Assert(inputBindings != null);
            Debug.Assert(commandTarget != null);

            lock (RegisterAppShortcutKeysBehavior._appInputBindingsLock)
            {
                foreach (InputBinding inputBinding in inputBindings)
                {
                    if (inputBinding.Command == null)
                    {
                        BindingHelper.UpdateBinding(inputBinding, InputBinding.CommandProperty,
                                                    commandTarget.DataContext);
                    }
                    // I only add input bindings that are KeyGestures and have a command.
                    if ((!(inputBinding.Gesture is KeyGesture)) || (inputBinding.Command == null))
                    {
                        continue;
                    }
                    inputBinding.CommandTarget = commandTarget;
                    RegisterAppShortcutKeysBehavior._appInputBindings.Add(inputBinding);
                }

                RegisterAppShortcutKeysBehavior._readOnlyAppInputBindings = RegisterAppShortcutKeysBehavior._appInputBindings.ToArray();
            }
        }
Exemple #14
0
        public void RemoveBinding(ViewModelBase model, InputBinding binding)
        {
            FrameworkElement element = model.ViewElement as FrameworkElement;

            if (element == null)
            {
                return;
            }

            InputBindingCollection elementBindings = element.InputBindings;

            // need to find the exact class instance that was added.
            for (int i = elementBindings.Count - 1; i >= 0; i--)
            {
                if (!BindingsEqual(elementBindings[i], binding))
                {
                    continue;
                }
                Console.WriteLine("removing binding: " + binding.Gesture);
                this.GetBindingList(model).Remove(elementBindings[i]);
                elementBindings.RemoveAt(i);

                return;
            }             // for-loop.
        }
Exemple #15
0
        public void AddBindings(ViewModelBase viewModel, IEnumerable <InputBinding> new_bindings)
        {
            if (viewModel.ViewElement == null)
            {
                Console.WriteLine("ViewElement null. No Bindings created.");
                return;
            }

            FrameworkElement elm = viewModel.ViewElement as FrameworkElement;

            if (elm == null)
            {
                Console.WriteLine("!!! InputBinder Error: framework element is null");
                return;
            }

            InputBindingCollection elementBindings = elm.InputBindings;

            foreach (InputBinding b in new_bindings)
            {
                Console.WriteLine("adding binding: " + b.Gesture.ToString());
                elementBindings.Add(b);
            }
            Console.WriteLine("BINDING ADD COUNT: " + new_bindings.Count());
            this.GetBindingList(viewModel).AddRange(new_bindings);
        }         //
 /// <summary>
 /// Adds a new gesture to associate inputbindings
 /// </summary>
 public void AddGesture(InputGesture gesture)
 {
     if (_inputBinding == null)
     {
         _inputBinding = new InputBindingCollection();
     }
     _inputBinding.Add(new InputBinding(this, gesture));
 }
 /// <summary>
 /// Create an object for setting the resources of a frame window.
 /// </summary>
 /// <param name="menu">The main menu.</param>
 /// <param name="statusBar">The status bar.</param>
 /// <param name="toolBar">The tool bar.</param>
 public FrameCommandArgs(Menu menu, StatusBar statusBar, ToolBar toolBar)
 {
     // Initialize the object
     this.ToolBar       = toolBar;
     this.Menu          = menu;
     this.StatusBar     = statusBar;
     this.InputBindings = null;
 }
Exemple #18
0
        public UndoRedoVM(InputBindingCollection inputBinding)
        {
            KeyBinding Undokey = new KeyBinding(UndoCommand, Key.Z, ModifierKeys.Control);
            KeyBinding Redokey = new KeyBinding(RedoCommand, Key.Y, ModifierKeys.Control);

            inputBinding.Add(Undokey);
            inputBinding.Add(Redokey);
        }
 /// <summary>
 /// Create an object for setting the resources of a frame window.
 /// </summary>
 /// <param name="menu">The main menu.</param>
 /// <param name="statusBar">The status bar.</param>
 /// <param name="toolBar">The tool bar.</param>
 public FrameCommandArgs(Menu menu, StatusBar statusBar, ToolBar toolBar, InputBindingCollection inputBindings)
 {
     // Initialize the object
     this.ToolBar       = toolBar;
     this.Menu          = menu;
     this.StatusBar     = statusBar;
     this.InputBindings = inputBindings;
 }
Exemple #20
0
 private static void SetInputBindings(DataGrid grid, InputBindingCollection inputBindingCollection)
 {
     if (grid == null || inputBindingCollection == null || inputBindingCollection.Count == 0)
     {
         return;
     }
     grid.InputBindings.Clear();
     grid.InputBindings.AddRange(inputBindingCollection);
 }
Exemple #21
0
 private static void CleanupInputBindings(InputBindingCollection inputBindings)
 {
     for (int i = inputBindings.Count - 1; i >= 0; i--)
     {
         if (inputBindings[i] is InputBindingEx)
         {
             inputBindings.RemoveAt(i);
         }
     }
 }
Exemple #22
0
 private static void ParseKeyBindings(InputBindingCollection inputBindings, IGestureTranslator?translator, Dictionary <string, string> gestureTable)
 {
     foreach (InputBinding Binding in inputBindings)
     {
         if (Binding is KeyBinding AsKeyBinding)
         {
             ParseKeyBinding(AsKeyBinding, translator, gestureTable);
         }
     }
 }
Exemple #23
0
        public static void SetInputBindings(List <DataGrid> grids, List <InputBindingCollection> inputBindingCollections)
        {
//            Debug.Assert(grids.Count == inputBindingCollections.Count, "grid count <> inputBindingCollections count");
            for (int i = 0; i < grids.Count; i++)
            {
                DataGrid grid = grids[i];
                InputBindingCollection inputBindingCollection = inputBindingCollections[i];
                SetInputBindings(grid, inputBindingCollection);
            }
        }
Exemple #24
0
        /// <summary>
        /// Adds a new gesture to associate inputbindings
        /// </summary>
        public DelegateCommand AddGesture(InputGesture gesture)
        {
            if (this.inputBindings == null)
            {
                this.inputBindings = new InputBindingCollection();
            }

            this.inputBindings.Add(new InputBinding(this, gesture));

            return(this);
        }
        public MainPage()
        {
            InitializeComponent();

            OpenHelpPageCommand = new DelegateCommand(ExecuteOpenHelpPage);
            this.DataContext    = OpenHelpPageCommand;
            InputBindingCollection inputBindCollection = new InputBindingCollection();

            inputBindCollection.Add(new KeyBinding(this.OpenHelpPageCommand, new KeyGesture(Key.F1)));
            CommandManager.SetInputBindings(this, inputBindCollection);
        }
Exemple #26
0
        public DelegateCommand AddKeyGesture(Key key, ModifierKeys mk)
        {
            if (this.inputBindings == null)
            {
                this.inputBindings = new InputBindingCollection();
            }

            this.inputBindings.Add(new InputBinding(this, new KeyGesture(key, mk)));

            return(this);
        }
Exemple #27
0
 public InputBindingsEventProcessor()
 {
     InputBindings = new InputBindingCollection();
     _processEvents.AddRange(
         new[] {
         FrameworkElement.KeyDownEvent,
         FrameworkElement.PreviewMouseDownEvent,
         FrameworkElement.PreviewTouchDownEvent,
         FrameworkElement.PreviewMouseWheelEvent
     });
 }
Exemple #28
0
 /// <summary>
 /// Remove if modifiers and key matched
 /// </summary>
 public static void MatchedRemove(this InputBindingCollection coll, KeyBinding kb)
 {
     foreach (KeyBinding elem in coll)
     {
         if (elem.Modifiers == kb.Modifiers && elem.Key == kb.Key)
         {
             coll.Remove(elem);
             return;
         }
     }
 }
Exemple #29
0
 private static void ParseKeyBindings(InputBindingCollection InputBindings, IGestureTranslator Translator, Dictionary <string, string> GestureTable)
 {
     foreach (InputBinding Binding in InputBindings)
     {
         KeyBinding AsKeyBinding;
         if ((AsKeyBinding = Binding as KeyBinding) != null)
         {
             ParseKeyBinding(AsKeyBinding, Translator, GestureTable);
         }
     }
 }
Exemple #30
0
        /// <summary>
        /// Skip add if modifiers and key identity
        /// </summary>
        public static void SkippedAdd(this InputBindingCollection coll, KeyBinding kb)
        {
            foreach (KeyBinding elem in coll)
            {
                if (elem.Modifiers == kb.Modifiers && elem.Key == kb.Key)
                {
                    return;
                }
            }

            coll.Add(kb);
        }