Esempio n. 1
0
        /// <summary>
        /// Gets the parent class or structure for given cursor location in file.
        /// </summary>
        public static bool GetParent(Data.CodeEditPoint editorEditPoint, out CodeClass codeClass, out CodeStruct codeStruct)
        {
            codeClass  = editorEditPoint.GetCurrentCodeElement <CodeClass>(vsCMElement.vsCMElementClass);
            codeStruct = editorEditPoint.GetCurrentCodeElement <CodeStruct>(vsCMElement.vsCMElementStruct);

            if (codeClass != null && codeStruct != null)
            {
                if (codeClass.GetStartPoint(vsCMPart.vsCMPartBody).Line < codeStruct.GetStartPoint(vsCMPart.vsCMPartBody).Line)
                {
                    codeClass = null;
                }
                else
                if (codeStruct.GetStartPoint(vsCMPart.vsCMPartBody).Line < codeClass.GetStartPoint(vsCMPart.vsCMPartBody).Line)
                {
                    codeStruct = null;
                }
            }

            return(codeClass != null || codeStruct != null);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the currently selected methods inside the code editor.
        /// </summary>
        public static Data.CodeEditSelection GetSelectedMethods(Data.CodeEditPoint editorEditPoint, bool oneMethodAllowed)
        {
            CodeClass  codeClass;
            CodeStruct codeStruct;
            bool       partialSelection = true;

            IList <CodeFunction> methods = null;

            // get the method and class at cursor in the IDE:
            CodeFunction codeMethod = editorEditPoint.GetCurrentCodeElement <CodeFunction>(vsCMElement.vsCMElementFunction);

            // get parent objects:
            GetParent(editorEditPoint, out codeClass, out codeStruct);


            // if there is only one method is selected:
            if (oneMethodAllowed && codeMethod != null && (codeMethod.StartPoint.Line <= editorEditPoint.Selection.TopPoint.Line && codeMethod.EndPoint.Line >= editorEditPoint.Selection.BottomPoint.Line))
            {
                methods = new List <CodeFunction>();
                methods.Add(codeMethod);

                codeClass  = codeMethod.Parent as CodeClass;
                codeStruct = codeMethod.Parent as CodeStruct;
            }
            else
            {
                // if text selected:
                if (editorEditPoint.Selection.TopLine != editorEditPoint.Selection.BottomLine)
                {
                    // get all the methods that are selected:
                    if (codeClass != null)
                    {
                        methods = GetList <CodeFunction>(codeClass.Members, vsCMElement.vsCMElementFunction, editorEditPoint.Selection.TopPoint.Line, editorEditPoint.Selection.BottomPoint.Line);
                        if (methods != null)
                        {
                            codeClass = methods[0].Parent as CodeClass;
                        }
                    }
                    else
                    if (codeStruct != null)
                    {
                        methods = GetList <CodeFunction>(codeStruct.Members, vsCMElement.vsCMElementFunction, editorEditPoint.Selection);
                        if (methods != null)
                        {
                            codeStruct = methods[0].Parent as CodeStruct;
                        }
                    }
                }
                else
                {
                    // otherwise the the whole class will be changed to properties:
                    if (codeClass != null)
                    {
                        methods          = GetList <CodeFunction>(codeClass.Members, vsCMElement.vsCMElementFunction);
                        partialSelection = false;
                    }
                    else
                    // or struct
                    if (codeStruct != null)
                    {
                        methods          = GetList <CodeFunction>(codeStruct.Members, vsCMElement.vsCMElementFunction);
                        partialSelection = false;
                    }
                }
            }

            // validate is something has been found:
            if (codeClass != null || codeStruct != null)
            {
                return(new Data.CodeEditSelection(codeClass, codeStruct, null, methods, null, partialSelection));
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the currently selected variables inside the code editor.
        /// </summary>
        public static Data.CodeEditSelection GetSelectedVariables(Data.CodeEditPoint editorEditPoint)
        {
            CodeClass  codeClass;
            CodeStruct codeStruct;
            bool       partialSelection = true;

            IList <CodeVariable> vars  = null;
            IList <CodeProperty> props = null;

            // get the variable and class at cursor in the IDE:
            CodeVariable codeVariable = editorEditPoint.GetCurrentCodeElement <CodeVariable>(vsCMElement.vsCMElementVariable);
            CodeProperty codeProperty = editorEditPoint.GetCurrentCodeElement <CodeProperty>(vsCMElement.vsCMElementProperty);

            // get parent objects:
            GetParent(editorEditPoint, out codeClass, out codeStruct);

            // if text selected:
            if (editorEditPoint.Selection.TopLine != editorEditPoint.Selection.BottomLine)
            {
                // get all the variables that are selected:
                if (codeClass != null)
                {
                    vars  = GetList <CodeVariable>(codeClass.Members, vsCMElement.vsCMElementVariable, editorEditPoint.Selection);
                    props = GetList <CodeProperty>(codeClass.Members, vsCMElement.vsCMElementProperty, editorEditPoint.Selection);
                    if (vars != null)
                    {
                        codeClass = vars[0].Parent as CodeClass;
                    }
                    if (codeClass == null && props != null)
                    {
                        codeClass = props[0].Parent;
                    }
                }
                else
                if (codeStruct != null)
                {
                    vars  = GetList <CodeVariable>(codeStruct.Members, vsCMElement.vsCMElementVariable, editorEditPoint.Selection);
                    props = GetList <CodeProperty>(codeStruct.Members, vsCMElement.vsCMElementProperty, editorEditPoint.Selection);
                    if (vars != null)
                    {
                        codeStruct = vars[0].Parent as CodeStruct;
                    }
                    if (codeStruct == null && props != null)
                    {
                        codeStruct = props[0].Parent as CodeStruct;
                    }
                }
            }
            else
            {
                // if there is only one variable selected:
                if (codeVariable != null && codeVariable.StartPoint.Line == editorEditPoint.EditPoint.Line)
                {
                    vars = new List <CodeVariable>();
                    vars.Add(codeVariable);

                    codeClass  = codeVariable.Parent as CodeClass;
                    codeStruct = codeVariable.Parent as CodeStruct;
                }
                else
                // if there is only one property selected:
                if (codeProperty != null && editorEditPoint.Selection.TopLine == editorEditPoint.Selection.BottomLine)
                {
                    props = new List <CodeProperty>();
                    props.Add(codeProperty);

                    codeClass  = codeProperty.Parent;
                    codeStruct = codeProperty.Parent as CodeStruct;
                }
                else
                // otherwise the the whole class will be changed to properties:
                if (codeClass != null)
                {
                    vars             = GetList <CodeVariable>(codeClass.Members, vsCMElement.vsCMElementVariable);
                    props            = GetList <CodeProperty>(codeClass.Members, vsCMElement.vsCMElementProperty);
                    partialSelection = false;
                }
                else
                // or struct
                if (codeStruct != null)
                {
                    vars             = GetList <CodeVariable>(codeStruct.Members, vsCMElement.vsCMElementVariable);
                    props            = GetList <CodeProperty>(codeStruct.Members, vsCMElement.vsCMElementProperty);
                    partialSelection = false;
                }
            }

            // validate is something has been found:
            if (codeClass != null || codeStruct != null)
            {
                return(new Data.CodeEditSelection(codeClass, codeStruct, vars, null, props, partialSelection));
            }

            return(null);
        }