示例#1
0
        /// <summary>
        /// This constructor takes a view and will use CompoundViewAction to make the updates
        /// and it will update the current selection accordingly.
        /// <param name="source">The buffer to operate on</param>
        /// <param name="view">The text view to use for CompoundViewAction and whose selection you want updated</param>
        /// <param name="merge">Whether to attempt to merge edits</param>
        /// <param name="description">Name used in compound action</param>
        /// </summary>
        internal EditArray(ISource source, IVsTextView view, bool merge, string description)
        {
            this.source      = source;
            this.editList    = new ArrayList();
            this.merge       = merge;
            this.description = description;

            if (view != null)
            {
                TextSpan[] pSpan = new TextSpan[1];
                view.GetSelectionSpan(pSpan);
                this.selection = pSpan[0];
                this.view      = view;

                this.cva = new CompoundViewAction(this.view, description);
                this.cva.FlushEditActions(); // make sure we see a consistent coordinate system.
            }
            else
            {
                this.ca = new CompoundAction(this.source, description);
                this.ca.FlushEditActions();
            }

            // Sanity check - make sure others are not modifying the buffer while the
            // caller is preparing the big edit operation.
            this.changeCount = source.ChangeCount;
        }
        /// <summary>
        /// This method is called when it is time to save the designer values to the
        /// underlying buffer.
        /// </summary>
        /// <param name="undoEntry"></param>
        void SaveModelToXmlModel(string undoEntry)
        {
            LanguageService langsvc = GetXmlLanguageService();

            try
            {
                //We can't edit this file (perhaps the user cancelled a SCC prompt, etc...)
                if (!CanEditFile())
                {
                    DesignerDirty = false;
                    BufferDirty   = true;
                    throw new Exception();
                }

                //PopulateModelFromReferencesBindingList();
                //PopulateModelFromContentBindingList();

                XmlSerializer serializer = new XmlSerializer(typeof(VSTemplate));
                XDocument     documentFromDesignerState = new XDocument();
                using (XmlWriter w = documentFromDesignerState.CreateWriter())
                {
                    serializer.Serialize(w, _vstemplateModel);
                }

                _synchronizing = true;
                XDocument document = GetParseTree();
                Source    src      = GetSource();
                if (src == null || langsvc == null)
                {
                    return;
                }

                langsvc.IsParsing = true; // lock out the background parse thread.

                // Wrap the buffer sync and the formatting in one undo unit.
                using (CompoundAction ca = new CompoundAction(src, Resources.SynchronizeBuffer))
                {
                    using (XmlEditingScope scope = _xmlStore.BeginEditingScope(Resources.SynchronizeBuffer, this))
                    {
                        //Replace the existing XDocument with the new one we just generated.
                        document.Root.ReplaceWith(documentFromDesignerState.Root);
                        scope.Complete();
                    }
                    ca.FlushEditActions();
                    FormatBuffer(src);
                }
                DesignerDirty = false;
            }
            catch (Exception)
            {
                // if the synchronization fails then we'll just try again in a second.
                _dirtyTime = Environment.TickCount;
            }
            finally
            {
                langsvc.IsParsing = false;
                _synchronizing    = false;
            }
        }
示例#3
0
 public override void ReformatSpan(EditArray mgr, TextSpan span)
 {
     string description = "Reformat code";
     CompoundAction ca = new CompoundAction(this, description);
     using (ca)
     {
         ca.FlushEditActions();      // Flush any pending edits
         DoFormatting(mgr, span);    // Format the span
     }
 }
示例#4
0
 private void Dispose(bool disposing)
 {
     if (cva != null)
     {
         cva.Close();
         cva = null;
     }
     if (ca != null)
     {
         ca.Close();
         ca = null;
     }
     view   = null;
     source = null;
 }
示例#5
0
        void ISource.Save(Action saveAction)
        {
            // Wrap the buffer sync and the formatting in one undo unit.
            using (var ca = new CompoundAction(source, "Synchronize buffer"))
            {
                saveAction();

                /*using (var scope = xmlStore.BeginEditingScope(Resources.SynchronizeBuffer, this))
                 * {
                 *  //Replace the existing XDocument with the new one we just generated.
                 *  document.Root.ReplaceWith(documentFromDesignerState.Root);
                 *  scope.Complete();
                 * }*/
                ca.FlushEditActions();
                FormatBuffer(source);
            }
        }
示例#6
0
        internal void ApplyEdits()
        {
            try {
                if (this.editList.Count == 0)
                {
                    return;
                }

                if (this.changeCount != this.source.ChangeCount)
                {
                    throw new InvalidOperationException(SR.GetString(SR.BufferChanged));
                }

                if (this.view != null)
                {
                    using (cva) {
                        Apply();
                        cva.FlushEditActions(); // make sure text view has same coordinates
                    }
                    this.cva = null;
                    // Update selection.
                    this.view.SetSelection(this.selection.iStartLine, this.selection.iStartIndex, this.selection.iEndLine, this.selection.iEndIndex);
                    this.view.EnsureSpanVisible(this.selection);
                }
                else
                {
                    using (this.ca) {
                        Apply();
                    }
                    this.ca = null;
                }
            } finally {
                // If compound actions are not null then we need to abort them.
                Dispose();
            }
        }