Browse Source

add Ctrl+F7: Add selected text as watch; simplify EnqueueForEach

pull/59/merge
Siegfried Pammer 13 years ago
parent
commit
cb0f290477
  1. 16
      src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin
  2. 2
      src/AddIns/Debugger/Debugger.AddIn/Pads/WatchPad.cs
  3. 16
      src/AddIns/Debugger/Debugger.AddIn/Pads/WatchPadCommands.cs
  4. 56
      src/AddIns/Debugger/Debugger.AddIn/TreeModel/Utils.cs

16
src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.addin

@ -75,6 +75,16 @@
label = "${res:MainWindow.Windows.Debug.DebugExecutable}" label = "${res:MainWindow.Windows.Debug.DebugExecutable}"
class = "Debugger.AddIn.DebugExecutableMenuCommand"/> class = "Debugger.AddIn.DebugExecutableMenuCommand"/>
</Condition> </Condition>
<MenuItem id="AddExpressionBreakpoint"
insertafter="Toggle Breakpoint"
label = "${res:XML.MainMenu.DebugMenu.AddExpressionBreakpoint}"
shortcut="Shift|F7"
class = "Debugger.AddIn.AddExpressionBreakpointCommand"/>
<MenuItem id="AddWatchExpression"
insertafter="AddExpressionBreakpoint"
label = "${res:XML.MainMenu.DebugMenu.AddWatchExpression}"
shortcut="Ctrl|F7"
class = "Debugger.AddIn.AddWatchExpressionCommand"/>
</Path> </Path>
<Path name = "/SharpDevelop/Workbench/Pads"> <Path name = "/SharpDevelop/Workbench/Pads">
@ -128,12 +138,6 @@
defaultPosition = "Bottom, Hidden" /> defaultPosition = "Bottom, Hidden" />
</Path> </Path>
<Path name ="/SharpDevelop/Pads/WatchPad/ContextMenu">
<MenuItem id="AddWatch" label="${res:MainWindow.Windows.Debug.Watch.AddWatch}" class="Debugger.AddIn.AddWatchCommand" />
<MenuItem id="RemoveWatch" label="${res:MainWindow.Windows.Debug.Watch.RemoveWatch}" class="Debugger.AddIn.RemoveWatchCommand" />
<MenuItem id="ClearWatches" label="${res:MainWindow.Windows.Debug.Watch.RemoveAll}" class="Debugger.AddIn.ClearWatchesCommand" />
</Path>
<Path name = "/SharpDevelop/Dialogs/OptionsDialog"> <Path name = "/SharpDevelop/Dialogs/OptionsDialog">
<OptionPanel id = "Debugging" <OptionPanel id = "Debugging"
label = "${res:Dialog.Options.IDEOptions.Debugging}" label = "${res:Dialog.Options.IDEOptions.Debugging}"

2
src/AddIns/Debugger/Debugger.AddIn/Pads/WatchPad.cs

