// pre: must be a word before the end of the line moves to the end of
 // the word
 static private void GoToEndOfNextWord(
     EnvDTE.EditPoint pt)
 {
     while ((pt.GetText(1) == " ") ||
            (pt.GetText(1) == "\t"))
     {
         pt.CharRight(1);
     }
     while ((!pt.AtEndOfLine) &&
            (pt.GetText(1) != " ") &&
            (pt.GetText(1) != "\t"))
     {
         pt.CharRight(1);
     }
 }
        static private void SkipString(EnvDTE.EditPoint pt, string wanted)
        {
            string actual = GetTextOnLine(pt, wanted.Length);

            if (actual != wanted)
            {
                throw new System.ArgumentException("Error parsing expected string", wanted);
            }
            pt.CharRight(wanted.Length);
        }
 static private bool AtLineEndIgnoringWhiteSpace(
     EnvDTE.EditPoint pt)
 {
     EnvDTE.EditPoint temp = pt.CreateEditPoint();
     while ((!temp.AtEndOfLine) &&
            ((temp.GetText(1) == " ") ||
             (temp.GetText(1) == "\t")))
     {
         temp.CharRight(1);
     }
     return(temp.AtEndOfLine);
 }
 static private void GoToEndOfPreviousWord(
     EnvDTE.EditPoint pt)
 {
     pt.CharLeft(1);
     while ((pt.GetText(1) != " ") &&
            (pt.GetText(1) != "\t"))
     {
         pt.CharLeft(1);
     }
     while ((pt.GetText(1) == " ") ||
            (pt.GetText(1) == "\t"))
     {
         pt.CharLeft(1);
     }
     pt.CharRight(1);
 }
        static private void SkipColumns(
            EnvDTE.EditPoint pt,
            int blockIndentation)
        {
            int start     = pt.DisplayColumn;
            int startLine = pt.Line;

            while ((pt.DisplayColumn - start) < blockIndentation)
            {
                pt.CharRight(1);
                if (pt.Line != startLine)
                {
                    throw new System.ArgumentException("Error parsing columns");
                }
            }
            if ((pt.DisplayColumn - start) != blockIndentation)
            {
                throw new System.ArgumentException("Error parsing columns");
            }
        }
        /**
         * Helper function returns -1 if the line is empty else returns the
         * amount of whitespace pt is indented by
         */
        static private int SkipWhitespace(
            EnvDTE.EditPoint pt)
        {
            int start = pt.DisplayColumn;

            while (!pt.AtEndOfLine &&
                   ((pt.GetText(1) == " ") ||
                    (pt.GetText(1) == "\t")))
            {
                pt.CharRight(1);
            }
            if (pt.AtEndOfLine)
            {
                return(-1);
            }
            else
            {
                return(pt.DisplayColumn - start);
            }
        }
        static private void WrapBlock(
            ParameterSet pset,
            CommentBlock block,
            MatchedBlockData bdata,
            EnvDTE.TextPoint pt)
        {
            int blockTabSize = pt.Parent.TabSize;

            if (!pset.mUseTabsToIndent)
            {
                blockTabSize = 0;
            }

            bool isInPreformmatedBlock = false;
            bool isLastLine            = false;
            bool isStartOnSeparateLine = false;

            EnvDTE.EditPoint curPoint = pt.CreateEditPoint();
            curPoint.MoveToLineAndOffset(bdata.mStartLine, 1);

            // seems we have to pick the reight line ending ourselves
            string eol = "\r\n";

            if (curPoint.GetText(-1).Length == 1)
            {
                eol = "\n";
            }

            EnvDTE.EditPoint endPoint = pt.CreateEditPoint();
            endPoint.MoveToLineAndOffset(bdata.mEndLine, 1);

            if ((block.mBlockEndType == StartEndBlockType.OnOwnLineIfBlockIsMoreThanOne) ||
                (block.mBlockEndType == StartEndBlockType.NeverOnOwnLine))
            {
                // delete the end block string
                endPoint.StartOfLine();
                SkipColumns(endPoint, bdata.mIndentation);
                if (GetTextOnLine(endPoint, bdata.mMatchedBlockEnd.Length) == bdata.mMatchedBlockEnd)
                {
                    // delete the whole line
                    endPoint.EndOfLine();
                    EnvDTE.EditPoint secondLastLinePoint = endPoint.CreateEditPoint();
                    secondLastLinePoint.LineUp(1);
                    secondLastLinePoint.EndOfLine();
                    secondLastLinePoint.Delete(endPoint);
                }
                else
                {
                    // delete just the string
                    EnvDTE.EditPoint eolPoint = endPoint.CreateEditPoint();
                    eolPoint.EndOfLine();
                    int endOffset = endPoint.GetText(eolPoint).LastIndexOf(bdata.mMatchedBlockEnd);
                    endPoint.CharRight(endOffset);
                    endPoint.Delete(eolPoint);
                }
            }
            else if (block.mBlockEndType == StartEndBlockType.AlwaysOnOwnLine)
            {
                // just move up al line as there is nothing interesting on it
                endPoint.LineUp(1);
            }
            endPoint.EndOfLine();

            // now loop down the lines
            while (!isLastLine)
            {
                if (curPoint.Line >= endPoint.Line)
                {
                    isLastLine = true;
                }

                curPoint.StartOfLine();
                if ((curPoint.Line == bdata.mStartLine) &&
                    (block.mBlockStartType == StartEndBlockType.AlwaysOnOwnLine))
                {
                    curPoint.LineDown(1);// simply go to the next line
                    continue;
                }
                else if ((curPoint.Line == bdata.mStartLine) &&
                         (block.mBlockStartType == StartEndBlockType.NeverOnOwnLine))
                {
                    SkipColumns(curPoint, bdata.mIndentation);
                    SkipString(curPoint, bdata.mMatchedBlockStart);
                }
                else if ((curPoint.Line == bdata.mStartLine) &&
                         (block.mBlockStartType == StartEndBlockType.OnOwnLineIfBlockIsMoreThanOne))
                {
                    // we will automatically pull up the next line if we can. We
                    // also haqndle the case where traling spaces from the block
                    // start have been removed
                    SkipColumns(curPoint, bdata.mIndentation);
                    SkipString(curPoint, bdata.mMatchedBlockStart);

                    if ((!AtLineEndIgnoringWhiteSpace(curPoint)) || isLastLine)
                    {
                        isStartOnSeparateLine = false;
                    }
                    else if (LineJustContainsContinuation(curPoint.Line + 1, bdata.mIndentation, block.mLineStart, pset, pt))
                    {
                        isStartOnSeparateLine = true;
                    }
                    else
                    {
                        isStartOnSeparateLine = false;
                        if (bdata.mSpacesTrimmedOffBlockStart > 0)
                        {
                            curPoint.Insert(new String(' ', bdata.mSpacesTrimmedOffBlockStart));
                            // change these as we reprocess line!
                            bdata.mMatchedBlockStart         += new String(' ', bdata.mSpacesTrimmedOffBlockStart);
                            bdata.mSpacesTrimmedOffBlockStart = 0;
                        }
                        EnvDTE.EditPoint nextLineStartPoint = curPoint.CreateEditPoint();
                        nextLineStartPoint.LineDown(1);
                        nextLineStartPoint.StartOfLine();
                        SkipColumns(nextLineStartPoint, bdata.mIndentation);
                        SkipString(nextLineStartPoint, block.mLineStart);
                        curPoint.Delete(nextLineStartPoint);
                        continue;// reprocess the line as it now may be last
                    }
                }
                else // just a regular line start
                {
                    // pass over line start
                    SkipColumns(curPoint, bdata.mIndentation);
                    if (GetTextOnLine(curPoint, block.mLineStart.Length) != block.mLineStart)
                    {
                        if ((block.mBlockEndType == StartEndBlockType.OnOwnLineIfBlockIsMoreThanOne) &&
                            (GetTextOnLine(curPoint, bdata.mMatchedBlockEnd.Length) == bdata.mMatchedBlockEnd))
                        {
                            break;// we are done!
                        }
                        else if (GetTextOnLine(curPoint, block.mLineStart.TrimEnd().Length) == block.mLineStart.TrimEnd())
                        {
                            curPoint.LineDown(1);
                            continue; // empty line with just trimmed block line
                                      // start
                        }
                        else
                        {
                            throw new System.ArgumentException("Error parsing block line start");
                        }
                    }
                    curPoint.CharRight(block.mLineStart.Length);
                }

                // ASSERT: past the comment block start or comment line start
                // for the line

                int lastStartPre = GetRestOfLine(curPoint).ToLower().LastIndexOf("<pre>");
                int lastEndPre   = GetRestOfLine(curPoint).ToLower().LastIndexOf("</pre>");

                // work out if we are in a preformatted block
                if ((lastStartPre != -1) && (lastStartPre > lastEndPre))
                {
                    isInPreformmatedBlock = true;
                }

                // check all cases that stop wrapping of this line to the next
                if (isInPreformmatedBlock ||
                    AtLineEndIgnoringWhiteSpace(curPoint) ||
                    pset.matchesBreakFlowString(GetRestOfLine(curPoint), false))
                {
                    if ((lastEndPre != -1) && (lastEndPre > lastStartPre))
                    {
                        isInPreformmatedBlock = false;
                    }
                    curPoint.LineDown(1);
                    continue;
                }
                bool breakLine = pset.matchesBreakFlowString(GetRestOfLine(curPoint), true);

                // work out if we are in a preformatted block
                if ((lastEndPre != -1) && (lastEndPre > lastStartPre))
                {
                    isInPreformmatedBlock = false;
                }

                // work out indent for current line
                int currentIndent = -1;
                int thisIndent;
                if (pset.matchesBulletPoint(GetRestOfLine(curPoint), out thisIndent, out currentIndent))
                {
                    // We need to convert current indent to number of columns
                    // as at the moment it is number of characters.
                    EnvDTE.EditPoint tempPoint = curPoint.CreateEditPoint();
                    tempPoint.CharRight(currentIndent);
                    currentIndent = tempPoint.DisplayColumn - curPoint.DisplayColumn;
                    // Now advance on this line by the size of the bullet point.
                    curPoint.CharRight(thisIndent);
                }
                else
                {
                    currentIndent = SkipWhitespace(curPoint);
                }
                if ((block.mBlockStartType == StartEndBlockType.NeverOnOwnLine) &&
                    (curPoint.Line == bdata.mStartLine))
                {
                    // Need to account that on the first line the block start
                    // may have a different length to the line start.
                    //
                    // Note the reason we do not do the multi/ single option here
                    // is that if we are pulling up text onto the first line we
                    // actually break the reflowing indentation rule. This all
                    // needs to be thought through a bit better.
                    currentIndent += bdata.mMatchedBlockStart.Length - block.mLineStart.Length;
                }

                int blockWrapWidth = pset.mWrapWidth;
                if ((bdata.mIndentation + block.mLineStart.Length + currentIndent + pset.mMinimumBlockWidth) > blockWrapWidth)
                {
                    blockWrapWidth = bdata.mIndentation + block.mLineStart.Length + currentIndent + pset.mMinimumBlockWidth;
                }



                // Now see if we can wrap into the next line, or if we wrap by
                // inserting a new line before it.
                EnvDTE.EditPoint nextLinePoint    = null;
                bool             wrapIntoNextLine = false;
                if (!isLastLine && !breakLine)
                {
                    nextLinePoint = curPoint.CreateEditPoint();
                    nextLinePoint.LineDown(1);
                    nextLinePoint.StartOfLine();
                    SkipColumns(nextLinePoint, bdata.mIndentation);
                    if ((block.mLineStart.TrimEnd().Length != block.mLineStart.Length) &&
                        (GetRestOfLine(nextLinePoint).CompareTo(block.mLineStart.TrimEnd()) == 0))
                    {
                        // handle the next line that is completely empty with
                        // rimmed line end
                        nextLinePoint = null;
                    }
                    else
                    {
                        SkipString(nextLinePoint, block.mLineStart);
                        if (!pset.matchesBulletPoint(GetRestOfLine(nextLinePoint)) &&
                            !pset.matchesBreakFlowString(GetRestOfLine(nextLinePoint), false) &&
                            (SkipWhitespace(nextLinePoint) == currentIndent))
                        {
                            wrapIntoNextLine = true;
                        }
                        else
                        {
                            nextLinePoint = null;
                        }
                    }
                }

                // if on the first line and we can'd wrap the text into the next
                // line, then push any text on the first line down to a separate
                // line
                if ((block.mBlockStartType == StartEndBlockType.OnOwnLineIfBlockIsMoreThanOne) &&
                    (curPoint.Line == bdata.mStartLine) &&
                    !wrapIntoNextLine &&
                    !isLastLine &&
                    !isStartOnSeparateLine)
                {
                    isStartOnSeparateLine = true;
                    curPoint.StartOfLine();
                    SkipColumns(curPoint, bdata.mIndentation);
                    SkipString(curPoint, bdata.mMatchedBlockStart.TrimEnd());
                    curPoint.Delete(bdata.mMatchedBlockStart.Length - bdata.mMatchedBlockStart.TrimEnd().Length);
                    curPoint.Insert(eol + GetIndentationString(1, bdata.mIndentation, blockTabSize) + block.mLineStart);
                    continue;
                }

                // ASSERT: if we have got here, there is at least one word on
                // this line, and if wrapIntoNextLine then there is at least one
                // word on the next line

                // now go to the start of the first word that passes the wrap
                // point, or the end of the line if it is sooner
                int wordCount = 0;
                while (((curPoint.DisplayColumn - 1) <= blockWrapWidth) &&
                       !AtLineEndIgnoringWhiteSpace(curPoint))
                {
                    wordCount++;
                    GoToEndOfNextWord(curPoint);
                }

                if ((curPoint.DisplayColumn - 1) <= blockWrapWidth)
                {
                    // the end of line occurs at or before the wrap point. Try
                    // to fill in the gap from the next line if we can
                    if (!wrapIntoNextLine)
                    {
                        curPoint.LineDown(1);
                    }
                    else
                    {
                        int charsToFill = blockWrapWidth - ((curPoint.DisplayColumn - 1) + 1);//+1 for extra space

                        EnvDTE.EditPoint nextLineEndPoint = nextLinePoint.CreateEditPoint();
                        int numChars = 0;
                        int numWords = 0;
                        while ((numChars < charsToFill) &&
                               !AtLineEndIgnoringWhiteSpace(nextLineEndPoint))
                        {
                            numWords++;
                            GoToEndOfNextWord(nextLineEndPoint);
                            numChars = nextLineEndPoint.DisplayColumn - nextLinePoint.DisplayColumn;
                        }
                        if ((numChars > charsToFill) && (numWords > 1))
                        {
                            GoToEndOfPreviousWord(nextLineEndPoint);
                            numChars = nextLineEndPoint.DisplayColumn - nextLinePoint.DisplayColumn;
                        }
                        if ((numChars <= 0) || (numChars > charsToFill))
                        {
                            // the first word on the next line is too long to
                            // pull up

                            // push comment block start onto separate line and
                            // retry if we can
                            if ((curPoint.Line == bdata.mStartLine) &&
                                (block.mBlockStartType == StartEndBlockType.OnOwnLineIfBlockIsMoreThanOne) &&
                                !isStartOnSeparateLine)
                            {
                                isStartOnSeparateLine = true;
                                curPoint.StartOfLine();
                                SkipColumns(curPoint, bdata.mIndentation);
                                SkipString(curPoint, bdata.mMatchedBlockStart.TrimEnd());
                                curPoint.Delete(bdata.mMatchedBlockStart.Length - bdata.mMatchedBlockStart.TrimEnd().Length);
                                curPoint.Insert(eol + GetIndentationString(1, bdata.mIndentation, blockTabSize) + block.mLineStart);
                            }
                            else
                            {
                                // just skip onto the next line
                                curPoint.LineDown(1);
                            }
                        }
                        else
                        {
                            // delete trailing whitespace from this line
                            EnvDTE.EditPoint lineEndPoint = curPoint.CreateEditPoint();
                            lineEndPoint.EndOfLine();
                            curPoint.Delete(lineEndPoint);

                            // get new string from next line and insert it
                            string st = nextLinePoint.GetText(nextLineEndPoint);
                            if (AtLineEndIgnoringWhiteSpace(nextLineEndPoint))
                            {
                                // no text left on next line, so delete the
                                // whole thing
                                nextLineEndPoint.EndOfLine();
                                curPoint.Delete(nextLineEndPoint);
                                curPoint.Insert(" " + st);
                                // don't move curPoint down as we want to
                                // reprocess this line in case there is more
                                // room left
                            }
                            else
                            {
                                // there is still text left on the next line

                                // push comment block start onto separate line
                                // if neccesary
                                if ((curPoint.Line == bdata.mStartLine) &&
                                    (block.mBlockStartType == StartEndBlockType.OnOwnLineIfBlockIsMoreThanOne) &&
                                    !isStartOnSeparateLine)
                                {
                                    isStartOnSeparateLine = true;
                                    curPoint.StartOfLine();
                                    SkipColumns(curPoint, bdata.mIndentation);
                                    SkipString(curPoint, bdata.mMatchedBlockStart.TrimEnd());
                                    curPoint.Delete(bdata.mMatchedBlockStart.Length - bdata.mMatchedBlockStart.TrimEnd().Length);
                                    curPoint.Insert(eol + GetIndentationString(1, bdata.mIndentation, blockTabSize) + block.mLineStart);
                                    // reprocess this moved down line!
                                }
                                else
                                {
                                    // remove trailing string as well as
                                    // trailing spaces
                                    while ((nextLineEndPoint.GetText(1) == " ") ||
                                           (nextLineEndPoint.GetText(1) == "\t"))
                                    {
                                        nextLineEndPoint.CharRight(1);
                                    }
                                    nextLinePoint.Delete(nextLineEndPoint);
                                    curPoint.Insert(" " + st);
                                    curPoint.LineDown(1);//move to next line
                                }
                            }
                        }
                    }
                }
                else // ((curPoint.DisplayColumn-1) > blockWrapWidth)
                {
                    // push start onto separate line if neccesary
                    if ((curPoint.Line == bdata.mStartLine) &&
                        (block.mBlockStartType == StartEndBlockType.OnOwnLineIfBlockIsMoreThanOne) &&
                        !isStartOnSeparateLine)
                    {
                        isStartOnSeparateLine = true;
                        curPoint.StartOfLine();
                        SkipColumns(curPoint, bdata.mIndentation);
                        SkipString(curPoint, bdata.mMatchedBlockStart.TrimEnd());
                        curPoint.Delete(bdata.mMatchedBlockStart.Length - bdata.mMatchedBlockStart.TrimEnd().Length);
                        curPoint.Insert(eol + GetIndentationString(1, bdata.mIndentation, blockTabSize) + block.mLineStart);
                        isLastLine = false; // forces reprocess even if isLatLine
                                            // was just true
                        continue;           // reprocess the just moved line
                    }

                    // this line overflows the word wrap. Move back to the end
                    // of the last word that doesn't overflow if possible
                    if (wordCount > 1)
                    {
                        GoToEndOfPreviousWord(curPoint);
                    }
                    if (AtLineEndIgnoringWhiteSpace(curPoint))
                    {
                        curPoint.LineDown(1); // the single line is too long, so
                                              // forget about it
                        // and go to the next line
                    }
                    else
                    {
                        // copy the remainder of the line after a space but
                        // delete the space as well
                        if (!wrapIntoNextLine)
                        {
                            EnvDTE.EditPoint dataStartPoint = curPoint.CreateEditPoint();
                            SkipWhitespace(dataStartPoint);
                            curPoint.Delete(dataStartPoint);
                            // insert a whole new line
                            curPoint.Insert(eol + GetIndentationString(1, bdata.mIndentation, blockTabSize) + block.mLineStart);
                            if (currentIndent > 0)
                            {
                                curPoint.Insert(GetIndentationString(curPoint.DisplayColumn, currentIndent, blockTabSize));
                            }
                        }
                        else
                        {
                            // insert at the start of the next line
                            EnvDTE.EditPoint dataStartPoint = curPoint.CreateEditPoint();
                            SkipWhitespace(dataStartPoint);
                            EnvDTE.EditPoint lineEndPoint = curPoint.CreateEditPoint();
                            lineEndPoint.EndOfLine();
                            string st = dataStartPoint.GetText(lineEndPoint).TrimEnd();
                            curPoint.Delete(lineEndPoint);
                            nextLinePoint.Insert(st + " ");
                            curPoint.LineDown(1);
                        }
                        // if there is enough there to create one or multiple
                        // lines, then create them
                        while (true)
                        {
                            curPoint.StartOfLine();
                            SkipColumns(curPoint, bdata.mIndentation);
                            SkipString(curPoint, block.mLineStart);
                            SkipColumns(curPoint, currentIndent);
                            int myWordCount = 0;
                            while ((curPoint.DisplayColumn - 1) <= blockWrapWidth &&
                                   !AtLineEndIgnoringWhiteSpace(curPoint))
                            {
                                myWordCount++;
                                GoToEndOfNextWord(curPoint);
                            }
                            if ((curPoint.DisplayColumn - 1) <= blockWrapWidth)
                            {
                                break; // don't move down a line as we want to
                                       // reprocess this line
                            }
                            if (myWordCount > 1)
                            {
                                GoToEndOfPreviousWord(curPoint);
                            }
                            if (AtLineEndIgnoringWhiteSpace(curPoint))
                            {
                                break;
                            }
                            EnvDTE.EditPoint dataStartPoint = curPoint.CreateEditPoint();
                            SkipWhitespace(dataStartPoint);
                            curPoint.Delete(dataStartPoint);
                            curPoint.Insert(eol + GetIndentationString(1, bdata.mIndentation, blockTabSize) + block.mLineStart);
                            if (currentIndent > 0)
                            {
                                curPoint.Insert(GetIndentationString(curPoint.DisplayColumn, currentIndent, blockTabSize));
                            }
                            // process the just created line in the next
                            // iteration
                        }
                    }
                }
            }

            if ((block.mBlockEndType == StartEndBlockType.OnOwnLineIfBlockIsMoreThanOne) &&
                (endPoint.Line != bdata.mStartLine))
            {
                endPoint.EndOfLine();
                endPoint.Insert(eol + GetIndentationString(1, bdata.mIndentation, blockTabSize) + bdata.mMatchedBlockEnd);
            }
            else if ((block.mBlockEndType == StartEndBlockType.OnOwnLineIfBlockIsMoreThanOne) ||
                     (block.mBlockEndType == StartEndBlockType.NeverOnOwnLine))
            {
                endPoint.EndOfLine();
                endPoint.Insert(bdata.mMatchedBlockEnd);
            }
        }
