From ffad0368943424d1d53437a547b4b6932a9ce6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Mon, 8 Jan 2007 19:44:43 +0000 Subject: [PATCH] Unified model for both Local Variables Pad and Tooltips git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2270 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Debugger.AddIn.csproj | 8 + .../Project/Src/Pads/LocalVarPad.cs | 43 +---- .../Src/Pads/TreeListViewDebuggerItem.cs | 82 +++------ .../Src/Service/DynamicTreeDebuggerRow.cs | 171 +++--------------- .../Project/Src/Service/WindowsDebugger.cs | 15 ++ .../Project/Src/Variables/BaseTypeItem.cs | 124 +++++++++++++ .../Project/Src/Variables/FixedItem.cs | 74 ++++++++ .../Project/Src/Variables/ListItem.cs | 53 ++++++ .../Src/Variables/ListItemEventArgs.cs | 27 +++ .../Project/Src/Variables/ValueItem.cs | 154 ++++++++++++++++ 10 files changed, 514 insertions(+), 237 deletions(-) create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/BaseTypeItem.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/FixedItem.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ListItem.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ListItemEventArgs.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ValueItem.cs diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj index 1017ce4773..4da39c6ba2 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj @@ -67,6 +67,11 @@ + + + + + @@ -116,6 +121,9 @@ False + + + \ No newline at end of file diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs index 317b42bf1b..d1923d11a2 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LocalVarPad.cs @@ -7,9 +7,11 @@ using System; using System.Windows.Forms; -using Debugger; + using ICSharpCode.Core; +using Debugger; + namespace ICSharpCode.SharpDevelop.Gui.Pads { public class LocalVarPad : DebuggerPad @@ -51,17 +53,11 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads RedrawContent(); } - static string privateMembersName, staticMembersName, privateStaticMembersName; - public override void RedrawContent() { name.Text = ResourceService.GetString("Global.Name"); val.Text = ResourceService.GetString("Dialog.HighlightingEditor.Properties.Value"); type.Text = ResourceService.GetString("ResourceEditor.ResourceEdit.TypeColumn"); - - privateMembersName = StringParser.Parse("<${res:MainWindow.Windows.Debug.LocalVariables.PrivateMembers}>"); - staticMembersName = StringParser.Parse("<${res:MainWindow.Windows.Debug.LocalVariables.StaticMembers}>"); - privateStaticMembersName = StringParser.Parse("<${res:MainWindow.Windows.Debug.LocalVariables.PrivateStaticMembers}>"); } // This is a walkarond for a visual issue @@ -92,38 +88,17 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads localVarList.BeginUpdate(); localVarList.Items.Clear(); if (debuggedProcess != null) { - AddVariableCollectionToTree(debuggedProcess.LocalVariables, localVarList.Items); + foreach(NamedValue val in debuggedProcess.LocalVariables) { + localVarList.Items.Add(new TreeListViewDebuggerItem(val)); + } } localVarList.EndUpdate(); } - //delegate void AddVariableMethod(NamedValue val); - - public static void AddVariableCollectionToTree(NamedValueCollection collection, TreeListViewItemCollection tree) - { -// foreach(VariableCollection sub in varCollection.SubCollections) { -// VariableCollection subCollection = sub; -// TreeListViewItem subMenu = new TreeListViewItem("<" + subCollection.Name + ">", 0); -// subMenu.SubItems.Add(subCollection.Value); -// tree.Add(subMenu); -// TreeListViewItem.TreeListViewItemHanlder populate = null; -// populate = delegate { -// AddVariableCollectionToTree(subCollection, subMenu.Items); -// subMenu.AfterExpand -= populate; -// }; -// subMenu.AfterExpand += populate; -// } - foreach(NamedValue val in collection) { - tree.Add(new TreeListViewDebuggerItem(val)); - } - } - void localVarList_BeforeExpand(object sender, TreeListViewCancelEventArgs e) { if (debuggedProcess.IsPaused) { - if (e.Item is TreeListViewDebuggerItem) { - ((TreeListViewDebuggerItem)e.Item).BeforeExpand(); - } + ((TreeListViewDebuggerItem)e.Item).Populate(); } else { MessageService.ShowMessage("${res:MainWindow.Windows.Debug.LocalVariables.CannotExploreVariablesWhileRunning}"); e.Cancel = true; @@ -138,9 +113,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads static void UpdateSubTree(TreeListViewItem tree) { foreach(TreeListViewItem item in tree.Items) { - if (item is TreeListViewDebuggerItem) { - ((TreeListViewDebuggerItem)item).Update(); - } + ((TreeListViewDebuggerItem)item).Update(); if (item.IsExpanded) UpdateSubTree(item); } } diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/TreeListViewDebuggerItem.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/TreeListViewDebuggerItem.cs index 64c8418681..bf39a4b99d 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/TreeListViewDebuggerItem.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/TreeListViewDebuggerItem.cs @@ -15,48 +15,39 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads { public class TreeListViewDebuggerItem: TreeListViewItem { - NamedValue val; + ListItem listItem; + bool populated = false; - bool dirty = true; - public NamedValue Value { + public ListItem ListItem { get { - return val; + return listItem; } } - public bool Highlight { - set { - if (value) { - if (SubItems[1].ForeColor != Color.Blue) { // smart update - SubItems[1].ForeColor = Color.Blue; - SubItems[1].Font = new Font(SubItems[1].Font, FontStyle.Bold); - } + bool IsVisible { + get { + if (this.Parent == null) { + return true; } else { - if (SubItems[1].ForeColor != Color.Black) { // smart update - SubItems[1].ForeColor = Color.Black; - SubItems[1].Font = new Font(SubItems[1].Font, FontStyle.Regular); + foreach(TreeListViewItem parent in this.ParentsInHierarch) { + if (!parent.IsExpanded) return false; } + return true; } } } - bool IsVisible { - get { - if (this.Parent == null) return true; - foreach(TreeListViewItem parent in this.ParentsInHierarch) { - if (!parent.IsExpanded) return false; - } - return true; - } + public TreeListViewDebuggerItem(NamedValue val): this(new ValueItem(val)) + { + } - public TreeListViewDebuggerItem(NamedValue val) + public TreeListViewDebuggerItem(ListItem listItem) { - this.val = val; + this.listItem = listItem; - val.Changed += delegate { dirty = true; Update(); }; - val.Expired += delegate { this.Remove(); }; + listItem.Changed += delegate { Update(); }; SubItems.Add(""); SubItems.Add(""); @@ -66,48 +57,29 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads public void Update() { - if (!dirty) return; if (!IsVisible) return; - DateTime startTime = Debugger.Util.HighPrecisionTimer.Now; - if (this.TreeListView != null) { ((DebuggerTreeListView)this.TreeListView).DelayRefresh(); - Highlight = (val.AsString != SubItems[1].Text); } - this.SubItems[0].Text = val.Name; - this.SubItems[1].Text = val.AsString; - this.SubItems[2].Text = val.IsNull ? String.Empty : val.Type.FullName; - - this.ImageIndex = DebuggerIcons.GetImageListIndex(val); + this.ImageIndex = listItem.ImageIndex; + this.SubItems[0].Text = listItem.Name; + this.SubItems[1].Text = listItem.Text; + this.SubItems[2].Text = listItem.Type; - if (!IsExpanded) { - // Show plus sign - if ((val.IsObject || val.IsArray) && Items.Count == 0) { - TreeListViewItem dummy = new TreeListViewItem(); - this.AfterExpand += delegate { dummy.Remove(); }; - Items.Add(dummy); - } + if (!IsExpanded && !populated && listItem.HasSubItems) { + Items.Add(new TreeListViewItem()); // Show plus sign } - - dirty = false; - - TimeSpan totalTime = Debugger.Util.HighPrecisionTimer.Now - startTime; - //val.Process.TraceMessage("Local Variables Pad item updated: " + val.Name + " (" + totalTime.TotalMilliseconds + " ms)"); } - public void BeforeExpand() + public void Populate() { if (!populated) { Items.Clear(); - if (val.IsArray) { - // Do not sort names of array items - this.Items.SortOrder = SortOrder.None; - LocalVarPad.AddVariableCollectionToTree(val.GetArrayElements(), this.Items); - } else if (val.IsObject) { - this.Items.SortOrder = SortOrder.Ascending; - LocalVarPad.AddVariableCollectionToTree(val.GetMembers(), this.Items); + this.Items.SortOrder = SortOrder.None; + foreach(ListItem subItem in listItem.SubItems) { + Items.Add(new TreeListViewDebuggerItem(subItem)); } populated = true; } diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/DynamicTreeDebuggerRow.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/DynamicTreeDebuggerRow.cs index e241e058fa..81bd73231d 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/DynamicTreeDebuggerRow.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/DynamicTreeDebuggerRow.cs @@ -26,42 +26,32 @@ namespace ICSharpCode.SharpDevelop.Services // 2 = text // 3 = value - NamedValue val; + ListItem listItem; + Image image; bool populated = false; bool visible = true; - public NamedValue Value { - get { - return val; - } - set { - val = value; - } - } - - public static bool ShowValuesInHexadecimal { + public ListItem ListItem { get { - return ((WindowsDebugger)DebuggerService.CurrentDebugger).Properties.Get("ShowValuesInHexadecimal", false); - } - set { - ((WindowsDebugger)DebuggerService.CurrentDebugger).Properties.Set("ShowValuesInHexadecimal", value); + return listItem; } } - public DynamicTreeDebuggerRow() + public DynamicTreeDebuggerRow(NamedValue val): this(new ValueItem(val)) { + } - public DynamicTreeDebuggerRow(NamedValue val) + public DynamicTreeDebuggerRow(ListItem listItem) { - if (val == null) throw new ArgumentNullException("val"); + if (listItem == null) throw new ArgumentNullException("listItem"); - this.val = val; - this.val.Changed += delegate { Update(); }; + this.listItem = listItem; + this.listItem.Changed += delegate { Update(); }; this.Shown += delegate { visible = true; - DoInPausedState( delegate { Update(); } ); + WindowsDebugger.DoInPausedState( delegate { Update(); } ); }; this.Hidden += delegate { visible = false; @@ -80,17 +70,13 @@ namespace ICSharpCode.SharpDevelop.Services { if (!visible) return; - image = DebuggerIcons.GetImage(val); + this.image = listItem.Image; this[1].Text = ""; // Icon - this[2].Text = val.Name; - if (ShowValuesInHexadecimal && val.IsInteger) { - this[3].Text = String.Format("0x{0:X}", val.PrimitiveValue); - } else { - this[3].Text = val.AsString; - } - this[3].AllowLabelEdit = val.IsInteger && !ShowValuesInHexadecimal; + this[2].Text = listItem.Name; + this[3].Text = listItem.Text; + this[3].AllowLabelEdit = listItem.CanEditText; - this.ShowPlus = val.IsObject || val.IsArray; + this.ShowPlus = listItem.HasSubItems; this.ShowMinusWhileExpanded = true; } @@ -103,48 +89,16 @@ namespace ICSharpCode.SharpDevelop.Services void OnLabelEdited(object sender, DynamicListEventArgs e) { - string newValue = ((DynamicListItem)sender).Text; - try { - val.PrimitiveValue = newValue; - } catch (NotSupportedException) { - string format = ResourceService.GetString("MainWindow.Windows.Debug.LocalVariables.CannotSetValue.BadFormat"); - string msg = String.Format(format, newValue, val.Type.ManagedType.ToString()); - MessageService.ShowMessage(msg ,"${res:MainWindow.Windows.Debug.LocalVariables.CannotSetValue.Title}"); - } catch (COMException) { - // COMException (0x80131330): Cannot perfrom SetValue on non-leaf frames. - // Happens if trying to set value after exception is breaked - MessageService.ShowMessage("${res:MainWindow.Windows.Debug.LocalVariables.CannotSetValue.UnknownError}", - "${res:MainWindow.Windows.Debug.LocalVariables.CannotSetValue.Title}"); - } + listItem.SetText(((DynamicListItem)sender).Text); } void OnMouseDown(object sender, DynamicListMouseEventArgs e) { if (e.Button == MouseButtons.Right) { - ContextMenuStrip menu = new ContextMenuStrip(); - - ToolStripMenuItem copyItem; - copyItem = new ToolStripMenuItem(); - copyItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.LocalVariables.CopyToClipboard"); - copyItem.Checked = false; - copyItem.Click += delegate { - ClipboardWrapper.SetText(((DynamicListItem)sender).Text); - }; - - ToolStripMenuItem hewView; - hewView = new ToolStripMenuItem(); - hewView.Text = ResourceService.GetString("MainWindow.Windows.Debug.LocalVariables.ShowInHexadecimal"); - hewView.Checked = ShowValuesInHexadecimal; - hewView.Click += delegate { - ShowValuesInHexadecimal = !ShowValuesInHexadecimal; - }; - - menu.Items.AddRange(new ToolStripItem[] { - copyItem, - hewView - }); - - menu.Show(e.List, e.Location); + ContextMenuStrip menu = listItem.GetContextMenu(); + if (menu != null) { + menu.Show(e.List, e.Location); + } } } @@ -155,94 +109,17 @@ namespace ICSharpCode.SharpDevelop.Services protected override void OnExpanding(DynamicListEventArgs e) { if (!populated) { - DoInPausedState(delegate { Populate(); }); - } - } - - void DoInPausedState(MethodInvoker action) - { - if (val.Process.IsPaused) { - action(); - } else { - EventHandler onDebuggingPaused = null; - onDebuggingPaused = delegate { - action(); - val.Process.DebuggingPaused -= onDebuggingPaused; - }; - val.Process.DebuggingPaused += onDebuggingPaused; + WindowsDebugger.DoInPausedState(delegate { Populate(); }); } } void Populate() { this.ChildRows.Clear(); - if (val.IsArray) { - AddCollection(this, val.GetArrayElements()); - } - if (val.IsObject) { - AddObjectRows(this, val.Type); + foreach(ListItem subItem in listItem.SubItems) { + this.ChildRows.Add(new DynamicTreeDebuggerRow(subItem)); } populated = true; } - - void AddObjectRows(DynamicTreeRow tree, DebugType type) - { - NamedValueCollection publicInstance = val.GetMembers(type, BindingFlags.Public | BindingFlags.Instance); - NamedValueCollection publicStatic = val.GetMembers(type, BindingFlags.Public | BindingFlags.Static); - NamedValueCollection privateInstance = val.GetMembers(type, BindingFlags.NonPublic | BindingFlags.Instance); - NamedValueCollection privateStatic = val.GetMembers(type, BindingFlags.NonPublic | BindingFlags.Static); - - if (type.BaseType != null) { - tree.ChildRows.Add(MakeMenu("Base class", type.BaseType.FullName, - delegate(DynamicTreeRow t) { AddObjectRows(t, type.BaseType); } )); - } - - if (publicStatic.Count > 0) { - tree.ChildRows.Add(MakeMenu("Static members", String.Empty, - delegate(DynamicTreeRow t) { AddCollection(t, publicStatic); } )); - } - - if (privateInstance.Count > 0 || privateStatic.Count > 0) { - tree.ChildRows.Add(MakeMenu( - "Non-public members", String.Empty, - delegate(DynamicTreeRow t) { - if (privateStatic.Count > 0) { - t.ChildRows.Add(MakeMenu("Static members", String.Empty, - delegate(DynamicTreeRow t2) { AddCollection(t2, privateStatic); } )); - } - AddCollection(t, privateInstance); - })); - } - - AddCollection(this, publicInstance); - } - - void AddCollection(DynamicTreeRow tree, NamedValueCollection collection) - { - foreach(NamedValue val in collection) { - tree.ChildRows.Add(new DynamicTreeDebuggerRow(val)); - } - } - - delegate void PopulateMenu(DynamicTreeRow row); - - DynamicTreeRow MakeMenu(string name, string text, PopulateMenu populate) - { - DynamicTreeRow menu = new DynamicTreeRow(); - DebuggerGridControl.AddColumns(menu.ChildColumns); - menu[2].Text = name; - menu[3].Text = text; - menu.ShowMinusWhileExpanded = true; - - bool populated = false; - menu.Expanding += delegate { - if (!populated) { - populate(menu); - populated = true; - } - }; - - return menu; - } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs index a844fb86e9..9b3e530ebc 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs @@ -451,5 +451,20 @@ namespace ICSharpCode.SharpDevelop.Services } } } + + public static void DoInPausedState(MethodInvoker action) + { + Debugger.Process process = ((WindowsDebugger)DebuggerService.CurrentDebugger).DebuggedProcess; + if (process.IsPaused) { + action(); + } else { + EventHandler onDebuggingPaused = null; + onDebuggingPaused = delegate { + action(); + process.DebuggingPaused -= onDebuggingPaused; + }; + process.DebuggingPaused += onDebuggingPaused; + } + } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/BaseTypeItem.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/BaseTypeItem.cs new file mode 100644 index 0000000000..ac452511bc --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/BaseTypeItem.cs @@ -0,0 +1,124 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +using ICSharpCode.Core; + +namespace Debugger +{ + public class BaseTypeItem: ListItem + { + NamedValue val; + DebugType type; + + public NamedValue Value { + get { + return val; + } + } + + public DebugType DebugType { + get { + return type; + } + } + + public override int ImageIndex { + get { + return -1; + } + } + + public override string Name { + get { + return StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.BaseClass}"); + } + } + + public override string Text { + get { + return String.Empty; + } + } + + public override bool CanEditText { + get { + return false; + } + } + + public override string Type { + get { + return type.FullName; + } + } + + public override bool HasSubItems { + get { + return true; + } + } + + public override IList SubItems { + get { + return GetSubItems(); + } + } + + public BaseTypeItem(NamedValue val, DebugType type) + { + this.val = val; + this.type = type; + } + + List GetMembers(BindingFlags flags) + { + List list = new List(); + foreach(NamedValue v in val.GetMembers(type, flags)) { + list.Add(new ValueItem(v)); + } + return list; + } + + IList GetSubItems() + { + List list = new List(); + + string privateRes = StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.PrivateMembers}"); + string staticRes = StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.StaticMembers}"); + string privateStaticRes = StringParser.Parse("${res:MainWindow.Windows.Debug.LocalVariables.PrivateStaticMembers}"); + + List publicInstance = GetMembers(BindingFlags.Public | BindingFlags.Instance); + List publicStatic = GetMembers(BindingFlags.Public | BindingFlags.Static); + List privateInstance = GetMembers(BindingFlags.NonPublic | BindingFlags.Instance); + List privateStatic = GetMembers(BindingFlags.NonPublic | BindingFlags.Static); + + if (type.BaseType != null) { + list.Add(new BaseTypeItem(val, type.BaseType)); + } + + if (publicStatic.Count > 0) { + list.Add(new FixedItem(-1, staticRes, String.Empty, String.Empty, true, publicStatic)); + } + + if (privateInstance.Count > 0 || privateStatic.Count > 0) { + List nonPublicItems = new List(); + if (privateStatic.Count > 0) { + nonPublicItems.Add(new FixedItem(-1, privateStaticRes, String.Empty, String.Empty, true, privateStatic)); + } + nonPublicItems.AddRange(privateInstance); + list.Add(new FixedItem(-1, privateRes, String.Empty, String.Empty, true, nonPublicItems)); + } + + list.AddRange(publicInstance); + + return list; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/FixedItem.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/FixedItem.cs new file mode 100644 index 0000000000..7f46e38532 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/FixedItem.cs @@ -0,0 +1,74 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace Debugger +{ + public class FixedItem: ListItem + { + int imageIndex; + string name; + string text; + string type; + bool hasSubItems; + IList subItems; + + public override int ImageIndex { + get { + return imageIndex; + } + } + + public override string Name { + get { + return name; + } + } + + public override string Text { + get { + return text; + } + } + + public override bool CanEditText { + get { + return false; + } + } + + public override string Type { + get { + return type; + } + } + + public override bool HasSubItems { + get { + return hasSubItems; + } + } + + public override IList SubItems { + get { + return subItems; + } + } + + public FixedItem(int imageIndex, string name, string text, string type, bool hasSubItems, IList subItems) + { + this.imageIndex = imageIndex; + this.name = name; + this.text = text; + this.type = type; + this.hasSubItems = hasSubItems; + this.subItems = subItems; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ListItem.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ListItem.cs new file mode 100644 index 0000000000..ae07490b8c --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ListItem.cs @@ -0,0 +1,53 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace Debugger +{ + public abstract class ListItem + { + public event EventHandler Changed; + + public abstract int ImageIndex { get; } + public abstract string Name { get; } + public abstract string Text { get; } + public abstract bool CanEditText { get; } + public abstract string Type { get; } + public abstract bool HasSubItems { get; } + public abstract IList SubItems { get; } + + public System.Drawing.Image Image { + get { + if (ImageIndex == -1) { + return null; + } else { + return DebuggerIcons.ImageList.Images[ImageIndex]; + } + } + } + + protected virtual void OnChanged(ListItemEventArgs e) + { + if (Changed != null) { + Changed(this, e); + } + } + + public virtual bool SetText(string newValue) + { + throw new NotImplementedException(); + } + + public virtual ContextMenuStrip GetContextMenu() + { + return null; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ListItemEventArgs.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ListItemEventArgs.cs new file mode 100644 index 0000000000..b97a40ae8e --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ListItemEventArgs.cs @@ -0,0 +1,27 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace Debugger +{ + public class ListItemEventArgs: EventArgs + { + ListItem listItem; + + public ListItem ListItem { + get { + return listItem; + } + } + + public ListItemEventArgs(ListItem listItem) + { + this.listItem = listItem; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ValueItem.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ValueItem.cs new file mode 100644 index 0000000000..b24efd5243 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Variables/ValueItem.cs @@ -0,0 +1,154 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Services; +using ICSharpCode.SharpDevelop.Debugging; + +namespace Debugger +{ + class ValueItem: ListItem + { + NamedValue val; + + public NamedValue Value { + get { + return val; + } + } + + public static bool ShowValuesInHexadecimal { + get { + return ((WindowsDebugger)DebuggerService.CurrentDebugger).Properties.Get("ShowValuesInHexadecimal", false); + } + set { + ((WindowsDebugger)DebuggerService.CurrentDebugger).Properties.Set("ShowValuesInHexadecimal", value); + } + } + + public override int ImageIndex { + get { + if (val.IsObject) { + return 0; // Class + } else { + return 1; // Field + } + } + } + + public override string Name { + get { + return val.Name; + } + } + + public override string Text { + get { + if (ShowValuesInHexadecimal && val.IsInteger) { + return String.Format("0x{0:X}", val.PrimitiveValue); + } else { + return val.AsString; + } + } + } + + public override bool CanEditText { + get { + return val.IsInteger && !ShowValuesInHexadecimal; + } + } + + public override string Type { + get { + if (val.Type != null) { + return val.Type.FullName; + } else { + return String.Empty; + } + } + } + + public override bool HasSubItems { + get { + return val.IsObject || val.IsArray; + } + } + + public override IList SubItems { + get { + List list = new List(); + if (val.IsArray) { + foreach(NamedValue element in val.GetArrayElements()) { + list.Add(new ValueItem(element)); + } + } + if (val.IsObject) { + return new BaseTypeItem(val, val.Type).SubItems; + } + return list; + } + } + + public ValueItem(NamedValue val) + { + this.val = val; + + val.Changed += delegate { OnChanged(new ListItemEventArgs(this)); }; + } + + public override bool SetText(string newValue) + { + try { + val.PrimitiveValue = newValue; + return true; + } catch (NotSupportedException) { + string format = ResourceService.GetString("MainWindow.Windows.Debug.LocalVariables.CannotSetValue.BadFormat"); + string msg = String.Format(format, newValue, val.Type.ManagedType.ToString()); + MessageService.ShowMessage(msg ,"${res:MainWindow.Windows.Debug.LocalVariables.CannotSetValue.Title}"); + } catch (COMException) { + // COMException (0x80131330): Cannot perfrom SetValue on non-leaf frames. + // Happens if trying to set value after exception is breaked + MessageService.ShowMessage("${res:MainWindow.Windows.Debug.LocalVariables.CannotSetValue.UnknownError}", + "${res:MainWindow.Windows.Debug.LocalVariables.CannotSetValue.Title}"); + } + return false; + } + + public override ContextMenuStrip GetContextMenu() + { + ContextMenuStrip menu = new ContextMenuStrip(); + + ToolStripMenuItem copyItem; + copyItem = new ToolStripMenuItem(); + copyItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.LocalVariables.CopyToClipboard"); + copyItem.Checked = false; + copyItem.Click += delegate { + ClipboardWrapper.SetText(this.Text); + }; + + ToolStripMenuItem hewView; + hewView = new ToolStripMenuItem(); + hewView.Text = ResourceService.GetString("MainWindow.Windows.Debug.LocalVariables.ShowInHexadecimal"); + hewView.Checked = ShowValuesInHexadecimal; + hewView.Click += delegate { + ShowValuesInHexadecimal = !ShowValuesInHexadecimal; + }; + + menu.Items.AddRange(new ToolStripItem[] { + copyItem, + hewView + }); + + return menu; + } + } +}