Beispiel #1
0
        /// <summary>
        /// Tries to match Regex on input text
        /// </summary>
        /// <returns>Position in line at start of matched image comment. -1 if not matched</returns>
        public static int Match(string contentTypeName, string lineText, out string matchedText)
        {
            matchedText = null;
            var result = -1;

            if (!string.IsNullOrEmpty(lineText))
            {
                Match match = null;
                switch (contentTypeName)
                {
                case ContentTypes.Cpp:
                case ContentTypes.CSharp:
                case ContentTypes.Java:
                case ContentTypes.JavaScript:
                case ContentTypes.TypeScript:
                    match = _csharpImageCommentRegex.Match(lineText);
                    break;

                case ContentTypes.VisualBasic:
                    match = _vbImageCommentRegex.Match(lineText);
                    break;

                case ContentTypes.FSharp:
                    // match // <image or /// <image
                    match = _csharpImageCommentRegex.Match(lineText);
                    if (match == null || string.IsNullOrEmpty(match.Value))
                    {
                        // match (*
                        match = _fSharpImageCommentRegex.Match(lineText);
                    }
                    if (match == null || string.IsNullOrEmpty(match.Value))
                    {
                        // just match <image, could be in a multi-line comment
                        match = _xmlImageTagRegex.Match(lineText);
                    }
                    break;

                case ContentTypes.Python:
                    match = _pythonImageCommentRegex.Match(lineText);
                    break;

                default:
                    MyBookmarkManager.Log("Unsupported content type: " + contentTypeName);
                    break;
                }

                if (match != null)
                {
                    matchedText = match.Value;
                    if (!string.IsNullOrEmpty(matchedText))
                    {
                        result = match.Index;
                    }
                }
            }

            return(result);
        }
        // #command OnBookmarkAddCommand
        private void OnBookmarkAddCommand(object sender, EventArgs e)
        {
            MyBookmarkManager.Log("OnBookmarkAddCommand");

            MyBookmarkManager.GetInstance().AddEditBookmark();

            // Toggle the checked state of this command

            /* MenuCommand thisCommand = sender as MenuCommand;
             * if (thisCommand != null)
             * {
             *  thisCommand.Checked = !thisCommand.Checked;
             * } */
        }
        private static string GetErrorMessage(Exception exception)
        {
            MyBookmarkManager.Log("Problem parsing comment text or loading image...\n" + exception);

            string message;

            if (exception is XmlException)
            {
                message = "Problem with comment format: " + exception.Message;
            }
            else if (exception is NotSupportedException)
            {
                message = exception.Message + "\nThis problem could be caused by a corrupt, invalid or unsupported image file.";
            }
            else
            {
                message = exception.Message;
            }
            return(message);
        }
Beispiel #4
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 #5
0
        public static void SetView(CommentsManager commentsManager, SVsServiceProvider serviceProvider)
        {
            if (serviceProvider != null)
            {
                s_dte = (DTE)serviceProvider.GetService(typeof(DTE));
            }

            commentsManager.GetView().TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument document);
            ProjectItem projectItem = s_dte.Solution.FindProjectItem(document.FilePath);

            string backFileName = s_FullFileName;

            if (projectItem != null && projectItem.ContainingProject != null)
            {
                string solutionDirectory = "";
                string projectPath       = projectItem.ContainingProject.FileName;
                if (projectPath != "") // projectPath will be empty if file isn't part of a projec+t.
                {
                    s_projectDirectory = Path.GetDirectoryName(projectPath) + @"\";
                }

                string solutionPath = s_dte.Solution.FileName;
                if (solutionPath != "") // solutionPath will be empty if project isn't part of a saved solution
                {
                    solutionDirectory = Path.GetDirectoryName(solutionPath) + @"\";
                    solutionDirectory = solutionDirectory.ToUpper();
                }

                if (s_solutionDirectory == solutionDirectory)
                {       // Solution は同じ
                    SetFileName(commentsManager.m_FileName);
                }
                else
                {       // 新しい Solution が選択された
                    if (s_Instandce != null && s_bookmarkFileName != "")
                    {
                        Save();
                    }

                    s_solutionDirectory = solutionDirectory;
                    SetFileName(commentsManager.m_FileName);

                    // s_bookmarkDirectory = @"C:\MyProj\temp\mbook\";
                    s_bookmarkDirectory = s_solutionDirectory + @"MyBookmark\";
                    Directory.CreateDirectory(s_bookmarkDirectory);
                    s_bookmarkFileName = s_bookmarkDirectory + @"MyBookmark.mbk";

                    /* s_bookmarkFileName = s_solutionDirectory.Substring(3);
                     * s_bookmarkFileName = s_bookmarkFileName.Replace(':', '_');
                     * s_bookmarkFileName = s_bookmarkFileName.Replace('\\', '-');
                     * s_bookmarkFileName = s_bookmarkDirectory + s_bookmarkFileName + @".mbk"; */

                    Load(commentsManager);

                    string debugLogFileName = s_bookmarkDirectory + @"\debug.txt"; // debug.txtにログを出力する。
                    File.Delete(debugLogFileName);
                    s_LogWriter = new StreamWriter(debugLogFileName, true);
                    MyBookmarkManager.Log("### DebugLog Start");
                }
            }

            SetFileName(commentsManager.m_FileName);
            if (s_FullFileName != backFileName)
            {
                if (s_Instandce != null)
                {
                    BookmarkPrims bookmarkPrims = s_Instandce.CreateBookmarkPrims(commentsManager);            // m_FileBookmarkPrims.TryAdd(s_fileName, bookmarkPrims); する
                }
            }
        }