public HResult GetKeys(INiCommandBarButton button, out Keys[] keys) { keys = null; try { if (button == null) { throw new ArgumentNullException("button"); } List <Keys> mappedKeys; if (_mappingsByButton.TryGetValue(button.Id, out mappedKeys)) { keys = mappedKeys.ToArray(); } else { keys = EmptyKeys; } return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public HResult CreateCommandBarButton(Guid id, int priority, string code, out INiCommandBarButton button) { button = null; try { button = new NiCommandBarButton(id, priority, code); _objects[id] = button; return HResult.OK; } catch (Exception ex) { return ErrorUtil.GetHResult(ex); } }
public HResult CreateCommandBarButton(Guid id, int priority, string code, out INiCommandBarButton button) { button = null; try { button = new NiCommandBarButton(id, priority, code); _objects[id] = button; return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public Registration(INiCommandBarButton button) { Button = button; Code = GetButtonCode(button); }
private static string GetButtonCode(INiCommandBarButton button) { return(button.Code.Replace('_', '.')); }
public HResult SetKeys(INiCommandBarButton button, Keys[] keys) { try { if (button == null) { throw new ArgumentNullException("button"); } if (keys == null) { throw new ArgumentNullException("keys"); } foreach (var key in keys) { if (!ShortcutKeysUtil.IsValid(key)) { throw new ArgumentException(String.Format("{0} is not a valid shortcut", key)); } } var id = button.Id; List <Keys> currentKeys; if (!_mappingsByButton.TryGetValue(id, out currentKeys)) { currentKeys = new List <Keys>(); _mappingsByButton.Add(id, currentKeys); } // Remove the button from keys that are not set anymore. foreach (var key in currentKeys) { if (!keys.Contains(key)) { List <Guid> buttons; if (_mappingsByKeys.TryGetValue(key, out buttons)) { bool removed = buttons.Remove(id); Debug.Assert(removed); } else { Debug.Fail("Expected key to appear in mapping"); } } } // Add the button to new keys. foreach (var key in keys) { if (!currentKeys.Contains(key)) { List <Guid> buttons; if (!_mappingsByKeys.TryGetValue(key, out buttons)) { buttons = new List <Guid>(); _mappingsByKeys.Add(key, buttons); } buttons.Add(id); } } // Save the new key bindings. currentKeys.Clear(); currentKeys.AddRange(keys); // Update the new mappings with the new keys. if (AreSameKeys(_keyboardMappingManager._initialKeys[id], keys)) { Mappings.Remove(id); } else { Mappings[id] = keys.ToArray(); } return(HResult.OK); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
private static string GetButtonCode(INiCommandBarButton button) { return button.Code.Replace('_', '.'); }
public HResult CreateCommandBarButton(Guid id, int priority, out INiCommandBarButton button) { return CreateCommandBarButton(id, priority, null, out button); }
public HResult SetKeys(INiCommandBarButton button, Keys[] keys) { try { if (button == null) throw new ArgumentNullException("button"); if (keys == null) throw new ArgumentNullException("keys"); foreach (var key in keys) { if (!ShortcutKeysUtil.IsValid(key)) throw new ArgumentException(String.Format("{0} is not a valid shortcut", key)); } var id = button.Id; List<Keys> currentKeys; if (!_mappingsByButton.TryGetValue(id, out currentKeys)) { currentKeys = new List<Keys>(); _mappingsByButton.Add(id, currentKeys); } // Remove the button from keys that are not set anymore. foreach (var key in currentKeys) { if (!keys.Contains(key)) { List<Guid> buttons; if (_mappingsByKeys.TryGetValue(key, out buttons)) { bool removed = buttons.Remove(id); Debug.Assert(removed); } else { Debug.Fail("Expected key to appear in mapping"); } } } // Add the button to new keys. foreach (var key in keys) { if (!currentKeys.Contains(key)) { List<Guid> buttons; if (!_mappingsByKeys.TryGetValue(key, out buttons)) { buttons = new List<Guid>(); _mappingsByKeys.Add(key, buttons); } buttons.Add(id); } } // Save the new key bindings. currentKeys.Clear(); currentKeys.AddRange(keys); // Update the new mappings with the new keys. if (AreSameKeys(_keyboardMappingManager._initialKeys[id], keys)) Mappings.Remove(id); else Mappings[id] = keys.ToArray(); return HResult.OK; } catch (Exception ex) { return ErrorUtil.GetHResult(ex); } }
public HResult GetKeys(INiCommandBarButton button, out Keys[] keys) { keys = null; try { if (button == null) throw new ArgumentNullException("button"); List<Keys> mappedKeys; if (_mappingsByButton.TryGetValue(button.Id, out mappedKeys)) keys = mappedKeys.ToArray(); else keys = EmptyKeys; return HResult.OK; } catch (Exception ex) { return ErrorUtil.GetHResult(ex); } }
public HResult GetButtons(Keys keys, out INiCommandBarButton[] buttons) { buttons = null; try { List<Guid> mappedButtons; if (_mappingsByKeys.TryGetValue(keys, out mappedButtons)) { buttons = mappedButtons.Select( p => (INiCommandBarButton)_keyboardMappingManager._commandManager._objects[p] ).ToArray(); } else { buttons = EmptyButtons; } return HResult.OK; } catch (Exception ex) { return ErrorUtil.GetHResult(ex); } }
public HResult GetAllButtons(out INiCommandBarButton[] buttons) { buttons = null; try { buttons = _keyboardMappingManager._commandManager._objects.Values.OfType<INiCommandBarButton>().ToArray(); return HResult.OK; } catch (Exception ex) { return ErrorUtil.GetHResult(ex); } }
public HResult CreateCommandBarButton(Guid id, int priority, out INiCommandBarButton button) { return(CreateCommandBarButton(id, priority, null, out button)); }