Exemplo n.º 1
0
        private object OnButton(Button button)
        {
            var keys = ShortcutKeysUtil.Parse(button.Key);

            if (keys.Length > 0 && !ShortcutKeysUtil.IsValid(keys[0]))
            {
                throw new NetIdeException(String.Format(Labels.IllegalButtonShortcutKeys, button.Id, keys));
            }

            INiCommandBarButton command;

            ErrorUtil.ThrowOnFailure(_commandManager.CreateCommandBarButton(
                                         button.Guid != Guid.Empty ? button.Guid : Guid.NewGuid(),
                                         button.Priority,
                                         button.Id,
                                         out command
                                         ));

            command.Text         = _package.ResolveStringResource(button.Text);
            command.ToolTip      = _package.ResolveStringResource(button.ToolTip);
            command.DisplayStyle = Enum <NiCommandDisplayStyle> .Parse(button.Style.ToString());

            command.ShortcutKeys = keys.Length > 0 ? keys[0] : 0;
            ((NiCommandBarButton)command).Bitmap = ResolveBitmapResource(button.Image);

            return(command);
        }
Exemplo n.º 2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.KeyData == Backspace || !ShortcutKeysUtil.IsValid(e.KeyData))
            {
                Keys = 0;
            }
            else
            {
                Keys = e.KeyData;
            }
        }
Exemplo n.º 3
0
            private Dictionary <Guid, Keys[]> LoadFromRegistry()
            {
                var mappings = new Dictionary <Guid, Keys[]>();
                var keys     = new List <Keys>();

                using (var key = OpenRegistryKey(false))
                {
                    if (key != null)
                    {
                        foreach (string name in key.GetValueNames())
                        {
                            Guid guid;
                            if (Guid.TryParse(name, out guid))
                            {
                                keys.Clear();

                                string value = (string)key.GetValue(name);

                                if (!String.IsNullOrEmpty(value))
                                {
                                    foreach (string item in value.Split('|'))
                                    {
                                        var itemKeys = ShortcutKeysUtil.Parse(item);

                                        foreach (var itemKey in itemKeys)
                                        {
                                            if (!ShortcutKeysUtil.IsValid(itemKey))
                                            {
                                                Log.WarnFormat("Skipping illegal shortcut key '{0}' for button '{1}'", itemKey, guid);
                                            }
                                            else
                                            {
                                                keys.Add(itemKey);
                                            }
                                        }
                                    }
                                }

                                mappings.Add(guid, keys.ToArray());
                            }
                        }
                    }
                }

                return(mappings);
            }
Exemplo n.º 4
0
                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));
                    }
                }
Exemplo n.º 5
0
 protected override bool IsInputKey(Keys keyData)
 {
     return(base.IsInputKey(keyData) || ShortcutKeysUtil.IsValid(keyData) || keyData == Backspace);
 }