From 04b763d04701da5e2a2ddfea4208ea3165528289 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 27 Oct 2005 14:05:14 +0000 Subject: [PATCH] Display TreeGrid in debug mode (currently without content). git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@641 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../CompletionWindow/DeclarationViewWindow.cs | 8 +- .../Project/ICSharpCode.SharpDevelop.csproj | 1 + .../Project/Src/Gui/TreeGrid/DynamicList.cs | 19 ++++ .../Src/Gui/TreeGrid/DynamicTreeRow.cs | 23 ++-- .../Services/Debugger/DebuggerGridControl.cs | 103 ++++++++++++++++++ .../Src/Services/Debugger/DebuggerService.cs | 45 ++++++-- 6 files changed, 170 insertions(+), 29 deletions(-) create mode 100644 src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/DeclarationViewWindow.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/DeclarationViewWindow.cs index 832ea68c1a..3255e394cb 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/DeclarationViewWindow.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/DeclarationViewWindow.cs @@ -72,14 +72,14 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow protected override void OnPaint(PaintEventArgs pe) { - TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics, Font, null, description); + if (description != null && description.Length > 0) { + TipPainterTools.DrawHelpTipFromCombinedDescription(this, pe.Graphics, Font, null, description); + } } protected override void OnPaintBackground(PaintEventArgs pe) { - if (description != null && description.Length > 0) { - pe.Graphics.FillRectangle(SystemBrushes.Info, pe.ClipRectangle); - } + pe.Graphics.FillRectangle(SystemBrushes.Info, pe.ClipRectangle); } } } diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index a04efa07ab..9f332e201b 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -718,6 +718,7 @@ + diff --git a/src/Main/Base/Project/Src/Gui/TreeGrid/DynamicList.cs b/src/Main/Base/Project/Src/Gui/TreeGrid/DynamicList.cs index b440a19762..23bdac3978 100644 --- a/src/Main/Base/Project/Src/Gui/TreeGrid/DynamicList.cs +++ b/src/Main/Base/Project/Src/Gui/TreeGrid/DynamicList.cs @@ -203,6 +203,25 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid } } + public int GetRequiredWidth(Graphics graphics) + { + int width = 0; + for (int i = 0; i < columns.Count; i++) { + if (columns[i].AutoSize) { + int minimumWidth = DynamicListColumn.DefaultWidth; + foreach (DynamicListRow row in Rows) { + DynamicListItem item = row[i]; + item.MeasureMinimumWidth(graphics, ref minimumWidth); + } + width += minimumWidth; + } else { + width += columns[i].Width; + } + width += 1; + } + return width; + } + protected override void OnPaint(PaintEventArgs e) { //Debug.WriteLine("OnPaint"); diff --git a/src/Main/Base/Project/Src/Gui/TreeGrid/DynamicTreeRow.cs b/src/Main/Base/Project/Src/Gui/TreeGrid/DynamicTreeRow.cs index eeab0244c2..79ac88ccdc 100644 --- a/src/Main/Base/Project/Src/Gui/TreeGrid/DynamicTreeRow.cs +++ b/src/Main/Base/Project/Src/Gui/TreeGrid/DynamicTreeRow.cs @@ -38,7 +38,7 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, r); } - class ChildForm : Form + public class ChildForm : Form { bool isActive = true; @@ -71,15 +71,12 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid } } - ChildForm frm; static bool isOpeningChild; protected virtual void OnPlusClick(object sender, DynamicListEventArgs e) { - if (frm != null) { - frm.Close(); - } - frm = new ChildForm(); + OnExpanding(e); + ChildForm frm = new ChildForm(); frm.Closed += delegate { frm = null; OnCollapsed(EventArgs.Empty); @@ -92,7 +89,6 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid frm.ShowInTaskbar = false; frm.Text = childWindowCaption; frm.Owner = e.List.FindForm(); - OnExpanding(e); VerticalScrollContainer scrollContainer = new VerticalScrollContainer(); scrollContainer.Dock = DockStyle.Fill; @@ -113,12 +109,14 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid int screenHeight = Screen.FromPoint(p).WorkingArea.Bottom - p.Y; screenHeight -= frm.Size.Height - frm.ClientSize.Height; - int formHeight = Math.Min(childList.TotalRowHeight + 4, screenHeight); - if (formHeight < 100) { - formHeight += 100; - frm.Top -= 100; + int requiredHeight = childList.TotalRowHeight + 4; + int formHeight = Math.Min(requiredHeight, screenHeight); + if (formHeight < requiredHeight) { + int missingHeight = Math.Min(100, requiredHeight - formHeight); + formHeight += missingHeight; + frm.Top -= missingHeight; } - frm.ClientSize = new Size(e.List.Width, formHeight); + frm.ClientSize = new Size(e.List.Width + 4, formHeight); isOpeningChild = true; frm.Show(); isOpeningChild = false; @@ -159,7 +157,6 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid if (value == null) throw new ArgumentNullException(); childWindowCaption = value; - if (frm != null) frm.Text = value; } } diff --git a/src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs b/src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs new file mode 100644 index 0000000000..35842b265b --- /dev/null +++ b/src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs @@ -0,0 +1,103 @@ +/* + * Created by SharpDevelop. + * User: Daniel Grunwald + * Date: 27.10.2005 + * Time: 14:18 + */ + +using System; +using System.Drawing; +using System.Windows.Forms; +using ICSharpCode.SharpDevelop.Gui.TreeGrid; + +namespace ICSharpCode.Core +{ + public class DebuggerGridControl : DynamicList + { + // Columns: + // 0 = plus sign + // 1 = icon + // 2 = text + // 3 = value + + DynamicTreeRow row = new DynamicTreeRow(); + + public DebuggerGridControl(string text, string value) + { + BeginUpdate(); + Columns.Add(new DynamicListColumn()); + Columns.Add(new DynamicListColumn()); + Columns.Add(new DynamicListColumn()); + Columns.Add(new DynamicListColumn()); + Columns[0].BackgroundBrush = SystemBrushes.ControlLightLight; + // default is allowgrow = true and autosize = false + Columns[0].AllowGrow = false; + Columns[1].AllowGrow = false; + Columns[1].Width = 18; + Columns[2].AutoSize = true; + Columns[3].AutoSize = true; + Rows.Add(row); + row.ChildWindowCaption = text; + row[2].Text = text; + row[3].Text = value; + + foreach (DynamicListColumn col in Columns) { + row.ChildColumns.Add(col.Clone()); + } + row.Expanding += RowExpanding; + row.Expanded += delegate { isExpanded = true; }; + row.Collapsed += delegate { isExpanded = false; }; + + CreateControl(); + using (Graphics g = CreateGraphics()) { + this.Width = GetRequiredWidth(g); + } + this.Height = row.Height; + EndUpdate(); + } + + Form frm; + + public void ShowForm(ICSharpCode.TextEditor.TextArea textArea, Point logicTextPos) + { + frm = new DynamicTreeRow.ChildForm(); + frm.FormBorderStyle = FormBorderStyle.None; + frm.Owner = textArea.FindForm(); + int ypos = (textArea.Document.GetVisibleLine(logicTextPos.Y) + 1) * textArea.TextView.FontHeight - textArea.VirtualTop.Y; + Point p = new Point(0, ypos); + p = textArea.PointToScreen(p); + p.X = Control.MousePosition.X; + frm.StartPosition = FormStartPosition.Manual; + frm.ShowInTaskbar = false; + frm.Location = p; + frm.Size = new Size(Width, row.Height); + Dock = DockStyle.Fill; + frm.Controls.Add(this); + ICSharpCode.TextEditor.Gui.CompletionWindow.AbstractCompletionWindow.ShowWindowWithoutFocus(frm); + textArea.Click += OnTextAreaClick; + textArea.KeyDown += OnTextAreaClick; + frm.Height = row.Height; + } + + void OnTextAreaClick(object sender, EventArgs e) + { + ((ICSharpCode.TextEditor.TextArea)sender).KeyDown -= OnTextAreaClick; + ((ICSharpCode.TextEditor.TextArea)sender).Click -= OnTextAreaClick; + frm.Close(); + } + + bool isExpanded; + + public bool AllowClose { + get { + return !isExpanded; + } + } + + void RowExpanding(object sender, EventArgs e) + { + row.ChildRows.Clear(); + row.ChildRows.Add(row); + } + } +} diff --git a/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs b/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs index 99a8bcb2bd..10c5c8875f 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs @@ -278,6 +278,7 @@ namespace ICSharpCode.Core #region Tool tips static string oldExpression, oldToolTip; + static DebuggerGridControl oldToolTipControl; static int oldLine; public class SetIPArgs: EventArgs @@ -297,6 +298,7 @@ namespace ICSharpCode.Core try { TextArea textArea = (TextArea)sender; if (textArea.ToolTipVisible) return; + if (oldToolTipControl != null && !oldToolTipControl.AllowClose) return; if (!CodeCompletionOptions.TooltipsEnabled) return; if (CodeCompletionOptions.TooltipsOnlyWhenDebugging) { @@ -311,7 +313,7 @@ namespace ICSharpCode.Core mousepos.Y - viewRect.Top); if (logicPos.Y >= 0 && logicPos.Y < textArea.Document.TotalNumberOfLines) { // This is for testing olny - it must be reworked properly - if (Control.ModifierKeys == Keys.Control && currentDebugger != null && currentDebugger.IsDebugging) { + if (Control.ModifierKeys == (Keys.Control | Keys.Shift) && currentDebugger != null && currentDebugger.IsDebugging) { SetIPArgs a = new SetIPArgs(); a.filename = textArea.MotherTextEditorControl.FileName; a.line = logicPos.Y; @@ -343,14 +345,29 @@ namespace ICSharpCode.Core } else { // Look if it is variable ResolveResult result = ParserService.Resolve(expressionResult, logicPos.Y + 1, logicPos.X + 1, textArea.MotherTextEditorControl.FileName, textContent); - string value = GetText(result, expression); - if (value != null) { + bool debuggerCanShowValue; + string toolTipText = GetText(result, expression, out debuggerCanShowValue); + DebuggerGridControl toolTipControl = null; + if (toolTipText != null) { if (Control.ModifierKeys == Keys.Control) { - value = "expr: " + expressionResult.ToString() + "\n" + value; + toolTipText = "expr: " + expressionResult.ToString() + "\n" + toolTipText; + } else if (debuggerCanShowValue) { + toolTipControl = new DebuggerGridControl("hello", "world"); + toolTipText = null; } - textArea.SetToolTip(value); } - oldToolTip = value; + if (toolTipText != null) { + textArea.SetToolTip(toolTipText); + } + if (oldToolTipControl != null) { + Form frm = oldToolTipControl.FindForm(); + if (frm != null) frm.Close(); + } + if (toolTipControl != null) { + toolTipControl.ShowForm(textArea, logicPos); + } + oldToolTip = toolTipText; + oldToolTipControl = toolTipControl; } } oldLine = logicPos.Y; @@ -362,18 +379,19 @@ namespace ICSharpCode.Core } } - static string GetText(ResolveResult result, string expression) + static string GetText(ResolveResult result, string expression, out bool debuggerCanShowValue) { + debuggerCanShowValue = false; if (result == null) { // when pressing control, show the expression even when it could not be resolved return (Control.ModifierKeys == Keys.Control) ? "" : null; } if (result is MixedResolveResult) - return GetText(((MixedResolveResult)result).PrimaryResult, expression); + return GetText(((MixedResolveResult)result).PrimaryResult, expression, out debuggerCanShowValue); IAmbience ambience = AmbienceService.CurrentAmbience; ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowAccessibility; if (result is MemberResolveResult) { - return GetMemberText(ambience, ((MemberResolveResult)result).ResolvedMember, expression); + return GetMemberText(ambience, ((MemberResolveResult)result).ResolvedMember, expression, out debuggerCanShowValue); } else if (result is LocalResolveResult) { LocalResolveResult rr = (LocalResolveResult)result; ambience.ConversionFlags = ConversionFlags.UseFullyQualifiedNames @@ -388,6 +406,7 @@ namespace ICSharpCode.Core if (currentDebugger != null) { string currentValue = currentDebugger.GetValueAsString(rr.Field.Name); if (currentValue != null) { + debuggerCanShowValue = true; b.Append(" = "); b.Append(currentValue); } @@ -398,14 +417,14 @@ namespace ICSharpCode.Core } else if (result is TypeResolveResult) { IClass c = ((TypeResolveResult)result).ResolvedClass; if (c != null) - return GetMemberText(ambience, c, expression); + return GetMemberText(ambience, c, expression, out debuggerCanShowValue); else return ambience.Convert(result.ResolvedType); } else if (result is MethodResolveResult) { MethodResolveResult mrr = result as MethodResolveResult; IMethod m = mrr.GetMethodIfSingleOverload(); if (m != null) - return GetMemberText(ambience, m, expression); + return GetMemberText(ambience, m, expression, out debuggerCanShowValue); else return "Overload of " + ambience.Convert(mrr.ContainingType) + "." + mrr.Name; } else { @@ -420,9 +439,10 @@ namespace ICSharpCode.Core } } - static string GetMemberText(IAmbience ambience, IDecoration member, string expression) + static string GetMemberText(IAmbience ambience, IDecoration member, string expression, out bool debuggerCanShowValue) { bool tryDisplayValue = false; + debuggerCanShowValue = false; StringBuilder text = new StringBuilder(); if (member is IField) { text.Append(ambience.Convert(member as IField)); @@ -443,6 +463,7 @@ namespace ICSharpCode.Core if (tryDisplayValue && currentDebugger != null) { string currentValue = currentDebugger.GetValueAsString(expression); if (currentValue != null) { + debuggerCanShowValue = true; text.Append(" = "); text.Append(currentValue); }