示例#1
0
        /// <summary>
        /// Invokes proper processing assigned to current action.
        /// </summary>
        public void Execute(object sender, EventArgs e)
        {
            CodeEditPoint editorEditPoint = parent.CurrentEditPoint;
            bool          isSelection     = editorEditPoint.IsSelected;
            string        newName         = nameGenerator.NextName();

            try
            {
                // open the undo-context to combine all the modifications of the source code into one:
                parent.DTE.UndoContext.Open(SharedStrings.UndoContext_ExtractPropertyRefactor, true);

                if (isSelection)
                {
                    // paste into selected text:
                    editorEditPoint.Selection.Insert(newName, (int)vsInsertFlags.vsInsertFlagsContainNewText);
                }
                else
                {
                    // just insert text:
                    editorEditPoint.EditPoint.Insert(newName);
                }
            }
            finally
            {
                // close the undo-context, so all the changes will be threated as one:
                parent.DTE.UndoContext.Close();
            }
        }