示例#8
0
        private void button_Click_add_to_export(object sender, RoutedEventArgs e)
        {
            EnvDTE80.DTE2 dte2 = FGetter.dte2;

            if (!dte2.Solution.IsOpen)
            {
                MessageBox.Show(string.Format(System.Globalization.CultureInfo.CurrentUICulture, "No solution is opened!"), "Couldn't find a solution");
                return;
            }
            if (dte2.Solution.Projects.Count == 0)
            {
                MessageBox.Show(string.Format(System.Globalization.CultureInfo.CurrentUICulture, "No projects is opened!"), "Couldn't find a project");
                return;
            }

            EnvDTE.Project project = dte2.Solution.Projects.Item(1);

            if (!CheckForProjectItem(project, "M3D_export.cpp"))
            {
                MessageBoxResult create_export_file = MessageBox.Show(
                    string.Format(System.Globalization.CultureInfo.CurrentUICulture, "Couldn't find M3D_export.cpp file. Would you like to create one?"),
                    "No export file", MessageBoxButton.OKCancel
                    );

                if (create_export_file != MessageBoxResult.OK)
                {
                    return;
                }

                button_Click_c_ex_btn(sender, e);
            }

            if (!FGetter.GetM3DFWStuff())
            {
                MessageBox.Show(string.Format(System.Globalization.CultureInfo.CurrentUICulture, "Couldn't find proper M3D definitions.\nDid you mess with the export file?"), "No proper definitions found!");
                return;
            }

            EnvDTE.EditPoint start_point1 = FGetter.getFctPtrList_function.GetStartPoint().CreateEditPoint();
            EnvDTE.EditPoint end_point1   = FGetter.getFctPtrList_function.GetEndPoint().CreateEditPoint();
            EnvDTE.EditPoint start_point2 = FGetter.getMemberFctPtrList_function.GetStartPoint().CreateEditPoint();
            EnvDTE.EditPoint end_point2   = FGetter.getMemberFctPtrList_function.GetEndPoint().CreateEditPoint();

            //EnvDTE.EditPoint place_to_write = end_point;

            if (!start_point1.FindPattern("//Body to be generated", 0, start_point1) || !start_point2.FindPattern("//Body to be generated", 0, start_point2))
            {
                MessageBox.Show(string.Format(System.Globalization.CultureInfo.CurrentUICulture, "Function definition requires the\n\"//Body to be generated\" comment\nto be properly recognized"), "No proper definitions found!");
                return;
            }

            start_point1.CharRight(22);
            start_point2.CharRight(22);

            if (content_list[ResListBox.SelectedIndex].Kind == FGetter.M3DCppFctKind.Free)
            {
                start_point1.Insert("\n\t\tdata.push_back(m3dfw::UFctInfo(\"" + ResListBox.SelectedItem.ToString() + "\", (UserFct_ptr)" + ResListBox.SelectedItem.ToString() + ");");
            }
            else if (content_list[ResListBox.SelectedIndex].Kind == FGetter.M3DCppFctKind.Member)
            {
                start_point2.Insert("\n\t\tdata.push_back(m3dfw::UMemberFctInfo(\"" + ResListBox.SelectedItem.ToString() + "\", CAST_TO_ACTOR_MEMBER(" + ResListBox.SelectedItem.ToString() + "));");
            }

            //EnvDTE.Document doc = dte2.Documents.Item("M3D_export.cpp").ProjectItem.FileCodeModel.CodeElements.Item;
        }
