private string GetTaskNameFromTechnology(string techName)
        {
            string configFile = System.IO.Path.GetDirectoryName(_dte.Solution.FullName) + TechnologicatorDefines.ConfigFile;

            _dte.ExecuteCommand("File.OpenFile", configFile);
            _dte.Find.MatchWholeWord    = false;
            _dte.Find.Action            = vsFindAction.vsFindActionFind;
            _dte.Find.Target            = vsFindTarget.vsFindTargetCurrentDocument;
            _dte.Find.MatchCase         = false;
            _dte.Find.Backwards         = false;
            _dte.Find.MatchInHiddenText = true;
            _dte.Find.PatternSyntax     = vsFindPatternSyntax.vsFindPatternSyntaxLiteral;
            _dte.Find.FindWhat          = "#define " + techName;
            if (_dte.Find.Execute() != vsFindResult.vsFindResultFound)
            {
                return("");
            }
            EnvDTE.TextSelection ts = _dte.ActiveWindow.Selection as EnvDTE.TextSelection;
            ts.SelectLine();
            string defLine          = ts.Text;
            string taskRegexPattern = TechnologicatorDefines.TaskRegex;

            System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(defLine, taskRegexPattern);

            if (m.Success)
            {
                return(m.Value);
            }
            else
            {
                return("");
            }
        }
        private bool SelectLines()
        {
            EnvDTE.TextSelection ts = _dte.ActiveWindow.Selection as EnvDTE.TextSelection;

            if (ts.IsEmpty)
            {
                ts.SelectLine();
                return(true);
            }
            else
            {
                int startLine = ts.AnchorPoint.Line;
                int endLine   = ts.ActivePoint.Line;

                if (endLine < startLine)
                {
                    int temp = startLine;
                    startLine = endLine;
                    endLine   = temp;
                    ts.SwapAnchor();
                }

                ts.EndOfLine(true);
                int endChar = ts.ActivePoint.LineCharOffset;


                ts.GotoLine(startLine, true);
                ts.MoveToLineAndOffset(endLine, endChar, true);

                return(false);
            }
        }
Ejemplo n.º 3
0
        static public void GetCursorWord(EnvDTE.TextSelection ts,out string name,out string longName,out int lineNum)
        {
            name     = null;
            longName = null;
            lineNum  = ts.AnchorPoint.Line;
            int lineOffset = ts.AnchorPoint.LineCharOffset;

            // If a line of text is selected, used as search word.
            var cursorStr = ts.Text.Trim();

            if (cursorStr.Length != 0 && cursorStr.IndexOf('\n') == -1)
            {
                name     = cursorStr;
                longName = cursorStr;
                return;
            }

            // Otherwise, use the word under the cursor.
            ts.SelectLine();
            string lineText = ts.Text;

            ts.MoveToLineAndOffset(lineNum,lineOffset);

            Regex           rx      = new Regex(@"\b(?<word>\w+)\b",RegexOptions.Compiled | RegexOptions.IgnoreCase);
            MatchCollection matches = rx.Matches(lineText);

            // Report on each match
            int lastStartIndex = 0;
            int lastEndIndex   = 0;

            for (int ithMatch = 0; ithMatch < matches.Count; ++ithMatch)
            {
                var    match      = matches[ithMatch];
                string word       = match.Groups["word"].Value;
                int    startIndex = match.Groups["word"].Index;
                int    endIndex   = startIndex + word.Length;
                int    lineIndex  = lineOffset - 1;
                if (startIndex <= lineIndex && endIndex >= lineIndex)
                {
                    name     = word;
                    longName = word;
                    var midStr = lineText.Substring(lastEndIndex,(startIndex - lastEndIndex));
                    if (ithMatch > 0 && midStr == "::")
                    {
                        longName = lineText.Substring(lastStartIndex,(endIndex - lastStartIndex));
                        break;
                    }
                }
                lastStartIndex = startIndex;
                lastEndIndex   = endIndex;
            }
        }
Ejemplo n.º 4
0
        //! \brief Gets either the selected text or the current line
        //! EnvDTE.TextSelection: [https://msdn.microsoft.com/en-us/library/envdte.textselection.aspx]
        protected string GetCurrentSelectionOrLine()
        {
            EnvDTE.TextSelection selection = (EnvDTE.TextSelection) this.CommandManager.ApplicationObject.ActiveDocument.Selection;
            string selectionText           = selection.Text.Trim();

            if (selectionText != "")
            {
                return(selectionText);
            }
            int currentLine = selection.CurrentLine;

            selection.SelectLine();
            string lineText = selection.Text.Trim();

            selection.GotoLine(currentLine, false);
            selection.Text = selectionText;
            return(lineText);
        }
Ejemplo n.º 5
0
        // ブックマークを追加、すでにあるなら edit する
        public void AddEditBookmark()
        {
            // EnvDTE.TextDocument textDocument = GetTextDocument();
            EnvDTE.TextSelection textSelection = GetTextSelection();
            if (textSelection != null)
            {
                Int32 lineNo = GetCursorLineNo();
                if (lineNo >= 1)
                {
                    BookmarkPrims bookmarkPrims = GetActiveBookmarkPrims();
                    BookmarkPrim  prim          = null;
                    if (bookmarkPrims.ContainsKey(lineNo))
                    {       // BookmarkPrim を edit する
                        prim = bookmarkPrims[lineNo];
                    }
                    else
                    {       // BookmarkPrim 作る
                        prim           = new BookmarkPrim();
                        prim.m_comment = "test";
                        textSelection.SelectLine();
                        prim.m_line0 = textSelection.Text;

                        if (lineNo + 1 <= textSelection.BottomLine)
                        {
                            textSelection.GotoLine(lineNo + 1);
                            textSelection.Cancel();
                            textSelection.SelectLine();
                            prim.m_line1 = textSelection.Text;
                        }
                        else
                        {
                            prim.m_line1 = "EOF";
                        }

                        if (lineNo + 2 <= textSelection.BottomLine)
                        {
                            textSelection.GotoLine(lineNo + 2);
                            textSelection.Cancel();
                            textSelection.SelectLine();
                            prim.m_line2 = textSelection.Text;
                        }
                        else
                        {
                            prim.m_line2 = "EOF";
                        }

                        bookmarkPrims.TryAdd(lineNo, prim);
                    }
                    EditBookmark(prim);
                    if (prim.m_comment == "")
                    {
                        DelBookmark();
                    }
                    else
                    {
                        bookmarkPrims.TryAdd(lineNo, prim);
                        bookmarkPrims.GetCommentsManager().SetBookmark(bookmarkPrims);
                        Save();
                        RedrawToolWindow();
                        textSelection.GotoLine(lineNo + 1);
                    }
                }
            }
        }