/// <summary>
        /// Adds the selection in the specified TextView to this view's MultiSelect list.
        /// </summary>
        /// <param name="textView">The TextView containing the MultiSelect list to add to.</param>
        public void Add(TextView textView)
        {
            if (textView == null)
                return;
            MultiSelect multiSelect = Get(textView);
            if (multiSelect == null)
            {
                multiSelect = new MultiSelect();
                multiSelect.FileName = textView.FileNode.Name;
                multiSelect.Language = textView.TextDocument.Language;
                multiSelect.TypeName = CodeRush.Source.ActiveTypeName;
                Set(textView, multiSelect);
            }
            else if (multiSelect.TypeName != CodeRush.Source.ActiveTypeName)		// Inconsistent class names, so let's clear it out.
                multiSelect.TypeName = String.Empty;

            MultiSelect redoMultiSelect = GetRedo(textView);
            if (redoMultiSelect != null)
                redoMultiSelect.Selections.Clear();

            multiSelect.AddSelection(textView);
        }
 public MultiSelectEnumerator(MultiSelect multiSelect, LanguageElementType elementType)
 {
     _MultiSelect = multiSelect;
     _ElementType = elementType;
     Reset();
 }
        private void QueueAdd(TextDocument activeTextDocument, TypeDeclaration activeType, MultiSelect multiSelect, LanguageElementType elementType)
        {
            string codeToGenerate = GetCode(multiSelect, elementType);
            if (codeToGenerate == String.Empty)
                return;

            // TODO: Change RelativeLocation.After, DefaultLocation.Bottom parameters to instead reference fields populated from the MultiSelect options.
            SourcePoint insertionPoint = GetInsertionPoint(activeType, elementType, RelativeLocation.After, DefaultLocation.Bottom);
            activeTextDocument.QueueInsert(insertionPoint, codeToGenerate);
        }
        private string GetCode(MultiSelect multiSelect, LanguageElementType elementType)
        {
            string result = String.Empty;

            MultiSelectEnumerator allElements = new MultiSelectEnumerator(multiSelect, elementType);
            while (allElements.MoveNext())
            {
                PartialSelection partialSelection = allElements.Current as PartialSelection;
                if (partialSelection != null)
                {
                    result += partialSelection.Text;
                    partialSelection.Generated = true; // Prevents this from coming in later when LanguageElementType.Unknown is passed in.
                }
            }
            return result;
        }
        public void Undo(TextView activeTextView)
        {
            MultiSelect multiSelect = Get(activeTextView);
            if (multiSelect == null || multiSelect.Selections.Count == 0)
                return;

            MultiSelect redoMultiSelect = GetRedo(activeTextView);
            if (redoMultiSelect == null)
            {
                redoMultiSelect = new MultiSelect();
                SetRedo(activeTextView, redoMultiSelect);
            }

            int lastIndex = multiSelect.Selections.Count - 1;
            PartialSelection selectionToRemove = multiSelect.GetSelectionAt(lastIndex);
            redoMultiSelect.Selections.Add(selectionToRemove);
            selectionToRemove.RemoveHighlighter();
            activeTextView.Caret.MoveTo(selectionToRemove.CaretPosition);
            multiSelect.RemoveSelectionAt(lastIndex);
        }
 public void SetRedo(TextView textView, MultiSelect redoMultiSelect)
 {
     textView.Storage.AttachObject(STR_RedoMultiSelectList, redoMultiSelect);
 }
 public void Set(TextView textView, MultiSelect multiSelect)
 {
     textView.Storage.AttachObject(STR_MultiSelectList, multiSelect);
 }
        public void Delete(MultiSelect multiSelect, string operation)
        {
            TextDocument textDocument = CodeRush.Documents.Get(multiSelect.FileName) as TextDocument;
            if (textDocument == null)
                return;
            foreach (PartialSelection selection in multiSelect.Selections)
                textDocument.QueueDelete(selection.Range);

            textDocument.ApplyQueuedEdits(operation);
        }
 /// <summary>
 /// Copies the specified MultiSelect object to the clipboard.
 /// </summary>
 /// <param name="multiSelect">The MultiSelect object to copy to the clipboard.</param>
 public void CopyToClipboard(MultiSelect multiSelect)
 {
     multiSelect.Sort();
     DataFormats.Format format = DataFormats.GetFormat(STR_ClipboardFormatName);
     IDataObject dataObject = new DataObject();
     dataObject.SetData(DataFormats.Text, multiSelect.ToText());
     dataObject.SetData(format.Name, multiSelect);
     Clipboard.SetDataObject(dataObject, true);
 }