示例#1
0
        int IVsDropdownBarClient.OnItemChosen(int iCombo, int iIndex)
        {
            int selection;

            // If we chose an item for the type drop-down, then refresh the member dropdown
            if (iCombo == (int)NavigationBarDropdownKind.Type)
            {
                _dropdownBar.GetCurrentSelection((int)NavigationBarDropdownKind.Member, out selection);
                _dropdownBar.RefreshCombo((int)NavigationBarDropdownKind.Member, selection);
            }

            _dropdownBar.GetCurrentSelection(iCombo, out selection);

            if (selection >= 0)
            {
                var item         = GetItem(iCombo, selection);
                var itemSelected = ItemSelected;
                if (itemSelected != null)
                {
                    itemSelected(this, new NavigationBarItemSelectedEventArgs(item));
                }
            }

            return(VSConstants.S_OK);
        }
        /// <summary>
        /// Called when the user chooses an item from the drop down
        /// </summary>
        public int OnItemChosen(int comboBoxId, int index)
        {
            if (_dropDownBar == null)
            {
                return(VSConstants.E_UNEXPECTED);
            }

            var entries = GetEntries(comboBoxId);

            if (entries != null && index < entries.Count)
            {
                SetSelectedIndex(comboBoxId, index);
                _dropDownBar.RefreshCombo(comboBoxId, index);

                var functionEntryInfo = entries[index] as FunctionDefinitionEntryInfo;
                if (functionEntryInfo != null)
                {
                    NavigationExtensions.NavigateToFunctionDefinition(_textView, functionEntryInfo.FunctionDefinition);
                }
                else
                {
                    NavigationExtensions.NavigateToLocation(_textView, entries[index].Start);
                }
            }

            return(VSConstants.S_OK);
        }
示例#3
0
        /// <summary>
        /// Called when the user selects an item from the drop down.  We will
        /// update the caret to beat the correct location, move the view port
        /// so that the code is centered on the screen, and we may refresh
        /// the combo box so that the 1st item is no longer grayed out if
        /// the user was originally outside of valid selection.
        /// </summary>
        public int OnItemChosen(int iCombo, int iIndex)
        {
            switch (iCombo)
            {
            case TopLevelComboBoxId:
                _dropDownBar.RefreshCombo(NestedComboBoxId, 0);
                var topLevel = _topLevelEntries;
                if (iIndex < topLevel.Count)
                {
                    int oldIndex = _curTopLevelIndex;
                    _curTopLevelIndex = iIndex;
                    if (oldIndex == -1)
                    {
                        _dropDownBar.RefreshCombo(TopLevelComboBoxId, iIndex);
                    }
                    CenterAndFocus(topLevel[iIndex].Start.Index);
                }
                break;

            case NestedComboBoxId:
                var nested = _nestedEntries;
                if (iIndex < nested.Count)
                {
                    int oldIndex = _curNestedIndex;
                    _curNestedIndex = iIndex;
                    if (oldIndex == -1)
                    {
                        _dropDownBar.RefreshCombo(NestedComboBoxId, iIndex);
                    }
                    CenterAndFocus(nested[iIndex].Start.Index);
                }
                break;
            }
            return(VSConstants.S_OK);
        }
