Beispiel #1
0
        private void timer_Jump(object sender, System.Timers.ElapsedEventArgs e)
        {
            m_timer.Stop();

            if (m_activeDocumentFileName != null)
            {
                s_dte.ExecuteCommand("Window.ActivateDocumentWindow");
                // s_dte.ExecuteCommand("File.OpenFile", m_activeDocumentFileName);
                s_dte.ItemOperations.OpenFile(m_activeDocumentFileName, EnvDTE.Constants.vsViewKindTextView);

                Document document = GetActiveDocument();
                if (document != null)
                {
                    EnvDTE.TextSelection textSelection = (EnvDTE.TextSelection)(document.Selection);
                    textSelection.GotoLine(m_activeDocumentLineNo, false);
                    document.Activate();
                    if (document.Windows.Count > 0)
                    {
                        document.Windows.Item(1).Activate();
                    }
                    textSelection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn);
                }

                m_activeDocumentFileName = null;
            }
        }
        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);
            }
        }
Beispiel #3
0
        internal void FillPreviewFromDocument(BlockCollection blocks, EnvDTE.TextSelection selection, ResultItem resultLine)
        {
            if (selection != null)
            {
                selection.EndOfDocument();
                int docLength  = selection.CurrentLine;
                int countEmpty = 0;

                Paragraph paragraph = new Paragraph();
                blocks.Add(paragraph);

                //Pre
                for (int i = resultLine.lineNumber.Value - 2; i < 1; i++)
                {
                    paragraph.Inlines.Add(new Run("\n"));
                    countEmpty++;
                }
                for (int i = Math.Max(1, resultLine.lineNumber.Value - 2); i < resultLine.lineNumber.Value; i++)
                {
                    selection.GotoLine(i, true);
                    paragraph.Inlines.Add(new Run(selection.Text + "\n"));
                }
                //Res
                selection.GotoLine(resultLine.lineNumber.Value, true);
                (string pre, string res, string post) = resultLine.GetSplitLine(selection.Text, false);
                paragraph.Inlines.Add(new Run(pre));
                paragraph.Inlines.Add(new Run(res)
                {
                    Foreground = Brushes.Red
                });
                paragraph.Inlines.Add(new Run(post + "\n"));
                //Post
                for (int i = 1; i <= Math.Min(2, docLength - resultLine.lineNumber.Value); i++)
                {
                    selection.GotoLine(resultLine.lineNumber.Value + i, true);
                    paragraph.Inlines.Add(new Run(selection.Text + "\n"));
                }
            }
            return;
        }
Beispiel #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);
        }
Beispiel #5
0
        public void DelBookmark()
        {
            MyBookmarkManager.Log("DelBookmark");

            BookmarkPrims bookmarkPrims = GetActiveBookmarkPrims();
            int           lineNo        = GetCursorLineNo();

            if (lineNo >= 1)
            {
                MyBookmarkManager.Log("bookmarkPrims.Remove lineNo=" + lineNo);
                BookmarkPrim prim = null;
                bookmarkPrims.TryRemove(lineNo, out prim);
                // bookmarkPrims.GetCommentsManager().DelBookmark(lineNo);
                Save();
                bookmarkPrims.GetCommentsManager().SetBookmark(bookmarkPrims);
                RedrawToolWindow();
                EnvDTE.TextSelection textSelection = GetTextSelection();
                if (textSelection != null)
                {
                    textSelection.GotoLine(GetCursorLineNo() + 1);
                }
            }
        }
Beispiel #6
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);
                    }
                }
            }
        }