public bool MoveNext()
 {
     while (true)
     {
         _Index++;
         if (_Index >= _MultiSelect.Selections.Count)
         {
             _Current = null;
             return false;
         }
         else
         {
             _Current = _MultiSelect.Selections[_Index];
             if (_ElementType == LanguageElementType.Unknown && _Current.Generated == false)		// Use LanguageElementType.Unknown to bring in everything else.
                 return true;
             if (_Current.ElementType == _ElementType)
                 return true;
             if (_ElementType == LanguageElementType.Variable && _Current.ElementType == LanguageElementType.InitializedVariable)
                 return true;
             if (_ElementType == LanguageElementType.InitializedVariable && _Current.ElementType == LanguageElementType.Variable)
                 return true;
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Adds the specified PartialSelection to this MultiSelect instance, highlighting the selection onscreen, and clears the Visual Studio selection.
 /// </summary>
 public void AddSelection(TextView textView, PartialSelection selection)
 {
     selection.AddHighlighter(textView);
     Selections.Add(selection);
     textView.Caret.MoveTo(selection.CaretPosition);
 }
Пример #3
0
        /// <summary>
        /// Adds the selection in the specified TextView (or the active member if there is no selection) to this MultiSelect instance.
        /// </summary>
        public void AddSelection(TextView textView)
        {
            if (textView == null)
                return;
            TextViewSelection textViewSelection = textView.Selection;
            if (textViewSelection == null)
                return;

            PartialSelection newPartialSelection = new PartialSelection(Selections.Count);

            // TODO: Refactor this so we find the selected member in one method (currently we have memberSelected, nodeAtTopOfSelection and selectionScanner performing similar functionality).
            SourcePoint finalCaretPosition = SourcePoint.Empty;
            LanguageElement memberSelected = null;
            if (!textViewSelection.Exists)
            {
                LanguageElement activeMember = CodeRush.Source.ActiveMember;
                if (activeMember != null)
                {
                    SourceRange declareRange = new SourceRange(activeMember.Range.Top, activeMember.NameRange.Bottom);
                    if (declareRange.Contains(textView.Caret.SourcePoint))
                    {
                        SourceRange fullBlockCutRange = activeMember.GetFullBlockCutRange();
                        textView.Selection.Set(fullBlockCutRange);
                        memberSelected = activeMember;
                    }
                    else
                        CodeRush.Command.Execute("SelectionExpand");
                }
                else
                    CodeRush.Command.Execute("SelectionExpand");
                if (!textViewSelection.Exists)
                    return;
            }

            SourceRange selectionRange = new SourceRange(textViewSelection.Range.Top, textViewSelection.Range.Bottom);

            for (int i = Selections.Count - 1; i >= 0; i--)
            {
                PartialSelection compareSelection = Selections[i];
                if (selectionRange.Overlaps(compareSelection.Range))
                {
                    selectionRange = SourceRange.Union(compareSelection.Range, selectionRange);
                    compareSelection.RemoveHighlighter();
                    Selections.RemoveAt(i);
                }
            }
            if (memberSelected != null)
            {
                newPartialSelection.ElementName = memberSelected.Name;
                newPartialSelection.ElementType = memberSelected.ElementType;
                finalCaretPosition = memberSelected.Range.Top;
            }
            else
            {
                LanguageElement nodeAtTopOfSelection = CodeRush.Source.GetNodeAt(selectionRange.Top);
                LanguageElement nodeBeforeEndOfSelection = CodeRush.Source.GetNodeBefore(selectionRange.Bottom);
                if (nodeAtTopOfSelection == nodeBeforeEndOfSelection || nodeAtTopOfSelection.Parents(nodeBeforeEndOfSelection) && selectionRange.Contains(nodeAtTopOfSelection.Range))
                {
                    newPartialSelection.ElementName = nodeAtTopOfSelection.Name;
                    newPartialSelection.ElementType = nodeAtTopOfSelection.ElementType;
                }
                else
                {
                    SelectionScanner selectionScanner = new SelectionScanner();
                    selectionScanner.Scan();
                    if (selectionScanner.ElementsFound == 1)
                        newPartialSelection.ElementName = selectionScanner.ElementName;
                    newPartialSelection.ElementType = selectionScanner.ElementType;
                }
            }
            newPartialSelection.Range = selectionRange;
            SourceRange highlightRange;
            if (memberSelected != null)
            {
                LanguageElement startNode;
                LanguageElement endNode;
                memberSelected.GetFullBlockNodes(out startNode, out endNode);
                highlightRange = new SourceRange(startNode.Range.Top, endNode.Range.Bottom);
                if (Selections.Count == 0)
                    ContainsOnlyMembers = true;
            }
            else
            {
                highlightRange = selectionRange;
                ContainsOnlyMembers = false;
            }
            newPartialSelection.HighlightRange = highlightRange;
            newPartialSelection.Text = textView.TextDocument.GetText(selectionRange);

            if (finalCaretPosition == SourcePoint.Empty)
                finalCaretPosition = textViewSelection.Range.Top;
            newPartialSelection.CaretPosition = finalCaretPosition;
            AddSelection(textView, newPartialSelection);
        }
 public void Reset()
 {
     _Current = null;
     _Index = -1;
 }