Exemplo n.º 1
0
 public void AddHotkey(ModeHotkey modeHotkey, bool hideWarningMessage = false)
 {
     Helper.RequireTrue(IsComposeMode || modeHotkey.Chord.Length == 1 && modeHotkey.Chord.First().Modifiers == Modifiers.None);
     foreach (var chord in _hotkeys.Select(z => z.Chord))
     {
         var small = modeHotkey.Chord;
         var big   = chord;
         if (small.Length > big.Length)
         {
             (small, big) = (big, small);
         }
         if (big.HasPrefix(small))
         {
             if (!hideWarningMessage)
             {
                 Env.Notifier.Warning($"Mode '{Name}' has ambiguous chord '{small}'.");
                 _hasAmbiguousChord = true;
             }
             break;
         }
     }
     _hotkeys.Add(modeHotkey);
 }
Exemplo n.º 2
0
        private void HandleComposeMode(ComboArgs e)
        {
            if (e.Combo.Input.IsMouseInput())
            {
                return;
            }

            // Capture any non-modifier key. Modifier keys should not be captured as that would prevent the key from modifying the virtual
            // modifier state.
            if (!e.Combo.Input.IsModifierKey())
            {
                e.Capture = true;
            }

            // Check for hit, update hotkeys and input count.
            ModeHotkey hit            = null;
            var        oldModeHotkeys = _modeHotkeys;
            var        oldCount       = _inputCount;

            if (!e.Combo.Input.IsModifierKey())
            {
                var newModeHotkeys = new List <ModeHotkey>();
                foreach (var modeHotkey in _modeHotkeys)
                {
                    if (modeHotkey.Chord.TestPosition(_inputCount, e.Combo))
                    {
                        if (modeHotkey.Chord.Length - 1 == _inputCount)
                        {
                            if (hit == null || modeHotkey.Chord.IsMoreSpecificThan(hit.Chord))
                            {
                                hit = modeHotkey;
                            }
                        }
                        else
                        {
                            newModeHotkeys.Add(modeHotkey);
                        }
                    }
                }
                _inputCount++;
                _modeHotkeys = newModeHotkeys;
            }
            else if (_inputCount == 0)
            {
                hit = _modeHotkeys.FirstOrDefault(z => z.Chord.Length == 1 && z.Chord.TestPosition(0, e.Combo));
            }

            if (hit == null)
            {
                if (e.Combo == Env.Config.ClearModeCombo)
                {
                    ClearInput();
                }
                else if (e.Combo == Env.Config.ShowModeCombo)
                {
                    _modeHotkeys = oldModeHotkeys;
                    _inputCount  = oldCount;
                    ToggleViewerVisibility();
                }
                else if (e.Combo == Env.Config.PrintModeCombo)
                {
                    _modeHotkeys = oldModeHotkeys;
                    _inputCount  = oldCount;
                    Helper.ShowSelectableText(GetDisplayText());
                    LeaveMode();
                }
                else if (Env.Config.ClearModeCombos.Contains(e.Combo))
                {
                    LeaveMode();
                }
            }
            else
            {
                LeaveMode();
                try
                {
                    hit.Action(e.Combo);
                }
                catch (Exception ex) when(!Helper.IsFatalException(ex))
                {
                    Env.Notifier.WriteError(ex);
                }
            }
            _modeViewer.UpdateText(GetDisplayText());
        }