示例#9
0
        public static bool go(
            EnvDTE.TextPoint searchPt,
            out EnvDTE.EditPoint finishPt

            /*,
             * bool pullupIfLineShortEnough,
             * int lengthToPutOnOneLine,
             * bool forceOneParamPerLine,
             * bool recurseOnSubCalls*/)
        {
            finishPt = null;

            EnvDTE.EditPoint curPt = searchPt.CreateEditPoint();
            // search right first for bracket
            // FIXME: "(" can't be in a string
            if ((curPt.GetText(1) != " ") && (curPt.GetText(1) != "\t"))
            {
                while ((!curPt.AtEndOfLine) && (curPt.GetText(1) != "("))
                {
                    curPt.CharRight(1);
                }
            }

            // now try back left if right did not succeed
            // FIXME: ";" and "(" can't be in a string
            if ((curPt.GetText(1) != "("))
            {
                curPt = searchPt.CreateEditPoint();
                while ((!curPt.AtStartOfDocument) &&
                       (curPt.GetText(1) != ";") &&
                       (curPt.GetText(1) != "("))
                {
                    curPt.CharLeft(1);
                }
            }

            // if no bracket then fail
            if (curPt.GetText(1) != "(")
            {
                return(false);
            }

            curPt.CharRight(1);

            // Fixed 23 Mar 2010: skip whitespace between "(" and first char
            while ((curPt.GetText(1) == " ") ||
                   (curPt.GetText(1) == "\t"))
            {
                curPt.CharRight(1);
            }

            int  indentPoint            = curPt.LineCharOffset;
            bool isFirstLineOfParameter = false; // note this is processed at the
                                                 // start of the next line, so
                                                 // unless the first line finishes
                                                 // with a comma then the second
                                                 // will not be the first line of
                                                 // a parameter.
            int  lineShiftRight    = 0;
            bool inCBlockComment   = false;
            bool inCppBlockComment = false;
            bool done = false;

            while (!done)
            {
                // skip any whitespace on the current line
                while ((curPt.GetText(1) == " ") ||
                       (curPt.GetText(1) == "\t"))
                {
                    curPt.CharRight(1);
                }

                if (curPt.AtEndOfDocument)
                {
                    throw new System.ArgumentException("Unexpected eod processing parameters");
                }
                else if (curPt.AtEndOfLine)
                {
                    curPt.LineDown(1);
                    curPt.StartOfLine();
                    while ((curPt.GetText(1) == " ") ||
                           (curPt.GetText(1) == "\t"))
                    {
                        curPt.CharRight(1);
                    }
                    if (curPt.AtEndOfLine)
                    {
                        continue;
                    }
                    if ((inCppBlockComment) && (curPt.GetText(2) != "//"))
                    {
                        inCppBlockComment      = false;
                        isFirstLineOfParameter = true;
                    }
                    if (isFirstLineOfParameter)
                    {
                        lineShiftRight = indentPoint - curPt.LineCharOffset;
                    }
                    isFirstLineOfParameter = false;

                    // delete or insert spaces to meet indentation
                    int finalPosition = curPt.LineCharOffset + lineShiftRight;
                    while (curPt.LineCharOffset > finalPosition)
                    {
                        curPt.Delete(-1);
                    }
                    while (curPt.LineCharOffset < finalPosition)
                    {
                        //FIXME: tabs as well
                        curPt.Insert(" ");
                    }
                }
                else if ((inCBlockComment) && (curPt.GetText(2) == "*/"))
                {
                    inCBlockComment        = false;
                    isFirstLineOfParameter = true;
                    curPt.CharRight(2);
                }
                else if (inCBlockComment)
                {
                    curPt.CharRight(1);
                }
                else if (inCppBlockComment)
                {
                    curPt.EndOfLine();
                }
                else if (curPt.GetText(1) == ";")
                {
                    throw new System.ArgumentException("Unexpected error parsing funtion call");
                }
                else if (curPt.GetText(1) == "(")
                {
                    // recurse
                    ParameterAlignerObj.go(curPt, out curPt);
                }
                else if (curPt.GetText(1) == ",")
                {
                    curPt.CharRight(1);
                    if (AtLineEndIgnoringWhiteSpace(curPt))
                    {
                        isFirstLineOfParameter = true;
                    }
                }
                else if (curPt.GetText(1) == ")")
                {
                    done = true;
                    curPt.CharRight(1);
                    finishPt = curPt;
                }
                else if (curPt.GetText(2) == "//")
                {
                    curPt.EndOfLine();
                    inCppBlockComment = true;
                }
                else if (curPt.GetText(2) == "/*")
                {
                    curPt.CharRight(2);
                    inCBlockComment = true;
                }
                else if (curPt.GetText(2) == "@\"")
                {
                    curPt.CharRight(2);
                    //scan ahead until close
                    while (curPt.GetText(1) != "\"")
                    {
                        curPt.CharRight(1);
                        if (curPt.AtEndOfLine)
                        {
                            throw new System.ArgumentException("Unexpected eol processing string");
                        }
                    }
                    curPt.CharRight(1);
                }
                else if ((curPt.GetText(1) == "\"") ||
                         (curPt.GetText(1) == "'"))
                {
                    string quote    = curPt.GetText(1);
                    string lastChar = quote;
                    curPt.CharRight(1);

                    //scan ahead until close
                    while (!((curPt.GetText(1) == quote) &&
                             (lastChar != "\\")))
                    {
                        lastChar = curPt.GetText(1);
                        curPt.CharRight(1);
                        if (curPt.AtEndOfLine)
                        {
                            throw new System.ArgumentException("Unexpected eol processing string");
                        }
                    }
                    curPt.CharRight(1);
                }
                else
                {
                    curPt.CharRight(1);
                }
            }
            return(true);
        }