Exemple #1
0
        private bool GetIncludeInfo(ref string path)
        {
            //first we need to find the text thing
            Document doc = App().ActiveDocument;

            if (doc != null)
            {
                TextDocument text = (TextDocument)doc.Object("");

                //this is the current selection's top line #
                int line = text.Selection.CurrentLine;
                int col  = text.Selection.CurrentColumn;

                VirtualPoint activepoint = text.Selection.ActivePoint;
                EditPoint    point       = activepoint.CreateEditPoint();
                point.EndOfLine();

                EditPoint  endfound = null;
                TextRanges found    = null;
                bool       result   = point.FindPattern("opinclude[ \t]+\\\"{.*}\\\"", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsRegularExpression), ref endfound, ref found);

                if (result)
                {
                    int foundline = endfound.Line;

                    //NOTE: I think this is correct...
                    int offset = line - foundline - 1;                    //TODO: get this 1 to be constant in macro expansion!

                    TextRange fullmatch = found.Item(1);

                    // need to break out if the active point wasn't in the line
                    if (fullmatch.StartPoint.Line != activepoint.Line)
                    {
                        return(false);
                    }

                    TextRange filematch = found.Item(2);
                    string    filetext  = filematch.StartPoint.GetText(filematch.EndPoint);

                    //NOTE: this returns what was in the opinclude, but does not resolve the path
                    path = filetext;

                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        /// <summary>mark the method and bring the Visual Studio on front</summary>
        /// <param term='codeFunction'>is the right codeFunction element to the searched method</param>
        /// <param name="methodString">name of the method</param>

        internal void markMethod(CodeFunction codeFunction)
        {
            dte.Documents.Open(codeFunction.ProjectItem.get_FileNames(0), "Auto", false);

            TextSelection textSelection = (TextSelection)dte.ActiveDocument.Selection;

            textSelection.MoveToLineAndOffset(codeFunction.StartPoint.Line, codeFunction.StartPoint.LineCharOffset, false);

            TextRanges textRanges = null;
            string     pattern    = @"[:b]<{" + codeFunction.Name + @"}>[:b(\n]";

            if (textSelection.FindPattern(pattern, (int)vsFindOptions.vsFindOptionsRegularExpression, ref textRanges))
            {
                TextRange r = textRanges.Item(2);
                textSelection.MoveToLineAndOffset(r.StartPoint.Line, r.StartPoint.LineCharOffset, false);
                textSelection.MoveToLineAndOffset(r.EndPoint.Line, r.EndPoint.LineCharOffset, true);
            }
            dte.MainWindow.Activate();
        }
Exemple #3
0
        void UpdateArguments()
        {
            Document doc = App().ActiveDocument;

            //whats the xml file's path?
            string xmlpath   = "";
            bool   available = UpdateXml(ref xmlpath);

            if (!available)
            {
                Arguments.Clear();
                return;
            }

            TextDocument text         = (TextDocument)doc.Object("");
            VirtualPoint currentpoint = text.Selection.ActivePoint;

            EditPoint point = currentpoint.CreateEditPoint();

            point.EndOfLine();

            EditPoint  endfound = null;
            TextRanges found    = null;

            Arguments.Clear();

            bool result = point.FindPattern("note[ \t]+{.*}\\({.*}\\)", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsRegularExpression), ref endfound, ref found);

            if (result)
            {
                TextRange fullmatch = found.Item(1);
                TextRange pathmatch = found.Item(2);
                TextRange argmatch  = found.Item(3);

                //only want it if the point was in the range
                if (fullmatch.EndPoint.LessThan(currentpoint) ||
                    fullmatch.StartPoint.GreaterThan(currentpoint))
                {
                    return;
                }

                ArgumentEnd = argmatch.EndPoint;

                string arguments = argmatch.StartPoint.GetText(argmatch.EndPoint).Trim();

                NoteArguments = arguments.Split(',');

                string notepath = pathmatch.StartPoint.GetText(pathmatch.EndPoint).Trim();

                XmlNoteNode note = XmlFile.GetNote(notepath);

                if (note != null)
                {
                    Arguments = new List <string>();

                    foreach (XmlArgumentNode n in note.Arguments)
                    {
                        Arguments.Add(n.Name);
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            // Verify the current thread is the UI thread.
            ThreadHelper.ThrowIfNotOnUIThread();

            // Don't attempt to insert a header if there's no active document.
            if (InsertConstructorHeaderCommand.environment.ActiveDocument == null)
            {
                return;
            }

            // Get the selected text from the editor environment.
            TextSelection selection = InsertConstructorHeaderCommand.environment.ActiveDocument.Selection as TextSelection;

            // Create an edit point for the current location in the document.  The general idea here is to look backward from the current cursor
            // location until we find a class or structure declaration.  We'll then extract the name of the class (or structure) and look for the
            // constructor.  Once we find it, we'll replace the existing summary with the new boilerplate version that Style COP wants to see.
            EditPoint startPoint = selection.AnchorPoint.CreateEditPoint();

            // The 'FindPattern' will return a collection of found sub-tags in this collection.  The function seems to be a little brain damaged or
            // else it isn't documented clearly.  If you have two sub-tags in your pattern, three text ranges are returned.  It appears that one of
            // the ranges is the entire match, though it shows up in no particular order.
            TextRanges textRanges = null;

            // This starts the process by finding the class or structure declaration.
            if (startPoint.FindPattern(
                    InsertConstructorHeaderCommand.ClassDeclarationPattern,
                    (int)(vsFindOptions.vsFindOptionsRegularExpression | vsFindOptions.vsFindOptionsBackwards),
                    null,
                    ref textRanges))
            {
                // Whether the object is a class or a structure will be used when constructing the boilerplate summary comment.  The name of the
                // class is also used to create the summary.  The 'index' to the 'Item' indexer is a little brain damaged as well.  It turns out that
                // the COM class will only work with floating point numbers (go figure) and starts counting at 1.0.
                var    objectTypeRange = textRanges.Item(3.0);
                string objectType      = objectTypeRange.StartPoint.GetText(objectTypeRange.EndPoint);
                var    classNameRange  = textRanges.Item(4.0);
                string className       = classNameRange.StartPoint.GetText(classNameRange.EndPoint);

                TextRanges modifierRanges = null;

                // This will find the constructor for the class or structure.
                if (startPoint.FindPattern(
                        string.Format(CultureInfo.InvariantCulture, InsertConstructorHeaderCommand.ConstructorDeclarationPattern, className),
                        (int)vsFindOptions.vsFindOptionsRegularExpression,
                        null,
                        ref modifierRanges))
                {
                    var    modifierRange = modifierRanges.Item(1.0);
                    string modifier      = modifierRange.StartPoint.GetText(modifierRange.EndPoint);
                    bool   isStatic      = modifier.StartsWith("static", StringComparison.Ordinal);

                    // This will find the summary comment and return the entire range of the comment from the first line to the end of the line
                    // containing the ending tag.  This covers comments that have been compressed onto a single line as well as the more common
                    // multi-line 'summary' comment.
                    EditPoint endPoint = null;
                    if (startPoint.FindPattern(
                            InsertConstructorHeaderCommand.ConstructorSummaryPattern,
                            (int)(vsFindOptions.vsFindOptionsRegularExpression | vsFindOptions.vsFindOptionsBackwards),
                            ref endPoint,
                            ref textRanges))
                    {
                        // Extract the prefix of the comment.  This tells us how many tabs (or spaces) there are in the comment delimiter.
                        var    prefixRange = textRanges.Item(1.0);
                        string prefix      = prefixRange.StartPoint.GetText(prefixRange.EndPoint);

                        // Static and instance constructors have different formats.  This will chose a header template that is appropriate.
                        string constructorHeader = isStatic ?
                                                   Resources.StaticConstructorHeaderTemplate :
                                                   Resources.InstanceConstructorHeaderTemplate;

                        // Replace the existing summary comment with a boilerplate constructed from the information collected about the class.  This
                        // boilerplate comment will pass mustard in Style COP.
                        string replacementText = string.Format(
                            CultureInfo.InvariantCulture,
                            constructorHeader,
                            prefix,
                            className,
                            objectType);
                        startPoint.ReplaceText(
                            endPoint,
                            replacementText,
                            (int)(vsEPReplaceTextOptions.vsEPReplaceTextNormalizeNewlines | vsEPReplaceTextOptions.vsEPReplaceTextTabsSpaces));
                    }
                }
            }
        }
        //NOTE: should not check the file for existance...
        private bool GetGotoInfo(ref string actualfile, ref int actualline, ref int originalline, ref int gendepth, ref int filedepth)
        {
            //first we need to find the text thing
            Document doc = App().ActiveDocument;

            if (doc != null)
            {
                TextDocument text = (TextDocument)doc.Object("");

                //this is the current selection's top line #
                int line = text.Selection.CurrentLine;
                int col  = text.Selection.CurrentColumn;

                EditPoint point = text.Selection.ActivePoint.CreateEditPoint();
                point.EndOfLine();

                EditPoint  endfound = null;
                TextRanges found    = null;
                bool       result   = point.FindPattern("\\#line{.*}\\\"{.*}\\\"//\\[{.*}\\]", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsRegularExpression), ref endfound, ref found);

                if (result)
                {
                    int foundline = endfound.Line;

                    //NOTE: I think this is correct...
                    int offset = line - foundline - 1;

                    TextRange linematch     = found.Item(2);
                    string    linematchtext = linematch.StartPoint.GetText(linematch.EndPoint);

                    TextRange filematch     = found.Item(3);
                    string    filematchtext = filematch.StartPoint.GetText(filematch.EndPoint);

                    TextRange optionmatch = found.Item(4);
                    string    optionstext = optionmatch.StartPoint.GetText(optionmatch.EndPoint);

                    //parse the line directive
                    int    redirectedline = Convert.ToInt32(linematchtext);
                    string redirectedfile = filematchtext;

                    //parse the additional information
                    string[] options = optionstext.Split(',');

                    gendepth     = 0;
                    originalline = -1;
                    filedepth    = 0;

                    //first number: the depth of the generated path
                    if (options.Length > 0)
                    {
                        string generatedDepth = options[0];
                        gendepth = Convert.ToInt32(generatedDepth);
                    }

                    //second number: the depth of the file path (relative to the generated?)
                    if (options.Length > 1)
                    {
                        string fileDepth = options[1];
                        filedepth = Convert.ToInt32(fileDepth);
                    }

                    //third number: the original line number
                    if (options.Length > 2)
                    {
                        string originline = options[2];
                        originalline = Convert.ToInt32(originline);
                    }

                    if (offset == -1)
                    {
                        offset = 0;
                    }

                    if (offset >= 0)
                    {
                        string dots = "";

                        for (int i = 0; i < gendepth; i++)
                        {
                            dots += "..\\";
                        }

                        string myfile = StringUtility.RLeft(doc.FullName, "\\");

                        if (!System.IO.Path.IsPathRooted(redirectedfile))
                        {
                            actualfile = myfile + "\\" + dots + redirectedfile;
                        }
                        else
                        {
                            actualfile = redirectedfile;
                        }

                        actualfile = System.IO.Path.GetFullPath(actualfile);

                        actualline = redirectedline + offset;

                        return(true);
                    }
                }
            }

            return(false);
        }