Esempio n. 1
0
        private static bool GoToDefinition()
        {
            var    gateway      = PluginBase.GetGatewayFactory().Invoke();
            string selectedWord = gateway.GetCurrentWord();

            if (!string.IsNullOrEmpty(selectedWord))
            {
                JumpLocation jumpLocation = SearchEngine.FindDefinitionLocation(SearchContextFactory.Invoke(selectedWord, gateway));

                if (jumpLocation != null)
                {
                    JumpToLocation(jumpLocation);
                    NavigationHandler.UpdateHistory(jumpLocation, NavigateActionType.MOUSE_CLICK);
                    return(true);
                }
            }

            gateway.GrabFocus();

            if (_settings.Config.SoundEnabled)
            {
                System.Media.SystemSounds.Asterisk.Play();
            }

            return(false);
        }
Esempio n. 2
0
        private static void JumpToLocation(JumpLocation jumpLocation)
        {
            string file = jumpLocation.FilePath;
            int    line = jumpLocation.Line;

            Logger.Info($"Opening file '{file}'");

            var gateway = PluginBase.GetGatewayFactory().Invoke();

            gateway.OpenFile(file);

            if (_settings.Config.JumpToLineDelay > 0)
            {
                // задержка фиксит багу с выделением текста при переходе
                ThreadUtils.ExecuteDelayed(() => gateway.JumpToLine(line), _settings.Config.JumpToLineDelay);
            }
            else
            {
                gateway.JumpToLine(line);
            }
        }
 public void Reload(JumpLocation currentLocation)
 {
     _historyPosition = 0;
     _navigationHistory.Clear();
     _prevLocation = currentLocation;
 }
        public void UpdateHistory(JumpLocation newLocation, NavigateActionType actionType)
        {
            if (IsNavigationDisabled())
            {
                return;
            }
            if (newLocation.Line == _prevLocation.Line)
            {
                return;
            }

            var historySize = _navigationHistory.Count;

            if (_historyPosition > historySize)
            {
                Logger.Error($"invalid navigation history position={_historyPosition}, because history size={historySize}, navigation history will reset");
                Reload(newLocation);
                return;
            }

            switch (actionType)
            {
            case NavigateActionType.GO_FORWARD:
                if (_historyPosition == historySize)
                {
                    return;
                }
                _historyPosition++;
                _prevLocation = newLocation;
                break;

            case NavigateActionType.GO_BACKWARD:
                if (_historyPosition == 0)
                {
                    return;
                }

                if (_historyPosition == historySize)
                {
                    _navigationHistory.Add(_prevLocation);
                }

                _historyPosition--;
                _prevLocation = newLocation;
                break;

            case NavigateActionType.MOUSE_CLICK:

                // мы находимся не в самом конце истории. поэтому при изменении - вся остальная часть истории забывается
                if (_historyPosition < historySize)
                {
                    _navigationHistory.RemoveRange(_historyPosition, historySize - _historyPosition);
                }

                _navigationHistory.Add(_prevLocation);
                _historyPosition = _navigationHistory.Count;
                _prevLocation    = newLocation;

                break;

            case NavigateActionType.KEYBOARD_DOWN:
                _prevLocation = newLocation;
                break;
            }
        }
 public void Disable()
 {
     _prevLocation = null;
 }