示例#1
0
        private CocoJumperKeyboardActionResult PerformChoosing(char?key, KeyEventType eventType)
        {
            switch (eventType)
            {
            case KeyEventType.Backspace when _isSingleSearch:
                _state        = CocoJumperState.Searching;
                _searchString = string.Empty;
                _searchResults.Clear();
                RaiseRenderSearcherEvent();
                break;

            case KeyEventType.Backspace when !string.IsNullOrEmpty(_choosingString):
                _choosingString = RemoveLastChar(_choosingString);
                break;

            case KeyEventType.KeyPress when key.HasValue:
                char keyValue = GeyKeyValue(key);
                if (_searchResults
                    .Any(x => x.Key.ToLower().StartsWith(_choosingString + keyValue)))
                {
                    _choosingString += keyValue;
                }
                break;

            case KeyEventType.KeyPress:
                ThrowKeyPressWithNullKeyException();
                break;
            }

            SearchResult isFinished =
                _searchResults
                .SingleOrDefault(x => x.Key.ToLower() == _choosingString);

            if (isFinished != null)
            {
                if (_isHighlight)
                {
                    int caretPosition = _viewProvider.GetCaretPosition();
                    int toPosition    = caretPosition < isFinished.Position
                        ? isFinished.Position + 1
                        : isFinished.Position;
                    _viewProvider.MoveCaretTo(toPosition);
                    _viewProvider.SelectFromTo(caretPosition, toPosition);
                }
                else
                {
                    _viewProvider.MoveCaretTo(_jumpAfterChosenElement ? isFinished.Position + isFinished.Length : isFinished.Position);
                }
                _state = CocoJumperState.Inactive;
                RaiseExitEvent();

                return(CocoJumperKeyboardActionResult.Finished);
            }
            RaiseRenderSearcherEvent();
            RaiseSearchResultChangedEventWithFilter();
            return(CocoJumperKeyboardActionResult.Ok);
        }
示例#2
0
        private CocoJumperKeyboardActionResult PerformSearching(char?key, KeyEventType eventType)
        {
            if (!_isWordSearch)
            {
                switch (eventType)
                {
                case KeyEventType.Backspace when !string.IsNullOrEmpty(_searchString):
                    _searchString = RemoveLastChar(_searchString);
                    break;

                case KeyEventType.KeyPress when key.HasValue:
                    _searchString += GeyKeyValue(key);
                    break;

                case KeyEventType.KeyPress:
                    ThrowKeyPressWithNullKeyException();
                    break;

                case KeyEventType.ConfirmSearching when _searchResults.Count == 0:
                    RaiseRenderSearcherEvent();

                    return(CocoJumperKeyboardActionResult.Ok);

                case KeyEventType.ConfirmSearching:
                    _state = CocoJumperState.Choosing;

                    RaiseSearchResultChangedEvent();
                    RaiseRenderSearcherEvent();

                    return(CocoJumperKeyboardActionResult.Ok);
                }
            }

            SearchCurrentView();

            if (_isWordSearch ||
                _isSingleSearch &&
                !string.IsNullOrEmpty(_searchString) && _searchResults.Count != 0)
            {
                _state = CocoJumperState.Choosing;
            }

            RaiseSearchResultChangedEvent();
            RaiseRenderSearcherEvent();
            return(CocoJumperKeyboardActionResult.Ok);
        }
示例#3
0
        public void ActivateSearching(bool isSingle, bool isHighlight, bool isWord)
        {
            if (_state != CocoJumperState.Inactive)
            {
                throw new InvalidStateException($"{nameof(ActivateSearching)} in {nameof(CocoJumperLogic)}, state is in wrong state {_state}");
            }

            _autoExitDispatcherTimer.Stop();
            _autoExitDispatcherTimer.Start();
            _state          = CocoJumperState.Searching;
            _searchString   = string.Empty;
            _choosingString = string.Empty;
            _isSingleSearch = isSingle;
            _isHighlight    = isHighlight;
            _isWordSearch   = isWord;
            _viewProvider.ClearSelection();
            RaiseRenderSearcherEvent();
        }
示例#4
0
 public CocoJumperLogic(IWpfViewProvider renderer, CocoJumperCommandPackage package)
 {
     _state       = CocoJumperState.Inactive;
     _searchLimit = package.LimitResults;
     _disableMultiSearchHighlight        = package.DisableHighlightForMultiSearch;
     _disableSingleSearchHighlight       = package.DisableHighlightForSingleSearch;
     _disableSingleSearchSelectHighlight = package.DisableHighlightForSingleHighlight;
     _jumpAfterChosenElement             = package.JumpAfterChosenElement;
     _timer = new DispatcherTimer {
         Interval = TimeSpan.FromMilliseconds(package.TimerInterval)
     };
     _autoExitDispatcherTimer = new DispatcherTimer {
         Interval = TimeSpan.FromMilliseconds(package.AutomaticallyExitInterval)
     };
     _autoExitDispatcherTimer.Tick += OnAutoExitTimerEvent;
     _timer.Tick   += OnTimerTick;
     _searchResults = new List <SearchResult>();
     _viewProvider  = renderer;
 }