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(); } }
private void EditBookmark(BookmarkPrim prim) { CommentEditor commentEditor = new CommentEditor(); commentEditor.editTextBox.Text = prim.m_comment; commentEditor.ShowDialog(); prim.m_comment = commentEditor.editTextBox.Text; prim.SetTag(); commentEditor.Dispose(); }
public CommentRichTextBox(BookmarkPrim bookmarkPrim) : base() { // this.AcceptsReturn = true; // this.AcceptsTab = true; // Document.Blocks.FirstBlock.LineHeight = 1; m_bookmarkPrim = bookmarkPrim; m_comment = bookmarkPrim.m_comment; AppendText("a"); }
public VBookmarkPrim(string fileName, int lineNo, BookmarkPrim bookmarkPrim) { lineNo++; m_FileName = ToUpperFilePath(fileName); int idx = m_FileName.LastIndexOf(@"\"); m_Label = m_FileName.Substring(idx + 1); m_Label = m_Label + @":" + lineNo + @" " + bookmarkPrim.m_line; m_LineNo = lineNo; m_BookmarkPrim = bookmarkPrim; }
// #document SetAdjustmentLine private void SetAdjustmentLine(string[] doctext, ref int lineNo, BookmarkPrim bookmarkPrim) { int like = int.MaxValue; GetLikeLines(doctext, bookmarkPrim.m_line1, ref lineNo, ref like, -1); if (like == 0) { return; } GetLikeLines(doctext, bookmarkPrim.m_line0, ref lineNo, ref like, 0); if (like == 0) { return; } GetLikeLines(doctext, bookmarkPrim.m_line2, ref lineNo, ref like, -2); }
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 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); } } } }
public void RedrawToolWindow() { SortedDictionary <string, List <VBookmarkPrim> > labels = new SortedDictionary <string, List <VBookmarkPrim> >(); foreach (var bookmarkPrims in m_FileBookmarkPrims) { foreach (var bookmarkPrimIt in bookmarkPrims.Value) { BookmarkPrim bookmarkPrim = bookmarkPrimIt.Value; List <VBookmarkPrim> bookmarkPrimList = null; if (labels.ContainsKey(bookmarkPrim.m_tag)) { bookmarkPrimList = labels[bookmarkPrim.m_tag]; } else { bookmarkPrimList = new List <VBookmarkPrim>(); labels.Add(bookmarkPrim.m_tag, bookmarkPrimList); } VBookmarkPrim vBookmarkPrim = new VBookmarkPrim(bookmarkPrims.Key, bookmarkPrimIt.Key, bookmarkPrim); bookmarkPrimList.Add(vBookmarkPrim); } } /* ToolWindowControl toolWindowControl = ToolWindowControl.GetInstance(); * System.Windows.Forms.TreeView treeView = toolWindowControl.m_BookmarkTreeView; */ var treeView = ToolWindowControl.GetBookmarkTreeView(); if (treeView != null) { SortedDictionary <string, TreeViewItem> treeViewItems = new SortedDictionary <string, TreeViewItem>(); foreach (var item in treeView.Items) { TreeViewItem treeViewItem = item as TreeViewItem; if (treeViewItem != null) { treeViewItems.Add(treeViewItem.Header.ToString(), treeViewItem); } } // treeView.Items.Clear(); foreach (var label in labels) { TreeViewItem treeViewItem = null; string keystr = label.Key.ToString(); if (treeViewItems.ContainsKey(keystr)) { treeViewItem = treeViewItems[keystr]; // TreeViewItem prim = null; // treeViewItems.TryRemove(keystr, out prim); treeViewItems.Remove(keystr); treeViewItem.Items.Clear(); } else { treeViewItem = new TreeViewItem(); treeViewItem.Header = label.Key.ToString(); treeView.Items.Add(treeViewItem); } foreach (var vBookmarkPrim in label.Value) { TreeViewItem item = new TreeViewItem(); item.DataContext = vBookmarkPrim; item.Header = vBookmarkPrim.m_Label; treeViewItem.Items.Add(item); } } foreach (var treeViewItem in treeViewItems) { treeView.Items.Remove(treeViewItem.Value); } } }