示例#4
0
 public int SetDropdownBar(IVsDropdownBar dropdownBar)
 {
     _dropDownBar = dropdownBar;
     ThreadHelper.JoinableTaskFactory.Run(async delegate
     {
         await RefreshDropDownAsync(needsUI: false);
     });
     if (_dropDownBar != null)
     {
         _dropDownBar.RefreshCombo(0, 1);
         _dropDownBar.RefreshCombo(1, 1);
     }
     return(VSConstants.S_OK);
 }
        private void UpdateSelectedNavigationTargetsImpl()
        {
            var currentPosition = _currentTextView.Caret.Position.BufferPosition;

            for (int i = 0; i < _navigationControls.Length; i++)
            {
                var control = _navigationControls[i];

                control.Item2.RemoveAll(target => !ComboBoxFilter(control.Item1, control.Item2, target));

                if (control.Item2.Count == 0)
                {
                    continue;
                }

                var oldSelectedItem = _selectedItem[i];

                var positionOrderedItems = control.Item2.OrderBy(j => j.Span.Start).ToArray();
                var newSelectedItem      =
                    positionOrderedItems
                    .LastOrDefault(j => MapTo(j.Span, currentPosition.Snapshot, SpanTrackingMode.EdgeInclusive).Contains(currentPosition));

                if (newSelectedItem == null)
                {
                    // select the first item starting after the current position
                    newSelectedItem =
                        positionOrderedItems.FirstOrDefault(j => MapTo(j.Span, currentPosition.Snapshot, SpanTrackingMode.EdgeInclusive).Start > currentPosition);
                }

                if (newSelectedItem == null)
                {
                    // select the last item ending before the current position
                    newSelectedItem =
                        positionOrderedItems.LastOrDefault(j => MapTo(j.Span, currentPosition.Snapshot, SpanTrackingMode.EdgeInclusive).End < currentPosition);
                }

                if (newSelectedItem == null)
                {
                    // select the first item
                    newSelectedItem = control.Item2[0];
                }

                bool wasUpdating = Updating;
                try
                {
                    Updating = true;
                    int newIndex = control.Item2.IndexOf(newSelectedItem);
                    _selectedItem[i] = newSelectedItem;
                    if (_dropdownBar != null)
                    {
                        _dropdownBar.RefreshCombo(i, newIndex);
                    }
                }
                finally
                {
                    Updating = wasUpdating;
                }
            }
        }
示例#6
0
        /// <summary>
        /// Wired to parser event for when the parser has completed parsing a new tree and we need
        /// to update the navigation bar with the new data.
        /// </summary>
        private void ParserOnNewParseTree(object sender, EventArgs e)
        {
            if (_dropDownBar != null)
            {
                Action callback = () => {
                    BuildModel();
                    int position = _textView.Caret.Position.BufferPosition.Position;

                    ModuleEntry newModule = _entries.LocateModule(position);
                    MethodEntry newMethod = newModule.LocateMethod(position);
                    _dropDownBar.RefreshCombo(ModuleComboBoxId, newModule.Index);
                    _dropDownBar.RefreshCombo(MethodComboBoxId, newMethod != null ? newMethod.Index : -1);
                };

                _dispatcher.BeginInvoke(callback, DispatcherPriority.Background);
            }
        }
示例#7
0
        void UpdateProjectItems()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            _projectItems = NavigationBarProjectItemBuilder.Build(ParserService.SyntaxTreeAndSnapshot);

            _dropdownBar?.RefreshCombo(ProjectComboIndex, 0);
        }
示例#8
0
        /// <summary>
        /// Этот метод заменяет SynchronizeDropdowns который скрыт внутри TypeAndMemberDropdownBars.
        /// Замена требуется, так как в TypeAndMemberDropdownBars захардкожено обращение
        /// к DropDownMember в котором реализована кривые (рекурсивные) оператора сравнения
        /// приводящие к переполнению стека при попытке проверить объект этого класса на null.
        /// </summary>
        public void SynchronizeDropdownsRsdn(IVsTextView textView, int line, int col)
        {
            if (_dropDownBar == null)
            {
                return;
            }

            _textView = textView;

            line = line.ToNccLineCoord();
            col  = col.ToNccColCoord();

            if (UpdateDropDownTypes() | SyncSelectedType(line, col) | SyncSelectedMember(line, col))
            {
                ErrorHandler.ThrowOnFailure(_dropDownBar.RefreshCombo(DropClasses, _lastSelectedType < 0 ? -1 : _lastSelectedType));
                ErrorHandler.ThrowOnFailure(_dropDownBar.RefreshCombo(DropMethods, _lastSelectedMember < 0 ? -1 : _lastSelectedMember));
            }
        }
