/* internal void OnEncodingChanged(object sender, EncodingChangedEventArgs args)
         * {
         * }
         * internal void OnDirtyStateChanged(object sender, EventArgs args)
         * {
         * } */

        public CommentsManager(IWpfTextView view, ITextDocumentFactoryService textDocumentFactory, SVsServiceProvider serviceProvider)
        {
            // AddCommandFilter(view, new KeyBindingCommandFilter(view));            // #eiichi

            // #hang_no 1 コメントアウトしたらハングしなかった
            m_textDocumentFactory = textDocumentFactory;
            m_view  = view;
            m_layer = view.GetAdornmentLayer("CommentImageAdornmentLayer");

            // #hang_no 2
            m_view.TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument document);
            document.FileActionOccurred += OnFileActionOccurred;
            // document.EncodingChanged += OnEncodingChanged;
            // document.DirtyStateChanged += OnDirtyStateChanged;

            m_FileName = MyBookmarkManager.ToUpperFilePath(document.FilePath);

            Images       = new ConcurrentDictionary <int, CommentImage>();          // #Image Images = new ConcurrentDictionary
            RichTextBoxs = new ConcurrentDictionary <int, CommentRichTextBox>();    // #eiichi

            // MyBookmarkManager.SetView(this, serviceProvider);

            m_view.LayoutChanged     += OnLayoutChanged;
            m_view.GotAggregateFocus += delegate { MyBookmarkManager.SetView(this, serviceProvider); };
            m_view.Closed            += delegate { MyBookmarkManager.CloseView(this); };

            m_contentTypeName = view.TextBuffer.ContentType.TypeName;
            m_view.TextBuffer.ContentTypeChanged += OnContentTypeChanged;
            // m_view.TextBuffer.Delete

            m_errorTags = new List <ITagSpan <ErrorTag> >();
            m_Util      = new Util(m_view, serviceProvider);

            m_timer.Elapsed += _timer_Elapsed;
        }
        /* void AddCommandFilter(IWpfTextView textView, KeyBindingCommandFilter commandFilter)
         * {
         *  if (commandFilter.m_added == false)
         *  {
         *      //get the view adapter from the editor factory
         *      IOleCommandTarget next;
         *      IVsTextView view = editorFactory.GetViewAdapter(textView);
         *
         *      int hr = view.AddCommandFilter(commandFilter, out next);
         *
         *      if (hr == VSConstants.S_OK)
         *      {
         *          commandFilter.m_added = true;
         *          //you'll need the next target for Exec and QueryStatus
         *          if (next != null)
         *              commandFilter.m_nextTarget = next;
         *      }
         *  }
         * } */

        internal void OnFileActionOccurred(object sender, TextDocumentFileActionEventArgs args)
        {
            if (args.FileActionType == FileActionTypes.ContentLoadedFromDisk)
            {
                MyBookmarkManager.Reload(this);
            }
        }
        internal void OnLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)          // #eiichi OnLayoutChanged
        {
            // #hang_no 3
            try
            {
                if (!Enabled)
                {
                    return;
                }

                m_errorTags.Clear();

                int dline = e.NewSnapshot.LineCount - e.OldSnapshot.LineCount;
                if (dline != 0)
                {
                    foreach (ITextViewLine line in e.NewOrReformattedLines)
                    {
                        int editLineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
                        MyBookmarkManager.GetInstance().ChangeLine(editLineNumber + 1, dline);
                        return;
                    }

                    /* foreach (ITextViewLine line in e.TranslatedLines)
                     * {
                     *  int lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
                     *  m_editedLines[lineNumber] = line;
                     * } */
                }

                RequestRedrawView();

                foreach (ITextViewLine line in e.NewOrReformattedLines)
                {
                    int lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
                    m_editedLines[lineNumber] = line;            // #Image _editedLines[lineNumber] = line
                }

                ResetTimer();

                // Sometimes, on loading a file in an editor view, the line transform gets triggered before the image adornments
                // have been added, so the lines don't resize to the image height. So here's a workaround:
                // Changing the zoom level triggers the required update.
                // Need to do it twice - once to trigger the event, and again to change it back to the user's expected level.
                if (!m_initialised1)
                {
                    m_view.ZoomLevel++;
                    m_initialised1 = true;
                }
                if (!m_initialised2)
                {
                    m_view.ZoomLevel--;
                    m_initialised2 = true;
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Notify(ex, true);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 private void BookmarkTreeViewSelectionChanged(object sender, RoutedPropertyChangedEventArgs <Object> e)
 {
     // MessageBox.Show(((TreeViewItem)e.NewValue).Header.ToString());
     // MyBookmarkManager.Jump(((TreeViewItem)e.NewValue).Header.ToString());
     if (e.NewValue != null)
     {
         MyBookmarkManager.Jump(((TreeViewItem)e.NewValue).DataContext);
     }
 }
Exemplo n.º 6
0
        private void OnBookmarkOptCommand(object sender, EventArgs e)
        {
            MyBookmarkManager.GetInstance().DelBookmark();

            // 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);
        }
Exemplo n.º 8
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);
                }
            }
        }
Exemplo n.º 9
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); する
                }
            }
        }
Exemplo n.º 10
0
        public static bool Load(CommentsManager commentsManager)
        {
            try
            {
                s_Instandce = new MyBookmarkManager();

                using (StreamReader s = new StreamReader(s_bookmarkFileName))
                {
                    s_SaveJsonString = s.ReadToEnd();
                    var json = DynamicJson.Parse(s_SaveJsonString);
                    if (json != null)
                    {
                        foreach (string array1index in json.GetDynamicMemberNames())
                        {
                            var bpfjson = json[int.Parse(array1index)];
                            foreach (string bpf in bpfjson.GetDynamicMemberNames())
                            {
                                if (bpf == "Key")
                                {
                                    SetFileName(bpfjson[bpf]);
                                }
                                else if (bpf == "Value")
                                {
                                    foreach (string array2index in bpfjson[bpf].GetDynamicMemberNames())
                                    {
                                        var bpjson = bpfjson[bpf][int.Parse(array2index)];

                                        BookmarkPrims bookmarkPrims = s_Instandce.CreateBookmarkPrims();
                                        int           lineNo        = 1;
                                        foreach (string bp in bpjson.GetDynamicMemberNames())
                                        {
                                            if (bp == "Key")
                                            {
                                                lineNo = int.Parse(bpjson[bp].ToString());
                                                if (lineNo < 1)
                                                {
                                                    lineNo = 1;
                                                }
                                            }
                                            else if (bp == "Value")
                                            {
                                                // BookmarkPrim prim = bpjson[bp].Deserialize<BookmarkPrim>();
                                                dynamic      bpjsonv = bpjson[bp];
                                                BookmarkPrim prim    = new BookmarkPrim();
                                                prim.m_comment = GetJsonString(bpjsonv, "m_comment");
                                                prim.m_line0   = GetJsonString(bpjsonv, "m_line0");
                                                prim.m_line1   = GetJsonString(bpjsonv, "m_line1");
                                                prim.m_line2   = GetJsonString(bpjsonv, "m_line2");
                                                prim.SetTag();
                                                bookmarkPrims.TryAdd(lineNo, prim);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    s_Instandce.RedrawToolWindow();
                }
            }
            catch
            {
                return(false);
            }
            return(true);

            // return BinaryDeserialize<MyBookmarkManager>(s_bookmarkFileName, out s_Instandce);      // ブックマーク読み込み
        }
 public string RelativeFileName()
 {
     return(MyBookmarkManager.RelativeFileName(m_FileName));
 }