Ejemplo n.º 1
0
        /// <summary>
        /// Invokes proper processing assigned to current action.
        /// </summary>
        public void Execute(object sender, EventArgs e)
        {
            CodeEditPoint editorEditPoint = parent.CurrentEditPoint;

            if (!editorEditPoint.IsRefactorValid)
            {
                return;
            }

            CodeEditSelection editorSelection = EditorHelper.GetSelectedVariables(editorEditPoint);

            if (editorSelection != null)
            {
                int  gotoLine;
                bool isRefactored;
                try
                {
                    // open the undo-context to combine all the modifications of the source code into one:
                    parent.DTE.UndoContext.Open(SharedStrings.UndoContext_ExtractPropertyRefactor, true);

                    isRefactored = Refactor(editorSelection.AllVariables, editorSelection.DisabledVariables, editorSelection.ParentName, editorSelection.ParentLanguage, editorSelection.CodeMembers, editorSelection.GetEndPoint(vsCMPart.vsCMPartBody).CreateEditPoint(), out gotoLine);
                }
                finally
                {
                    // close the undo-context, so all the changes will be threated as one:
                    parent.DTE.UndoContext.Close();
                }

                // jump without selection to the insertion place:
                if (isRefactored && gotoLine >= 0)
                {
                    editorEditPoint.GotoLine(gotoLine, 1);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invokes proper processing assigned to current action.
        /// </summary>
        public void Execute(object sender, EventArgs e)
        {
            CodeEditPoint editorEditPoint = parent.CurrentEditPoint;
            bool          isRefactored;

            if (!editorEditPoint.IsRefactorValid)
            {
                return;
            }

            // get selected variables:
            CodeEditSelection editorSelection = EditorHelper.GetSelectedVariables(editorEditPoint);

            if (editorSelection != null && (editorSelection.Variables != null || editorSelection.Properties != null))
            {
                IList <CodeVariable> vars = editorSelection.AllVariables;
                EditPoint            ep;

                if (vars != null)
                {
                    ep = vars[vars.Count - 1].GetEndPoint(vsCMPart.vsCMPartWholeWithAttributes).CreateEditPoint();
                }
                else
                if (editorSelection.Variables != null)
                {
                    ep = editorSelection.Variables[editorSelection.Variables.Count - 1].GetEndPoint(vsCMPart.vsCMPartWholeWithAttributes).CreateEditPoint();
                }
                else
                {
                    ep = editorSelection.Properties[editorSelection.Properties.Count - 1].GetEndPoint(vsCMPart.vsCMPartWholeWithAttributes).CreateEditPoint();
                }

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

                    // move cursor to the end of the line, not to interrupt any comments:
                    ep.EndOfLine();

                    // update the source code:
                    isRefactored = Refactor(CreateCodeNamedElements(editorSelection.AllVariables, editorSelection.DisabledVariables, editorSelection.AllProperties, editorSelection.DisabledProperties),
                                            editorSelection.ParentName, editorSelection.ParentLanguage, editorSelection.CodeMembers, ep, out gotoLine);
                }
                finally
                {
                    // close the undo-context, so all the changes will be threated as one:
                    parent.DTE.UndoContext.Close();
                }

                // jump without selection to the insertion place:
                if (isRefactored && gotoLine >= 0)
                {
                    editorEditPoint.GotoLine(gotoLine, 1);
                }
            }
        }