コード例 #1
0
ファイル: ButtonControl.cs プロジェクト: vector-man/netide
            protected override void UpdateItem()
            {
                base.UpdateItem();

                Item.Checked = NiCommand.IsLatched;

                string toolTip = Item.ToolTipText;

                if (String.IsNullOrEmpty(toolTip))
                {
                    toolTip = Item.Text;
                }

                var shortcutKeys = NiCommand.ShortcutKeys;

                if (shortcutKeys != 0)
                {
                    if (toolTip.Length > 0)
                    {
                        toolTip += " ";
                    }
                    toolTip += "(" + ShortcutKeysUtil.ToDisplayString(shortcutKeys) + ")";
                }

                Item.ToolTipText = toolTip;
            }
コード例 #2
0
ファイル: MenuBuilder.cs プロジェクト: vector-man/netide
        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);
        }
コード例 #3
0
        private void _shortcut_KeysChanged(object sender, EventArgs e)
        {
            INiCommandBarButton[] buttons;
            ErrorUtil.ThrowOnFailure(_mappings.GetButtons(_shortcut.Keys, out buttons));

            _shortcutsConflicts.BeginUpdate();
            _shortcutsConflicts.Items.Clear();

            foreach (var button in buttons)
            {
                _shortcutsConflicts.Items.Add(String.Format(
                                                  "{0} ({1})",
                                                  GetButtonCode(button),
                                                  ShortcutKeysUtil.ToDisplayString(_shortcut.Keys)
                                                  ));
            }

            if (_shortcutsConflicts.Items.Count > 0)
            {
                _shortcutsConflicts.SelectedIndex = 0;
            }

            _shortcutsConflicts.EndUpdate();

            UpdateEnabled();
        }
コード例 #4
0
ファイル: KeysTextBox.cs プロジェクト: vector-man/netide
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.KeyData == Backspace || !ShortcutKeysUtil.IsValid(e.KeyData))
            {
                Keys = 0;
            }
            else
            {
                Keys = e.KeyData;
            }
        }
コード例 #5
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);
            }
コード例 #6
0
            private string CreateKeysValue(Keys[] keys)
            {
                var sb = new StringBuilder();

                if (keys != null)
                {
                    foreach (var key in keys)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append('|');
                        }

                        sb.Append(ShortcutKeysUtil.ToString(key));
                    }
                }

                return(sb.ToString());
            }
コード例 #7
0
 public override string ToString()
 {
     return(ShortcutKeysUtil.ToDisplayString(Keys));
 }
コード例 #8
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));
                    }
                }
コード例 #9
0
ファイル: KeysTextBox.cs プロジェクト: vector-man/netide
 protected override bool IsInputKey(Keys keyData)
 {
     return(base.IsInputKey(keyData) || ShortcutKeysUtil.IsValid(keyData) || keyData == Backspace);
 }