Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
[Debugger] Add logpoints to the icon margin
Browse files Browse the repository at this point in the history
A log point is a breakpoint that just prints a message and continues. Add
support for them to the icon margin.
  • Loading branch information
iain holmes committed Apr 17, 2018
1 parent 7774db2 commit a2388e5
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
defaultHandler = "MonoDevelop.Debugger.NewCatchpointHandler"
_label = "New Exception Catchpoint"
icon = "md-catchpoint-new" />
<Command id = "MonoDevelop.Debugger.DebugCommands.ToggleLogpoint"
defaultHandler = "MonoDevelop.Debugger.ToggleLogpointHandler"
_label = "Toggle Logpoint" />
<Command id = "MonoDevelop.Debugger.DebugCommands.ShowBreakpoints"
defaultHandler = "MonoDevelop.Debugger.ShowBreakpointsHandler"
_label = "View Breakpoints"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public enum DebugCommands
SetNextStatement,
ShowNextStatement,
NewCatchpoint,
NewFunctionBreakpoint
NewFunctionBreakpoint,
ToggleLogpoint
}

class DebugHandler: CommandHandler
Expand Down Expand Up @@ -325,11 +326,27 @@ protected override void Run ()

protected override void Update (CommandInfo info)
{
var breakpoints = DebuggingService.Breakpoints;
info.Visible = DebuggingService.IsFeatureSupported (DebuggerFeatures.Breakpoints);
info.Enabled = IdeApp.Workbench.ActiveDocument != null &&
IdeApp.Workbench.ActiveDocument.Editor != null &&
IdeApp.Workbench.ActiveDocument.FileName != FilePath.Null &&
!DebuggingService.Breakpoints.IsReadOnly;
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.Where (bp => 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;
}
}
}

Expand Down Expand Up @@ -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<Logpoint> ()) {
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);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,15 @@
<Extension path = "/MonoDevelop/SourceEditor2/IconContextMenu/Editor">
<CommandItem id = "MonoDevelop.Ide.Editor.MessageBubbleCommands.Toggle" />
<SeparatorItem id = "Separator1" />
<CommandItem id = "MonoDevelop.Debugger.DebugCommands.ToggleLogpoint" />
<CommandItem id = "MonoDevelop.Debugger.DebugCommands.ToggleBreakpoint" />
<CommandItem id = "MonoDevelop.Ide.Commands.SearchCommands.ToggleBookmark" />
<SeparatorItem id = "Separator1" />
<CommandItem id = "MonoDevelop.Debugger.DebugCommands.NewBreakpoint" />
<CommandItem id = "MonoDevelop.Debugger.DebugCommands.ShowBreakpointProperties" />
<SeparatorItem id = "Separator1" />
<CommandItem id = "MonoDevelop.Debugger.DebugCommands.EnableDisableBreakpoint" />
<CommandItem id = "MonoDevelop.Debugger.DebugCommands.DisableAllBreakpoints" />
<SeparatorItem id = "Separator1" />
<CommandItem id = "MonoDevelop.Debugger.DebugCommands.RemoveBreakpoint" />
<CommandItem id = "MonoDevelop.Debugger.DebugCommands.ClearAllBreakpoints" />
<CommandItem id = "MonoDevelop.Ide.Commands.SearchCommands.ClearBookmarks" />
</Extension>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,25 @@ protected void ToggleFolding ()
#endregion

#region Bookmarks
[CommandUpdateHandler (SearchCommands.ToggleBookmark)]
[CommandUpdateHandler (SearchCommands.PrevBookmark)]
[CommandUpdateHandler (SearchCommands.NextBookmark)]
[CommandUpdateHandler (SearchCommands.ClearBookmarks)]
protected void UpdateBookmarkCommands (CommandInfo info)
{
info.Enabled = GetContent <IBookmarkBuffer> () != null;
}


[CommandUpdateHandler (SearchCommands.ToggleBookmark)]
protected void UpdateToggleBookmark (CommandInfo info)
{
info.Enabled = GetContent <IBookmarkBuffer> () != null;
var markBuffer = GetContent <IBookmarkBuffer> ();
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 ()
{
Expand Down

0 comments on commit a2388e5

Please sign in to comment.