public void ChangeLine(int editLineNumber, int dline) { if (dline != 0) { BookmarkPrims bookmarkPrims = GetActiveBookmarkPrims(); // BookmarkPrims newBookmarkPrims = new BookmarkPrims(bookmarkPrims.GetCommentsManager()); List <int> keyList = new List <int>(); foreach (var bookmarkPrimIt in bookmarkPrims) { if (bookmarkPrimIt.Key >= editLineNumber) { keyList.Add(bookmarkPrimIt.Key); } } foreach (var key in keyList) { BookmarkPrim bookmarkPrim = null; bookmarkPrims.TryRemove(key, out bookmarkPrim); bookmarkPrims.TryAdd(key + dline, bookmarkPrim); // newBookmarkPrims.TryAdd(bookmarkPrimIt.Key + dline, bookmarkPrim); } /* foreach (var bookmarkPrimIt in newBookmarkPrims) * { * bookmarkPrims.TryAdd(bookmarkPrimIt.Key, bookmarkPrimIt.Value); * } */ Save(); bookmarkPrims.GetCommentsManager().SetBookmark(bookmarkPrims); RedrawToolWindow(); } }
// #ducoment BookmarkAdjustment private BookmarkPrims BookmarkAdjustment(BookmarkPrims bookmarkPrims) { BookmarkPrims newBookmarkPrims = bookmarkPrims; if (bookmarkPrims != null) { // bookmarkPrims.GetCommentsManager().GetView().TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument document); IWpfTextView textView = bookmarkPrims.GetCommentsManager().GetView(); SnapshotPoint caretPosition = textView.Caret.Position.BufferPosition; string documentText = caretPosition.Snapshot.GetText(); if (documentText != null) { // document のテキストを取得する List <string> doclist = new List <string>(); StringReader strReader = new StringReader(documentText); doclist.Add(@"TOF"); while (true) { string line = strReader.ReadLine(); if (line == null) { break; } doclist.Add(Util.GetWithoutUselessCharacter(line)); } doclist.Add(@"EOF"); doclist.Add(@"EOF2"); // doctext[0] = "TOF" // doctext[最後の行+1] = "EOF" string[] doctext = doclist.ToArray(); newBookmarkPrims = new BookmarkPrims(bookmarkPrims.GetCommentsManager()); foreach (var bookmarkPrim in bookmarkPrims) { int lineNo = bookmarkPrim.Key; SetAdjustmentLine(doctext, ref lineNo, bookmarkPrim.Value); bookmarkPrim.Value.m_line0 = doctext[lineNo]; bookmarkPrim.Value.m_line1 = doctext[lineNo + 1]; bookmarkPrim.Value.m_line2 = doctext[lineNo + 2]; newBookmarkPrims.TryAdd(lineNo, bookmarkPrim.Value); } m_FileBookmarkPrims[bookmarkPrims.GetCommentsManager().RelativeFileName()] = newBookmarkPrims; Save(); } } return(newBookmarkPrims); }
public void SetBookmark(BookmarkPrims bookmarkPrims) { var pipeline = new Markdig.MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); Viewbox viewbox = new Viewbox(); RichTextBoxs.Clear(); foreach (var it in bookmarkPrims) { int lineNo = it.Key - 1; bool redraw = false; CommentRichTextBox TextBox = null; if (!RichTextBoxs.ContainsKey(lineNo)) { TextBox = new CommentRichTextBox(it.Value); RichTextBoxs.TryAdd(lineNo, TextBox); redraw = true; } else if (RichTextBoxs[lineNo].m_comment != it.Value.m_comment) { TextBox = RichTextBoxs[lineNo]; redraw = true; } if (TextBox != null) { var html = Markdig.Markdown.ToHtml(it.Value.m_comment, pipeline); var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, true); CommentRichTextBox rtb = new CommentRichTextBox(); rtb.Document = XamlReader.Parse(xaml) as FlowDocument; SetLineHeight(rtb); double Height = GethDocumentHeight(viewbox, rtb); TextBox.Document = XamlReader.Parse(xaml) as FlowDocument; TextBox.Document.Background = Brushes.LightGray; SetLineHeight(TextBox); TextBox.Height = Height; TextBox.Visibility = Visibility.Visible; } if (redraw) { RequestRedrawLine(lineNo); } } }
/* private void OnWindowActivated(EnvDTE.Window GotFocus, EnvDTE.Window LostFocus) * { * } */ public BookmarkPrims CreateBookmarkPrims(CommentsManager commentsManager = null) { BookmarkPrims bookmarkPrims = null; if (!m_FileBookmarkPrims.ContainsKey(s_RelativeFileName)) { bookmarkPrims = new BookmarkPrims(commentsManager); m_FileBookmarkPrims.TryAdd(s_RelativeFileName, bookmarkPrims); } else { bookmarkPrims = m_FileBookmarkPrims[s_RelativeFileName]; bookmarkPrims.SetCommentsManager(commentsManager); } if (commentsManager != null) { bookmarkPrims = BookmarkAdjustment(bookmarkPrims); commentsManager.SetBookmark(bookmarkPrims); } return(bookmarkPrims); }
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); } } }
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); する } } }
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); // ブックマーク読み込み }
// ブックマークを追加、すでにあるなら 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); } } } }