@ -56,7 +56,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
tree.ShowRoot = false; tree.ShowRoot = false;
tree.View = (GridView)res["variableGridView"]; tree.View = (GridView)res["variableGridView"];
tree.SetValue(GridViewColumnAutoSize.AutoWidthProperty, "50%;25%;25%"); tree.SetValue(GridViewColumnAutoSize.AutoWidthProperty, "50%;25%;25%");
//tree.ContextMenu = MenuService.CreateContextMenu(this, "/SharpDevelop/Pads/WatchPad/ContextMenu");
tree.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e) { tree.MouseDoubleClick += delegate(object sender, MouseButtonEventArgs e) {
if (this.tree.SelectedItem == null) { if (this.tree.SelectedItem == null) {
AddWatch(focus: true); AddWatch(focus: true);
@ -124,6 +123,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
process.EnqueueForEach( process.EnqueueForEach(
Dispatcher.CurrentDispatcher, Dispatcher.CurrentDispatcher,
expressions, expressions,
expr => this.Items.Add(MakeNode(expr)),
expr => this.Items.Add(MakeNode(expr)) expr => this.Items.Add(MakeNode(expr))
); );
} }

16
src/AddIns/Debugger/Debugger.AddIn/Pads/WatchPadCommands.cs

@ -3,6 +3,9 @@
using System; using System;
using System.Linq; using System.Linq;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using Debugger.AddIn.Pads; using Debugger.AddIn.Pads;
using Debugger.AddIn.Pads.Controls; using Debugger.AddIn.Pads.Controls;
using Debugger.AddIn.TreeModel; using Debugger.AddIn.TreeModel;
@ -47,4 +50,17 @@ namespace Debugger.AddIn
} }
} }
} }
public class AddWatchExpressionCommand : AbstractMenuCommand
{
public override void Run()
{
var editor = SD.GetActiveViewContentService<ITextEditor>();
if (editor == null) return;
var pad = SD.Workbench.GetPad(typeof(WatchPad));
if (pad == null) return;
pad.BringPadToFront();
((WatchPad)pad.PadContent).AddWatch(editor.SelectedText);
}
}
} }

56
src/AddIns/Debugger/Debugger.AddIn/TreeModel/Utils.cs

@ -7,6 +7,7 @@ using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Threading; using System.Windows.Threading;
using ICSharpCode.SharpDevelop;
using Debugger.AddIn.Pads.Controls; using Debugger.AddIn.Pads.Controls;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
@ -41,46 +42,39 @@ namespace Debugger.AddIn.TreeModel
); );
} }
public static void EnqueueForEach<T>(this Process process, Dispatcher dispatcher, IList<T> items, Action<T> work) public static void EnqueueForEach<T>(this Process process, Dispatcher dispatcher, IList<T> items, Action<T> work, Action<T> failAction = null)
{ {
long debuggeeStateWhenEnqueued = process.DebuggeeState; long debuggeeStateWhenEnqueued = process.DebuggeeState;
dispatcher.BeginInvoke( foreach (T item in items) {
DispatcherPriority.Normal, var workItem = item;
(Action)delegate { ProcessItems(process, dispatcher, 0, items, work, debuggeeStateWhenEnqueued); } dispatcher.BeginInvoke(
); DispatcherPriority.Normal,
(Action)delegate {
if (!ProcessItem(process, workItem, work, debuggeeStateWhenEnqueued) && failAction != null)
failAction(workItem);
}
);
}
} }
static void ProcessItems<T>(Process process, Dispatcher dispatcher, int startIndex, IList<T> items, Action<T> work, long debuggeeStateWhenEnqueued) static bool ProcessItem<T>(Process process, T item, Action<T> work, long debuggeeStateWhenEnqueued)
{ {
var watch = new System.Diagnostics.Stopwatch(); if (process.IsPaused && debuggeeStateWhenEnqueued == process.DebuggeeState) {
watch.Start(); try {
// Do the work, this may recursively enqueue more work
for (int i = startIndex; i < items.Count; i++) { work(item);
int index = i; return true;
if (process.IsPaused && debuggeeStateWhenEnqueued == process.DebuggeeState) { } catch (System.Exception ex) {
try { if (process == null || process.HasExited) {
// Do the work, this may recursively enqueue more work // Process unexpectedly exited - silently ignore
work(items[index]); } else {
} catch (System.Exception ex) { MessageService.ShowException(ex);
if (process == null || process.HasExited) {
// Process unexpectedly exited - silently ignore
} else {
MessageService.ShowException(ex);
}
break;
} }
} SD.Log.Error("ProcessItem cancelled", ex);
// if we are too slow move to background
if (watch.ElapsedMilliseconds > 100) {
dispatcher.BeginInvoke(
DispatcherPriority.Background,
(Action)delegate { ProcessItems(process, dispatcher, index + 1, items, work, debuggeeStateWhenEnqueued); }
);
break;
} }
} }
return false;
} }
} }

Loading…
Cancel
Save