From a2388e5a22b1eb3c964276c0b10819f5cf0c87fc Mon Sep 17 00:00:00 2001 From: iain holmes Date: Tue, 17 Apr 2018 11:22:02 +0100 Subject: [PATCH] [Debugger] Add logpoints to the icon margin A log point is a breakpoint that just prints a message and continues. Add support for them to the icon margin. --- .../MonoDevelop.Debugger.addin.xml | 3 + .../MonoDevelop.Debugger/DebugCommands.cs | 80 +++++++++++++++++-- .../MonoDevelop.SourceEditor.addin.xml | 3 +- .../ViewCommandHandlers.cs | 14 +++- 4 files changed, 91 insertions(+), 9 deletions(-) diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.addin.xml b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.addin.xml index 14ce427929e..05404cc24c4 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.addin.xml +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.addin.xml @@ -126,6 +126,9 @@ defaultHandler = "MonoDevelop.Debugger.NewCatchpointHandler" _label = "New Exception Catchpoint" icon = "md-catchpoint-new" /> + bp.GetType () == typeof (Breakpoint)).FirstOrDefault () != null) { + info.Text = GettextCatalog.GetString ("Remove Breakpoint"); + } else { + info.Text = GettextCatalog.GetString ("New Breakpoint"); + } + } + + info.Enabled = true; + } else { + info.Enabled = false; + } } } @@ -702,4 +719,57 @@ protected override void Run () DebuggingService.ShowNextStatement (); } } + + class ToggleLogpointHandler : CommandHandler + { + protected override void Update(CommandInfo info) + { + var breakpoints = DebuggingService.Breakpoints; + + info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Breakpoints); + if (IdeApp.Workbench.ActiveDocument != null && + IdeApp.Workbench.ActiveDocument.Editor != null && + IdeApp.Workbench.ActiveDocument.FileName != FilePath.Null && + !breakpoints.IsReadOnly) { + lock (breakpoints) { + var filename = IdeApp.Workbench.ActiveDocument.FileName; + var line = IdeApp.Workbench.ActiveDocument.Editor.CaretLine; + if (breakpoints.ContainsLogpoint (filename, line)) { + info.Text = GettextCatalog.GetString ("Remove Logpoint"); + } else { + info.Text = GettextCatalog.GetString ("New Logpoint"); + } + info.Enabled = true; + } + } else { + info.Enabled = false; + } + } + + protected override void Run() + { + var activeDoc = IdeApp.Workbench.ActiveDocument; + if (activeDoc != null && activeDoc.Editor != null && activeDoc.FileName != FilePath.Null) { + var filename = activeDoc.FileName; + var line = activeDoc.Editor.CaretLine; + var column = activeDoc.Editor.CaretColumn; + + var breakpoints = DebuggingService.Breakpoints; + + lock (breakpoints) { + if (breakpoints.ContainsLogpoint (filename, line)) { + foreach (var lp in breakpoints.OfType ()) { + if (BreakpointStore.FileNameEquals (lp.FileName, filename) && (lp.OriginalLine == line || lp.Line == line)) { + breakpoints.Remove (lp); + break; + } + } + } else { + var bp = new Logpoint (filename, line, column); + breakpoints.Add (bp); + } + } + } + } + } } diff --git a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml index 8280a14dfda..b5f4a05a2a1 100644 --- a/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml +++ b/main/src/addins/MonoDevelop.SourceEditor2/MonoDevelop.SourceEditor.addin.xml @@ -131,16 +131,15 @@ + - - diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ViewCommandHandlers.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ViewCommandHandlers.cs index 864ca29f0ea..4aca6a54c05 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ViewCommandHandlers.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ViewCommandHandlers.cs @@ -554,7 +554,6 @@ protected void ToggleFolding () #endregion #region Bookmarks - [CommandUpdateHandler (SearchCommands.ToggleBookmark)] [CommandUpdateHandler (SearchCommands.PrevBookmark)] [CommandUpdateHandler (SearchCommands.NextBookmark)] [CommandUpdateHandler (SearchCommands.ClearBookmarks)] @@ -562,7 +561,18 @@ protected void UpdateBookmarkCommands (CommandInfo info) { info.Enabled = GetContent () != null; } - + + [CommandUpdateHandler (SearchCommands.ToggleBookmark)] + protected void UpdateToggleBookmark (CommandInfo info) + { + info.Enabled = GetContent () != null; + var markBuffer = GetContent (); + Debug.Assert (markBuffer != null); + int position = markBuffer.CursorPosition; + + info.Text = markBuffer.IsBookmarked (position) ? GettextCatalog.GetString ("Remove Bookmark") : GettextCatalog.GetString ("New Bookmark"); + } + [CommandHandler (SearchCommands.ToggleBookmark)] public void ToggleBookmark () {