示例#9
0
        void RefreshComboOnUiThread(int combo, int selectedItem)
        {
            Action refreshCombo = () =>
            {
                dropdown.RefreshCombo(combo, selectedItem);
            };

            dispatcher.BeginInvoke(refreshCombo, DispatcherPriority.Background);
        }
示例#10
0
        /// <summary>
        /// Called when the user selects an item from the drop down.  We will
        /// update the caret to beat the correct location, move the view port
        /// so that the code is centered on the screen, and we may refresh
        /// the combo box so that the 1st item is no longer grayed out if
        /// the user was originally outside of valid selection.
        /// </summary>
        public int OnItemChosen(int iCombo, int iIndex)
        {
            if (_dropDownBar == null)
            {
                return(VSConstants.E_UNEXPECTED);
            }

            int oldIndex      = _curSelection[iCombo];
            var newNavigation = GetNewNavigation(iCombo, iIndex);

            _curSelection[iCombo] = iIndex;

            if (newNavigation != null)
            {
                if (oldIndex == -1)
                {
                    _dropDownBar.RefreshCombo(iCombo, iIndex);
                }
                CenterAndFocus(newNavigation.Span.Start);
            }

            return(VSConstants.S_OK);
        }
示例#11
0
        int IVsDropdownBarClient.OnItemChosen(int iCombo, int iIndex)
        {
            if (_dropdownBar == null)
            {
                return(VSConstants.E_UNEXPECTED);
            }

            var item = GetActiveSelectionItem(iCombo, iIndex);

            if (item?.NavigationPoint >= 0)
            {
                _dropdownBar.RefreshCombo(iCombo, iIndex);

                GdLanguagePackage.NavigateToLocation(GetCurrentView(), item.NavigationPoint);
            }
            else
            {
                // ReSharper disable once SuspiciousTypeConversion.Global
                (GetCurrentView() as Control)?.Focus();
            }

            return(VSConstants.S_OK);
        }
示例#12
0
        private void UpdateSelectedNavigationTargetsImpl()
        {
            if (!_navigationItems.Any())
            {
                return;
            }

            var currentPosition = _currentTextView.Caret.Position.BufferPosition;

            // Set selected type.
            _selectedType = 0;
            var typeIndex = 0;

            foreach (var navigationItem in _navigationItems)
            {
                if (navigationItem.Span.Snapshot == currentPosition.Snapshot && navigationItem.Span.Contains(currentPosition))
                {
                    _selectedType = typeIndex;
                }
                ++typeIndex;
            }

            var navigationMembers = _navigationItems[_selectedType].Children;

            foreach (var navigationMember in navigationMembers)
            {
                navigationMember.IsGray = false;
            }

            // Set selected member - if caret is not on a member, then fallback
            // to the next member, but grey it out.
            var selectedMember = -1;

            for (var i = 0; i < navigationMembers.Count; i++)
            {
                var navigationItem = navigationMembers[i];
                if (navigationItem.Span.Snapshot != currentPosition.Snapshot)
                {
                    continue;
                }
                if (currentPosition < navigationMembers[i].Span.Start)
                {
                    selectedMember = i;
                    navigationMembers[i].IsGray = true;
                    break;
                }
                if (navigationItem.Span.Contains(currentPosition))
                {
                    selectedMember = i;
                    break;
                }
            }
            if (selectedMember == -1 && navigationMembers.Count > 0)
            {
                selectedMember = navigationMembers.Count - 1;
                navigationMembers[selectedMember].IsGray = true;
            }
            if (selectedMember == -1)
            {
                selectedMember = 0;
            }

            bool wasUpdating = Updating;

            try
            {
                Updating = true;
                if (_dropdownBar != null)
                {
                    _dropdownBar.RefreshCombo(0, _selectedType);
                    _dropdownBar.RefreshCombo(1, selectedMember);
                }
            }
            finally
            {
                Updating = wasUpdating;
            }
        }