diff --git a/AddIns/ICSharpCode.SharpDevelop.addin b/AddIns/ICSharpCode.SharpDevelop.addin index 4874bdcb25..abed0959b5 100644 --- a/AddIns/ICSharpCode.SharpDevelop.addin +++ b/AddIns/ICSharpCode.SharpDevelop.addin @@ -1404,7 +1404,7 @@ - + + + @@ -1739,7 +1745,7 @@ + class = "ICSharpCode.SharpDevelop.Bookmarks.ClearBookmarks"/> + diff --git a/data/templates/file/CSharp/CSharp.Web.WebForm.xft b/data/templates/file/CSharp/CSharp.Web.WebForm.xft new file mode 100644 index 0000000000..de10ca6559 --- /dev/null +++ b/data/templates/file/CSharp/CSharp.Web.WebForm.xft @@ -0,0 +1,194 @@ + + diff --git a/data/templates/file/CSharp/CSharp.Web.WebService.xft b/data/templates/file/CSharp/CSharp.Web.WebService.xft new file mode 100644 index 0000000000..6c65d50f45 --- /dev/null +++ b/data/templates/file/CSharp/CSharp.Web.WebService.xft @@ -0,0 +1,82 @@ + + diff --git a/data/templates/project/CSharp/WebpageProject.xpt b/data/templates/project/CSharp/WebpageProject.xpt new file mode 100644 index 0000000000..017efe090f --- /dev/null +++ b/data/templates/project/CSharp/WebpageProject.xpt @@ -0,0 +1,512 @@ + + diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj b/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj index 14e77821f4..c5cfc2cc1e 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/BooBinding.csproj @@ -86,6 +86,9 @@ + + Always + diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Resources/BuildOptions.xfrm b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Resources/BuildOptions.xfrm index 0d90359ddc..fac73231be 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Resources/BuildOptions.xfrm +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Resources/BuildOptions.xfrm @@ -12,16 +12,24 @@ + + + + + + + + - + - + diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BuildOptions.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BuildOptions.cs index 7e7789fda6..802fe08455 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BuildOptions.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/BuildOptions.cs @@ -31,14 +31,14 @@ namespace Grunwald.BooBinding //InitXmlDoc(); InitDebugInfo(); - ConfigurationGuiBinding b; + //ConfigurationGuiBinding b; //b = helper.BindString("conditionalSymbolsTextBox", "DefineConstants"); //b.DefaultLocation = PropertyStorageLocations.ConfigurationSpecific; //b.CreateLocationButton("conditionalSymbolsTextBox"); - b = helper.BindBoolean("noCorlibCheckBox", "NoStdLib", false); - b.CreateLocationButton("noCorlibCheckBox"); + helper.BindBoolean("noCorlibCheckBox", "NoStdLib", false).CreateLocationButton("noCorlibCheckBox"); + helper.BindBoolean("duckyCheckBox", "Ducky", false).CreateLocationButton("duckyCheckBox"); helper.BindString("pipelineTextBox", "Pipeline").CreateLocationButton("pipelineLabel"); diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs index af0c77fe7a..d28e082e50 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Src/CodeCompletion/VariableLookupVisitor.cs @@ -13,64 +13,17 @@ using Boo.Lang.Compiler.Ast; namespace Grunwald.BooBinding.CodeCompletion { - /// - /// Finds an variable declaration in the boo AST. - /// - public class VariableLookupVisitor : DepthFirstVisitor + public abstract class VariableLookupVisitorBase : DepthFirstVisitor { - BooResolver resolver; - string lookFor; - bool acceptImplicit; - - public VariableLookupVisitor(BooResolver resolver, string lookFor, bool acceptImplicit) - { - this.resolver = resolver; - this.lookFor = lookFor; - this.acceptImplicit = acceptImplicit; - } + protected BooResolver resolver; + protected bool acceptImplicit = true; - IField result; - - public IField Result { - get { - return result; - } - } - - private void InferResult(Expression expr, string name, LexicalInfo lexicalInfo, bool useElementType) - { - if (expr == null) - return; - if (result != null) - return; - IReturnType returnType = new InferredReturnType(expr, resolver.CallingClass); - if (useElementType) - returnType = new ElementReturnType(returnType); - result = new DefaultField.LocalVariableField(returnType, name, - new DomRegion(lexicalInfo.Line, lexicalInfo.Column), - resolver.CallingClass); - } - - public override void OnDeclaration(Declaration node) - { - if (result != null) - return; - if (node.Name == lookFor) { - if (node.Type != null) { - result = new DefaultField.LocalVariableField(resolver.ConvertType(node.Type), - node.Name, - new DomRegion(node.LexicalInfo.Line, node.LexicalInfo.Column), - resolver.CallingClass); - } - } - } + protected abstract void DeclarationFound(string declarationName, TypeReference declarationType, Expression initializer, LexicalInfo lexicalInfo); + protected abstract void IterationDeclarationFound(string declarationName, TypeReference declarationType, Expression initializer, LexicalInfo lexicalInfo); public override void OnDeclarationStatement(DeclarationStatement node) { - if (node.Declaration.Name == lookFor) { - Visit(node.Declaration); - InferResult(node.Initializer, node.Declaration.Name, node.LexicalInfo, false); - } + DeclarationFound(node.Declaration.Name, node.Declaration.Type, node.Initializer, node.LexicalInfo); } protected override void OnError(Node node, Exception error) @@ -84,9 +37,7 @@ namespace Grunwald.BooBinding.CodeCompletion ReferenceExpression reference = node.Left as ReferenceExpression; if (node.Operator == BinaryOperatorType.Assign && reference != null) { if (!(reference is MemberReferenceExpression)) { - if (reference.Name == lookFor) { - InferResult(node.Right, reference.Name, reference.LexicalInfo, false); - } + DeclarationFound(reference.Name, null, node.Right, node.LexicalInfo); } } } @@ -95,18 +46,12 @@ namespace Grunwald.BooBinding.CodeCompletion public override void OnForStatement(ForStatement node) { - if (node.LexicalInfo.Line > resolver.CaretLine || node.Block.EndSourceLocation.Line < resolver.CaretLine) - return; - - if (node.Declarations.Count != 1) { - // TODO: support unpacking - base.OnForStatement(node); - return; - } - if (node.Declarations[0].Name == lookFor) { - Visit(node.Declarations[0]); - InferResult(node.Iterator, node.Declarations[0].Name, node.LexicalInfo, true); + if (node.LexicalInfo.Line <= resolver.CaretLine && node.Block.EndSourceLocation.Line >= resolver.CaretLine - 1) { + foreach (Declaration decl in node.Declarations) { + IterationDeclarationFound(decl.Name, decl.Type, node.Iterator, node.LexicalInfo); + } } + base.OnForStatement(node); } public override void OnGeneratorExpression(GeneratorExpression node) @@ -114,16 +59,90 @@ namespace Grunwald.BooBinding.CodeCompletion if (node.LexicalInfo.Line != resolver.CaretLine) return; LoggingService.Warn("GeneratorExpression: " + node.EndSourceLocation.Line); - if (node.Declarations.Count != 1) { - // TODO: support unpacking - base.OnGeneratorExpression(node); + foreach (Declaration decl in node.Declarations) { + IterationDeclarationFound(decl.Name, decl.Type, node.Iterator, node.LexicalInfo); + } + base.OnGeneratorExpression(node); + } + + public override void OnUnpackStatement(UnpackStatement node) + { + ArrayLiteralExpression ale = node.Expression as ArrayLiteralExpression; + for (int i = 0; i < node.Declarations.Count; i++) { + Declaration decl = node.Declarations[i]; + if (acceptImplicit && ale != null && ale.Items.Count > i) { + DeclarationFound(decl.Name, decl.Type, ale.Items[i], decl.LexicalInfo); + } else if (decl.Type != null) { + DeclarationFound(decl.Name, decl.Type, null, decl.LexicalInfo); + } + } + } + } + + /// + /// Finds an variable declaration in the boo AST. + /// + public class VariableLookupVisitor : VariableLookupVisitorBase + { + string lookFor; + + public VariableLookupVisitor(BooResolver resolver, string lookFor, bool acceptImplicit) + { + this.resolver = resolver; + this.lookFor = lookFor; + this.acceptImplicit = acceptImplicit; + } + + IField result; + + public IField Result { + get { + return result; + } + } + + protected override void IterationDeclarationFound(string declarationName, TypeReference declarationType, Expression iterator, LexicalInfo lexicalInfo) + { + if (result != null) return; + if (declarationName == lookFor) { + if (declarationType != null) { + result = new DefaultField.LocalVariableField(resolver.ConvertType(declarationType), + declarationName, + new DomRegion(lexicalInfo.Line, lexicalInfo.Column), + resolver.CallingClass); + } else if (iterator != null) { + InferResult(iterator, declarationName, lexicalInfo, true); + } } - if (node.Declarations[0].Name == lookFor) { - Visit(node.Declarations[0]); - InferResult(node.Iterator, node.Declarations[0].Name, node.LexicalInfo, true); + } + + protected override void DeclarationFound(string declarationName, TypeReference declarationType, Expression initializer, LexicalInfo lexicalInfo) + { + if (result != null) + return; + if (declarationName == lookFor) { + if (declarationType != null) { + result = new DefaultField.LocalVariableField(resolver.ConvertType(declarationType), + declarationName, + new DomRegion(lexicalInfo.Line, lexicalInfo.Column), + resolver.CallingClass); + } else if (initializer != null) { + InferResult(initializer, declarationName, lexicalInfo, false); + } } - base.OnGeneratorExpression(node); + } + + private void InferResult(Expression expr, string name, LexicalInfo lexicalInfo, bool useElementType) + { + if (expr == null) + return; + IReturnType returnType = new InferredReturnType(expr, resolver.CallingClass); + if (useElementType) + returnType = new ElementReturnType(returnType); + result = new DefaultField.LocalVariableField(returnType, name, + new DomRegion(lexicalInfo.Line, lexicalInfo.Column), + resolver.CallingClass); } } @@ -131,10 +150,9 @@ namespace Grunwald.BooBinding.CodeCompletion /// Creates a hashtable name => (Expression or TypeReference) for the local /// variables in the block that is visited. /// - public class VariableListLookupVisitor : DepthFirstVisitor + public class VariableListLookupVisitor : VariableLookupVisitorBase { List knownVariableNames; - BooResolver resolver; public VariableListLookupVisitor(List knownVariableNames, BooResolver resolver) { @@ -171,48 +189,22 @@ namespace Grunwald.BooBinding.CodeCompletion results.Add(name, resolver.ConvertType(reference)); } - public override void OnDeclaration(Declaration node) - { - Add(node.Name, node.Type); - } - - public override void OnDeclarationStatement(DeclarationStatement node) - { - Visit(node.Declaration); - Add(node.Declaration.Name, node.Initializer, false); - } - - protected override void OnError(Node node, Exception error) - { - MessageService.ShowError(error, "VariableListLookupVisitor: error processing " + node); - } - - public override void OnBinaryExpression(BinaryExpression node) + protected override void DeclarationFound(string declarationName, TypeReference declarationType, Expression initializer, LexicalInfo lexicalInfo) { - if (node.Operator == BinaryOperatorType.Assign && node.Left is ReferenceExpression) { - ReferenceExpression reference = node.Left as ReferenceExpression; - if (node.Operator == BinaryOperatorType.Assign && reference != null) { - if (!(reference is MemberReferenceExpression)) { - if (!knownVariableNames.Contains(reference.Name)) { - Add(reference.Name, node.Right, false); - } - } - } + if (declarationType != null) { + Add(declarationName, declarationType); + } else if (initializer != null) { + Add(declarationName, initializer, false); } - base.OnBinaryExpression(node); } - public override void OnForStatement(ForStatement node) + protected override void IterationDeclarationFound(string declarationName, TypeReference declarationType, Expression initializer, LexicalInfo lexicalInfo) { - if (node.LexicalInfo.Line > resolver.CaretLine || node.Block.EndSourceLocation.Line < resolver.CaretLine) - return; - - if (node.Declarations.Count != 1) { - // TODO: support unpacking - base.OnForStatement(node); - return; + if (declarationType != null) { + Add(declarationName, declarationType); + } else if (initializer != null) { + Add(declarationName, initializer, true); } - Add(node.Declarations[0].Name, node.Iterator, true); } } } diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/DefaultAssemblyInfo.boo b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/DefaultAssemblyInfo.boo new file mode 100644 index 0000000000..0f9e27ce77 --- /dev/null +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/DefaultAssemblyInfo.boo @@ -0,0 +1,26 @@ +import System.Reflection +import System.Runtime.CompilerServices + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle('')] +[assembly: AssemblyDescription('')] +[assembly: AssemblyConfiguration('')] +[assembly: AssemblyCompany('')] +[assembly: AssemblyProduct('')] +[assembly: AssemblyCopyright('')] +[assembly: AssemblyTrademark('')] +[assembly: AssemblyCulture('')] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.0.0")] diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/FormsProject.xpt b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/FormsProject.xpt index 912adf8b2d..4b0b2ec249 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/FormsProject.xpt +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/FormsProject.xpt @@ -70,35 +70,7 @@ partial class MainForm(System.Windows.Forms.Form): self.Name = 'MainForm' ]]> - - + diff --git a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/Library.xpt b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/Library.xpt index 8add952bf1..44f1664374 100644 --- a/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/Library.xpt +++ b/src/AddIns/BackendBindings/Boo/BooBinding/Project/Templates/Library.xpt @@ -38,35 +38,7 @@ class MyClass: pass ]]> - - + diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs index f09ad0cf1d..20adfd29d6 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs @@ -333,7 +333,7 @@ namespace ICSharpCode.FormsDesigner tabs = line.Substring(0, line.Length - line.TrimStart().Length); } this.c = c; - this.completeClass = c.DefaultReturnType.GetUnderlyingClass(); + this.completeClass = c.GetCompoundClass(); this.formClass = initializeComponents.DeclaringType; break; } diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs index dc6889a18c..715e5c1771 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerLoader/NRefactoryDesignerLoader.cs @@ -150,7 +150,7 @@ namespace ICSharpCode.FormsDesigner throw new FormsDesignerLoadException("No class derived from Form or UserControl was found."); // Initialize designer for formClass - formClass = formClass.DefaultReturnType.GetUnderlyingClass(); + formClass = formClass.GetCompoundClass(); List parts; if (formClass is CompoundClass) { parts = (formClass as CompoundClass).Parts; diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/SecondaryDisplayBinding.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/SecondaryDisplayBinding.cs index 181bada180..1bad1e98fd 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/SecondaryDisplayBinding.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/SecondaryDisplayBinding.cs @@ -37,9 +37,7 @@ namespace ICSharpCode.FormsDesigner public static IMethod GetInitializeComponents(IClass c) { - c = c.DefaultReturnType.GetUnderlyingClass(); - if (c == null) - return null; + c = c.GetCompoundClass(); foreach (IMethod method in c.Methods) { if (IsInitializeComponentsMethodName(method.Name) && method.Parameters.Count == 0) { return method; @@ -51,7 +49,7 @@ namespace ICSharpCode.FormsDesigner public static bool BaseClassIsFormOrControl(IClass c) { // Simple test for fully qualified name - c = c.DefaultReturnType.GetUnderlyingClass(); + c = c.GetCompoundClass(); foreach (IReturnType baseType in c.BaseTypes) { if (baseType.FullyQualifiedName == "System.Windows.Forms.Form" || baseType.FullyQualifiedName == "System.Windows.Forms.UserControl" 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 1092f39d88..03a5799278 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Debugger.AddIn.csproj @@ -62,6 +62,9 @@ Configuration\GlobalAssemblyInfo.cs + + + @@ -91,4 +94,4 @@ - \ No newline at end of file + diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.Menu.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.Menu.cs new file mode 100644 index 0000000000..6908b0ea5c --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.Menu.cs @@ -0,0 +1,100 @@ +// +// +// +// +// $Revision: 1253 $ +// + +using System; +using System.Windows.Forms; +using System.Drawing; +using System.CodeDom.Compiler; +using System.Collections; +using System.ComponentModel; +using System.IO; +using System.Diagnostics; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Services; + +using Debugger; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + public partial class CallStackPad + { + public bool ShowArgumentNames { + get { + return debugger.Properties.Get("ShowArgumentNames", true); + } + set { + debugger.Properties.Set("ShowArgumentNames", value); + } + } + + public bool ShowArgumentValues { + get { + return debugger.Properties.Get("ShowArgumentValues", true); + } + set { + debugger.Properties.Set("ShowArgumentValues", value); + } + } + + public bool ShowExternalMethods { + get { + return debugger.Properties.Get("ShowExternalMethods", false); + } + set { + debugger.Properties.Set("ShowExternalMethods", value); + } + } + + ContextMenuStrip CreateContextMenuStrip() + { + ContextMenuStrip menu = new ContextMenuStrip(); + menu.Opening += FillContextMenuStrip; + return menu; + } + + void FillContextMenuStrip(object sender, CancelEventArgs e) + { + ContextMenuStrip menu = sender as ContextMenuStrip; + menu.Items.Clear(); + + ToolStripMenuItem argNamesItem; + argNamesItem = new ToolStripMenuItem(); + argNamesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentNames"); + argNamesItem.Checked = ShowArgumentNames; + argNamesItem.Click += delegate { + ShowArgumentNames = !ShowArgumentNames; + RefreshPad(); + }; + + ToolStripMenuItem argValuesItem; + argValuesItem = new ToolStripMenuItem(); + argValuesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentValues"); + argValuesItem.Checked = ShowArgumentValues; + argValuesItem.Click += delegate { + ShowArgumentValues = !ShowArgumentValues; + RefreshPad(); + }; + + ToolStripMenuItem extMethodsItem; + extMethodsItem = new ToolStripMenuItem(); + extMethodsItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowExternalMethods"); + extMethodsItem.Checked = ShowExternalMethods; + extMethodsItem.Click += delegate { + ShowExternalMethods = !ShowExternalMethods; + RefreshPad(); + }; + + menu.Items.AddRange(new ToolStripItem[] { + argNamesItem, + argValuesItem, + extMethodsItem + }); + + e.Cancel = false; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs index 5d3c7717ca..7693e582e0 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/CallStackPad.cs @@ -20,11 +20,8 @@ using Debugger; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class CallStackPad : AbstractPadContent + public partial class CallStackPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - ListView callStackList; ColumnHeader name = new ColumnHeader(); @@ -36,15 +33,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads } } - public CallStackPad()// : base("${res:MainWindow.Windows.Debug.CallStack}", null) - { - InitializeComponents(); - } - - void InitializeComponents() + protected override void InitializeComponents() { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; - callStackList = new ListView(); callStackList.FullRowSelect = true; callStackList.AutoArrange = true; @@ -60,24 +50,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads language.Width = 50; RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } - } - - public void InitializeDebugger() - { - debuggerCore = debugger.DebuggerCore; - - debuggerCore.DebuggeeStateChanged += DebuggeeStateChanged; - debuggerCore.DebuggingResumed += DebuggingResumed; - - RefreshList(); } public override void RedrawContent() @@ -86,82 +58,11 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads language.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.Language"); } - public bool ShowArgumentNames { - get { - return debugger.Properties.Get("ShowArgumentNames", true); - } - set { - debugger.Properties.Set("ShowArgumentNames", value); - } - } - - public bool ShowArgumentValues { - get { - return debugger.Properties.Get("ShowArgumentValues", true); - } - set { - debugger.Properties.Set("ShowArgumentValues", value); - } - } - - public bool ShowExternalMethods { - get { - return debugger.Properties.Get("ShowExternalMethods", false); - } - set { - debugger.Properties.Set("ShowExternalMethods", value); - } - } - - ContextMenuStrip CreateContextMenuStrip() + + protected override void RegisterDebuggerEvents() { - ContextMenuStrip menu = new ContextMenuStrip(); - menu.Opening += FillContextMenuStrip; - return menu; - } - - void FillContextMenuStrip(object sender, CancelEventArgs e) - { - ContextMenuStrip menu = sender as ContextMenuStrip; - menu.Items.Clear(); - - ToolStripMenuItem argNamesItem; - argNamesItem = new ToolStripMenuItem(); - argNamesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentNames"); - argNamesItem.Checked = ShowArgumentNames; - argNamesItem.Click += - delegate { - ShowArgumentNames = !ShowArgumentNames; - RefreshList(); - }; - - ToolStripMenuItem argValuesItem; - argValuesItem = new ToolStripMenuItem(); - argValuesItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowArgumentValues"); - argValuesItem.Checked = ShowArgumentValues; - argValuesItem.Click += - delegate { - ShowArgumentValues = !ShowArgumentValues; - RefreshList(); - }; - - ToolStripMenuItem extMethodsItem; - extMethodsItem = new ToolStripMenuItem(); - extMethodsItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.CallStack.ShowExternalMethods"); - extMethodsItem.Checked = ShowExternalMethods; - extMethodsItem.Click += - delegate { - ShowExternalMethods = !ShowExternalMethods; - RefreshList(); - }; - - menu.Items.AddRange(new ToolStripItem[] { - argNamesItem, - argValuesItem, - extMethodsItem - }); - - e.Cancel = false; + debuggerCore.DebuggeeStateChanged += delegate { RefreshPad(); }; + debuggerCore.ProcessExited += delegate { callStackList.Items.Clear(); }; } void CallStackListItemActivate(object sender, EventArgs e) @@ -169,8 +70,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads if (debuggerCore.IsPaused) { Function f = (Function)(callStackList.SelectedItems[0].Tag); if (f.HasSymbols) { - if (debuggerCore.CurrentThread != null) { - debuggerCore.CurrentThread.SetCurrentFunction(f); + if (debuggerCore.SelectedThread != null) { + debuggerCore.SelectedThread.SelectedFunction = f; + debuggerCore.OnDebuggeeStateChanged(); // Force refresh of pads } } else { MessageBox.Show("You can not switch to function without symbols", "Function switch"); @@ -179,18 +81,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads MessageBox.Show("You can not switch functions while the debugger is running.", "Function switch"); } } - - void DebuggeeStateChanged(object sender, DebuggerEventArgs e) - { - RefreshList(); - } - - void DebuggingResumed(object sender, DebuggerEventArgs e) - { - RefreshList(); - } - public void RefreshList() + public override void RefreshPad() { bool showArgumentNames = ShowArgumentNames; bool showArgumentValues = ShowArgumentValues; @@ -200,8 +92,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads callStackList.BeginUpdate(); callStackList.Items.Clear(); - if (debuggerCore != null && debuggerCore.CurrentThread != null) { - foreach (Function f in debuggerCore.CurrentThread.Callstack) { + if (debuggerCore != null && debuggerCore.SelectedThread != null && debuggerCore.IsPaused) { + foreach (Function f in debuggerCore.SelectedThread.Callstack) { ListViewItem item; if (f.HasSymbols || showExternalMethods) { // Show the method in the list diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/DebuggerPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/DebuggerPad.cs new file mode 100644 index 0000000000..ecbb249341 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/DebuggerPad.cs @@ -0,0 +1,60 @@ +// +// +// +// +// $Revision: 1064 $ +// + +using System; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Services; + +using Debugger; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + public abstract class DebuggerPad: AbstractPadContent + { + protected WindowsDebugger debugger; + protected NDebugger debuggerCore; + + public DebuggerPad() + { + debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; + + InitializeComponents(); + + if (debugger.ServiceInitialized) { + InitializeDebugger(); + } else { + debugger.Initialize += delegate { + InitializeDebugger(); + }; + } + } + + protected virtual void InitializeComponents() + { + + } + + void InitializeDebugger() + { + debuggerCore = debugger.DebuggerCore; + + RegisterDebuggerEvents(); + + RefreshPad(); + } + + protected virtual void RegisterDebuggerEvents() + { + + } + + public virtual void RefreshPad() + { + + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs index 110d07b163..e245e4212d 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/ExceptionHistoryPad.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using System.Drawing; using System.CodeDom.Compiler; using System.Collections; +using System.Collections.Generic; using System.IO; using System.Diagnostics; using ICSharpCode.Core; @@ -19,13 +20,12 @@ using Debugger; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class ExceptionHistoryPad : AbstractPadContent + public class ExceptionHistoryPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - ListView exceptionHistoryList; + List exceptions = new List(); + ColumnHeader time = new ColumnHeader(); ColumnHeader exception = new ColumnHeader(); ColumnHeader location = new ColumnHeader(); @@ -36,15 +36,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads } } - public ExceptionHistoryPad() - { - InitializeComponents(); - } - - void InitializeComponents() + protected override void InitializeComponents() { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; - exceptionHistoryList = new ListView(); exceptionHistoryList.FullRowSelect = true; exceptionHistoryList.AutoArrange = true; @@ -60,25 +53,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads time.Width = 80; RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } } - public void InitializeDebugger() - { - debuggerCore = debugger.DebuggerCore; - - debugger.ExceptionHistoryModified += new EventHandler(ExceptionHistoryModified); - - RefreshList(); - } - public override void RedrawContent() { time.Text = ResourceService.GetString("MainWindow.Windows.Debug.ExceptionHistory.Time"); @@ -86,6 +62,21 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads location.Text = ResourceService.GetString("AddIns.HtmlHelp2.Location"); } + + protected override void RegisterDebuggerEvents() + { + debuggerCore.ProcessExited += delegate { + exceptions.Clear(); + RefreshPad(); + }; + debuggerCore.DebuggingPaused += delegate (object sender, DebuggingPausedEventArgs e) { + if (e.Reason == PausedReason.Exception) { + exceptions.Add(debuggerCore.SelectedThread.CurrentException); + RefreshPad(); + } + }; + } + void ExceptionHistoryListItemActivate(object sender, EventArgs e) { SourcecodeSegment nextStatement = ((Debugger.Exception)(exceptionHistoryList.SelectedItems[0].Tag)).Location; @@ -102,31 +93,15 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads if (content is IPositionable) { ((IPositionable)content).JumpTo((int)nextStatement.StartLine - 1, (int)nextStatement.StartColumn - 1); } - - /*if (content.Control is TextEditorControl) { - IDocument document = ((TextEditorControl)content.Control).Document; - LineSegment line = document.GetLineSegment((int)nextStatement.StartLine - 1); - int offset = line.Offset + (int)nextStatement.StartColumn; - currentLineMarker = new TextMarker(offset, (int)nextStatement.EndColumn - (int)nextStatement.StartColumn, TextMarkerType.SolidBlock, Color.Yellow); - currentLineMarkerParent = document; - currentLineMarkerParent.MarkerStrategy.TextMarker.Add(currentLineMarker); - document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.WholeTextArea)); - document.CommitUpdate(); - }*/ } } - - void ExceptionHistoryModified(object sender, EventArgs e) - { - RefreshList(); - } - public void RefreshList() + public override void RefreshPad() { exceptionHistoryList.BeginUpdate(); exceptionHistoryList.Items.Clear(); - foreach(Debugger.Exception exception in debugger.ExceptionHistory) { + foreach(Debugger.Exception exception in exceptions) { string location; if (exception.Location != null) { location = exception.Location.SourceFilename + ":" + exception.Location.StartLine; diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs index 328bbaa214..072661368a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs @@ -19,11 +19,8 @@ using Debugger; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class LoadedModulesPad : AbstractPadContent + public class LoadedModulesPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - ListView loadedModulesList; ColumnHeader name = new ColumnHeader(); @@ -41,16 +38,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads return loadedModulesList; } } - - public LoadedModulesPad() //: base("${res:MainWindow.Windows.Debug.Modules}", null) - { - InitializeComponents(); - } - - void InitializeComponents() + + protected override void InitializeComponents() { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; - loadedModulesList = new ListView(); loadedModulesList.FullRowSelect = true; loadedModulesList.AutoArrange = true; @@ -70,24 +60,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads information.Width = 130; RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } - } - - public void InitializeDebugger() - { - debuggerCore = debugger.DebuggerCore; - - debuggerCore.ModuleLoaded += new EventHandler(AddModule); - debuggerCore.ModuleUnloaded += new EventHandler(RemoveModule); - - RefreshList(); } public override void RedrawContent() @@ -101,8 +73,15 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads timestamp.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.TimestampColumn}"); information.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.InformationColumn}"); } + + + protected override void RegisterDebuggerEvents() + { + debuggerCore.ModuleLoaded += AddModule; + debuggerCore.ModuleUnloaded += RemoveModule; + } - void RefreshList() + public override void RefreshPad() { loadedModulesList.Items.Clear(); foreach(Module m in debuggerCore.Modules) { 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 d052ca1a83..8e709e4851 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 @@ -20,11 +20,8 @@ using System.Collections.Generic; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class LocalVarPad : AbstractPadContent + public class LocalVarPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - TreeListView localVarList; ColumnHeader name = new ColumnHeader(); @@ -37,15 +34,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads } } - public LocalVarPad() //: base("${res:MainWindow.Windows.Debug.Local}", null) - { - InitializeComponents(); - } - - void InitializeComponents() + protected override void InitializeComponents() { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; - //iconsService = (ClassBrowserIconsService)ServiceManager.Services.GetService(typeof(ClassBrowserIconsService)); localVarList = new TreeListView(); localVarList.SmallImageList = DebuggerIcons.ImageList; @@ -65,14 +55,13 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } + } + + 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"); } // This is a walkarond for a visual issue @@ -81,13 +70,16 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads localVarList.Visible = true; } - public void InitializeDebugger() + + protected override void RegisterDebuggerEvents() { - debuggerCore = debugger.DebuggerCore; - debuggerCore.DebuggeeStateChanged += delegate { debuggerCore.LocalVariables.Update(); }; - + } + + public override void RefreshPad() + { localVarList.BeginUpdate(); + localVarList.Items.Clear(); AddVariableCollectionToTree(debuggerCore.LocalVariables, localVarList.Items); localVarList.EndUpdate(); } @@ -109,13 +101,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads tree.Add(newItem); } - - 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"); - } private void localVarList_BeforeExpand(object sender, TreeListViewCancelEventArgs e) { diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.Menu.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.Menu.cs new file mode 100644 index 0000000000..2ff067a778 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.Menu.cs @@ -0,0 +1,76 @@ +// +// +// +// +// $Revision: 1253 $ +// + +using System; +using System.Windows.Forms; +using System.Drawing; +using System.CodeDom.Compiler; +using System.Collections; +using System.ComponentModel; +using System.IO; +using System.Diagnostics; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Services; + +using Debugger; + +namespace ICSharpCode.SharpDevelop.Gui.Pads +{ + public partial class RunningThreadsPad + { + ContextMenuStrip CreateContextMenuStrip() + { + ContextMenuStrip menu = new ContextMenuStrip(); + menu.Opening += FillContextMenuStrip; + return menu; + } + + void FillContextMenuStrip(object sender, CancelEventArgs e) + { + ListView.SelectedListViewItemCollection items = runningThreadsList.SelectedItems; + + if (items.Count == 0) { + e.Cancel = true; + return; + } + + ListViewItem item = items[0]; + + ContextMenuStrip menu = sender as ContextMenuStrip; + menu.Items.Clear(); + + ToolStripMenuItem freezeItem; + freezeItem = new ToolStripMenuItem(); + freezeItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Freeze"); + freezeItem.Checked = (item.Tag as Thread).Suspended; + freezeItem.Click += + delegate { + ListView.SelectedListViewItemCollection selItems = runningThreadsList.SelectedItems; + if (selItems.Count == 0) { + return; + } + bool suspended = (selItems[0].Tag as Thread).Suspended; + + if (!debuggerCore.IsPaused) { + MessageBox.Show("You can not freeze or thaw thread while the debugger is running.", "Thread freeze"); + return; + } + + foreach(ListViewItem i in selItems) { + (i.Tag as Thread).Suspended = !suspended; + } + RefreshPad(); + }; + + menu.Items.AddRange(new ToolStripItem[] { + freezeItem, + }); + + e.Cancel = false; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs index fa385ed301..ea5f981eed 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs @@ -20,11 +20,8 @@ using Debugger; namespace ICSharpCode.SharpDevelop.Gui.Pads { - public class RunningThreadsPad : AbstractPadContent + public partial class RunningThreadsPad : DebuggerPad { - WindowsDebugger debugger; - NDebugger debuggerCore; - ListView runningThreadsList; ColumnHeader id = new ColumnHeader(); @@ -38,16 +35,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads return runningThreadsList; } } - - public RunningThreadsPad() //: base("${res:MainWindow.Windows.Debug.Threads}", null) - { - InitializeComponents(); - } - - void InitializeComponents() - { - debugger = (WindowsDebugger)DebuggerService.CurrentDebugger; + protected override void InitializeComponents() + { runningThreadsList = new ListView(); runningThreadsList.FullRowSelect = true; runningThreadsList.AutoArrange = true; @@ -66,26 +56,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads breaked.Width = 80; RedrawContent(); - - if (debugger.ServiceInitialized) { - InitializeDebugger(); - } else { - debugger.Initialize += delegate { - InitializeDebugger(); - }; - } - } - - public void InitializeDebugger() - { - debuggerCore = debugger.DebuggerCore; - - debuggerCore.DebuggeeStateChanged += DebuggeeStateChanged; - debuggerCore.ThreadStarted += ThreadStarted; - debuggerCore.ThreadStateChanged += ThreadStateChanged; - debuggerCore.ThreadExited += ThreadExited; - - RefreshList(); } public override void RedrawContent() @@ -97,58 +67,22 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads breaked.Text = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Frozen"); } - ContextMenuStrip CreateContextMenuStrip() - { - ContextMenuStrip menu = new ContextMenuStrip(); - menu.Opening += FillContextMenuStrip; - return menu; - } - - void FillContextMenuStrip(object sender, CancelEventArgs e) + + protected override void RegisterDebuggerEvents() { - ListView.SelectedListViewItemCollection items = runningThreadsList.SelectedItems; - - if (items.Count == 0) { - e.Cancel = true; - return; - } - - ListViewItem item = items[0]; - - ContextMenuStrip menu = sender as ContextMenuStrip; - menu.Items.Clear(); - - ToolStripMenuItem freezeItem; - freezeItem = new ToolStripMenuItem(); - freezeItem.Text = ResourceService.GetString("MainWindow.Windows.Debug.Threads.Freeze"); - freezeItem.Checked = (item.Tag as Thread).Suspended; - freezeItem.Click += - delegate { - ListView.SelectedListViewItemCollection selItems = runningThreadsList.SelectedItems; - if (selItems.Count == 0) { - return; - } - bool suspended = (selItems[0].Tag as Thread).Suspended; - - if (!debuggerCore.IsPaused) { - MessageBox.Show("You can not freeze or thaw thread while the debugger is running.", "Thread freeze"); - return; - } - - foreach(ListViewItem i in selItems) { - (i.Tag as Thread).Suspended = !suspended; - } - RefreshList(); + debuggerCore.DebuggeeStateChanged += delegate { RefreshPad(); }; + debuggerCore.ThreadStarted += delegate(object sender, ThreadEventArgs e) { + AddThread(e.Thread); + }; + debuggerCore.ThreadStateChanged += delegate(object sender, ThreadEventArgs e) { + RefreshThread(e.Thread); + }; + debuggerCore.ThreadExited += delegate(object sender, ThreadEventArgs e) { + RemoveThread(e.Thread); }; - - menu.Items.AddRange(new ToolStripItem[] { - freezeItem, - }); - - e.Cancel = false; } - void RefreshList() + public override void RefreshPad() { foreach (Thread t in debuggerCore.Threads) { RefreshThread(t); @@ -158,34 +92,14 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads void RunningThreadsListItemActivate(object sender, EventArgs e) { if (debuggerCore.IsPaused) { - if (debuggerCore.CurrentProcess != null) { - debuggerCore.CurrentProcess.SetCurrentThread((Thread)(runningThreadsList.SelectedItems[0].Tag)); + if (debuggerCore.SelectedProcess != null) { + debuggerCore.SelectedProcess.SelectedThread = (Thread)(runningThreadsList.SelectedItems[0].Tag); + debuggerCore.OnDebuggeeStateChanged(); // Force refresh of pads } } else { MessageBox.Show("You can not switch threads while the debugger is running.", "Thread switch"); } - } - - void DebuggeeStateChanged(object sender, DebuggerEventArgs e) - { - RefreshList(); - } - - void ThreadStarted(object sender, ThreadEventArgs e) - { - AddThread(e.Thread); - } - - void ThreadStateChanged(object sender, ThreadEventArgs e) - { - RefreshThread(e.Thread); - } - - void ThreadExited(object sender, ThreadEventArgs e) - { - RemoveThread(e.Thread); - } - + } void AddThread(Thread thread) { @@ -201,10 +115,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads item.Text = thread.ID.ToString(); item.Tag = thread; item.SubItems.Add(thread.Name); - Function location; - location = thread.LastFunctionWithLoadedSymbols; - if (location == null) { - location = thread.LastFunction; + Function location = null; + if (thread.Process.IsPaused) { + location = thread.LastFunctionWithLoadedSymbols; + if (location == null) { + location = thread.LastFunction; + } } if (location != null) { item.SubItems.Add(location.Name); 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 dce11dbb67..7b656faf94 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 @@ -146,7 +146,16 @@ namespace ICSharpCode.SharpDevelop.Services protected override void OnExpanding(DynamicListEventArgs e) { if (!populated) { - Populate(); + if (Variable.Debugger.IsPaused) { + Populate(); + } else { + EventHandler populate = null; + populate = delegate { + Populate(); + Variable.Debugger.DebuggingPaused -= populate; + }; + Variable.Debugger.DebuggingPaused += populate; + } } } 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 d59ae06758..fd2dbc06a0 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 @@ -39,21 +39,8 @@ namespace ICSharpCode.SharpDevelop.Services Properties properties; - bool isDebuggingCache = false; - bool isProcessRunningCache = false; bool serviceInitialized = false; - - List exceptionHistory = new List(); - - public event EventHandler ExceptionHistoryModified; - - protected virtual void OnExceptionHistoryModified() - { - if (ExceptionHistoryModified != null) { - ExceptionHistoryModified(this, EventArgs.Empty); - } - } - + public NDebugger DebuggerCore { get { return debugger; @@ -71,12 +58,6 @@ namespace ICSharpCode.SharpDevelop.Services return serviceInitialized; } } - - public IList ExceptionHistory { - get { - return exceptionHistory.AsReadOnly(); - } - } public WindowsDebugger() { @@ -87,13 +68,13 @@ namespace ICSharpCode.SharpDevelop.Services public bool IsDebugging { get { - return isDebuggingCache; + return serviceInitialized && (debugger.Processes.Count > 0); } } public bool IsProcessRunning { get { - return isProcessRunningCache; + return IsDebugging && debugger.IsRunning; } } @@ -138,7 +119,7 @@ namespace ICSharpCode.SharpDevelop.Services public void StepInto() { - if (debugger.CurrentFunction == null) { + if (debugger.SelectedFunction == null || debugger.IsRunning) { MessageBox.Show("You can not step because there is no function selected to be stepped","Step into"); } else { debugger.StepInto(); @@ -147,7 +128,7 @@ namespace ICSharpCode.SharpDevelop.Services public void StepOver() { - if (debugger.CurrentFunction == null) { + if (debugger.SelectedFunction == null || debugger.IsRunning) { MessageBox.Show("You can not step because there is no function selected to be stepped","Step over"); } else { debugger.StepOver(); @@ -156,7 +137,7 @@ namespace ICSharpCode.SharpDevelop.Services public void StepOut() { - if (debugger.CurrentFunction == null) { + if (debugger.SelectedFunction == null || debugger.IsRunning) { MessageBox.Show("You can not step because there is no function selected to be stepped","Step out"); } else { debugger.StepOut(); @@ -164,15 +145,7 @@ namespace ICSharpCode.SharpDevelop.Services } public event EventHandler DebugStarted; - - protected virtual void OnDebugStarted(EventArgs e) - { - if (DebugStarted != null) { - DebugStarted(this, e); - } - } - - + public event EventHandler DebugStopped; public event EventHandler IsProcessRunningChanged; protected virtual void OnIsProcessRunningChanged(EventArgs e) @@ -181,16 +154,6 @@ namespace ICSharpCode.SharpDevelop.Services IsProcessRunningChanged(this, e); } } - - - public event EventHandler DebugStopped; - - protected virtual void OnDebugStopped(EventArgs e) - { - if (DebugStopped != null) { - DebugStopped(this, e); - } - } /// /// Gets variable of given name. @@ -233,7 +196,7 @@ namespace ICSharpCode.SharpDevelop.Services /// public DebuggerGridControl GetTooltipControl(string variableName) { - Variable variable = GetVariableFromName(variableName); + Variable variable = GetVariableFromName(variableName.Trim()); if (variable == null) { return null; @@ -244,8 +207,8 @@ namespace ICSharpCode.SharpDevelop.Services public bool CanSetInstructionPointer(string filename, int line, int column) { - if (debugger != null && debugger.IsPaused && debugger.CurrentFunction != null) { - SourcecodeSegment seg = debugger.CurrentFunction.CanSetIP(filename, line, column); + if (debugger != null && debugger.IsPaused && debugger.SelectedFunction != null) { + SourcecodeSegment seg = debugger.SelectedFunction.CanSetIP(filename, line, column); return seg != null; } else { return false; @@ -255,7 +218,7 @@ namespace ICSharpCode.SharpDevelop.Services public bool SetInstructionPointer(string filename, int line, int column) { if (CanSetInstructionPointer(filename, line, column)) { - SourcecodeSegment seg = debugger.CurrentFunction.SetIP(filename, line, column); + SourcecodeSegment seg = debugger.SelectedFunction.SetIP(filename, line, column); return seg != null; } else { return false; @@ -296,9 +259,6 @@ namespace ICSharpCode.SharpDevelop.Services foreach (BreakpointBookmark b in DebuggerService.Breakpoints) { AddBreakpoint(b); } - - isDebuggingCache = false; - isProcessRunningCache = true; if (Initialize != null) { Initialize(this, null); @@ -346,31 +306,27 @@ namespace ICSharpCode.SharpDevelop.Services void ProcessStarted(object sender, ProcessEventArgs e) { if (debugger.Processes.Count == 1) { - OnDebugStarted(EventArgs.Empty); - isDebuggingCache = true; - isProcessRunningCache = true; + if (DebugStarted != null) { + DebugStarted(this, EventArgs.Empty); + } } } void ProcessExited(object sender, ProcessEventArgs e) { if (debugger.Processes.Count == 0) { - exceptionHistory.Clear(); - OnDebugStopped(EventArgs.Empty); - isDebuggingCache = false; - isProcessRunningCache = false; + if (DebugStopped != null) { + DebugStopped(this, e); + } } } void DebuggingPaused(object sender, DebuggingPausedEventArgs e) { - isProcessRunningCache = false; OnIsProcessRunningChanged(EventArgs.Empty); if (e.Reason == PausedReason.Exception) { - exceptionHistory.Add(debugger.CurrentThread.CurrentException); - OnExceptionHistoryModified(); - if (debugger.CurrentThread.CurrentException.ExceptionType != ExceptionType.DEBUG_EXCEPTION_UNHANDLED) { + if (debugger.SelectedThread.CurrentException.ExceptionType != ExceptionType.DEBUG_EXCEPTION_UNHANDLED) { // Ignore the exception e.ResumeDebuggingAfterEvent(); return; @@ -378,14 +334,15 @@ namespace ICSharpCode.SharpDevelop.Services JumpToCurrentLine(); - switch (ExceptionForm.Show(debugger.CurrentThread.CurrentException)) { + switch (ExceptionForm.Show(debugger.SelectedThread.CurrentException)) { case ExceptionForm.Result.Break: break; case ExceptionForm.Result.Continue: e.ResumeDebuggingAfterEvent(); return; case ExceptionForm.Result.Ignore: - debugger.CurrentThread.InterceptCurrentException(); + debugger.SelectedThread.InterceptCurrentException(); + e.ResumeDebuggingAfterEvent(); // HACK: Start interception break; } } @@ -398,7 +355,6 @@ namespace ICSharpCode.SharpDevelop.Services void DebuggingResumed(object sender, DebuggerEventArgs e) { - isProcessRunningCache = true; if (!debugger.Evaluating) { DebuggerService.RemoveCurrentLineMarker(); } @@ -410,9 +366,9 @@ namespace ICSharpCode.SharpDevelop.Services SourcecodeSegment nextStatement = debugger.NextStatement; if (nextStatement == null) { DebuggerService.RemoveCurrentLineMarker(); - return; + } else { + DebuggerService.JumpToCurrentLine(nextStatement.SourceFullFilename, nextStatement.StartLine, nextStatement.StartColumn, nextStatement.EndLine, nextStatement.EndColumn); } - DebuggerService.JumpToCurrentLine(nextStatement.SourceFullFilename, nextStatement.StartLine, nextStatement.StartColumn, nextStatement.EndLine, nextStatement.EndColumn); } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj index 8d43d439a7..3c1b14aafe 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj @@ -373,6 +373,9 @@ + + + diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs index ad0d346f46..b997657ba1 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs @@ -13,6 +13,7 @@ // \1\2\n\1{\n\1\tEnterCallback(PausedReason.Other, "\3");\n\1\t\n\1\tExitCallback_Continue();\n\1} using System; +using System.Collections.Generic; using System.Runtime.InteropServices; using Debugger.Wrappers.CorDebug; @@ -37,10 +38,11 @@ namespace Debugger void EnterCallback(PausedReason pausedReason, string name, ICorDebugProcess pProcess) { debugger.TraceMessage("Callback: " + name); - debugger.AssertRunning(); + // ExitProcess may be called at any time when debuggee is killed + if (name != "ExitProcess") debugger.AssertRunning(); debugger.PauseSession = new PauseSession(pausedReason); - debugger.CurrentProcess = debugger.GetProcess(pProcess); - debugger.CurrentProcess.IsRunning = false; + debugger.SelectedProcess = debugger.GetProcess(pProcess); + debugger.SelectedProcess.IsRunning = false; } void EnterCallback(PausedReason pausedReason, string name, ICorDebugAppDomain pAppDomain) @@ -55,22 +57,32 @@ namespace Debugger if (name != "ExitProcess") debugger.AssertRunning(); Thread thread = debugger.GetThread(pThread); debugger.PauseSession = new PauseSession(pausedReason); - debugger.CurrentProcess = thread.Process; - debugger.CurrentProcess.IsRunning = false; - debugger.CurrentProcess.CurrentThread = thread; + debugger.SelectedProcess = thread.Process; + debugger.SelectedProcess.IsRunning = false; + debugger.SelectedProcess.SelectedThread = thread; } void ExitCallback_Continue() { - debugger.CurrentProcess.Continue(); + debugger.SelectedProcess.Continue(); } void ExitCallback_Paused() { - if (debugger.CurrentThread != null) { - debugger.CurrentThread.DeactivateAllSteppers(); + if (debugger.Evaluating) { + // Ignore events during property evaluation + ExitCallback_Continue(); + } else { + if (debugger.SelectedThread != null) { + // Disable all steppers - do not Deactivate since function tracking still needs them + foreach(Stepper s in debugger.SelectedThread.Steppers) { + s.PauseWhenComplete = false; + } + + debugger.SelectedThread.SelectedFunction = debugger.SelectedThread.LastFunctionWithLoadedSymbols; + } + debugger.Pause(); } - debugger.Pause(); } @@ -80,23 +92,22 @@ namespace Debugger { EnterCallback(PausedReason.StepComplete, "StepComplete (" + reason.ToString() + ")", pThread); - Stepper stepper = debugger.GetThread(pThread).GetStepper(pStepper); - if (stepper != null) { - stepper.OnStepComplete(); - if (!stepper.PauseWhenComplete) { + Thread thread = debugger.GetThread(pThread); + Stepper stepper = thread.GetStepper(pStepper); + + thread.Steppers.Remove(stepper); + stepper.OnStepComplete(); + if (stepper.PauseWhenComplete) { + if (debugger.SelectedThread.LastFunction.HasSymbols) { + ExitCallback_Paused(); + } else { + // This should not happen with JMC enabled + debugger.TraceMessage(" - leaving code without symbols"); + ExitCallback_Continue(); - return; } - } - - if (!debugger.CurrentThread.LastFunction.HasSymbols) { - // This should not happen with JMC enabled - debugger.TraceMessage(" - leaving code without symbols"); - - ExitCallback_Continue(); } else { - - ExitCallback_Paused(); + ExitCallback_Continue(); } } @@ -339,11 +350,16 @@ namespace Debugger debugger.RemoveThread(thread); - if (thread.Process.CurrentThread == thread) { - thread.Process.CurrentThread = null; + if (thread.Process.SelectedThread == thread) { + thread.Process.SelectedThread = null; } - ExitCallback_Continue(); + try { + ExitCallback_Continue(); + } catch (COMException e) { + // For some reason this sometimes happens in .NET 1.1 + debugger.TraceMessage("Continue failed in ExitThread callback: " + e.Message); + } } public void ExitAppDomain(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain) @@ -400,7 +416,7 @@ namespace Debugger // Whatch out for the zeros and null! // Exception -> Exception2(pAppDomain, pThread, null, 0, exceptionType, 0); - debugger.CurrentThread.CurrentExceptionType = (ExceptionType)exceptionType; + debugger.SelectedThread.CurrentExceptionType = (ExceptionType)exceptionType; if (ExceptionType.DEBUG_EXCEPTION_UNHANDLED != (ExceptionType)exceptionType) { // Handled exception diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs index 0ed8842dbc..47477bbed9 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs @@ -24,7 +24,7 @@ namespace Debugger PauseSession pauseSession; DebugeeState debugeeState; - Process currentProcess; + Process selectedProcess; public event EventHandler DebuggingResumed; public event EventHandler DebuggingPaused; @@ -59,7 +59,8 @@ namespace Debugger } } - protected virtual void OnDebuggeeStateChanged() + // HACK: should not be public + public virtual void OnDebuggeeStateChanged() { TraceMessage ("Debugger event: OnDebuggeeStateChanged (" + PausedReason.ToString() + ")"); if (DebuggeeStateChanged != null) { @@ -67,35 +68,31 @@ namespace Debugger } } - public Process CurrentProcess { + public Process SelectedProcess { get { - if (IsRunning) return null; - if (currentProcess == null) { - return null; - } else { - return currentProcess; - } + return selectedProcess; } set { - currentProcess = value; + selectedProcess = value; } } - public Thread CurrentThread { + public Thread SelectedThread { get { - if (IsRunning) return null; - if (CurrentProcess == null) return null; - return CurrentProcess.CurrentThread; + if (SelectedProcess == null) { + return null; + } else { + return SelectedProcess.SelectedThread; + } } } - public Function CurrentFunction { + public Function SelectedFunction { get { - if (IsRunning) return null; - if (CurrentThread == null) { + if (SelectedThread == null) { return null; } else { - return CurrentThread.CurrentFunction; + return SelectedThread.SelectedFunction; } } } @@ -119,6 +116,10 @@ namespace Debugger get { return debugeeState; } + private set { + debugeeState = value; + OnDebuggeeStateChanged(); + } } public void AssertPaused() @@ -160,17 +161,14 @@ namespace Debugger internal void Pause() { + if (PausedReason != PausedReason.EvalComplete) { + DebugeeState = new DebugeeState(); + } + OnDebuggingPaused(); // Debugger state is unknown after calling OnDebuggingPaused (it may be resumed) - if (IsPaused) { - if (PausedReason != PausedReason.EvalComplete) { - debugeeState = new DebugeeState(); - OnDebuggeeStateChanged(); - } - } - if (IsPaused) { pausedHandle.Set(); } @@ -181,14 +179,10 @@ namespace Debugger if (IsRunning) { throw new DebuggerException("Already resumed"); } - + + pauseSession = null; OnDebuggingResumed(); - pausedHandle.Reset(); - - pauseSession = null; - - currentProcess = null; } /// @@ -230,22 +224,22 @@ namespace Debugger public void StepInto() { - CurrentFunction.StepInto(); + SelectedFunction.StepInto(); } public void StepOver() { - CurrentFunction.StepOver(); + SelectedFunction.StepOver(); } public void StepOut() { - CurrentFunction.StepOut(); + SelectedFunction.StepOut(); } public void Continue() { - CurrentProcess.Continue(); + SelectedProcess.Continue(); } public void Terminate() diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs index d56d5be9ad..2846127f23 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs @@ -130,7 +130,7 @@ namespace Debugger ClearThreads(); - currentProcess = null; + selectedProcess = null; pausedHandle.Reset(); pauseSession = null; @@ -201,10 +201,10 @@ namespace Debugger public SourcecodeSegment NextStatement { get { - if (CurrentFunction == null) { + if (SelectedFunction == null || IsRunning) { return null; } else { - return CurrentFunction.NextStatement; + return SelectedFunction.NextStatement; } } } @@ -218,11 +218,11 @@ namespace Debugger void OnUpdatingLocalVariables(object sender, VariableCollectionEventArgs e) { - if (CurrentFunction == null) { + if (SelectedFunction == null || IsRunning) { e.VariableCollection.UpdateTo(new Variable[] {}); // Make it empty } else { - e.VariableCollection.UpdateTo(CurrentFunction.Variables); - CurrentFunction.Expired += delegate { + e.VariableCollection.UpdateTo(SelectedFunction.Variables); + SelectedFunction.Expired += delegate { e.VariableCollection.UpdateTo(new Variable[] {}); }; } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs index 94e52016a1..7560d9be71 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs @@ -25,6 +25,8 @@ namespace Debugger ICorDebugILFrame corILFrame; object corILFramePauseSession; + Stepper stepOutStepper; + bool steppedOut; Thread thread; uint chainIndex; @@ -109,18 +111,17 @@ namespace Debugger this.thread = thread; this.chainIndex = chainIndex; this.frameIndex = frameIndex; - this.corILFrame = corILFrame; - this.corILFramePauseSession = debugger.PauseSession; + this.CorILFrame = corILFrame; corFunction = corILFrame.Function; module = debugger.GetModule(corFunction.Module); methodProps = module.MetaData.GetMethodProps(corFunction.Token); // Expiry the function when it is finished - Stepper tracingStepper = thread.CreateStepper(); - tracingStepper.CorStepper.StepOut(); - tracingStepper.PauseWhenComplete = false; - tracingStepper.StepComplete += delegate { + stepOutStepper = CreateStepper(); + stepOutStepper.CorStepper.StepOut(); + stepOutStepper.PauseWhenComplete = false; + stepOutStepper.StepComplete += delegate { steppedOut = true; OnExpired(EventArgs.Empty); }; @@ -130,11 +131,15 @@ namespace Debugger get { if (HasExpired) throw new DebuggerException("Function has expired"); if (corILFramePauseSession != debugger.PauseSession) { - corILFrame = thread.GetFunctionAt(chainIndex, frameIndex).CorILFrame; - corILFramePauseSession = debugger.PauseSession; + CorILFrame = thread.GetFrameAt(chainIndex, frameIndex).As(); } return corILFrame; } + set { + if (value == null) throw new DebuggerException("Can not set frame to null"); + corILFrame = value; + corILFramePauseSession = debugger.PauseSession; + } } internal uint corInstructionPtr { @@ -167,6 +172,17 @@ namespace Debugger } } + internal Stepper CreateStepper() + { + Stepper stepper = new Stepper(debugger, corILFrame.CreateStepper()); + if (stepper.CorStepper.Is()) { // Is the debuggee .NET 2.0? + stepper.CorStepper.SetUnmappedStopMask(CorDebugUnmappedStop.STOP_NONE); + (stepper.CorStepper.CastTo()).SetJMC(1 /* true */); + } + thread.Steppers.Add(stepper); + return stepper; + } + public void StepInto() { Step(true); @@ -179,11 +195,7 @@ namespace Debugger public void StepOut() { - ICorDebugStepper stepper = CorILFrame.CreateStepper(); - stepper.StepOut(); - - debugger.CurrentThread.AddActiveStepper(stepper); - + stepOutStepper.PauseWhenComplete = true; debugger.Continue(); } @@ -200,38 +212,18 @@ namespace Debugger throw new DebuggerException("Unable to step. Next statement not aviable"); } - ICorDebugStepper stepper; + Stepper stepper; if (stepIn) { - stepper = CorILFrame.CreateStepper(); - - if (stepper.Is()) { // Is the debuggee .NET 2.0? - stepper.SetUnmappedStopMask(CorDebugUnmappedStop.STOP_NONE); - (stepper.CastTo()).SetJMC(1 /* true */); - } - - fixed (int* ranges = nextSt.StepRanges) { - stepper.StepRange(1 /* true - step in*/ , (IntPtr)ranges, (uint)nextSt.StepRanges.Length / 2); - } - - debugger.CurrentThread.AddActiveStepper(stepper); + stepper = CreateStepper(); + stepper.CorStepper.StepRange(true /* step in */, nextSt.StepRanges); } - // Mind that step in which ends in code without symblols is cotinued - // so the next step over ensures that we atleast do step over + // Without JMC step in which ends in code without symblols is cotinued. + // The next step over ensures that we at least do step over. - stepper = CorILFrame.CreateStepper(); - - if (stepper.Is()) { // Is the debuggee .NET 2.0? - stepper.SetUnmappedStopMask(CorDebugUnmappedStop.STOP_NONE); - (stepper.CastTo()).SetJMC(1 /* true */); - } - - fixed (int* ranges = nextSt.StepRanges) { - stepper.StepRange(0 /* false - step over*/ , (IntPtr)ranges, (uint)nextSt.StepRanges.Length / 2); - } - - debugger.CurrentThread.AddActiveStepper(stepper); + stepper = CreateStepper(); + stepper.CorStepper.StepRange(false /* step over */ , nextSt.StepRanges); debugger.Continue(); } @@ -420,28 +412,26 @@ namespace Debugger } } - internal ICorDebugValue GetArgumentValue(int index) - { - // Non-static functions include 'this' as first argument - return CorILFrame.GetArgument((uint)(IsStatic? index : (index + 1))); - } - public Variable GetArgumentVariable(int index) { return new Variable(debugger, GetParameterName(index), - delegate { - if (this.HasExpired) { - return new UnavailableValue(debugger, "Function has expired"); - } else { - try { - return Value.CreateValue(debugger, GetArgumentValue(index)); - } catch (COMException e) { - if ((uint)e.ErrorCode == 0x80131304) return new UnavailableValue(debugger, "Unavailable in optimized code"); - throw; - } - } - }); + delegate { return GetArgumentValue(index); }); + } + + Value GetArgumentValue(int index) + { + if (this.HasExpired) { + return new UnavailableValue(debugger, "Function has expired"); + } else { + try { + // Non-static functions include 'this' as first argument + return Value.CreateValue(debugger, CorILFrame.GetArgument((uint)(IsStatic? index : (index + 1)))); + } catch (COMException e) { + if ((uint)e.ErrorCode == 0x80131304) return new UnavailableValue(debugger, "Unavailable in optimized code"); + throw; + } + } } public IEnumerable ArgumentVariables { @@ -481,20 +471,23 @@ namespace Debugger { return new Variable(debugger, symVar.Name, - delegate { - if (this.HasExpired) { - return new UnavailableValue(debugger, "Function has expired"); - } else { - ICorDebugValue corValue; - try { - corValue = CorILFrame.GetLocalVariable((uint)symVar.AddressField1); - } catch (COMException e) { - if ((uint)e.ErrorCode == 0x80131304) return new UnavailableValue(debugger, "Unavailable in optimized code"); - throw; - } - return Value.CreateValue(debugger, corValue); - } - }); + delegate { return GetValueOfLocalVariable(symVar); }); + } + + Value GetValueOfLocalVariable(ISymUnmanagedVariable symVar) + { + if (this.HasExpired) { + return new UnavailableValue(debugger, "Function has expired"); + } else { + ICorDebugValue corValue; + try { + corValue = CorILFrame.GetLocalVariable((uint)symVar.AddressField1); + } catch (COMException e) { + if ((uint)e.ErrorCode == 0x80131304) return new UnavailableValue(debugger, "Unavailable in optimized code"); + throw; + } + return Value.CreateValue(debugger, corValue); + } } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs index 65a646ed45..f1e13ca554 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs @@ -20,7 +20,7 @@ namespace Debugger ICorDebugProcess corProcess; - Thread currentThread; + Thread selectedThread; bool isProcessRunning = true; public NDebugger Debugger { @@ -41,27 +41,14 @@ namespace Debugger } } - public Thread CurrentThread { + public Thread SelectedThread { get { - if (currentThread == null) { - IList threads = Threads; - if (threads.Count > 0) { - currentThread = threads[0]; - } - } - return currentThread; + return selectedThread; } - internal set { - currentThread = value; + set { + selectedThread = value; } } - - public void SetCurrentThread(Thread thread) - { - CurrentThread = thread; - - debugger.Pause(); - } public IList Threads { get { @@ -127,7 +114,21 @@ namespace Debugger isProcessRunning = false; debugger.PauseSession = new PauseSession(PausedReason.Break); - debugger.CurrentProcess = this; + debugger.SelectedProcess = this; + + if (this.SelectedThread == null && this.Threads.Count > 0) { + this.SelectedThread = this.Threads[0]; + } + + if (debugger.SelectedThread != null) { + // Disable all steppers - do not Deactivate since function tracking still needs them + foreach(Stepper s in debugger.SelectedThread.Steppers) { + s.PauseWhenComplete = false; + } + + debugger.SelectedThread.SelectedFunction = debugger.SelectedThread.LastFunctionWithLoadedSymbols; + } + debugger.Pause(); } @@ -146,7 +147,7 @@ namespace Debugger { // Resume stoped tread if (corProcess.IsRunning == 0) { - Continue(); // TODO: Remove this... + corProcess.Continue(0); // TODO: Remove this... } // Stop&terminate - both must be called corProcess.Stop(5000); // TODO: ...and this diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs index 83fb4f0a2d..182055ff77 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs @@ -23,7 +23,6 @@ namespace Debugger internal ExceptionType currentExceptionType; Process process; - List activeSteppers = new List(); List steppers = new List(); uint id; @@ -32,7 +31,7 @@ namespace Debugger string lastName = string.Empty; bool hasBeenLoaded = false; - Function currentFunction; + Function selectedFunction; public NDebugger Debugger { get { @@ -137,19 +136,6 @@ namespace Debugger if (corThread.Is()) { // Is the debuggee .NET 2.0? corThread.CastTo().InterceptCurrentException(LastFunction.CorILFrame.CastTo()); } - process.Continue(); - } - - internal Stepper CreateStepper() - { - Stepper stepper = new Stepper(debugger, corThread.CreateStepper()); - stepper.StepComplete += delegate { - steppers.Remove(stepper); - }; - - steppers.Add(stepper); - - return stepper; } internal Stepper GetStepper(ICorDebugStepper corStepper) @@ -159,35 +145,13 @@ namespace Debugger return stepper; } } - return null; - } - - internal IList Steppers { - get { - return steppers.AsReadOnly(); - } + throw new DebuggerException("Stepper is not in collection"); } - internal IList ActiveSteppers { + internal List Steppers { get { - return activeSteppers.AsReadOnly(); - } - } - - internal void AddActiveStepper(ICorDebugStepper stepper) - { - activeSteppers.Add(stepper); - } - - internal void DeactivateAllSteppers() - { - foreach(ICorDebugStepper stepper in activeSteppers) { - if (stepper.IsActive != 0) { - stepper.Deactivate(); - debugger.TraceMessage("Stepper deactivated"); - } + return steppers; } - activeSteppers.Clear(); } public event EventHandler ThreadStateChanged; @@ -203,123 +167,101 @@ namespace Debugger { return String.Format("ID = {0,-10} Name = {1,-20} Suspended = {2,-8}", ID, Name, Suspended); } - - + + public Exception CurrentException { get { return new Exception(this); } } - + public IEnumerable Callstack { get { - return GetCallstackAt(uint.MaxValue, uint.MaxValue); + process.AssertPaused(); + + ICorDebugChainEnum corChainEnum = corThread.EnumerateChains(); + uint chainIndex = corChainEnum.Count; + foreach(ICorDebugChain corChain in corChainEnum.Enumerator) { + chainIndex--; + + if (corChain.IsManaged == 0) continue; // Only managed ones + + ICorDebugFrameEnum corFrameEnum = corChain.EnumerateFrames(); + uint frameIndex = corFrameEnum.Count; + foreach(ICorDebugFrame corFrame in corFrameEnum.Enumerator) { + frameIndex--; + + if (corFrame.Is()) { + Function function = GetFunctionFromCache(chainIndex, frameIndex, corFrame.As()); + if (function != null) { + yield return function; + } + } + } + } } } - internal Function GetFunctionAt(uint firstChainIndex, uint firstFrameIndex) + Dictionary chainCache = new Dictionary(); + + class Chain { + public Dictionary Frames = new Dictionary(); + } + + Function GetFunctionFromCache(uint chainIndex, uint frameIndex, ICorDebugILFrame corFrame) { - foreach(Function f in GetCallstackAt(firstChainIndex, firstFrameIndex)) { - return f; - } - throw new DebuggerException("Function not found"); + try { + if (chainCache.ContainsKey(chainIndex) && + chainCache[chainIndex].Frames.ContainsKey(frameIndex) && + !chainCache[chainIndex].Frames[frameIndex].HasExpired) { + + Function function = chainCache[chainIndex].Frames[frameIndex]; + function.CorILFrame = corFrame; + return function; + } else { + Function function = new Function(this, chainIndex, frameIndex, corFrame.CastTo()); + if (!chainCache.ContainsKey(chainIndex)) chainCache[chainIndex] = new Chain(); + chainCache[chainIndex].Frames[frameIndex] = function; + function.Expired += delegate { chainCache[chainIndex].Frames.Remove(frameIndex); }; + return function; + } + } catch (COMException) { // TODO + return null; + }; } - internal IEnumerable GetCallstackAt(uint firstChainIndex, uint firstFrameIndex) + internal ICorDebugFrame GetFrameAt(uint chainIndex, uint frameIndex) { process.AssertPaused(); ICorDebugChainEnum corChainEnum = corThread.EnumerateChains(); + if (chainIndex >= corChainEnum.Count) throw new ArgumentException("Chain index too big", "chainIndex"); + corChainEnum.Skip(corChainEnum.Count - chainIndex - 1); - uint chainCount = corChainEnum.Count; + ICorDebugChain corChain = corChainEnum.Next(); - uint chainIndex = chainCount; + if (corChain.IsManaged == 0) throw new ArgumentException("Chain is not managed", "chainIndex"); - if (firstChainIndex != uint.MaxValue) { - int skipCount = (int)chainCount - (int)firstChainIndex - 1; - if (skipCount < 0) throw new ArgumentException("Chain index too big", "firstChainIndex"); - corChainEnum.Skip((uint)skipCount); - chainIndex -= (uint)skipCount; - firstChainIndex = chainIndex - 1; - } + ICorDebugFrameEnum corFrameEnum = corChain.EnumerateFrames(); + if (frameIndex >= corFrameEnum.Count) throw new ArgumentException("Frame index too big", "frameIndex"); + corFrameEnum.Skip(corFrameEnum.Count - frameIndex - 1); - while (true) { - ICorDebugChain[] corChains = new ICorDebugChain[1]; // One at time - uint chainsFetched = corChainEnum.Next(1, corChains); - if (chainsFetched == 0) break; // We are done - - chainIndex--; - - CorDebugChainReason reason = corChains[0].Reason; - - if (corChains[0].IsManaged == 0) continue; // Only managed ones - - ICorDebugFrameEnum corFrameEnum = corChains[0].EnumerateFrames(); - - uint frameCount = corFrameEnum.Count; - - uint frameIndex = frameCount; - - if (firstFrameIndex != uint.MaxValue && chainIndex == firstChainIndex) { - int skipCount = (int)frameCount - (int)firstFrameIndex - 1; - if (skipCount < 0) throw new ArgumentException("Frame index too big", "firstFrameIndex"); - corFrameEnum.Skip((uint)skipCount); - frameIndex -= (uint)skipCount; - } - - while (true) { - ICorDebugFrame[] corFrames = new ICorDebugFrame[1]; // Only one at time - uint framesFetched = corFrameEnum.Next(1, corFrames); - if (framesFetched == 0) break; // We are done - - frameIndex--; - - Function function = null; - try { - if (corFrames[0].Is()) { - function = new Function(this, chainIndex, frameIndex, corFrames[0].CastTo()); - } - } catch (COMException) { - // TODO - }; - - if (function != null) { - yield return function; - } - } - } + return corFrameEnum.Next(); } - public Function CurrentFunction { + public Function SelectedFunction { get { - process.AssertPaused(); - - if (currentFunction == null) { - currentFunction = LastFunctionWithLoadedSymbols; - } - - if (currentFunction != null && currentFunction.HasSymbols) { - return currentFunction; - } else { - return null; - } + return selectedFunction; } - internal set { + set { if (value != null && !value.HasSymbols) { - throw new DebuggerException("CurrentFunction must have symbols"); + throw new DebuggerException("SelectedFunction must have symbols"); } - currentFunction = value; + selectedFunction = value; } } - public void SetCurrentFunction(Function function) - { - CurrentFunction = function; - - debugger.Pause(); - } - public Function LastFunctionWithLoadedSymbols { get { foreach (Function function in Callstack) { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs index 0721f27cc7..32bc6a6bee 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ArrayValue.cs @@ -18,32 +18,36 @@ namespace Debugger { public class ArrayValue: Value { - ICorDebugArrayValue corArrayValue; uint[] dimensions; - - + uint lenght; CorElementType corElementType; readonly uint rank; - + + protected ICorDebugArrayValue CorArrayValue { + get { + return this.CorValue.CastTo(); + } + } + public uint Lenght { get { return lenght; } } - + public string ElementsType { get { return CorTypeToString(corElementType); } } - + public uint Rank { get { return rank; } } - + public override string AsString { get { string txt = "{" + ElementsType + "["; @@ -57,15 +61,14 @@ namespace Debugger internal unsafe ArrayValue(NDebugger debugger, ICorDebugValue corValue):base(debugger, corValue) { - corArrayValue = this.corValue.CastTo(); - corElementType = (CorElementType)corArrayValue.ElementType; + corElementType = (CorElementType)CorArrayValue.ElementType; - rank = corArrayValue.Rank; - lenght = corArrayValue.Count; + rank = CorArrayValue.Rank; + lenght = CorArrayValue.Count; dimensions = new uint[rank]; fixed (void* pDimensions = dimensions) - corArrayValue.GetDimensions(rank, new IntPtr(pDimensions)); + CorArrayValue.GetDimensions(rank, new IntPtr(pDimensions)); } @@ -106,20 +109,23 @@ namespace Debugger return new Variable(debugger, elementName, - delegate { - ArrayValue updatedVal = getter() as ArrayValue; - if (this.IsEquivalentValue(updatedVal)) { - ICorDebugValue element; - unsafe { - fixed (void* pIndices = indices) { - element = updatedVal.corArrayValue.GetElement(rank, new IntPtr(pIndices)); - } - } - return Value.CreateValue(debugger, element); - } else { - return new UnavailableValue(debugger, "Value is not array"); - } - }); + delegate { return GetValueOfItem(indices, getter); }); + } + + Value GetValueOfItem(uint[] indices, ValueGetter getter) + { + ArrayValue updatedVal = getter() as ArrayValue; + if (this.IsEquivalentValue(updatedVal)) { + ICorDebugValue element; + unsafe { + fixed (void* pIndices = indices) { + element = updatedVal.CorArrayValue.GetElement(rank, new IntPtr(pIndices)); + } + } + return Value.CreateValue(debugger, element); + } else { + return new UnavailableValue(debugger, "Value is not array"); + } } public override bool MayHaveSubVariables { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs index c71d069ddd..8c695a4339 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/Eval.cs @@ -32,6 +32,8 @@ namespace Debugger Value result; string error; + DebugeeState debugeeStateWhenEvaluated; + public event EventHandler EvalStarted; public event EventHandler EvalComplete; @@ -43,7 +45,7 @@ namespace Debugger public EvalState EvalState { get { - if (result != null && result.IsExpired) { + if (result != null && (debugeeStateWhenEvaluated != debugger.DebugeeState || result.IsExpired)) { return EvalState.Expired; } else { return evalState; @@ -117,7 +119,7 @@ namespace Debugger ICorDebugValue[] args = getArgs(); if (args == null) { - error = "Can not evaluate property of property"; + error = "Can not get args for eval"; evalState = EvalState.Error; if (EvalComplete != null) { EvalComplete(this, new EvalEventArgs(this)); @@ -156,8 +158,11 @@ namespace Debugger protected internal virtual void OnEvalComplete(bool successful) { + // Eval result should be ICorDebugHandleValue so it should survive Continue() result = Value.CreateValue(debugger, corEval.Result); + debugeeStateWhenEvaluated = debugger.DebugeeState; + if (result == null) { evalState = EvalState.EvaluatedNoResult; } else { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NDebugger-Evals.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NDebugger-Evals.cs index b09bbff6b5..5c1cbdab26 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NDebugger-Evals.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Evals/NDebugger-Evals.cs @@ -110,7 +110,7 @@ namespace Debugger this.AssertPaused(); // TODO: Investigate other threads, are they alowed to run? - if (SetupNextEvaluation(CurrentThread)) { + if (SetupNextEvaluation(SelectedThread)) { evaluating = true; this.Continue(); return true; diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs index 316e72a751..a7a3145aa5 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectValue.cs @@ -67,16 +67,6 @@ namespace Debugger } */ - internal ICorDebugHandleValue SoftReference { - get { - ICorDebugHeapValue2 heapValue = this.CorValue.As(); - if (heapValue == null) { // TODO: Investigate - return null; - } - return heapValue.CreateHandle(CorDebugHandleType.HANDLE_WEAK_TRACK_RESURRECTION); - } - } - public override string Type { get{ return classProps.Name; @@ -97,7 +87,7 @@ namespace Debugger internal unsafe ObjectValue(NDebugger debugger, ICorDebugValue corValue):base(debugger, corValue) { - corClass = this.corValue.CastTo().Class; + corClass = this.CorValue.CastTo().Class; InitObjectVariable(); } @@ -141,20 +131,23 @@ namespace Debugger foreach(FieldProps f in metaData.EnumFields(ClassToken)) { FieldProps field = f; // One per scope/delegate if (field.IsStatic && field.IsLiteral) continue; // Skip field - if (!field.IsStatic && corValue == null) continue; // Skip field + if (!field.IsStatic && CorValue == null) continue; // Skip field yield return new ClassVariable(debugger, field.Name, field.IsStatic, field.IsPublic, - delegate { - Value updatedVal = getter(); - if (updatedVal is UnavailableValue) return updatedVal; - if (this.IsEquivalentValue(updatedVal)) { - return GetValue(updatedVal, field); - } else { - return new UnavailableValue(debugger, "Object type changed"); - } - }); + delegate { return GetValueOfField(field, getter); }); + } + } + + Value GetValueOfField(FieldProps field, ValueGetter getter) + { + Value updatedVal = getter(); + if (updatedVal is UnavailableValue) return updatedVal; + if (this.IsEquivalentValue(updatedVal)) { + return GetValue(updatedVal, field); + } else { + return new UnavailableValue(debugger, "Object type changed"); } } @@ -167,35 +160,38 @@ namespace Debugger method.Name.Remove(0, 4), method.IsStatic, method.IsPublic, - delegate { - Value updatedVal = getter(); - if (updatedVal is UnavailableValue) return null; - if (this.IsEquivalentValue(updatedVal) && ((ObjectValue)updatedVal).SoftReference != null) { - return CreatePropertyEval(method, getter); - } else { - return null; - } - }); + delegate { return CreatePropertyEval(method, getter); }); } } } Eval CreatePropertyEval(MethodProps method, ValueGetter getter) { - ICorDebugFunction evalCorFunction = Module.CorModule.GetFunctionFromToken(method.Token); - - return new Eval(debugger, evalCorFunction, delegate { - Value updatedVal = getter(); - if (this.IsEquivalentValue(updatedVal) && ((ObjectValue)updatedVal).SoftReference != null) { - if (method.IsStatic) { - return new ICorDebugValue[] {}; - } else { - return new ICorDebugValue[] {((ObjectValue)updatedVal).SoftReference.CastTo()}; - } - } else { - return null; - } - }); + Value updatedVal = getter(); + if (updatedVal is UnavailableValue) { + return null; + } + if (this.IsEquivalentValue(updatedVal) && ((ObjectValue)updatedVal).SoftReference != null) { + ICorDebugFunction evalCorFunction = Module.CorModule.GetFunctionFromToken(method.Token); + + return new Eval(debugger, evalCorFunction, delegate { return GetArgsForEval(method, getter); }); + } else { + return null; + } + } + + ICorDebugValue[] GetArgsForEval(MethodProps method, ValueGetter getter) + { + Value updatedVal = getter(); + if (this.IsEquivalentValue(updatedVal) && ((ObjectValue)updatedVal).SoftReference != null) { + if (method.IsStatic) { + return new ICorDebugValue[] {}; + } else { + return new ICorDebugValue[] {((ObjectValue)updatedVal).SoftReference.CastTo()}; + } + } else { + return null; + } } public override bool IsEquivalentValue(Value val) @@ -209,8 +205,8 @@ namespace Debugger { // Current frame is used to resolve context specific static values (eg. ThreadStatic) ICorDebugFrame curFrame = null; - if (debugger.CurrentThread != null && debugger.CurrentThread.LastFunction != null && debugger.CurrentThread.LastFunction.CorILFrame != null) { - curFrame = debugger.CurrentThread.LastFunction.CorILFrame.CastTo(); + if (debugger.IsPaused && debugger.SelectedThread != null && debugger.SelectedThread.LastFunction != null && debugger.SelectedThread.LastFunction.CorILFrame != null) { + curFrame = debugger.SelectedThread.LastFunction.CorILFrame.CastTo(); } try { @@ -231,20 +227,23 @@ namespace Debugger if (HasBaseClass) { return new Variable(debugger, "", - delegate { - Value updatedVal = getter(); - if (updatedVal is UnavailableValue) return updatedVal; - if (this.IsEquivalentValue(updatedVal)) { - return ((ObjectValue)updatedVal).BaseClass; - } else { - return new UnavailableValue(debugger, "Object type changed"); - } - }); + delegate { return GetBaseClassValue(getter); }); } else { return null; } } + Value GetBaseClassValue(ValueGetter getter) + { + Value updatedVal = getter(); + if (updatedVal is UnavailableValue) return updatedVal; + if (this.IsEquivalentValue(updatedVal)) { + return ((ObjectValue)updatedVal).BaseClass; + } else { + return new UnavailableValue(debugger, "Object type changed"); + } + } + public unsafe ObjectValue BaseClass { get { if (baseClass == null) baseClass = GetBaseClass(); @@ -296,7 +295,11 @@ namespace Debugger throw new DebuggerException("Unable to get base class: " + fullTypeName); } else { ICorDebugClass superClass = corModuleSuperclass.GetClassFromToken(classProps.SuperClassToken); - return new ObjectValue(debugger, corValue, superClass); + if (corHandleValue != null) { + return new ObjectValue(debugger, corHandleValue.As(), superClass); + } else { + return new ObjectValue(debugger, CorValue, superClass); + } } } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PrimitiveValue.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PrimitiveValue.cs index e8956ddcd7..e86833bb58 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PrimitiveValue.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PrimitiveValue.cs @@ -28,9 +28,9 @@ namespace Debugger public object Primitive { get { if (CorType == CorElementType.STRING) { - return (corValue.CastTo()).String; + return (CorValue.CastTo()).String; } else { - return (corValue.CastTo()).Value; + return (CorValue.CastTo()).Value; } } set { @@ -45,7 +45,7 @@ namespace Debugger if (CorType == CorElementType.STRING) { throw new NotSupportedException(); } else { - (corValue.CastTo()).Value = newValue; + (CorValue.CastTo()).Value = newValue; } OnValueChanged(); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs index 109239235d..732d714914 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/PropertyVariable.cs @@ -24,13 +24,16 @@ namespace Debugger internal PropertyVariable(NDebugger debugger, string name, bool isStatic, bool isPublic, EvalCreator evalCreator):base(debugger, name, isStatic, isPublic, null) { this.evalCreator = evalCreator; - this.valueGetter = delegate { - if (Eval != null) { - return Eval.Result; - } else { - return new UnavailableValue(debugger, "Property has expired"); - } - }; + this.valueGetter = delegate { return GetValueOfResult(); }; + } + + Value GetValueOfResult() + { + if (Eval != null) { + return Eval.Result; + } else { + return new UnavailableValue(debugger, "Property unavailable"); + } } public bool IsEvaluated { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs index 95381dff8f..d643f57dc8 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Value.cs @@ -16,7 +16,9 @@ namespace Debugger public abstract class Value: RemotingObjectBase { protected NDebugger debugger; - protected ICorDebugValue corValue; + ICorDebugValue corValue; + // ICorDebugHandleValue can be used to get corValue back after Continue() + protected ICorDebugHandleValue corHandleValue; object pauseSessionAtCreation; public event EventHandler ValueChanged; @@ -29,7 +31,30 @@ namespace Debugger internal ICorDebugValue CorValue { get { - return corValue; + if (pauseSessionAtCreation == debugger.PauseSession) { + return corValue; + } else { + if (corHandleValue == null) { + throw new DebuggerException("CorValue has expired"); + } else { + corValue = DereferenceUnbox(corHandleValue.As()); + pauseSessionAtCreation = debugger.PauseSession; + return corValue; + } + } + } + } + + protected ICorDebugHandleValue SoftReference { + get { + if (corHandleValue != null) return corHandleValue; + + ICorDebugHeapValue2 heapValue = this.CorValue.As(); + if (heapValue == null) { // TODO: Investigate - hmmm, value types are not at heap? + return null; + } else { + return heapValue.CreateHandle(CorDebugHandleType.HANDLE_WEAK_TRACK_RESURRECTION); + } } } @@ -38,13 +63,17 @@ namespace Debugger /// public bool IsExpired { get { - return pauseSessionAtCreation != debugger.PauseSession; + if (corHandleValue == null) { + return pauseSessionAtCreation != debugger.PauseSession; + } else { + return false; + } } } internal CorElementType CorType { get { - return GetCorType(corValue); + return GetCorType(CorValue); } } @@ -104,6 +133,9 @@ namespace Debugger { this.debugger = debugger; if (corValue != null) { + if (corValue.Is()) { + corHandleValue = corValue.As(); + } this.corValue = DereferenceUnbox(corValue); } this.pauseSessionAtCreation = debugger.PauseSession; @@ -203,12 +235,12 @@ namespace Debugger internal static Value CreateValue(NDebugger debugger, ICorDebugValue corValue) { CorElementType type = Value.GetCorType(corValue); - + if (Value.DereferenceUnbox(corValue) == null) { return new NullValue(debugger, corValue); } - + switch(type) { case CorElementType.BOOLEAN: diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugChainEnum.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugChainEnum.cs new file mode 100644 index 0000000000..e9c25a1b93 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugChainEnum.cs @@ -0,0 +1,40 @@ +// +// +// +// +// $Revision$ +// + +namespace Debugger.Wrappers.CorDebug +{ + using System; + using System.Collections.Generic; + + + public partial class ICorDebugChainEnum + { + public IEnumerable Enumerator { + get { + while (true) { + ICorDebugChain corChain = Next(); + if (corChain != null) { + yield return corChain; + } else { + break; + } + } + } + } + + public ICorDebugChain Next() + { + ICorDebugChain[] corChains = new ICorDebugChain[1]; + uint chainsFetched = this.Next(1, corChains); + if (chainsFetched == 0) { + return null; + } else { + return corChains[0]; + } + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugFrameEnum.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugFrameEnum.cs new file mode 100644 index 0000000000..f19e2b5031 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugFrameEnum.cs @@ -0,0 +1,40 @@ +// +// +// +// +// $Revision$ +// + +namespace Debugger.Wrappers.CorDebug +{ + using System; + using System.Collections.Generic; + + + public partial class ICorDebugFrameEnum + { + public IEnumerable Enumerator { + get { + while (true) { + ICorDebugFrame corFrame = Next(); + if (corFrame != null) { + yield return corFrame; + } else { + break; + } + } + } + } + + public ICorDebugFrame Next() + { + ICorDebugFrame[] corFrames = new ICorDebugFrame[1]; + uint framesFetched = this.Next(1, corFrames); + if (framesFetched == 0) { + return null; + } else { + return corFrames[0]; + } + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugStepper.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugStepper.cs new file mode 100644 index 0000000000..5492043279 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugStepper.cs @@ -0,0 +1,22 @@ +// +// +// +// +// $Revision$ +// + +namespace Debugger.Wrappers.CorDebug +{ + using System; + + + public partial class ICorDebugStepper + { + public unsafe void StepRange(bool bStepIn, int[] ranges) + { + fixed (int* pRanges = ranges) { + this.StepRange(bStepIn?1:0, (IntPtr)pRanges, (uint)ranges.Length / 2); + } + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs index bb92006faf..d0ffe2cb9b 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs @@ -227,20 +227,20 @@ namespace Debugger.Tests StartProgram("Callstack"); WaitForPause(PausedReason.Break, null); - callstack = new List(debugger.CurrentThread.Callstack); + callstack = new List(debugger.SelectedThread.Callstack); Assert.AreEqual("Sub2", callstack[0].Name); Assert.AreEqual("Sub1", callstack[1].Name); Assert.AreEqual("Main", callstack[2].Name); debugger.StepOut(); WaitForPause(PausedReason.StepComplete, null); - callstack = new List(debugger.CurrentThread.Callstack); + callstack = new List(debugger.SelectedThread.Callstack); Assert.AreEqual("Sub1", callstack[0].Name); Assert.AreEqual("Main", callstack[1].Name); debugger.StepOut(); WaitForPause(PausedReason.StepComplete, null); - callstack = new List(debugger.CurrentThread.Callstack); + callstack = new List(debugger.SelectedThread.Callstack); Assert.AreEqual("Main", callstack[0].Name); debugger.Continue(); @@ -258,7 +258,7 @@ namespace Debugger.Tests for(int i = 0; i < 2; i++) { debugger.Continue(); WaitForPause(PausedReason.Break, null); - args = new List(debugger.CurrentFunction.ArgumentVariables); + args = new List(debugger.SelectedFunction.ArgumentVariables); // names Assert.AreEqual("i", args[0].Name); Assert.AreEqual("s", args[1].Name); @@ -274,7 +274,7 @@ namespace Debugger.Tests debugger.Continue(); WaitForPause(PausedReason.Break, null); - args = new List(debugger.CurrentFunction.ArgumentVariables); + args = new List(debugger.SelectedFunction.ArgumentVariables); // types Assert.AreEqual(typeof(PrimitiveValue), args[0].Value.GetType()); Assert.AreEqual(typeof(PrimitiveValue), args[1].Value.GetType()); @@ -286,7 +286,7 @@ namespace Debugger.Tests debugger.Continue(); WaitForPause(PausedReason.Break, null); - args = new List(debugger.CurrentFunction.ArgumentVariables); + args = new List(debugger.SelectedFunction.ArgumentVariables); // types Assert.AreEqual(typeof(PrimitiveValue), args[0].Value.GetType()); Assert.AreEqual(typeof(NullValue), args[1].Value.GetType()); @@ -308,7 +308,7 @@ namespace Debugger.Tests StartProgram("FunctionLocalVariables"); WaitForPause(PausedReason.Break, null); - args = new List(debugger.CurrentFunction.LocalVariables); + args = new List(debugger.SelectedFunction.LocalVariables); // names Assert.AreEqual("i", args[0].Name); Assert.AreEqual("s", args[1].Name); @@ -339,7 +339,7 @@ namespace Debugger.Tests StartProgram("FunctionLifetime"); WaitForPause(PausedReason.Break, null); - function = debugger.CurrentFunction; + function = debugger.SelectedFunction; Assert.IsNotNull(function); Assert.AreEqual("Function", function.Name); Assert.AreEqual(false, function.HasExpired); @@ -347,19 +347,19 @@ namespace Debugger.Tests debugger.Continue(); // Go to the SubFunction WaitForPause(PausedReason.Break, null); - Assert.AreEqual("SubFunction", debugger.CurrentFunction.Name); + Assert.AreEqual("SubFunction", debugger.SelectedFunction.Name); Assert.AreEqual(false, function.HasExpired); Assert.AreEqual("1", function.GetArgumentVariable(0).Value.AsString); debugger.Continue(); // Go back to Function WaitForPause(PausedReason.Break, null); - Assert.AreEqual("Function", debugger.CurrentFunction.Name); + Assert.AreEqual("Function", debugger.SelectedFunction.Name); Assert.AreEqual(false, function.HasExpired); Assert.AreEqual("1", function.GetArgumentVariable(0).Value.AsString); debugger.Continue(); // Setp out of function WaitForPause(PausedReason.Break, null); - Assert.AreEqual("Main", debugger.CurrentFunction.Name); + Assert.AreEqual("Main", debugger.SelectedFunction.Name); Assert.AreEqual(true, function.HasExpired); debugger.Continue(); @@ -377,7 +377,7 @@ namespace Debugger.Tests StartProgram("FunctionVariablesLifetime"); // 1 - Enter program WaitForPause(PausedReason.Break, null); - function = debugger.CurrentFunction; + function = debugger.SelectedFunction; Assert.IsNotNull(function); Assert.AreEqual("Function", function.Name); argument = function.GetArgumentVariable(0); @@ -443,7 +443,7 @@ namespace Debugger.Tests StartProgram("ArrayValue"); WaitForPause(PausedReason.Break, null); - foreach(Variable var in debugger.CurrentFunction.LocalVariables) { + foreach(Variable var in debugger.SelectedFunction.LocalVariables) { local = var; break; } Assert.AreEqual("array", local.Name); @@ -471,7 +471,7 @@ namespace Debugger.Tests StartProgram("ObjectValue"); WaitForPause(PausedReason.Break, null); - foreach(Variable var in debugger.CurrentFunction.LocalVariables) { + foreach(Variable var in debugger.SelectedFunction.LocalVariables) { local = var; } Assert.AreEqual("val", local.Name); @@ -514,7 +514,7 @@ namespace Debugger.Tests StartProgram("PropertyVariable"); WaitForPause(PausedReason.Break, null); - foreach(Variable var in debugger.CurrentFunction.LocalVariables) { + foreach(Variable var in debugger.SelectedFunction.LocalVariables) { local = var; } foreach(Variable var in local.SubVariables) { @@ -559,7 +559,7 @@ namespace Debugger.Tests StartProgram("PropertyVariableForm"); WaitForPause(PausedReason.Break, null); - foreach(Variable var in debugger.CurrentFunction.LocalVariables) { + foreach(Variable var in debugger.SelectedFunction.LocalVariables) { local = var; } Assert.AreEqual("form", local.Name); @@ -596,9 +596,9 @@ namespace Debugger.Tests StartProgram("SetIP"); WaitForPause(PausedReason.Break, "1"); - Assert.IsNotNull(debugger.CurrentFunction.CanSetIP("SetIP.cs", 16, 0)); - Assert.IsNull(debugger.CurrentFunction.CanSetIP("SetIP.cs", 100, 0)); - debugger.CurrentFunction.SetIP("SetIP.cs", 16, 0); + Assert.IsNotNull(debugger.SelectedFunction.CanSetIP("SetIP.cs", 16, 0)); + Assert.IsNull(debugger.SelectedFunction.CanSetIP("SetIP.cs", 100, 0)); + debugger.SelectedFunction.SetIP("SetIP.cs", 16, 0); debugger.Continue(); WaitForPause(PausedReason.Break, "1"); Assert.AreEqual("1\r\n1\r\n", log); diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Designer/Factories.cs b/src/AddIns/Misc/SharpReport/SharpReport/Designer/Factories.cs index 9d20983f95..2ed99ddeaa 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Designer/Factories.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Designer/Factories.cs @@ -36,19 +36,21 @@ namespace SharpReport.Designer { } } - public class IDesignableFactory : SharpReportCore.GenericFactory { + public class IDesignableFactory : SharpReportCore.GenericFactory { - public IDesignableFactory() :base(Assembly.GetExecutingAssembly(),typeof(IDesignable)){ - } + public IDesignableFactory() :base(Assembly.GetExecutingAssembly(),typeof(IDesignable)){ + } - public new BaseReportItem Create(string name) { - if (name.LastIndexOf('.') > 0) { + public new BaseReportItem Create(string name) { + if (String.IsNullOrEmpty(name)) { + throw new ArgumentNullException("name"); + } + if (name.LastIndexOf('.') > 0) { StringBuilder b = new StringBuilder (name); b.Remove (0,name.LastIndexOf('.') +1); name = b.ToString(); } return (BaseReportItem) base.Create (name); - } - } + } } diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Designer/Report.cs b/src/AddIns/Misc/SharpReport/SharpReport/Designer/Report.cs index ef682aa3bf..8f8835d2d6 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Designer/Report.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Designer/Report.cs @@ -195,6 +195,7 @@ namespace SharpReport.Designer{ BaseReportItem br = (BaseReportItem)this.FindParent(iddea); baseReportItem.Location = new Point(iddea.ItemAtPoint.X - br.Location.X,10); } + baseReportItem.ResumeLayout(); } diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs b/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs index 04d6fd7586..7b3dae87a8 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/BaseDesignerControl.cs @@ -51,12 +51,17 @@ namespace SharpReport.Designer this.ReportControl.ReportSettings = reportModel.ReportSettings; } #region public'c - //if languages change, we need a way to chage the headlines here as well public void Localise() { reportControl.Localise(); } + public void RegisterEvents () { + this.reportControl.SectionChanged += new EventHandler (this.ReportControlSectionChanged); + this.reportControl.SizeChanged += new System.EventHandler(this.ReportControlSizeChanged); + this.reportControl.DesignViewChanged += new SharpReport.Designer.ItemDragDropEventHandler(this.ReportControlDesignViewChanged); + } + public void RemoveSelectedItem () { if (this.SelectedObject == null) { return; @@ -96,23 +101,23 @@ namespace SharpReport.Designer void ReportControlSizeChanged(object sender, System.EventArgs e){ this.ctrlRuler1.Width = reportControl.Width; this.ctrlRuler1.Invalidate(); - FireSaveNeeded(); + NotifyPropertyChanged(this.Name + "ReportControlSizeChanged"); } void ReportControlSectionChanged (object sender,SectionChangedEventArgs e) { - FireSaveNeeded(); + NotifyPropertyChanged(this.Name + "ReportControlSectionChanged"); } void ReportControlDesignViewChanged(object sender, SharpReport.Designer.ItemDragDropEventArgs e){ - FireSaveNeeded(); + NotifyPropertyChanged(this.Name + "ReportControlDesignViewChanged"); } #endregion #region privates - void FireSaveNeeded() { + void NotifyPropertyChanged(string info) { if (DesignerDirty != null) { - DesignerDirty (this,new PropertyChangedEventArgs("Designer")); + DesignerDirty (this,new PropertyChangedEventArgs(info)); } } #endregion @@ -216,9 +221,9 @@ namespace SharpReport.Designer this.reportControl.Name = "reportControl"; this.reportControl.Size = new System.Drawing.Size(592, 400); this.reportControl.TabIndex = 1; - this.reportControl.SectionChanged += new EventHandler (this.ReportControlSectionChanged); - this.reportControl.SizeChanged += new System.EventHandler(this.ReportControlSizeChanged); - this.reportControl.DesignViewChanged += new SharpReport.Designer.ItemDragDropEventHandler(this.ReportControlDesignViewChanged); +// this.reportControl.SectionChanged += new EventHandler (this.ReportControlSectionChanged); +// this.reportControl.SizeChanged += new System.EventHandler(this.ReportControlSizeChanged); +// this.reportControl.DesignViewChanged += new SharpReport.Designer.ItemDragDropEventHandler(this.ReportControlDesignViewChanged); // // BaseDesignerControl // diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/ReportSection.cs b/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/ReportSection.cs index ecb949513e..99f5276eaf 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/ReportSection.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Designer/SectionControls/ReportSection.cs @@ -211,24 +211,24 @@ namespace SharpReport{ public void OnItemSelect(object sender, EventArgs e){ - if (!base.Suspend) { +// if (!base.Suspend) { if (ItemSelected != null) ItemSelected(sender, e); - } +// } } public void VisualControlClick(object sender, EventArgs e){ - if (!base.Suspend) { +// if (!base.Suspend) { this.OnSelect(); - } +// } } public void ReportItemSelected(object sender, EventArgs e){ - if (!base.Suspend) { +// if (!base.Suspend) { this.OnSelect (); this.OnItemSelect(sender, e); - } +// } } diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/AbstractGraphicControl.cs b/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/AbstractGraphicControl.cs index 3d7ac13bea..8fc2e07bd8 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/AbstractGraphicControl.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/AbstractGraphicControl.cs @@ -22,16 +22,12 @@ namespace SharpReport.Designer int thickness = 1; DashStyle dashStyle = DashStyle.Solid; - public AbstractGraphicControl() - { - + public AbstractGraphicControl(){ InitializeComponent(); - base.DragEnter += new DragEventHandler (OnOver); } - void OnOver (object sender, DragEventArgs e) { - System.Console.WriteLine("AbstractGraphicControl:On Over"); - } + + #region property's /// diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportObjectControlBase.cs b/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportObjectControlBase.cs index c82cc072b5..1b42023078 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportObjectControlBase.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportObjectControlBase.cs @@ -21,7 +21,7 @@ namespace SharpReport.Designer /// and can have some common members managed easier. /// - public abstract class ReportObjectControlBase : System.Windows.Forms.UserControl + public abstract class ReportObjectControlBase : UserControl { private StringAlignment stringAlignment = StringAlignment.Near; private StringFormat stringFormat; diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportRectangleControl.cs b/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportRectangleControl.cs index c40752d967..83d423ec5a 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportRectangleControl.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportRectangleControl.cs @@ -37,7 +37,6 @@ namespace SharpReport.Designer { true); this.UpdateStyles(); } - #region overrides protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportTextControl.cs b/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportTextControl.cs index 3ef7f7761f..7e34c3640d 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportTextControl.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Designer/VisualControls/ReportTextControl.cs @@ -21,7 +21,7 @@ namespace SharpReport.Designer{ private TextDrawer textDrawer = new TextDrawer(); - public ReportTextControl(){ + public ReportTextControl():base(){ InitializeComponent(); this.SetStyle(ControlStyles.DoubleBuffer | @@ -79,7 +79,7 @@ namespace SharpReport.Designer{ // this.BackColor = System.Drawing.Color.White; this.Name = "ReportTextItem"; - this.Size = new System.Drawing.Size(120, 60); + this.Size = new System.Drawing.Size(120, 20); } #endregion diff --git a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportCircleItem.cs b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportCircleItem.cs index 5c54a81962..214dcc0945 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportCircleItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportCircleItem.cs @@ -8,8 +8,8 @@ */ using System; -using System.ComponentModel; using System.Drawing; +using System.ComponentModel; using SharpReportCore; using SharpReport.Designer; @@ -30,11 +30,12 @@ namespace SharpReport.ReportItems{ private ReportCircleControl visualControl; - private bool initDone; - - - public ReportCircleItem() : base(){ + + public ReportCircleItem() : base(){ visualControl = new ReportCircleControl(); + + ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); + this.visualControl.Click += new EventHandler(OnControlSelect); this.visualControl.VisualControlChanged += new EventHandler (OnControlChanged); this.visualControl.BackColorChanged += new EventHandler (OnControlChanged); @@ -42,20 +43,20 @@ namespace SharpReport.ReportItems{ this.visualControl.ForeColorChanged += new EventHandler (OnControlChanged); base.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler (BasePropertyChange); - ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); - this.initDone = true; - } + } #region EventHandling private void BasePropertyChange (object sender, PropertyChangedEventArgs e){ - if (initDone == true) { - ItemsHelper.UpdateControlFromGraphicBase (this.visualControl,this); - } + ItemsHelper.UpdateControlFromGraphicBase (this.visualControl,this); + this.HandlePropertyChanged(e.PropertyName); + } private void OnControlChanged (object sender, EventArgs e) { + base.SuspendLayout(); ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); + base.ResumeLayout(); this.HandlePropertyChanged("OnControlChanged"); } @@ -75,8 +76,8 @@ namespace SharpReport.ReportItems{ PropertyChanged (this,new PropertyChangedEventArgs(info)); } } - } + #endregion #region overrides @@ -120,7 +121,20 @@ namespace SharpReport.ReportItems{ this.HandlePropertyChanged("Location"); } } - + + public override Color BackColor { + get { + return base.BackColor; + } + set { + base.BackColor = value; + if (this.visualControl != null) { + this.visualControl.BackColor = value; + } + this.HandlePropertyChanged("Backcolor"); + } + } + #endregion #region SharpReport.Designer.IDesignable interface implementation diff --git a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportImageItem.cs b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportImageItem.cs index 6e45fcc239..44245af75c 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportImageItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportImageItem.cs @@ -26,52 +26,46 @@ namespace SharpReport.ReportItems { public class ReportImageItem : BaseImageItem,SharpReport.Designer.IDesignable { private ReportImageControl visualControl; - private bool initDone; - + public ReportImageItem() :base(){ + visualControl = new ReportImageControl(); + ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); + + Setup(); + this.visualControl.Click += new EventHandler(OnControlSelect); this.visualControl.VisualControlChanged += new EventHandler (OnControlChanged); this.visualControl.BackColorChanged += new EventHandler (OnControlChanged); this.visualControl.FontChanged += new EventHandler (OnControlChanged); this.visualControl.ForeColorChanged += new EventHandler (OnControlChanged); base.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler (BasePropertyChange); - - ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); - - this.initDone = true; - } - - #region overrides - public override void Dispose() { - base.Dispose(); - this.visualControl.Dispose(); } - public override string ToString(){ - return this.Name; + private void Setup() { + this.visualControl.Location = base.Location; + this.visualControl.Size = base.Size; + + if (base.Image != null) { + this.visualControl.Image = base.Image; + this.visualControl.ScaleImageToSize = base.ScaleImageToSize; + this.visualControl.Invalidate(); + } } - #endregion - #region EventHandling private void BasePropertyChange (object sender, PropertyChangedEventArgs e){ - if (initDone == true) { - - this.visualControl.Location = base.Location; - this.visualControl.Size = base.Size; - - if (base.Image != null) { - this.visualControl.Image = base.Image; - this.visualControl.ScaleImageToSize = base.ScaleImageToSize; - this.visualControl.Invalidate(); - } - } + Setup(); + ItemsHelper.UpdateControlFromGraphicBase(this.visualControl,this); + this.HandlePropertyChanged(e.PropertyName); } private void OnControlChanged (object sender, EventArgs e) { + Setup(); + base.SuspendLayout(); ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); + base.ResumeLayout(); this.HandlePropertyChanged("OnControlChanged"); } @@ -110,5 +104,50 @@ namespace SharpReport.ReportItems { #endregion + #region overrides + + public override Size Size { + get { + return base.Size; + } + set { + base.Size = value; + if (this.visualControl != null) { + this.visualControl.Size = value; + } + this.HandlePropertyChanged("Size"); + } + } + + public override Point Location { + get { + return base.Location; + } + set { + base.Location = value; + if (this.visualControl != null) { + this.visualControl.Location = value; + } + this.HandlePropertyChanged("Location"); + } + } + +// public override Image Image { +// get { +// return base.Image; +// } +// } +// + + public override void Dispose() { + base.Dispose(); + this.visualControl.Dispose(); + } + + public override string ToString(){ + return this.Name; + } + + #endregion } } diff --git a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportLineItem.cs b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportLineItem.cs index 623562b019..303df960fe 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportLineItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportLineItem.cs @@ -8,8 +8,8 @@ // //------------------------------------------------------------------------------ using System; -using System.ComponentModel; using System.Drawing; +using System.ComponentModel; using SharpReportCore; using SharpReport.Designer; @@ -26,14 +26,15 @@ namespace SharpReport.ReportItems{ public class ReportLineItem : BaseLineItem,SharpReport.Designer.IDesignable { private ReportLineControl visualControl; - private bool initDone; - + /// /// Default constructor - initializes all fields to default values /// public ReportLineItem():base() { visualControl = new ReportLineControl(); + ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); + this.visualControl.Click += new EventHandler(OnControlSelect); this.visualControl.VisualControlChanged += new EventHandler (OnControlChanged); this.visualControl.BackColorChanged += new EventHandler (OnControlChanged); @@ -41,20 +42,19 @@ namespace SharpReport.ReportItems{ this.visualControl.ForeColorChanged += new EventHandler (OnControlChanged); base.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler (BasePropertyChange); - ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); - this.initDone = true; } #region EventHandling private void BasePropertyChange (object sender, PropertyChangedEventArgs e){ - if (initDone == true) { ItemsHelper.UpdateControlFromGraphicBase (this.visualControl,this); - } + this.HandlePropertyChanged(e.PropertyName); } private void OnControlChanged (object sender, EventArgs e) { + base.SuspendLayout(); ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); + base.ResumeLayout(); this.HandlePropertyChanged("OnControlChanged"); } diff --git a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportRectangleItem.cs b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportRectangleItem.cs index d767b66d28..e312716dff 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportRectangleItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/GraphicBased/ReportRectangleItem.cs @@ -10,9 +10,8 @@ using System; -using System.ComponentModel; using System.Drawing; -using System.Windows.Forms; +using System.ComponentModel; using SharpReportCore; using SharpReport.Designer; @@ -32,41 +31,33 @@ namespace SharpReport.ReportItems{ public class ReportRectangleItem : BaseRectangleItem,SharpReport.Designer.IDesignable { private ReportRectangleControl visualControl; - private bool initDone; - - - + public ReportRectangleItem():base() { visualControl = new ReportRectangleControl(); + + ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); + this.visualControl.Click += new EventHandler(OnControlSelect); this.visualControl.VisualControlChanged += new EventHandler (OnControlChanged); this.visualControl.BackColorChanged += new EventHandler (OnControlChanged); this.visualControl.FontChanged += new EventHandler (OnControlChanged); this.visualControl.ForeColorChanged += new EventHandler (OnControlChanged); - this.visualControl.DragOver += new DragEventHandler (OnDragOver); - this.VisualControl.DragEnter += new DragEventHandler (OnDragEnter); - + base.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler (BasePropertyChange); - ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); - this.initDone = true; } - void OnDragEnter(object sender,DragEventArgs e) { -// System.Console.WriteLine("DragEnter"); - } - void OnDragOver(object sender,DragEventArgs e) { -// System.Console.WriteLine("DragOver"); - } #region EventHandling private void BasePropertyChange (object sender, PropertyChangedEventArgs e){ - if (initDone == true) { - ItemsHelper.UpdateControlFromGraphicBase (this.visualControl,this); - } + ItemsHelper.UpdateControlFromGraphicBase (this.visualControl,this); + this.HandlePropertyChanged(e.PropertyName); + } private void OnControlChanged (object sender, EventArgs e) { + base.SuspendLayout(); ItemsHelper.UpdateBaseFromGraphicControl (this.visualControl,this); + base.ResumeLayout(); this.HandlePropertyChanged("OnControlChanged"); } @@ -86,7 +77,6 @@ namespace SharpReport.ReportItems{ PropertyChanged (this,new PropertyChangedEventArgs(info)); } } - } #endregion @@ -133,6 +123,18 @@ namespace SharpReport.ReportItems{ } } + public override Color BackColor { + get { + return base.BackColor; + } + set { + base.BackColor = value; + if (this.visualControl != null) { + this.visualControl.BackColor = value; + } + this.HandlePropertyChanged("Backcolor"); + } + } #endregion diff --git a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ItemsHelper.cs b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ItemsHelper.cs index 2d4f3934c0..dd027b861c 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ItemsHelper.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ItemsHelper.cs @@ -24,52 +24,43 @@ namespace SharpReport { public static void UpdateBaseFromTextControl (ReportObjectControlBase control, - BaseReportItem item) { + BaseReportItem item) { - item.SuspendLayout(); item.Size = control.Size; item.Location = control.Location; item.Name = control.Name; item.BackColor = control.BackColor; item.ForeColor = control.ForeColor; item.Font = control.Font; - item.ResumeLayout(); } public static void UpdateBaseFromGraphicControl (AbstractGraphicControl control, - BaseGraphicItem item) { + BaseGraphicItem item) { ItemsHelper.UpdateBaseFromTextControl (control,item); - item.SuspendLayout(); item.Thickness = control.Thickness; item.DashStyle = control.DashStyle; - item.ResumeLayout(); } public static void UpdateControlFromTextBase (ReportObjectControlBase control, - BaseReportItem item) { + BaseReportItem item) { - control.SuspendLayout(); - item.SuspendLayout(); control.BackColor = item.BackColor; control.ForeColor = item.ForeColor; control.Location = item.Location; control.Size = item.Size; - control.Font = item.Font; + control.Font = item.Font; control.Name = item.Name; BaseTextItem b = item as BaseTextItem; if (b != null) { control.StringAlignment = b.StringAlignment; } - - item.ResumeLayout(); - control.ResumeLayout(); } public static void UpdateControlFromGraphicBase (AbstractGraphicControl control, - BaseGraphicItem item) { + BaseGraphicItem item) { ItemsHelper.UpdateControlFromTextBase(control,item); control.Location = item.Location; control.DashStyle = item.DashStyle; diff --git a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportDataItem.cs b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportDataItem.cs index bb0d3adc23..67493f1f99 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportDataItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportDataItem.cs @@ -23,7 +23,7 @@ namespace SharpReport.ReportItems{ private ReportDbTextControl visualControl; - bool initDone; +// bool initDone; #region Constructors @@ -40,6 +40,10 @@ namespace SharpReport.ReportItems{ visualControl = new ReportDbTextControl(); this.visualControl.Text = base.ColumnName; + visualControl.StringFormat = base.StandartStringFormat; + this.Text = base.ColumnName; + + ItemsHelper.UpdateBaseFromTextControl (this.visualControl,this); this.visualControl.Click += new EventHandler(OnControlSelect); this.visualControl.VisualControlChanged += new EventHandler (OnControlChanged); @@ -48,16 +52,6 @@ namespace SharpReport.ReportItems{ this.visualControl.ForeColorChanged += new EventHandler (OnControlChanged); base.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler (BasePropertyChange); - ItemsHelper.UpdateBaseFromTextControl (this.visualControl,this); - this.Text = base.ColumnName; - GrapFromBase(); - this.initDone = true; - } - - private void GrapFromBase() { - this.visualControl.SuspendLayout(); - visualControl.StringFormat = base.StandartStringFormat; - this.visualControl.ResumeLayout(); } #endregion @@ -71,14 +65,15 @@ namespace SharpReport.ReportItems{ #region events's private void BasePropertyChange (object sender, PropertyChangedEventArgs e){ - if (initDone == true) { - ItemsHelper.UpdateControlFromTextBase(this.visualControl,this); - } + ItemsHelper.UpdateControlFromTextBase(this.visualControl,this); + this.HandlePropertyChanged(e.PropertyName); } private void OnControlChanged (object sender, EventArgs e) { + base.SuspendLayout(); ItemsHelper.UpdateBaseFromTextControl (this.visualControl,this); + base.ResumeLayout(); this.HandlePropertyChanged("OnControlChanged"); } diff --git a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportRowItem.cs b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportRowItem.cs index b33e2a3005..45ff2ff93e 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportRowItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportRowItem.cs @@ -1,6 +1,6 @@ /* * Created by SharpDevelop. - * User: Forstmeier Helmut + * User: Forstmeier Peter * Date: 01.03.2006 * Time: 14:35 * @@ -8,6 +8,7 @@ */ using System; +using System.Drawing; using System.ComponentModel; using SharpReport.Designer; @@ -21,7 +22,7 @@ namespace SharpReport.ReportItems /// public class ReportRowItem : RowItem ,IDesignable{ private ReportRowControl visualControl; - private bool initDone; + #region Constructor public ReportRowItem():this (GlobalValues.UnboundName){ @@ -37,21 +38,19 @@ namespace SharpReport.ReportItems private void Setup(){ visualControl = new ReportRowControl(); - + ItemsHelper.UpdateBaseFromTextControl (this.visualControl,this); + this.visualControl.Click += new EventHandler(OnControlSelect); this.visualControl.VisualControlChanged += new EventHandler (OnControlChanged); this.visualControl.FontChanged += new EventHandler (OnControlChanged); this.visualControl.ForeColorChanged += new EventHandler (OnControlChanged); - this.visualControl.BackColorChanged += new EventHandler (OnAppereanceChanged); base.PropertyChanged += new PropertyChangedEventHandler (BasePropertyChange); - + base.Items.Added += OnAdd; base.Items.Removed += OnRemove; - ItemsHelper.UpdateControlFromTextBase (this.visualControl,this); - this.initDone = true; - } + } #endregion @@ -67,8 +66,9 @@ namespace SharpReport.ReportItems } private void ChildPropertyChange (object sender, PropertyChangedEventArgs e){ - if (initDone == true) { + if (! base.Suspend) { ItemsHelper.UpdateControlFromTextBase (this.visualControl,this); + this.HandlePropertyChanged(e.PropertyName); } } @@ -77,6 +77,10 @@ namespace SharpReport.ReportItems private void UpdateChilds () { foreach (BaseReportItem br in this.Items) { br.BackColor = this.BackColor; + IDesignable des = br as IDesignable; + if (des != null) { + des.VisualControl.BackColor = this.BackColor; + } } } @@ -103,22 +107,28 @@ namespace SharpReport.ReportItems private void BasePropertyChange (object sender, PropertyChangedEventArgs e){ - if (initDone == true) { - ItemsHelper.UpdateControlFromTextBase (this.visualControl,this); - } + ItemsHelper.UpdateControlFromTextBase (this.visualControl,this); + this.HandlePropertyChanged(e.PropertyName); } private void OnControlChanged (object sender, EventArgs e) { + this.SuspendLayout(); ItemsHelper.UpdateBaseFromTextControl (this.visualControl,this); + this.ResumeLayout(); this.HandlePropertyChanged("OnControlChanged"); + } private void OnAppereanceChanged (object sender, EventArgs e) { + this.SuspendLayout(); ItemsHelper.UpdateBaseFromTextControl (this.visualControl,this); + this.ResumeLayout(); UpdateChilds(); + this.HandlePropertyChanged("OnControlChanged"); } + private void OnControlSelect(object sender, EventArgs e){ if (Selected != null) Selected(this,e); @@ -153,7 +163,47 @@ namespace SharpReport.ReportItems public event EventHandler Selected; #endregion + + #region overrides + public override Size Size { + get { + return base.Size; + } + set { + base.Size = value; + if (this.visualControl != null) { + this.visualControl.Size = value; + } + this.HandlePropertyChanged("Size"); + } + } + + public override Point Location { + get { + return base.Location; + } + set { + base.Location = value; + if (this.visualControl != null) { + this.visualControl.Location = value; + } + this.HandlePropertyChanged("Location"); + } + } + + public override Font Font { + get { + return base.Font; + } + set { + base.Font = value; + if (this.visualControl != null) { + this.visualControl.Font = value; + } + this.HandlePropertyChanged("Font"); + } + } public override string ToString(){ return this.Name; diff --git a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportTextItem.cs b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportTextItem.cs index d8c6777819..13219d73ec 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportTextItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/ReportItems/TextBased/ReportTextItem.cs @@ -8,9 +8,8 @@ */ using System; -using System.ComponentModel; using System.Drawing; -using System.Drawing.Printing; +using System.ComponentModel; using SharpReportCore; using SharpReport.Designer; @@ -26,14 +25,17 @@ namespace SharpReport.ReportItems { public class ReportTextItem : BaseTextItem,IDesignable { - private ReportTextControl visualControl; - bool initDone; #region Constructor public ReportTextItem() : base(){ visualControl = new ReportTextControl(); + this.Text = visualControl.Name; + visualControl.StringFormat = base.StandartStringFormat; + + ItemsHelper.UpdateBaseFromTextControl (this.visualControl,this); + this.visualControl.Click += new EventHandler(OnControlSelect); this.visualControl.VisualControlChanged += new EventHandler (OnControlChanged); this.visualControl.BackColorChanged += new EventHandler (OnControlChanged); @@ -41,45 +43,32 @@ namespace SharpReport.ReportItems { this.visualControl.ForeColorChanged += new EventHandler (OnControlChanged); base.PropertyChanged += new PropertyChangedEventHandler (BasePropertyChange); -// ItemsHelper.UpdateTextControl (this.visualControl,this); - - this.Text = visualControl.Name; - visualControl.StringFormat = base.StandartStringFormat; - - ItemsHelper.UpdateControlFromTextBase (this.visualControl,this); - this.initDone = true; } #endregion - #region overrides - public override string ToString(){ - return this.Name; - } - - #endregion #region events private void BasePropertyChange (object sender, PropertyChangedEventArgs e){ - System.Console.WriteLine("Text:BasePropertyChanged"); - if (initDone == true) { - ItemsHelper.UpdateControlFromTextBase(this.visualControl,this); - } + ItemsHelper.UpdateControlFromTextBase(this.visualControl,this); + this.HandlePropertyChanged(e.PropertyName); } private void OnControlChanged (object sender, EventArgs e) { - System.Console.WriteLine("Text:OnControlChanged"); + base.SuspendLayout(); ItemsHelper.UpdateBaseFromTextControl (this.visualControl,this); + base.ResumeLayout(); this.HandlePropertyChanged("OnControlSelected"); } + private void OnControlSelect(object sender, EventArgs e){ - System.Console.WriteLine("Text:OnControlSelect"); - if (Selected != null) + if (Selected != null){ Selected(this,e); + } } /// @@ -88,15 +77,15 @@ namespace SharpReport.ReportItems { /// protected void HandlePropertyChanged(string info) { - System.Console.WriteLine("Text:HandlePropertyChanged"); if ( !base.Suspend) { if (PropertyChanged != null) { PropertyChanged (this,new PropertyChangedEventArgs(info)); } } } + #endregion - + public override Size Size { get { return base.Size; @@ -168,6 +157,13 @@ namespace SharpReport.ReportItems { #endregion + #region overrides + + public override string ToString(){ + return this.Name; + } + + #endregion /* #region IDisposable public override void Dispose(){ diff --git a/src/AddIns/Misc/SharpReport/SharpReport/Visitors/LoadReportVisitor.cs b/src/AddIns/Misc/SharpReport/SharpReport/Visitors/LoadReportVisitor.cs index d43c4500fc..a78dba8a06 100644 --- a/src/AddIns/Misc/SharpReport/SharpReport/Visitors/LoadReportVisitor.cs +++ b/src/AddIns/Misc/SharpReport/SharpReport/Visitors/LoadReportVisitor.cs @@ -89,21 +89,16 @@ namespace SharpReport.Visitors { if (sectionElem != null) { baseSection = (BaseSection)designer.ReportModel.SectionCollection.Find(sectionElem.GetAttribute("name")); if (baseSection != null) { - baseSection.SuspendLayout(); - XmlHelper.SetSectionValues (base.XmlFormReader,sectionElem,baseSection); XmlNodeList ctrlList = sectionElem.SelectNodes (base.NodesQuery); SetReportItems(baseSection,null,ctrlList); - baseSection.ResumeLayout(); } else { throw new MissingSectionException(); } } else { throw new MissingSectionException(); } - baseSection.ResumeLayout(); } - baseSection.ResumeLayout(); } @@ -120,26 +115,28 @@ namespace SharpReport.Visitors { itemRenderer = designableFactory.Create(ctrlElem.GetAttribute("type")); baseReportItem = (BaseReportItem)itemRenderer; + if (parentContainer == null) { -// System.Console.WriteLine("\tParent of {0} is Section",baseReportItem.Name); baseReportItem.Parent = baseSection; baseSection.Items.Add (baseReportItem); } else { -// System.Console.WriteLine("\tParent of <{0}> is Container",baseReportItem.Name); baseReportItem.Parent = parentContainer; parentContainer.Items.Add(baseReportItem); } - XmlHelper.BuildControl (base.XmlFormReader,ctrlElem,baseReportItem); - - IContainerItem iContainer = baseReportItem as IContainerItem; + XmlHelper.SetReportItemValues (base.XmlFormReader,ctrlElem,baseReportItem); - XmlNodeList newList = ctrlNode.SelectNodes (base.NodesQuery); - if (newList.Count > 0) { -// System.Console.WriteLine("\t recusiv call for <{0}> with {1} childs ", -// baseReportItem,newList.Count); - SetReportItems (baseSection,iContainer,newList); + IContainerItem iContainer = baseReportItem as IContainerItem; + + if (iContainer != null) { + XmlNodeList newList = ctrlNode.SelectNodes (base.NodesQuery); + if (newList.Count > 0) { + System.Console.WriteLine("\tLoadReportVisitor recursive call for <{0}> with {1} elements", + baseReportItem.Name, + newList.Count); + SetReportItems (baseSection,iContainer,newList); + } } } catch (Exception ) { diff --git a/src/AddIns/Misc/SharpReport/SharpReportAddin/FieldsExplorer/FieldsExplorer.cs b/src/AddIns/Misc/SharpReport/SharpReportAddin/FieldsExplorer/FieldsExplorer.cs index 673138d4ac..f3cbe22978 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportAddin/FieldsExplorer/FieldsExplorer.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportAddin/FieldsExplorer/FieldsExplorer.cs @@ -221,7 +221,7 @@ namespace SharpReportAddin { } #region PadEvents - private void OnWindowChange (object sender,EventArgs e) { + private void old_OnWindowChange (object sender,EventArgs e) { try { if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent is SharpReportView) { if (WorkbenchSingleton.Workbench.ActiveWorkbenchWindow == null || WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent == null) { @@ -248,13 +248,13 @@ namespace SharpReportAddin { } } else { - System.Console.WriteLine(" NO view"); } + System.Console.WriteLine("FieldsExplorer: NO view"); } } catch (Exception) { } } - private void old_OnWindowChange (object sender,EventArgs e) { + private void OnWindowChange (object sender,EventArgs e) { // System.Console.WriteLine("FieldsExplorer:OnWindowChange"); // System.Console.WriteLine("active control {0}",WorkbenchSingleton.ActiveControl.ToString()); // ICSharpCode.SharpDevelop.Gui.DefaultWorkbench dw = (ICSharpCode.SharpDevelop.Gui.DefaultWorkbench)sender; diff --git a/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs b/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs index 1246977a35..562457fcb8 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportDisplayBinding.cs @@ -44,7 +44,7 @@ namespace SharpReportAddin { view.FileName = view.DesignerControl.ReportModel.ReportSettings.FileName; view.UpdateView(true); view.Selected(); - view.ShowReportSettings(); + view.ShowReportSettings(); return view; } catch (SharpReportException) { if (view != null) { @@ -79,6 +79,7 @@ namespace SharpReportAddin { view.Load (fileName); view.UpdateView (false); view.Selected(); + view.DesignerControl.ReportModel.ReportSettings.InitDone = true; return view; } catch (Exception) { return new SharpReportView(); diff --git a/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs b/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs index 16f82dffc2..95fce93a09 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportAddin/SharpReportView.cs @@ -35,7 +35,7 @@ namespace SharpReportAddin{ public class SharpReportView : AbstractViewContent,IPrintable,IDisposable { - private SharpReportManager reportManager = null; + private SharpReportManager reportManager; private BaseDesignerControl designerControl; private TabControl tabControl; @@ -45,13 +45,15 @@ namespace SharpReportAddin{ // SideBar private AxSideTab sideTabItem = null; private AxSideTab sideTabFunctions = null; - private Panel panel = new Panel(); + private Panel panel; + private bool designerInitialised; #region privates void InitView() { try { reportManager = new SharpReportManager(); + panel = new Panel(); panel.AutoScroll = true; CreateTabControl(); BuildToolBarItems(); @@ -77,7 +79,8 @@ namespace SharpReportAddin{ private void SetOnPropertyChangedEvents () { try { ReportModel model = designerControl.ReportModel; - model.ReportSettings.PropertyChanged += new EventHandler (OnSettingsChanged); + + model.ReportSettings.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler (OnPropertyChanged); model.ReportHeader.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler (OnPropertyChanged); model.PageHeader.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler (OnPropertyChanged); model.DetailSection.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler (OnPropertyChanged); @@ -134,6 +137,7 @@ namespace SharpReportAddin{ SharpDevelopSideBar sideBar = GetSideBar(); sideBar.Tabs.Remove (sideTabItem); } + if (this.sideTabFunctions != null) { SharpDevelopSideBar sideBar = GetSideBar(); sideBar.Tabs.Remove(this.sideTabFunctions); @@ -187,14 +191,16 @@ namespace SharpReportAddin{ previewPage.Text = ResourceService.GetString("SharpReport.Preview"); this.OnTabPageChanged (this,EventArgs.Empty); this.designerControl.Localise(); + } private BaseDesignerControl CreateDesignerControl() { BaseDesignerControl ctrl = reportManager.BaseDesignControl; - + ctrl.SuspendLayout(); ctrl.ReportControl.Width = ctrl.ReportModel.ReportSettings.PageSettings.Bounds.Width; ctrl.ReportControl.AutoScroll = true; ctrl.Dock = DockStyle.Fill; + ctrl.ResumeLayout(); ctrl.ReportControl.ObjectSelected +=new EventHandler (OnObjectSelected); @@ -309,6 +315,9 @@ namespace SharpReportAddin{ } } + void SetTabTitel (string name) { + base.TitleName = String.Format("{0} [{1}]",name,this.tabControl.SelectedTab.Text); + } private void OnTabPageChanged (object sender, EventArgs e) { @@ -321,7 +330,7 @@ namespace SharpReportAddin{ } else { name = Path.GetFileName (base.FileName); } - base.TitleName = String.Format("{0} [{1}]",name,this.tabControl.SelectedTab.Text); + SetTabTitel (name); switch (tabControl.SelectedIndex) { case 0 : break; @@ -344,23 +353,39 @@ namespace SharpReportAddin{ base.IsDirty = true; } - public void OnPropertyChanged (object sender, - System.ComponentModel.PropertyChangedEventArgs e) { - base.IsDirty = true; - } - - private void OnSettingsChanged (object sender,EventArgs e) { - base.IsDirty = true; + private void OnPropertyChanged (object sender, + System.ComponentModel.PropertyChangedEventArgs e) { + if (this.designerInitialised) { + base.IsDirty = true; + OnObjectSelected (this,EventArgs.Empty); + } + this.designerInitialised = true; } + private void OnModelFileNameChanged (object sender,EventArgs e) { base.FileName = designerControl.ReportModel.ReportSettings.FileName; - base.IsDirty = true; - this.OnFileNameChanged(e); + if (designerControl.ReportModel.ReportSettings.InitDone) { + base.IsDirty = true; + this.OnFileNameChanged(e); + this.SetTabTitel(Path.GetFileName (base.FileName)); + } } private void OnObjectSelected (object sender,EventArgs e) { + if (designerControl.ReportControl.SelectedObject != null) { + BaseReportObject oldobj = PropertyPad.Grid.SelectedObject as BaseReportObject; + +// if (oldobj != null) { +// System.Console.WriteLine(""); +// System.Console.WriteLine("leaving {0} <{1}> ",oldobj.Name,oldobj.Suspend); +// } + + BaseReportObject newobj = designerControl.ReportControl.SelectedObject; + newobj.ResumeLayout(); +// System.Console.WriteLine("View:OnObjectSelected {0} <{1}>",newobj.Name,newobj.Suspend); + if (PropertyPad.Grid != null) { PropertyPad.Grid.SelectedObject = designerControl.ReportControl.SelectedObject; } @@ -368,10 +393,16 @@ namespace SharpReportAddin{ } } - protected override void OnFileNameChanged(System.EventArgs e) { - base.OnFileNameChanged(e); + private void old_OnObjectSelected (object sender,EventArgs e) { + + if (designerControl.ReportControl.SelectedObject != null) { + if (PropertyPad.Grid != null) { + PropertyPad.Grid.SelectedObject = designerControl.ReportControl.SelectedObject; + } + + } } - + #endregion #region Calls from outside commands @@ -406,6 +437,7 @@ namespace SharpReportAddin{ /// Change Sorting or Grouping etc. to update the View and set the DirtyFlag /// /// If true, set the DirtyFlag and Fire the PropertyChanged Event + public void UpdateView(bool setViewDirty) { this.tabControl.SelectedIndex = 0; this.OnTabPageChanged(this,EventArgs.Empty); @@ -513,6 +545,8 @@ namespace SharpReportAddin{ PropertyPad.Grid.Refresh(); } this.designerControl.ReportModel.ReportSettings.AvailableFieldsCollection = reportManager.AvailableFieldsCollection; + this.designerControl.RegisterEvents(); + } catch (Exception e) { MessageService.ShowError(e,"SharpReportView:Load"); throw ; @@ -522,9 +556,8 @@ namespace SharpReportAddin{ #endregion - - #region ICSharpCode.SharpDevelop.Gui.IPrintable interface implementation + public System.Drawing.Printing.PrintDocument PrintDocument { get { AbstractRenderer renderer; @@ -541,8 +574,8 @@ namespace SharpReportAddin{ #endregion - #region IDisposable + #region IDisposable public override void Dispose(){ if (PropertyPad.Grid != null) { @@ -575,6 +608,7 @@ namespace SharpReportAddin{ // Call Dispose on your base class. base.Dispose(); } + #endregion } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseDataItem.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseDataItem.cs index f4ea37d402..75f44f3372 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseDataItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseDataItem.cs @@ -32,15 +32,18 @@ namespace SharpReportCore { private string dbValue; private string dataType; private string nullValue; - /// - /// Default constructor - initializes all fields to default values - /// - public BaseDataItem() { + + #region Constructor + + public BaseDataItem():base() { } - public BaseDataItem(string columnName){ + public BaseDataItem(string columnName):base(){ this.columnName = columnName; } + + #endregion + #region privates //TODO Need a much better handling for 'null' values @@ -64,7 +67,7 @@ namespace SharpReportCore { string toPrint = CheckForNullValue(); string formattedString = base.FireFormatOutput(toPrint,this.FormatString,""); -// System.Console.WriteLine("\t\tBaseDataItem:Render {0} ",formattedString); + RectangleF rect = base.PrepareRectangle (rpea,formattedString); base.PrintTheStuff (rpea,formattedString,rect); base.NotiyfyAfterPrint (rpea.LocationAfterDraw); @@ -74,6 +77,8 @@ namespace SharpReportCore { return "BaseDataItem"; } + #region Properies + [XmlIgnoreAttribute] [Browsable(false)] public virtual string DbValue { @@ -152,5 +157,8 @@ namespace SharpReportCore { nullValue = value; } } + + #endregion + } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs index d97ef1c282..a7ab8cbeba 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportItem.cs @@ -28,7 +28,10 @@ namespace SharpReportCore { private Color foreColor; private Font font; - + + public event EventHandler ItemPrinting; + public event EventHandler ItemPrinted; + public event EventHandler FormatOutput; public event EventHandler Disposed; @@ -57,6 +60,22 @@ namespace SharpReportCore { #endregion + #region EventHandling + protected void NotiyfyAfterPrint (PointF afterPrintLocation) { + if (this.ItemPrinted != null) { + AfterPrintEventArgs rea = new AfterPrintEventArgs (afterPrintLocation); + ItemPrinted(this, rea); + } + } + + protected void NotifyBeforePrint () { + if (this.ItemPrinting != null) { + BeforePrintEventArgs ea = new BeforePrintEventArgs (); + ItemPrinting (this,ea); + } + } + + #endregion #region virtual method's protected RectangleF DrawingRectangle (ReportPageEventArgs e,SizeF measureSize) { @@ -102,6 +121,7 @@ namespace SharpReportCore { } set { drawBorder = value; + base.NotifyPropertyChanged ("DrawBorder"); } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs index b4b2cb237e..48bafe1962 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseReportObject.cs @@ -41,9 +41,6 @@ namespace SharpReportCore { private Color backColor; private int sectionOffset; - - public event EventHandler BeforePrinting; - public event EventHandler AfterPrinting; #region SharpReportCore.IPropertyChange interface implementation @@ -51,7 +48,7 @@ namespace SharpReportCore { #endregion public BaseReportObject() { - + this.suspend = true; } @@ -196,22 +193,7 @@ namespace SharpReportCore { } #endregion - #region EventHandling - public void NotiyfyAfterPrint (PointF afterPrintLocation) { - if (this.AfterPrinting != null) { - AfterPrintEventArgs rea = new AfterPrintEventArgs (afterPrintLocation); - AfterPrinting(this, rea); - } - } - - public void NotifyBeforePrint () { - if (this.BeforePrinting != null) { - BeforePrintEventArgs ea = new BeforePrintEventArgs (); - BeforePrinting (this,ea); - } - } - #endregion #region SharpReportCore.IBaseRenderer interface implementation public virtual void Render(ReportPageEventArgs rpea) { diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs index 950b6b90eb..a49237e4c1 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseSection.cs @@ -9,7 +9,7 @@ //------------------------------------------------------------------------------ using System; using System.ComponentModel; -//using System.Windows.Forms; + using System.Xml.Serialization; /// @@ -24,7 +24,12 @@ namespace SharpReportCore { private ReportItemCollection items; + public event EventHandler SectionPrinting; + public event EventHandler SectionPrinted; + + #region Constructors + public BaseSection(): base() { this.Name = String.Empty; } @@ -35,11 +40,28 @@ namespace SharpReportCore { #endregion + public override void Render(ReportPageEventArgs rpea){ + this.NotifyPrinting(); + base.Render(rpea); + this.NotifyPrinted(); + } #region properties + public void NotifyPrinting () { + if (this.SectionPrinting != null) { + SectionPrintingEventArgs ea = new SectionPrintingEventArgs (this); + SectionPrinting (this,ea); + } + } + + public void NotifyPrinted () { + if (this.SectionPrinted != null) { + SectionPrintingEventArgs ea = new SectionPrintingEventArgs (this); + SectionPrinted (this,ea); + } + } - public int SectionMargin { get { return this.sectionMargin; diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseTextItem.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseTextItem.cs index a00e0d6b93..14b8fa68f8 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseTextItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/BaseTextItem.cs @@ -20,6 +20,7 @@ using SharpReportCore; namespace SharpReportCore { + public class BaseTextItem : SharpReportCore.BaseReportItem,IItemRenderer { private string text; @@ -28,11 +29,14 @@ namespace SharpReportCore { private StringFormat standartStringFormat; private TextDrawer textDrawer = new TextDrawer(); - - public BaseTextItem() { + #region Constructor + + public BaseTextItem():base() { this.standartStringFormat = GlobalValues.StandartStringFormat(); } + #endregion + public override void Render(ReportPageEventArgs rpea) { if (rpea == null) { throw new ArgumentNullException("rpea"); diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs index 7f9e11bba4..c26753c0ca 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/Graphics/BaseImageItem.cs @@ -88,9 +88,7 @@ namespace SharpReportCore { #region properties - -// [EditorAttribute(typeof(System.Windows.Forms.Design.f.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))] - + public virtual string FileName { get { return fileName; @@ -106,7 +104,7 @@ namespace SharpReportCore { /// /// The Image loaded from a File /// - public Image Image { + public virtual Image Image { get { return image; } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/RowItem.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/RowItem.cs index a5043507bc..1ab7034164 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/RowItem.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseItems/RowItem.cs @@ -59,7 +59,7 @@ namespace SharpReportCore{ public override void Render(ReportPageEventArgs rpea){ - System.Console.WriteLine("Render RowItem"); + if (rpea == null) { throw new ArgumentNullException("rpea"); } @@ -71,11 +71,9 @@ namespace SharpReportCore{ foreach (BaseReportItem childItem in this.items) { Point loc = new Point (childItem.Location.X,childItem.Location.Y); - - childItem.Location = new Point(this.Location.X + childItem.Location.X, - this.SectionOffset + this.Location.Y); - + childItem.Location = new Point(this.Location.X + childItem.Location.X, + this.SectionOffset + childItem.Location.Y); childItem.Render (rpea); childItem.Location = new Point(loc.X,loc.Y); diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseSettings.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseSettings.cs index 9c2dfe7fb2..8aeb98dc2e 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/BaseSettings.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/BaseSettings.cs @@ -34,7 +34,7 @@ using System.Xml.Serialization; /// created on - 07.10.2005 22:50:43 /// namespace SharpReportCore { - public class BaseSettings : object { + public class BaseSettings : INotifyPropertyChanged{ private const string defaultReportName = "SharpReport1"; @@ -51,13 +51,16 @@ namespace SharpReportCore { private Margins defaultMargins = new Margins (50,50,50,50); private Size gridSize; private Padding padding; - public event EventHandler PropertyChanged; + public event EventHandler FileNameChanged; + #region SharpReportCore.IPropertyChange interface implementation + public event PropertyChangedEventHandler PropertyChanged; + #endregion + #region Constructor public BaseSettings():this(new PageSettings(),"","") { BaseValues(); - this.initDone = true; } public BaseSettings(PageSettings pageSettings , string reportName,string fileName){ @@ -77,12 +80,10 @@ namespace SharpReportCore { this.fileName = MakePoperFilename(fileName); } - this.pageSettings = pageSettings; - - BaseValues(); } + void BaseValues() { this.useStandartPrinter = true; this.graphicsUnit = GraphicsUnit.Millimeter; @@ -106,9 +107,12 @@ namespace SharpReportCore { } #endregion - protected void NotifyPropertyChanged() { - if (PropertyChanged != null) { - PropertyChanged (this,new EventArgs()); + protected void NotifyPropertyChanged(string info) { + if (this.initDone) { + if (PropertyChanged != null) { + System.Console.WriteLine("BaseSettings : PropertyChanged {0}",info); + PropertyChanged (this,new PropertyChangedEventArgs (info)); + } } } @@ -125,8 +129,9 @@ namespace SharpReportCore { } } - - protected bool InitDone { + [Browsable(false)] + [XmlIgnoreAttribute] + public bool InitDone { get { return initDone; } @@ -147,7 +152,7 @@ namespace SharpReportCore { set { if (reportName != value) { reportName = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("ReportName"); } } } @@ -165,7 +170,7 @@ namespace SharpReportCore { set { if (fileName != value) { fileName = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("FileName"); if (FileNameChanged != null ){ FileNameChanged (this,EventArgs.Empty); } @@ -182,7 +187,7 @@ namespace SharpReportCore { set { if (useStandartPrinter != value) { useStandartPrinter = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("UseStandrtPrinter"); } } } @@ -196,7 +201,7 @@ namespace SharpReportCore { } set { this.pageSettings = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("PageSettings"); } } @@ -210,7 +215,7 @@ namespace SharpReportCore { if (defaultMargins != value) { defaultMargins = value; PageSettings.Margins = defaultMargins; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("DefaultMargins"); } } @@ -228,7 +233,7 @@ namespace SharpReportCore { set { if (graphicsUnit != value) { graphicsUnit = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("GraphicsUnit"); } } } @@ -240,7 +245,7 @@ namespace SharpReportCore { set { if (this.gridSize != value) { this.gridSize = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("GridSize"); } } } @@ -253,7 +258,7 @@ namespace SharpReportCore { set { if (this.padding != value) { this.padding = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("Padding"); } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Events/PrintEventArgs.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Events/PrintEventArgs.cs index b043149c3e..753970523c 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Events/PrintEventArgs.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Events/PrintEventArgs.cs @@ -23,6 +23,22 @@ using System.Drawing; namespace SharpReportCore { + public class SectionPrintingEventArgs : System.EventArgs { + BaseSection section; + + public SectionPrintingEventArgs(BaseSection section){ + this.section = section; + } + + public BaseSection Section { + get { + return section; + } + } + + } + + /// /// This event is fired just bevore an Item is printed /// Use this event for formatting etc. diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Factories/BaseItemFactory.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Factories/BaseItemFactory.cs index e8bb207d06..0dfe4661e5 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Factories/BaseItemFactory.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Factories/BaseItemFactory.cs @@ -33,8 +33,7 @@ namespace SharpReportCore { } public new BaseReportItem Create (string name){ if (String.IsNullOrEmpty(name)) { - String str = String.Format("<{0}>",name); - throw new UnkownItemException(str); + throw new ArgumentNullException("name"); } if (name.LastIndexOf('.') > 0) { StringBuilder b = new StringBuilder (name); diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractDataRenderer.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractDataRenderer.cs index 62a73a381d..a777109540 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractDataRenderer.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractDataRenderer.cs @@ -17,6 +17,8 @@ namespace SharpReportCore{ public class AbstractDataRenderer : AbstractRenderer{ DataManager dataManager; DataNavigator navigator; + + public AbstractDataRenderer(ReportModel model,DataManager dataManager):base(model){ if (dataManager == null) { throw new ArgumentNullException("dataManager"); @@ -24,8 +26,7 @@ namespace SharpReportCore{ this.dataManager = dataManager; } - protected override void ReportBegin(object sender, ReportPageEventArgs e) - { + protected override void ReportBegin(object sender, ReportPageEventArgs e){ base.ReportBegin(sender, e); } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs index 1dddea14eb..1277481902 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/AbstractRenderer.cs @@ -113,7 +113,7 @@ namespace SharpReportCore { throw new ArgumentNullException("rpea"); } - System.Console.WriteLine("Debug Rectangle {0}",rectangle); +// System.Console.WriteLine("Debug Rectangle {0}",rectangle); rpea.PrintPageEventArgs.Graphics.DrawRectangle (Pens.Black,rectangle); } @@ -132,54 +132,65 @@ namespace SharpReportCore { return rect; } - - /// - /// Prints the ReportHader printjob is the same in all Types of reportz - /// - /// ReportpageEventArgs - /// - protected PointF DrawReportHeader (ReportPageEventArgs e) { - float offset = 0; - BaseSection section = null; + protected PointF MeasureReportHeader (ReportPageEventArgs e) { + PointF endAt = new PointF(); if (e.PageNumber == 1) { - sectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportHeader,CultureInfo.InvariantCulture); + sectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportHeader, + CultureInfo.InvariantCulture); + if (this.CurrentSection.Items.Count > 0) { + this.CurrentSection.SectionOffset = reportSettings.DefaultMargins.Top; + FitSectionToItems (this.CurrentSection,e); + endAt = new PointF (0, + reportSettings.DefaultMargins.Top + this.CurrentSection.Size.Height + Gap); + } else { + endAt = new PointF(0,reportSettings.DefaultMargins.Top); + } - section = CurrentSection; - section.SectionOffset = reportSettings.DefaultMargins.Top; - FitSectionToItems (section,e); - offset = RenderSection (section,e); } - return new PointF (0,offset + reportSettings.DefaultMargins.Top + Gap); + return endAt; } - - /// - /// Prints the PageHeader printjob is the same in all Types of reportz /// /// Section start at this PointF /// ReportPageEventArgs - protected PointF DrawPageHeader (PointF startat,ReportPageEventArgs e) { - float offset = 0F; - BaseSection section = null; - sectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportPageHeader,CultureInfo.InvariantCulture); - section = CurrentSection; + protected PointF MeasurePageHeader (PointF startat,ReportPageEventArgs e) { + + sectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportPageHeader, + CultureInfo.InvariantCulture); if (e.PageNumber == 1) { - section.SectionOffset = (int)startat.Y + Gap; + this.CurrentSection.SectionOffset = (int)startat.Y + Gap; } else { - section.SectionOffset = reportSettings.DefaultMargins.Top; + this.CurrentSection.SectionOffset = reportSettings.DefaultMargins.Top; } - FitSectionToItems (section,e); - offset = RenderSection (section,e); - return new PointF (0,section.SectionOffset + offset + Gap); + FitSectionToItems (this.CurrentSection,e); + return new PointF (0, + this.CurrentSection.SectionOffset + this.CurrentSection.Size.Height + Gap); + } + + protected PointF MeasurePageEnd (ReportPageEventArgs e) { + sectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportPageFooter, + CultureInfo.InvariantCulture); + this.CurrentSection.SectionOffset = reportSettings.PageSettings.Bounds.Height - reportSettings.DefaultMargins.Top - reportSettings.DefaultMargins.Bottom; + FitSectionToItems (this.CurrentSection,e); + this.DetailEnds = new Point (0,this.CurrentSection.SectionOffset); + return new PointF(0,this.CurrentSection.SectionOffset); } + protected PointF MeasureReportFooter (ReportPageEventArgs e) { + sectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportFooter, + CultureInfo.InvariantCulture); + FitSectionToItems (this.CurrentSection,e); + return new PointF(0,this.CurrentSection.SectionOffset + this.CurrentSection.Size.Height); + } + + + protected virtual int RenderSection (BaseSection section,ReportPageEventArgs rpea) { - Point drawPoint = new Point(0,0); if (section.Visible){ section.Render (rpea); @@ -204,7 +215,7 @@ namespace SharpReportCore { } return drawPoint.Y; } - + protected void DrawSingleItem (ReportPageEventArgs rpea,BaseReportItem item){ item.SuspendLayout(); @@ -216,12 +227,12 @@ namespace SharpReportCore { // Called by FormatOutPutEvent of the BaseReportItem void FormatBaseReportItem (object sender, FormatOutputEventArgs rpea) { - System.Console.WriteLine("FormatBaseReportItem"); +// System.Console.WriteLine("FormatBaseReportItem"); BaseDataItem baseDataItem = sender as BaseDataItem; if (baseDataItem != null) { if (!String.IsNullOrEmpty(baseDataItem.FormatString)) { rpea.FormatedValue = defaultFormatter.FormatItem (baseDataItem); - System.Console.WriteLine("\tFormated Value = {0}",rpea.FormatedValue); +// System.Console.WriteLine("\tFormated Value = {0}",rpea.FormatedValue); } else { rpea.FormatedValue = rpea.ValueToFormat; } @@ -333,7 +344,8 @@ namespace SharpReportCore { } protected virtual void PrintBodyStart (object sender,ReportPageEventArgs e) { - + this.SectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportDetail, + CultureInfo.InvariantCulture); } @@ -341,12 +353,12 @@ namespace SharpReportCore { } - protected virtual void PrintPageEnd (object sender,ReportPageEventArgs e) { - BaseSection section = null; - section = CurrentSection; - section.SectionOffset = reportSettings.PageSettings.Bounds.Height - reportSettings.DefaultMargins.Top - reportSettings.DefaultMargins.Bottom; - FitSectionToItems (section,e); - RenderSection (section,e); + protected virtual void PrintPageEnd (object sender,ReportPageEventArgs e) { +// BaseSection section = null; +// section = CurrentSection; +// section.SectionOffset = reportSettings.PageSettings.Bounds.Height - reportSettings.DefaultMargins.Top - reportSettings.DefaultMargins.Bottom; +// FitSectionToItems (section,e); +// RenderSection (section,e); } #endregion diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs index 77e39512a6..25f5a11d93 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderDataReport.cs @@ -40,12 +40,12 @@ using SharpReportCore; /// namespace SharpReportCore { -// public class RenderDataReport : AbstractRenderer { - public class RenderDataReport : AbstractDataRenderer { + public class RenderDataReport : AbstractDataRenderer { private PointF currentPoint; private DataNavigator dataNavigator; + public RenderDataReport(ReportModel model,DataManager dataManager):base (model,dataManager){ base.DataManager.GroupChanged += new EventHandler(OnGroupChanged); base.DataManager.GroupChanging += new EventHandler (OnGroupChanging); @@ -63,20 +63,89 @@ namespace SharpReportCore { } private void OnListChanged (object sender,System.ComponentModel.ListChangedEventArgs e) { - System.Console.WriteLine("List Changed sender <{0}> reason <{1}>", - sender.ToString(), - e.ListChangedType); +// System.Console.WriteLine("List Changed sender <{0}> reason <{1}>", +// sender.ToString(), +// e.ListChangedType); + } + + + private void OnSectionPrinting (object sender,SectionPrintingEventArgs e) { + System.Console.WriteLine(""); + System.Console.WriteLine("Begin Print <{0}> with <{1}> Items ",e.Section.Name, + e.Section.Items.Count); + } + + private void OnSectionPrinted (object sender,SectionPrintingEventArgs e) { + System.Console.WriteLine("Section Printed <{0}> ",e.Section.Name); + + } + + private void AddSectionEvents () { + base.CurrentSection.SectionPrinting += new EventHandler(OnSectionPrinting); + base.CurrentSection.SectionPrinted += new EventHandler(OnSectionPrinted); + } + + private void RemoveSectionEvents () { + base.CurrentSection.SectionPrinting -= new EventHandler(OnSectionPrinting); + base.CurrentSection.SectionPrinted -= new EventHandler(OnSectionPrinted); } #region overrides + #region Draw the different report Sections + private PointF DoReportHeader (ReportPageEventArgs rpea){ + PointF endAt = base.MeasureReportHeader (rpea); + + this.AddSectionEvents(); + base.RenderSection (base.CurrentSection,rpea); + this.RemoveSectionEvents(); + + if (base.CurrentSection.PageBreakAfter) { + base.PageBreak(rpea,base.CurrentSection); + base.CurrentSection.PageBreakAfter = false; + return new PointF(); + } + return endAt; + } + + + private PointF DoPageHeader (PointF startAt,ReportPageEventArgs rpea){ + + PointF endAt = base.MeasurePageHeader (startAt,rpea); + + this.AddSectionEvents(); + base.RenderSection (base.CurrentSection,rpea); + this.RemoveSectionEvents(); + return endAt; + } + + + private void DoPageEnd (ReportPageEventArgs rpea){ + System.Console.WriteLine("\tDoPageEnd"); + base.PrintPageEnd(this,rpea); + base.MeasurePageEnd (rpea); + + this.AddSectionEvents(); + base.RenderSection (base.CurrentSection,rpea); + this.RemoveSectionEvents(); + + } + //TODO how should we handle ReportFooter, print it on an seperate page ???? + private void DoReportFooter (PointF startAt,ReportPageEventArgs rpea){ + base.MeasureReportFooter(rpea); + + this.AddSectionEvents(); + base.RenderSection (base.CurrentSection,rpea); + this.RemoveSectionEvents(); + } + #endregion - protected override void ReportQueryPage(object sender, QueryPageSettingsEventArgs e) { - base.ReportQueryPage (sender,e); + protected override void ReportQueryPage(object sender, QueryPageSettingsEventArgs qpea) { + base.ReportQueryPage (sender,qpea); } - protected override void ReportBegin(object sender, ReportPageEventArgs e) { - base.ReportBegin (sender,e); + protected override void ReportBegin(object sender, ReportPageEventArgs rpea) { + base.ReportBegin (sender,rpea); base.DataManager.ListChanged += new EventHandler (OnListChanged); dataNavigator = base.DataManager.GetNavigator; @@ -90,88 +159,91 @@ namespace SharpReportCore { if (rpea == null) { throw new ArgumentNullException("rpea"); } + base.BeginPrintPage (sender,rpea); - //Draw ReportHeader - currentPoint = base.DrawReportHeader (rpea); - if (base.CurrentSection.PageBreakAfter) { - base.PageBreak(rpea,base.CurrentSection); - base.CurrentSection.PageBreakAfter = false; - return; + + if (rpea.PageNumber == 1) { + //Draw ReportHeader + this.currentPoint = DoReportHeader (rpea); } //Draw Pageheader - currentPoint = base.DrawPageHeader (currentPoint,rpea); + this.currentPoint = DoPageHeader (this.currentPoint,rpea); + base.DetailStart = new Point ((int)currentPoint.X,(int)currentPoint.Y); + } - protected override void PrintBodyStart(object sender, ReportPageEventArgs e) { + + + protected override void PrintBodyStart(object sender, ReportPageEventArgs rpea) { Rectangle sectionRect; Rectangle detailRect; - - base.PrintBodyStart (sender,e); - base.SectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportDetail,CultureInfo.InvariantCulture); - + + base.PrintBodyStart (sender,rpea); + BaseSection section = base.CurrentSection; section.SectionOffset = (int)this.currentPoint.Y + base.Gap; - detailRect = base.DetailRectangle (e); + detailRect = base.DetailRectangle (rpea); //this is only for the first record, zhe other details will be calculated - sectionRect = new Rectangle (e.PrintPageEventArgs.MarginBounds.Left, + sectionRect = new Rectangle (rpea.PrintPageEventArgs.MarginBounds.Left, section.SectionOffset, - e.PrintPageEventArgs.MarginBounds.Width, + rpea.PrintPageEventArgs.MarginBounds.Width, section.Size.Height); // DebugRectangle (e,detailRect); // no loop if there is no data if (! this.dataNavigator.HasMoreData ) { - e.PrintPageEventArgs.HasMorePages = false; + rpea.PrintPageEventArgs.HasMorePages = false; return; } while (this.dataNavigator.MoveNext()) { this.dataNavigator.Fill (base.CurrentSection.Items); - base.RenderSection (section,e); + base.RenderSection (section,rpea); section.SectionOffset = section.SectionOffset + section.Size.Height + 2 * base.Gap; - base.FitSectionToItems (base.CurrentSection,e); + base.FitSectionToItems (base.CurrentSection,rpea); - sectionRect = new Rectangle (e.PrintPageEventArgs.MarginBounds.Left, + sectionRect = new Rectangle (rpea.PrintPageEventArgs.MarginBounds.Left, section.SectionOffset, - e.PrintPageEventArgs.MarginBounds.Width, + rpea.PrintPageEventArgs.MarginBounds.Width, section.Size.Height); if (!detailRect.Contains(sectionRect)) { - base.PageBreak(e,section); + base.PageBreak(rpea,section); return; } } - e.PrintPageEventArgs.HasMorePages = false; + DoReportFooter (new PointF(0,section.SectionOffset + section.Size.Height), + rpea); + + rpea.PrintPageEventArgs.HasMorePages = false; //Did we have a pagebreak if (base.CurrentSection.PageBreakAfter) { - base.PageBreak(e,section); + base.PageBreak(rpea,section); base.CurrentSection.PageBreakAfter = false; return; } } - protected override void PrintBodyEnd(object sender, ReportPageEventArgs e) { - base.PrintBodyEnd (sender,e); + protected override void PrintBodyEnd(object sender, ReportPageEventArgs rpea) { +// System.Console.WriteLine("PrintBodyEnd"); + base.PrintBodyEnd (sender,rpea); } - protected override void PrintPageEnd(object sender, ReportPageEventArgs e) { - base.SectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportPageFooter, - CultureInfo.InvariantCulture); - base.PrintPageEnd (sender,e); - base.DetailEnds = new Point (0,base.CurrentSection.SectionOffset); + protected override void PrintPageEnd(object sender, ReportPageEventArgs rpea) { + this.DoPageEnd (rpea); } public override string ToString() { diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderFormSheetReport.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderFormSheetReport.cs index 42cfc1691a..fc017fa790 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderFormSheetReport.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Printing/RenderFormSheetReport.cs @@ -46,15 +46,84 @@ namespace SharpReportCore { } + private void OnSectionPrinting (object sender,SectionPrintingEventArgs e) { + System.Console.WriteLine(""); + System.Console.WriteLine("Begin Print <{0}> with <{1}> Items ",e.Section.Name, + e.Section.Items.Count); + } + + private void OnSectionPrinted (object sender,SectionPrintingEventArgs e) { + System.Console.WriteLine("Section Printed {0} ",e.Section.Name); + + } + + private void AddSectionEvents () { + base.CurrentSection.SectionPrinting += new EventHandler(OnSectionPrinting); + base.CurrentSection.SectionPrinted += new EventHandler(OnSectionPrinted); + } + + private void RemoveSectionEvents () { + base.CurrentSection.SectionPrinting -= new EventHandler(OnSectionPrinting); + base.CurrentSection.SectionPrinted -= new EventHandler(OnSectionPrinted); + } + + + + #region Draw the different report Sections + private PointF DoReportHeader (ReportPageEventArgs rpea){ + PointF endAt = base.MeasureReportHeader (rpea); + + this.AddSectionEvents(); + base.RenderSection (base.CurrentSection,rpea); + this.RemoveSectionEvents(); + + if (base.CurrentSection.PageBreakAfter) { + base.PageBreak(rpea,base.CurrentSection); + base.CurrentSection.PageBreakAfter = false; + return new PointF(); + } + return endAt; + } + + private PointF DoPageHeader (PointF startAt,ReportPageEventArgs rpea){ + + PointF endAt = base.MeasurePageHeader (startAt,rpea); + + this.AddSectionEvents(); + base.RenderSection (base.CurrentSection,rpea); + this.RemoveSectionEvents(); + return endAt; + } + + private void DoPageEnd (ReportPageEventArgs rpea){ + base.PrintPageEnd(this,rpea); + base.MeasurePageEnd (rpea); + + this.AddSectionEvents(); + base.RenderSection (base.CurrentSection,rpea); + this.RemoveSectionEvents(); + + } + + //TODO how should we handle ReportFooter, print it on an seperate page ???? + private void DoReportFooter (PointF startAt,ReportPageEventArgs rpea){ + base.MeasureReportFooter(rpea); + + this.AddSectionEvents(); + base.RenderSection (base.CurrentSection,rpea); + this.RemoveSectionEvents(); + } + + #endregion #region event's - protected override void ReportQueryPage (object sender,QueryPageSettingsEventArgs e) { - base.ReportQueryPage (sender,e); + protected override void ReportQueryPage (object sender,QueryPageSettingsEventArgs qpea) { + base.ReportQueryPage (sender,qpea); } - protected override void ReportBegin (object sender,ReportPageEventArgs e) { - base.ReportBegin (sender,e); + protected override void ReportBegin (object sender,ReportPageEventArgs rpea) { + base.ReportBegin (sender,rpea); } /// @@ -63,19 +132,31 @@ namespace SharpReportCore { /// /// /// - protected override void BeginPrintPage (object sender,ReportPageEventArgs e) { - base.BeginPrintPage (sender,e); + protected override void BeginPrintPage (object sender,ReportPageEventArgs rpea) { + + if (rpea == null) { + throw new ArgumentNullException("rpea"); + } + + base.BeginPrintPage (sender,rpea); + //Draw ReportHeader - currentPoint = base.DrawReportHeader (e); + if (rpea.PageNumber == 1) { + //Draw ReportHeader + this.currentPoint = DoReportHeader (rpea); + } + if (base.CurrentSection.PageBreakAfter) { - base.PageBreak(e,base.CurrentSection); + base.PageBreak(rpea,base.CurrentSection); base.CurrentSection.PageBreakAfter = false; return; } //Draw Pageheader - currentPoint = base.DrawPageHeader (currentPoint,e); + + this.currentPoint = DoPageHeader (this.currentPoint,rpea); + base.DetailStart = new Point ((int)currentPoint.X,(int)currentPoint.Y); } @@ -85,61 +166,38 @@ namespace SharpReportCore { /// /// /// - protected override void PrintBodyStart (object sender,ReportPageEventArgs e) { - base.PrintBodyStart (sender,e); + protected override void PrintBodyStart (object sender,ReportPageEventArgs rpea) { + base.PrintBodyStart (sender,rpea); - base.SectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportDetail, - CultureInfo.InvariantCulture); BaseSection section = base.CurrentSection; section.SectionOffset = (int)this.currentPoint.Y + base.Gap; - Rectangle detailRect = base.DetailRectangle (e); - FitSectionToItems (section,e); - base.RenderSection (section,e); -// DebugRectangle (e,detailRect); - } - - - protected override void PrintBodyEnd (object sender,ReportPageEventArgs e) { - base.PrintBodyEnd (sender,e); + Rectangle detailRect = base.DetailRectangle (rpea); + FitSectionToItems (section,rpea); + + this.AddSectionEvents(); + base.RenderSection (section,rpea); + this.RemoveSectionEvents(); } - - /// - /// PageFooter and, if LastPage ReportFooter + /// Print the PageFooter /// /// /// - protected override void PrintPageEnd (object sender,ReportPageEventArgs e) { + protected override void PrintPageEnd(object sender, ReportPageEventArgs rpea) { + this.DoPageEnd (rpea); + } - //PageFooter - base.SectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportPageFooter, - CultureInfo.InvariantCulture); - base.PrintPageEnd (sender,e); - - - Rectangle r = new Rectangle (e.PrintPageEventArgs.MarginBounds.Left, - base.CurrentSection.SectionOffset , - e.PrintPageEventArgs.MarginBounds.Width, - base.CurrentSection.Size.Height); -// DebugRectangle (e,r); - - int off = base.CurrentSection.SectionOffset + base.CurrentSection.Size.Height + base.Gap; - //ReportFooter - base.SectionInUse = Convert.ToInt16(GlobalEnums.enmSection.ReportFooter, - CultureInfo.InvariantCulture); - BaseSection section = base.CurrentSection; - - section.SectionOffset = off; - FitSectionToItems (section,e); - Rectangle rr = new Rectangle (e.PrintPageEventArgs.MarginBounds.Left, - base.CurrentSection.SectionOffset , - e.PrintPageEventArgs.MarginBounds.Width, - base.CurrentSection.Size.Height); - - base.RenderSection (section,e); -// DebugRectangle (e,rr); + + + protected override void PrintBodyEnd (object sender,ReportPageEventArgs rpea) { + base.PrintBodyEnd (sender,rpea); + this.DoReportFooter (new PointF(0,base.CurrentSection.SectionOffset + base.CurrentSection.Size.Height), + rpea); } + + + #endregion } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs index 2f41b59916..676762d638 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/ReportSettings.cs @@ -40,7 +40,8 @@ namespace SharpReportCore{ /// public class ReportSettings : BaseSettings,SharpReportCore.IStoreable, - IBaseRenderer,IDisposable{ + IBaseRenderer,IDisposable{ + private string connectionString; private string commandText; @@ -60,7 +61,8 @@ namespace SharpReportCore{ private ColumnCollection groupingsCollection; private ColumnCollection sortingCollection; - + + #region Constructor's public ReportSettings(System.Drawing.Printing.PageSettings defaultPageSettings) @@ -228,7 +230,7 @@ namespace SharpReportCore{ } } } - base.InitDone = true; +// base.InitDone = true; } #endregion @@ -492,7 +494,7 @@ namespace SharpReportCore{ set { if (reportType != value) { reportType = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("ReportType"); } } } @@ -560,7 +562,7 @@ namespace SharpReportCore{ } if (reportParametersCollection != value) { reportParametersCollection = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("SqlParametersCollection"); } } } @@ -577,7 +579,7 @@ namespace SharpReportCore{ set { if (connectionString != value) { connectionString = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("ConnectionString"); } } } @@ -592,7 +594,7 @@ namespace SharpReportCore{ set { if (commandText != value) { commandText = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("CommandText"); } } } @@ -606,7 +608,7 @@ namespace SharpReportCore{ set { if (commandType != value) { commandType = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("CommandType"); } } } @@ -620,7 +622,7 @@ namespace SharpReportCore{ set { if (dataModel != value) { dataModel = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("DataModel"); } } } @@ -640,7 +642,7 @@ namespace SharpReportCore{ set { if (defaultFont != value) { defaultFont = value; - this.NotifyPropertyChanged(); + this.NotifyPropertyChanged("DefaultFont"); } } } diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Visitors/LoadModelVisitor.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Visitors/LoadModelVisitor.cs index 90eca5d864..7aea187159 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Visitors/LoadModelVisitor.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Visitors/LoadModelVisitor.cs @@ -68,6 +68,7 @@ namespace SharpReportCore { if (node is XmlElement) { XmlElement sectionElem = (XmlElement)node; baseSection = (BaseSection)model.SectionCollection.Find(sectionElem.GetAttribute("name")); + baseSection.SuspendLayout(); if (baseSection != null) { XmlHelper.SetSectionValues (xmlFormReader,sectionElem,baseSection); XmlNodeList ctrlList = sectionElem.SelectNodes ("controls/control"); @@ -80,10 +81,10 @@ namespace SharpReportCore { //Read the Element rpt = (BaseReportItem)baseItemFactory.Create(ctrlElem.GetAttribute("basetype")); if (rpt != null) { - rpt.SuspendLayout(); +// rpt.SuspendLayout(); rpt.Parent = baseSection; baseSection.Items.Add (rpt); - XmlHelper.BuildControl (xmlFormReader,ctrlElem,rpt); + XmlHelper.SetReportItemValues (xmlFormReader,ctrlElem,rpt); rpt.Visible = true; rpt.ResumeLayout(); } else { diff --git a/src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs b/src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs index bd882edb09..751fbfa4e0 100644 --- a/src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs +++ b/src/AddIns/Misc/SharpReport/SharpReportCore/Xml/XmlHelper.cs @@ -117,7 +117,7 @@ namespace SharpReportCore { /// See XMLFormReader /// The Control for wich the values are /// Element witch contains the values - public static void BuildControl (XmlFormReader reader, + public static void SetReportItemValues (XmlFormReader reader, XmlElement ctrlElem, BaseReportItem item) { @@ -131,7 +131,8 @@ namespace SharpReportCore { item.Font = XmlFormReader.MakeFont (elem.GetAttribute("value")); } - reader.SetValue (item,elem.Name,elem.GetAttribute("value")); + reader.SetValue (item, + elem.Name,elem.GetAttribute("value")); } } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Resources/ASPX.xshd b/src/Libraries/ICSharpCode.TextEditor/Project/Resources/ASPX.xshd index 8650acd8b3..04a5b1edca 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Resources/ASPX.xshd +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Resources/ASPX.xshd @@ -1,49 +1,17 @@ - - - - - - - - - - - - - - - - - - - - - - - + - - <> - - <% - %> - - - - < - > - - - - - - - ' - - + + + <% + %> + + - + + + // + diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Resources/Mode.xsd b/src/Libraries/ICSharpCode.TextEditor/Project/Resources/Mode.xsd index 98dd64e43d..97bbeaf63e 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Resources/Mode.xsd +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Resources/Mode.xsd @@ -320,7 +320,7 @@ - + + + diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Resources/SyntaxModes.xml b/src/Libraries/ICSharpCode.TextEditor/Project/Resources/SyntaxModes.xml index 20ec50e9d0..c14fe14c2a 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Resources/SyntaxModes.xml +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Resources/SyntaxModes.xml @@ -1,7 +1,7 @@ + name = "ASP/XHTML" + extensions = ".asp;.aspx;.asax;.asmx"/> (); } currentSpanStack.Push(span); - + UpdateSpanStateVariables(); } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightRuleSet.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightRuleSet.cs index c01d8236fa..49ee6d89dc 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightRuleSet.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightRuleSet.cs @@ -107,7 +107,7 @@ namespace ICSharpCode.TextEditor.Document public HighlightRuleSet(XmlElement el) { - XmlNodeList nodes = el.GetElementsByTagName("KeyWords"); + XmlNodeList nodes; if (el.Attributes["name"] != null) { Name = el.Attributes["name"].InnerText; @@ -126,13 +126,13 @@ namespace ICSharpCode.TextEditor.Document } for (int i = 0; i < Delimiters.Length; ++i) { - Delimiters[i] = false; + delimiters[i] = false; } if (el["Delimiters"] != null) { string delimiterString = el["Delimiters"].InnerText; foreach (char ch in delimiterString) { - Delimiters[(int)ch] = true; + delimiters[(int)ch] = true; } } @@ -142,6 +142,7 @@ namespace ICSharpCode.TextEditor.Document prevMarkers = new LookupTable(!IgnoreCase); nextMarkers = new LookupTable(!IgnoreCase); + nodes = el.GetElementsByTagName("KeyWords"); foreach (XmlElement el2 in nodes) { HighlightColor color = new HighlightColor(el2); @@ -171,5 +172,22 @@ namespace ICSharpCode.TextEditor.Document nextMarkers[next.What] = next; } } + + /// + /// Merges spans etc. from the other rule set into this rule set. + /// + public void MergeFrom(HighlightRuleSet ruleSet) + { + for (int i = 0; i < delimiters.Length; i++) { + delimiters[i] |= ruleSet.delimiters[i]; + } + // insert merged spans in front of old spans + ArrayList oldSpans = spans; + spans = (ArrayList)ruleSet.spans.Clone(); + spans.AddRange(oldSpans); + //keyWords.MergeFrom(ruleSet.keyWords); + //prevMarkers.MergeFrom(ruleSet.prevMarkers); + //nextMarkers.MergeFrom(ruleSet.nextMarkers); + } } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingDefinitionParser.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingDefinitionParser.cs index 218e1b226d..f3ccc67416 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingDefinitionParser.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingDefinitionParser.cs @@ -11,6 +11,7 @@ using System.Xml; using System.Xml.Schema; using System.Text; using System.Collections; +using System.Collections.Generic; using System.Windows.Forms; using System.Reflection; @@ -51,8 +52,17 @@ namespace ICSharpCode.TextEditor.Document if (highlighter == null) highlighter = new DefaultHighlightingStrategy(doc.DocumentElement.Attributes["name"].InnerText); - if (doc.DocumentElement.Attributes["extensions"]!= null) { - highlighter.Extensions = doc.DocumentElement.Attributes["extensions"].InnerText.Split(new char[] { ';', '|' }); + if (doc.DocumentElement.HasAttribute("extends")) { + KeyValuePair entry = HighlightingManager.Manager.FindHighlighterEntry(doc.DocumentElement.GetAttribute("extends")); + if (entry.Key == null) { + MessageBox.Show("Cannot find referenced highlighting source " + doc.DocumentElement.GetAttribute("extends")); + } else { + highlighter = Parse(highlighter, entry.Key, entry.Value.GetSyntaxModeFile(entry.Key)); + if (highlighter == null) return null; + } + } + if (doc.DocumentElement.HasAttribute("extensions")) { + highlighter.Extensions = doc.DocumentElement.GetAttribute("extensions").Split(new char[] { ';', '|' }); } XmlElement environment = doc.DocumentElement["Environment"]; @@ -91,7 +101,7 @@ namespace ICSharpCode.TextEditor.Document return highlighter; } } catch (Exception e) { - MessageBox.Show("Could not load mode definition file.\n" + e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); + MessageBox.Show("Could not load mode definition file '" + syntaxMode.FileName + "'.\n" + e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return null; } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingManager.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingManager.cs index aa58d3ebd1..f6b02e70d5 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingManager.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightingManager.cs @@ -8,6 +8,7 @@ using System; using System.Collections; using System.Collections.Specialized; +using System.Collections.Generic; using System.Windows.Forms; using System.IO; using System.Reflection; @@ -93,19 +94,40 @@ namespace ICSharpCode.TextEditor.Document ISyntaxModeFileProvider syntaxModeFileProvider = (ISyntaxModeFileProvider)entry.Value; DefaultHighlightingStrategy highlightingStrategy = HighlightingDefinitionParser.Parse(syntaxMode, syntaxModeFileProvider.GetSyntaxModeFile(syntaxMode)); + if (highlightingStrategy == null) { + highlightingStrategy = DefaultHighlighting; + } highlightingDefs[syntaxMode.Name] = highlightingStrategy; highlightingStrategy.ResolveReferences(); return highlightingStrategy; } + public DefaultHighlightingStrategy DefaultHighlighting { + get { + return (DefaultHighlightingStrategy)highlightingDefs["Default"]; + } + } + + internal KeyValuePair FindHighlighterEntry(string name) + { + foreach (ISyntaxModeFileProvider provider in syntaxModeFileProviders) { + foreach (SyntaxMode mode in provider.SyntaxModes) { + if (mode.Name == name) { + return new KeyValuePair(mode, provider); + } + } + } + return new KeyValuePair(null, null); + } + public IHighlightingStrategy FindHighlighter(string name) { object def = highlightingDefs[name]; if (def is DictionaryEntry) { return LoadDefinition((DictionaryEntry)def); } - return (IHighlightingStrategy)(def == null ? highlightingDefs["Default"] : def); + return def == null ? DefaultHighlighting : (IHighlightingStrategy)def; } public IHighlightingStrategy FindHighlighterForFile(string fileName) @@ -116,9 +138,9 @@ namespace ICSharpCode.TextEditor.Document if (def is DictionaryEntry) { return LoadDefinition((DictionaryEntry)def); } - return (IHighlightingStrategy)(def == null ? highlightingDefs["Default"] : def); + return def == null ? DefaultHighlighting : (IHighlightingStrategy)def; } else { - return (IHighlightingStrategy)highlightingDefs["Default"]; + return DefaultHighlighting; } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/FileSyntaxModeProvider.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/FileSyntaxModeProvider.cs index 257788cc3c..fe858e63fd 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/FileSyntaxModeProvider.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/FileSyntaxModeProvider.cs @@ -7,7 +7,7 @@ using System; using System.IO; -using System.Collections; +using System.Collections.Generic; using System.Reflection; using System.Windows.Forms; using System.Xml; @@ -17,9 +17,9 @@ namespace ICSharpCode.TextEditor.Document public class FileSyntaxModeProvider : ISyntaxModeFileProvider { string directory; - ArrayList syntaxModes = null; + List syntaxModes = null; - public ArrayList SyntaxModes { + public ICollection SyntaxModes { get { return syntaxModes; } @@ -53,10 +53,10 @@ namespace ICSharpCode.TextEditor.Document return new XmlTextReader(File.OpenRead(syntaxModeFile)); } - ArrayList ScanDirectory(string directory) + List ScanDirectory(string directory) { string[] files = Directory.GetFiles(directory); - ArrayList modes = new ArrayList(); + List modes = new List(); foreach (string file in files) { if (Path.GetExtension(file).Equals(".XSHD", StringComparison.OrdinalIgnoreCase)) { XmlTextReader reader = new XmlTextReader(file); diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/ISyntaxModeFileProvider.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/ISyntaxModeFileProvider.cs index 5aee29052d..1df1176d1c 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/ISyntaxModeFileProvider.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/ISyntaxModeFileProvider.cs @@ -6,14 +6,14 @@ // using System; -using System.Collections; +using System.Collections.Generic; using System.Xml; namespace ICSharpCode.TextEditor.Document { public interface ISyntaxModeFileProvider { - ArrayList SyntaxModes { + ICollection SyntaxModes { get; } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/ResourceSyntaxModeProvider.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/ResourceSyntaxModeProvider.cs index 523021c529..80465ef0ab 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/ResourceSyntaxModeProvider.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/ResourceSyntaxModeProvider.cs @@ -6,7 +6,7 @@ // using System; -using System.Collections; +using System.Collections.Generic; using System.Reflection; using System.Xml; using System.IO; @@ -15,9 +15,9 @@ namespace ICSharpCode.TextEditor.Document { public class ResourceSyntaxModeProvider : ISyntaxModeFileProvider { - ArrayList syntaxModes = null; + List syntaxModes = null; - public ArrayList SyntaxModes { + public ICollection SyntaxModes { get { return syntaxModes; } @@ -30,7 +30,7 @@ namespace ICSharpCode.TextEditor.Document if (syntaxModeStream != null) { syntaxModes = SyntaxMode.GetSyntaxModes(syntaxModeStream); } else { - syntaxModes = new ArrayList(); + syntaxModes = new List(); } } diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/SyntaxMode.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/SyntaxMode.cs index c2d7cfca96..c47d086427 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/SyntaxMode.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/SyntaxModes/SyntaxMode.cs @@ -7,7 +7,7 @@ using System; using System.IO; -using System.Collections; +using System.Collections.Generic; using System.Windows.Forms; using System.Xml; @@ -60,10 +60,10 @@ namespace ICSharpCode.TextEditor.Document this.extensions = extensions; } - public static ArrayList GetSyntaxModes(Stream xmlSyntaxModeStream) + public static List GetSyntaxModes(Stream xmlSyntaxModeStream) { XmlTextReader reader = new XmlTextReader(xmlSyntaxModeStream); - ArrayList syntaxModes = new ArrayList(); + List syntaxModes = new List(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/TextWord.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/TextWord.cs index cdbcc2207a..6312789fda 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/TextWord.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/TextWord.cs @@ -158,7 +158,7 @@ namespace ICSharpCode.TextEditor.Document return color; } set { - Debug.Assert(color != null); + Debug.Assert(value != null); color = value; } } diff --git a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs index 1a394ff7e0..417edef8dc 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs @@ -320,14 +320,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter void OutputEnumMembers(TypeDeclaration typeDeclaration, object data) { - bool first = true; - foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) { - if (first) { - first = false; - } else { - outputFormatter.PrintToken(Tokens.Comma); - outputFormatter.NewLine(); - } + for (int i = 0; i < typeDeclaration.Children.Count; i++) { + FieldDeclaration fieldDeclaration = (FieldDeclaration)typeDeclaration.Children[i]; + nodeTracker.BeginNode(fieldDeclaration); VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0]; VisitAttributes(fieldDeclaration.Attributes, data); outputFormatter.Indent(); @@ -338,8 +333,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter outputFormatter.Space(); nodeTracker.TrackedVisit(f.Initializer, data); } + if (i < typeDeclaration.Children.Count - 1) { + outputFormatter.PrintToken(Tokens.Comma); + } + outputFormatter.NewLine(); + nodeTracker.EndNode(fieldDeclaration); } - outputFormatter.NewLine(); } TypeDeclaration currentType = null; diff --git a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs index 52c8a2313d..63c415ce85 100644 --- a/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs +++ b/src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs @@ -374,6 +374,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter void OutputEnumMembers(TypeDeclaration typeDeclaration, object data) { foreach (FieldDeclaration fieldDeclaration in typeDeclaration.Children) { + nodeTracker.BeginNode(fieldDeclaration); VariableDeclaration f = (VariableDeclaration)fieldDeclaration.Fields[0]; VisitAttributes(fieldDeclaration.Attributes, data); outputFormatter.Indent(); @@ -385,6 +386,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter nodeTracker.TrackedVisit(f.Initializer, data); } outputFormatter.NewLine(); + nodeTracker.EndNode(fieldDeclaration); } } diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs index 5421c6400e..ebedf04772 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs @@ -4629,7 +4629,7 @@ la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) { Expect(1); #line 2149 "cs.ATG" - if (type.Type == "global") { type.IsGlobal = true; type.Type = t.val; } else type.Type += "." + t.val; + if (type.Type == "global") { type.IsGlobal = true; type.Type = (t.val ?? "?"); } else type.Type += "." + (t.val ?? "?"); } else if (la.kind == 1) { lexer.NextToken(); diff --git a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG index 766d90a8e9..ce497567ec 100644 --- a/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG +++ b/src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG @@ -2146,7 +2146,7 @@ PrimaryExpr | IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) ident (. type = new TypeReference(t.val); .) "::" (. pexpr = new TypeReferenceExpression(type); .) - ident (. if (type.Type == "global") { type.IsGlobal = true; type.Type = t.val; } else type.Type += "." + t.val; .) + ident (. if (type.Type == "global") { type.IsGlobal = true; type.Type = (t.val ?? "?"); } else type.Type += "." + (t.val ?? "?"); .) /*--- simple name: */ | ident (. pexpr = new IdentifierExpression(t.val); .) /*--- parenthesized expression: */ diff --git a/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs b/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs index 8aee4dbd56..bad08317d5 100644 --- a/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs +++ b/src/Libraries/NRefactory/Test/Output/SpecialOutputVisitor.cs @@ -32,6 +32,21 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter parser.Dispose(); } + void TestProgramVB(string program) + { + IParser parser = ParserFactory.CreateParser(SupportedLanguage.VBNet, new StringReader(program)); + parser.Parse(); + Assert.AreEqual("", parser.Errors.ErrorOutput); + VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); + using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(), + outputVisitor)) { + outputVisitor.Visit(parser.CompilationUnit, null); + } + Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); + Assert.AreEqual(program, outputVisitor.Text.TrimEnd().Replace("\r", "")); + parser.Dispose(); + } + [Test] public void SimpleComments() { @@ -63,5 +78,32 @@ namespace ICSharpCode.NRefactory.Tests.PrettyPrinter "}\n" + "#end if"); } + + [Test] + public void Enum() + { + TestProgram("enum Test\n" + + "{\n" + + "\t// a\n" + + "\tm1,\n" + + "\t// b\n" + + "\tm2\n" + + "\t// c\n" + + "}\n" + + "// d"); + } + + [Test] + public void EnumVB() + { + TestProgramVB("Enum Test\n" + + "\t' a\n" + + "\tm1\n" + + "\t' b\n" + + "\tm2\n" + + "\t' c\n" + + "End Enum\n" + + "' d"); + } } } diff --git a/src/Libraries/NRefactory/Test/Parser/Expressions/TypeReferenceExpressionTests.cs b/src/Libraries/NRefactory/Test/Parser/Expressions/TypeReferenceExpressionTests.cs index 4fce6a634e..80f596d4c8 100644 --- a/src/Libraries/NRefactory/Test/Parser/Expressions/TypeReferenceExpressionTests.cs +++ b/src/Libraries/NRefactory/Test/Parser/Expressions/TypeReferenceExpressionTests.cs @@ -26,6 +26,22 @@ namespace ICSharpCode.NRefactory.Tests.AST public class TypeReferenceExpressionTests { #region C# + [Test] + public void GlobalTypeReferenceExpression() + { + TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression("global::System"); + Assert.AreEqual("System", tr.TypeReference.Type); + Assert.IsTrue(tr.TypeReference.IsGlobal); + } + + [Test] + public void GlobalTypeReferenceExpressionWithoutTypeName() + { + TypeReferenceExpression tr = ParseUtilCSharp.ParseExpression("global::", true); + Assert.AreEqual("?", tr.TypeReference.Type); + Assert.IsTrue(tr.TypeReference.IsGlobal); + } + [Test] public void IntReferenceExpression() { diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index b021edbdc0..6e68872f26 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -764,6 +764,7 @@ + @@ -792,4 +793,4 @@ - \ No newline at end of file + diff --git a/src/Main/Base/Project/Resources/FullscreenPanel.xfrm b/src/Main/Base/Project/Resources/FullscreenPanel.xfrm index 18e1be55a6..e27c3e1dbc 100644 --- a/src/Main/Base/Project/Resources/FullscreenPanel.xfrm +++ b/src/Main/Base/Project/Resources/FullscreenPanel.xfrm @@ -42,6 +42,7 @@ + @@ -50,6 +51,7 @@ + @@ -58,6 +60,7 @@ + @@ -82,6 +85,7 @@ + diff --git a/src/Main/Base/Project/Src/Commands/DebugCommands.cs b/src/Main/Base/Project/Src/Commands/DebugCommands.cs index 62fa78c9de..d1ca63f637 100644 --- a/src/Main/Base/Project/Src/Commands/DebugCommands.cs +++ b/src/Main/Base/Project/Src/Commands/DebugCommands.cs @@ -8,6 +8,9 @@ using System; using System.Diagnostics; using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; +using ICSharpCode.TextEditor; namespace ICSharpCode.SharpDevelop.Project.Commands { @@ -87,4 +90,18 @@ namespace ICSharpCode.SharpDevelop.Project.Commands DebuggerService.CurrentDebugger.StepOut(); } } + + public class ToggleBreakpointCommand : AbstractMenuCommand + { + public override void Run() + { + IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; + + if (window == null || !(window.ViewContent is ITextEditorControlProvider)) { + return; + } + TextEditorControl textEditor = ((ITextEditorControlProvider)window.ViewContent).TextEditorControl; + DebuggerService.ToggleBreakpointAt(textEditor.Document, textEditor.FileName, textEditor.ActiveTextAreaControl.Caret.Line); + } + } } diff --git a/src/Main/Base/Project/Src/Dom/IClass.cs b/src/Main/Base/Project/Src/Dom/IClass.cs index 145630aeea..1a60f3c83b 100644 --- a/src/Main/Base/Project/Src/Dom/IClass.cs +++ b/src/Main/Base/Project/Src/Dom/IClass.cs @@ -102,6 +102,12 @@ namespace ICSharpCode.SharpDevelop.Dom get; } + /// + /// If this is a partial class, gets the compound class containing information from all parts. + /// If this is not a partial class, a reference to this class is returned. + /// + IClass GetCompoundClass(); + IClass GetInnermostClass(int caretLine, int caretColumn); List GetAccessibleTypes(IClass callingClass); diff --git a/src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs b/src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs index 9416dc844e..6c8d4ff2e9 100644 --- a/src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs +++ b/src/Main/Base/Project/Src/Dom/Implementations/DefaultClass.cs @@ -126,6 +126,11 @@ namespace ICSharpCode.SharpDevelop.Dom } } + public IClass GetCompoundClass() + { + return this.DefaultReturnType.GetUnderlyingClass() ?? this; + } + protected override void OnFullyQualifiedNameChanged(EventArgs e) { base.OnFullyQualifiedNameChanged(e); diff --git a/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs b/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs index 8410e0a8c6..54a2dd95c0 100644 --- a/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs +++ b/src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs @@ -296,7 +296,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver if (c.ClassType != ClassType.Enum && typeDeclaration.BaseTypes != null) { foreach (AST.TypeReference type in typeDeclaration.BaseTypes) { - c.BaseTypes.Add(CreateReturnType(type)); + IReturnType rt = CreateReturnType(type); + if (rt != null) { + c.BaseTypes.Add(rt); + } } } @@ -350,7 +353,10 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver DefaultTypeParameter ConvertConstraints(AST.TemplateDefinition template, DefaultTypeParameter typeParameter) { foreach (AST.TypeReference typeRef in template.Bases) { - typeParameter.Constraints.Add(CreateReturnType(typeRef)); + IReturnType rt = CreateReturnType(typeRef); + if (rt != null) { + typeParameter.Constraints.Add(rt); + } } return typeParameter; } diff --git a/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideContainer.cs b/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideContainer.cs index e7944f2c38..084a88a20b 100644 --- a/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideContainer.cs +++ b/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideContainer.cs @@ -16,10 +16,11 @@ namespace ICSharpCode.SharpDevelop.Gui { protected Control control; - protected bool autoHide = true; - protected bool showOnMouseMove = true; - protected bool showOnMouseDown = true; - protected int activatorHeight = 1; + bool autoHide = true; + bool showOverlay = false; + bool showOnMouseMove = true; + bool showOnMouseDown = true; + int activatorHeight = 1; protected bool mouseIn; @@ -29,16 +30,45 @@ namespace ICSharpCode.SharpDevelop.Gui } set { autoHide = value; - RefreshSize(); + Reformat(); } } - protected virtual void RefreshSize() + public bool ShowOverlay { + get { + return showOverlay; + } + set { + showOverlay = value; + Reformat(); + } + } + + protected virtual void Reformat() { if (autoHide) { - this.Height = activatorHeight; - this.Controls.Clear(); + if (showOverlay) { + // Show as overlay + this.Height = activatorHeight; + control.Dock = DockStyle.None; + control.Size = new Size(this.Width, control.PreferredSize.Height); + if (this.Dock != DockStyle.Bottom) { + control.Location = new Point(this.Left, this.Top); + } else { + control.Location = new Point(this.Left, this.Top - control.PreferredSize.Height + 1); + } + Parent.Controls.Add(control); + control.BringToFront(); + } else { + // Hidden + this.Height = activatorHeight; + control.Dock = DockStyle.None; + control.Size = new Size(this.Width, 1); + control.Location = new Point(0, activatorHeight); + this.Controls.Add(control); + } } else { + // Permanently shown this.Height = PreferredHeight; control.Dock = DockStyle.Fill; this.Controls.Add(control); @@ -51,6 +81,28 @@ namespace ICSharpCode.SharpDevelop.Gui } } + public AutoHideContainer(Control control) + { + if (control == null) throw new ArgumentNullException("control"); + this.control = control; + this.MouseMove += delegate { if (showOnMouseMove) ShowOverlay = true; }; + this.MouseDown += delegate { if (showOnMouseDown) ShowOverlay = true; }; + control.MouseEnter += OnControlMouseEnter; + control.MouseLeave += OnControlMouseLeave; + Reformat(); + } + + protected virtual void OnControlMouseEnter(object sender, EventArgs e) + { + mouseIn = true; + } + + protected virtual void OnControlMouseLeave(object sender, EventArgs e) + { + mouseIn = false; + ShowOverlay = false; + } + public bool ShowOnMouseMove { get { return showOnMouseMove; @@ -86,63 +138,5 @@ namespace ICSharpCode.SharpDevelop.Gui activatorHeight = value; } } - - public AutoHideContainer(Control control) - { - if (control == null) { - throw new ArgumentNullException("control"); - } - this.control = control; - RefreshSize(); - this.MouseMove += OnPanelMouseMove; - this.MouseDown += OnPanelMouseDown; - control.MouseEnter += OnControlMouseEnter; - control.MouseLeave += OnControlMouseLeave; - } - - protected virtual void OnPanelMouseMove(object sender, MouseEventArgs e) - { - if (showOnMouseMove && autoHide) { - ShowOverlay(); - } - } - - protected virtual void OnPanelMouseDown(object sender, MouseEventArgs e) - { - if (showOnMouseDown && autoHide) { - ShowOverlay(); - } - } - - protected virtual void OnControlMouseEnter(object sender, EventArgs e) - { - mouseIn = true; - } - - protected virtual void OnControlMouseLeave(object sender, EventArgs e) - { - mouseIn = false; - HideOverlay(); - } - - public virtual void ShowOverlay() - { - control.Dock = DockStyle.None; - control.Size = new Size(this.Width, control.PreferredSize.Height); - if (this.Dock != DockStyle.Bottom) { - control.Location = new Point(this.Left, this.Top); - } else { - control.Location = new Point(this.Left, this.Top - control.PreferredSize.Height + 1); - } - Parent.Controls.Add(control); - control.BringToFront(); - } - - public virtual void HideOverlay() - { - if (Parent.Controls.Contains(control)) { - Parent.Controls.Remove(control); - } - } } } diff --git a/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideMenuStripContainer.cs b/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideMenuStripContainer.cs index 84ad56cbdf..6b4d29bbdd 100644 --- a/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideMenuStripContainer.cs +++ b/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideMenuStripContainer.cs @@ -22,17 +22,13 @@ namespace ICSharpCode.SharpDevelop.Gui Padding? defaultPadding; - public override bool AutoHide { - get { - return base.AutoHide; - } - set { - if (defaultPadding == null) { - defaultPadding = ((MenuStrip)control).Padding; - } - ((MenuStrip)control).Padding = value?Padding.Empty:(Padding)defaultPadding; - base.AutoHide = value; + protected override void Reformat() + { + if (defaultPadding == null) { + defaultPadding = ((MenuStrip)control).Padding; } + ((MenuStrip)control).Padding = AutoHide ? Padding.Empty : (Padding)defaultPadding; + base.Reformat(); } public AutoHideMenuStripContainer(MenuStrip menuStrip):base(menuStrip) @@ -51,29 +47,14 @@ namespace ICSharpCode.SharpDevelop.Gui void AddEventHandlersForItem(ToolStripMenuItem menuItem) { - menuItem.DropDownOpened += OnDropDownOpened; - menuItem.DropDownClosed += OnDropDownClosed; - } - - void OnDropDownOpened(object sender, EventArgs e) - { - dropDownOpened = true; - } - - void OnDropDownClosed(object sender, EventArgs e) - { - dropDownOpened = false; - if (!mouseIn) { - HideOverlay(); - } + menuItem.DropDownOpened += delegate { dropDownOpened = true; }; + menuItem.DropDownClosed += delegate { dropDownOpened = false; if (!mouseIn) ShowOverlay = false; }; } protected override void OnControlMouseLeave(object sender, EventArgs e) { mouseIn = false; - if (!dropDownOpened) { - HideOverlay(); - } + if (!dropDownOpened) ShowOverlay = false; } } } diff --git a/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideStatusStripContainer.cs b/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideStatusStripContainer.cs index a95f9ab859..b27e73147c 100644 --- a/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideStatusStripContainer.cs +++ b/src/Main/Base/Project/Src/Gui/Components/AutoHide/AutoHideStatusStripContainer.cs @@ -22,12 +22,18 @@ namespace ICSharpCode.SharpDevelop.Gui { statusStrip.AutoSize = false; statusStrip.MouseMove += StatusStripMouseMove; + statusStrip.ItemAdded += delegate(object sender, ToolStripItemEventArgs e) { + e.Item.MouseMove += StatusStripMouseMove; + }; + foreach(ToolStripItem i in statusStrip.Items) { + i.MouseMove += StatusStripMouseMove; + } } void StatusStripMouseMove(object sender, MouseEventArgs e) { - if (e.Y < control.Height - 3) { - HideOverlay(); + if (e.Y < control.Height / 2) { + ShowOverlay = false; } } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs b/src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs index e585b1a6b0..4c9298b237 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/NewFileDialog.cs @@ -374,6 +374,7 @@ namespace ICSharpCode.SharpDevelop.Gui if (parsedFileName.StartsWith("/") || parsedFileName.StartsWith("\\")) parsedFileName = parsedFileName.Substring(1); if (newfile.IsDependentFile && Path.IsPathRooted(parsedFileName)) { + Directory.CreateDirectory(Path.GetDirectoryName(parsedFileName)); File.WriteAllText(parsedFileName, parsedContent, ParserService.DefaultFileEncoding); ParserService.ParseFile(parsedFileName, parsedContent); } else { @@ -438,7 +439,11 @@ namespace ICSharpCode.SharpDevelop.Gui string[] subdirs = relPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); StringBuilder standardNameSpace = new StringBuilder(project.RootNamespace); foreach(string subdir in subdirs) { - if (subdir == "." || subdir == ".." || subdir == "" || subdir.Equals("src", StringComparison.OrdinalIgnoreCase)) + if (subdir == "." || subdir == ".." || subdir.Length == 0) + continue; + if (subdir.Equals("src", StringComparison.OrdinalIgnoreCase)) + continue; + if (subdir.Equals("source", StringComparison.OrdinalIgnoreCase)) continue; standardNameSpace.Append('.'); standardNameSpace.Append(GenerateValidClassName(subdir)); diff --git a/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/ClassBrowser.cs b/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/ClassBrowser.cs index 3c719f56a7..e919f62bc8 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/ClassBrowser.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/ClassBrowser.cs @@ -99,21 +99,22 @@ namespace ICSharpCode.SharpDevelop.Gui.ClassBrowser toolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; contentPanel.Controls.Add(toolStrip); - ProjectService.SolutionLoaded += ProjectServiceSolutionLoaded; + ProjectService.SolutionLoaded += ProjectServiceSolutionChanged; + ProjectService.ProjectAdded += ProjectServiceSolutionChanged; // rebuild view when project is added to solution + ProjectService.SolutionFolderRemoved += ProjectServiceSolutionChanged; // rebuild view when project is removed from solution ProjectService.SolutionClosed += ProjectServiceSolutionClosed; ParserService.ParseInformationUpdated += new ParseInformationEventHandler(ParserServiceParseInformationUpdated); AmbienceService.AmbienceChanged += new EventHandler(AmbienceServiceAmbienceChanged); if (ProjectService.OpenSolution != null) { - ProjectServiceSolutionLoaded(null, null); + ProjectServiceSolutionChanged(null, null); } - Application.Idle += new EventHandler(UpdateThread); UpdateToolbars(); } List pending = new List (); - void UpdateThread(object sender, EventArgs ea) + void UpdateThread() { lock (pending) { foreach (ICompilationUnit[] units in pending) { @@ -135,6 +136,7 @@ namespace ICSharpCode.SharpDevelop.Gui.ClassBrowser lock (pending) { pending.Add(new ICompilationUnit[] { e.ParseInformation.BestCompilationUnit as ICompilationUnit, e.CompilationUnit}); } + WorkbenchSingleton.SafeThreadAsyncCall(new MethodInvoker(UpdateThread)); } #region Navigation @@ -276,7 +278,7 @@ namespace ICSharpCode.SharpDevelop.Gui.ClassBrowser } } - void ProjectServiceSolutionLoaded(object sender, SolutionEventArgs e) + void ProjectServiceSolutionChanged(object sender, EventArgs e) { classBrowserTreeView.Nodes.Clear(); foreach (IProject project in ProjectService.OpenSolution.Projects) { diff --git a/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/ProjectNode.cs b/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/ProjectNode.cs index b44c3eb6a8..b9330888a9 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/ProjectNode.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/ProjectNode.cs @@ -44,7 +44,7 @@ namespace ICSharpCode.SharpDevelop.Gui.ClassBrowser if (oldUnit != null) { foreach (IClass c in oldUnit.Classes) { - classDictionary[c.FullyQualifiedName] = c; + classDictionary[c.FullyQualifiedName] = c.GetCompoundClass(); wasUpdatedDictionary[c.FullyQualifiedName] = false; } } @@ -53,9 +53,9 @@ namespace ICSharpCode.SharpDevelop.Gui.ClassBrowser TreeNode path = GetNodeByPath(c.Namespace, true); ClassNode node = GetNodeByName(path.Nodes, c.Name) as ClassNode; if (node != null) { - node.Class = c; + node.Class = c.GetCompoundClass(); } else { - new ClassNode(Project, c).AddTo(path); + new ClassNode(Project, c.GetCompoundClass()).AddTo(path); } wasUpdatedDictionary[c.FullyQualifiedName] = true; } @@ -65,10 +65,16 @@ namespace ICSharpCode.SharpDevelop.Gui.ClassBrowser IClass c = classDictionary[entry.Key]; TreeNode path = GetNodeByPath(c.Namespace, true); - TreeNode node = GetNodeByName(path.Nodes, c.Name); + ClassNode node = GetNodeByName(path.Nodes, c.Name) as ClassNode; + if (node != null) { - path.Nodes.Remove(node); - RemoveEmptyNamespace(path); + CompoundClass cc = c as CompoundClass; + if (cc != null && cc.Parts.Count > 0) { + node.Class = cc; // update members after part has been removed + } else { + path.Nodes.Remove(node); + RemoveEmptyNamespace(path); + } } } } @@ -111,8 +117,11 @@ namespace ICSharpCode.SharpDevelop.Gui.ClassBrowser void InsertParseInformation(ICompilationUnit unit) { foreach (IClass c in unit.Classes) { - TreeNode node = GetNodeByPath(c.Namespace, true); - new ClassNode(Project, c).AddTo(node); + TreeNode path = GetNodeByPath(c.Namespace, true); + TreeNode node = GetNodeByName(path.Nodes, c.Name); + if (node == null) { + new ClassNode(Project, c.GetCompoundClass()).AddTo(path); + } } } diff --git a/src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/OutputTextLineParser.cs b/src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/OutputTextLineParser.cs index 2a4f202121..b9d1f5ffe7 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/OutputTextLineParser.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/CompilerMessageView/OutputTextLineParser.cs @@ -14,6 +14,12 @@ namespace ICSharpCode.SharpDevelop.Gui /// Parses output text in the Output Build pad window and extracts source code /// file references. /// + /// + /// Supported formats: + /// C#: "d:\somedir\somefile.ext(12,34)" + /// NUnit: "in d:\somedir\somefile.ext:line 12" (stacktrace format) + /// C++: "d:\somedir\somefile.ext(12)" (also VB and some NUnit failures) + /// public static class OutputTextLineParser { /// @@ -25,7 +31,7 @@ namespace ICSharpCode.SharpDevelop.Gui public static FileLineReference GetCSharpCompilerFileLineReference(string lineText) { if (lineText != null) { - Match match = Regex.Match(lineText, @"^.*?(\w+:[/\\].*?)\(([\d]*),([\d]*)\)"); + Match match = Regex.Match(lineText, @"\b(\w:[/\\].*?)\((\d+),(\d+)\)"); if (match.Success) { try { // Take off 1 for line/col since SharpDevelop is zero index based. @@ -33,7 +39,8 @@ namespace ICSharpCode.SharpDevelop.Gui int col = Convert.ToInt32(match.Groups[3].Value) - 1; return new FileLineReference(match.Groups[1].Value, line, col); - } catch (Exception) { + } catch (FormatException) { + } catch (OverflowException) { // Ignore. } } @@ -65,7 +72,7 @@ namespace ICSharpCode.SharpDevelop.Gui } /// - /// Extracts source code file reference from NUnit output. + /// Extracts source code file reference from NUnit output. (stacktrace format) /// /// The text line to parse. /// The text is multilined. @@ -75,20 +82,23 @@ namespace ICSharpCode.SharpDevelop.Gui { RegexOptions regexOptions = multiline ? RegexOptions.Multiline : RegexOptions.None; + FileLineReference result = null; + if (lineText != null) { - Match match = Regex.Match(lineText, @"^.*?\sin\s(.*?):line\s(\d*)?\r?$", regexOptions); - - if (match.Success) { + Match match = Regex.Match(lineText, @"\sin\s(.*?):line\s(\d+)?\r?$", regexOptions); + while (match.Success) { try { int line = Convert.ToInt32(match.Groups[2].Value) - 1; - return new FileLineReference(match.Groups[1].Value, line); - } catch (Exception) { + result = new FileLineReference(match.Groups[1].Value, line); + } catch (FormatException) { + } catch (OverflowException) { // Ignore. } + match = match.NextMatch(); } } - return null; + return result; } /// @@ -101,7 +111,7 @@ namespace ICSharpCode.SharpDevelop.Gui { if (lineText != null ) { - Match match = Regex.Match(lineText, @"^.*?(\w+:[/\\].*?)\(([\d]*)\) :"); + Match match = Regex.Match(lineText, @"\b(\w:[/\\].*?)\((\d+)\)"); if (match.Success) { try { @@ -109,7 +119,8 @@ namespace ICSharpCode.SharpDevelop.Gui int line = Convert.ToInt32(match.Groups[2].Value) - 1; return new FileLineReference(match.Groups[1].Value.Trim(), line); - } catch (Exception) { + } catch (FormatException) { + } catch (OverflowException) { // Ignore. } } diff --git a/src/Main/Base/Project/Src/Gui/Pads/FileScout.cs b/src/Main/Base/Project/Src/Gui/Pads/FileScout.cs index 7214140bfc..3db7737677 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/FileScout.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/FileScout.cs @@ -256,51 +256,61 @@ namespace ICSharpCode.SharpDevelop.Gui void fileDeleted(object sender, FileSystemEventArgs e) { - foreach(FileListItem fileItem in Items) - { - if(fileItem.FullName.Equals(e.FullPath, StringComparison.OrdinalIgnoreCase)) { - Items.Remove(fileItem); - break; + MethodInvoker method = delegate { + foreach(FileListItem fileItem in Items) + { + if(fileItem.FullName.Equals(e.FullPath, StringComparison.OrdinalIgnoreCase)) { + Items.Remove(fileItem); + break; + } } - } + }; + WorkbenchSingleton.SafeThreadAsyncCall(method); } void fileChanged(object sender, FileSystemEventArgs e) { - foreach(FileListItem fileItem in Items) - { - if(fileItem.FullName.Equals(e.FullPath, StringComparison.OrdinalIgnoreCase)) { - - FileInfo info = new FileInfo(e.FullPath); - - fileItem.SubItems[1].Text = Math.Round((double)info.Length / 1024).ToString() + " KB"; - fileItem.SubItems[2].Text = info.LastWriteTime.ToString(); - break; + MethodInvoker method = delegate { + foreach(FileListItem fileItem in Items) + { + if(fileItem.FullName.Equals(e.FullPath, StringComparison.OrdinalIgnoreCase)) { + + FileInfo info = new FileInfo(e.FullPath); + + fileItem.SubItems[1].Text = Math.Round((double)info.Length / 1024).ToString() + " KB"; + fileItem.SubItems[2].Text = info.LastWriteTime.ToString(); + break; + } } - } + }; + WorkbenchSingleton.SafeThreadAsyncCall(method); } void fileCreated(object sender, FileSystemEventArgs e) { - FileInfo info = new FileInfo(e.FullPath); - - ListViewItem fileItem = Items.Add(new FileListItem(e.FullPath)); - fileItem.SubItems.Add(Math.Round((double)info.Length / 1024).ToString() + " KB"); - fileItem.SubItems.Add(info.LastWriteTime.ToString()); - - Items.Add(fileItem); + MethodInvoker method = delegate { + FileInfo info = new FileInfo(e.FullPath); + + ListViewItem fileItem = Items.Add(new FileListItem(e.FullPath)); + fileItem.SubItems.Add(Math.Round((double)info.Length / 1024).ToString() + " KB"); + fileItem.SubItems.Add(info.LastWriteTime.ToString()); + }; + WorkbenchSingleton.SafeThreadAsyncCall(method); } void fileRenamed(object sender, RenamedEventArgs e) { - foreach(FileListItem fileItem in Items) - { - if(fileItem.FullName.Equals(e.OldFullPath, StringComparison.OrdinalIgnoreCase)) { - fileItem.FullName = e.FullPath; - fileItem.Text = e.Name; - break; + MethodInvoker method = delegate { + foreach(FileListItem fileItem in Items) + { + if(fileItem.FullName.Equals(e.OldFullPath, StringComparison.OrdinalIgnoreCase)) { + fileItem.FullName = e.FullPath; + fileItem.Text = e.Name; + break; + } } - } + }; + WorkbenchSingleton.SafeThreadAsyncCall(method); } void renameFile(object sender, EventArgs e) diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs index 8692097e03..cd4f4ef9bc 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/FolderNodeCommands.cs @@ -276,6 +276,9 @@ namespace ICSharpCode.SharpDevelop.Project.Commands bool additionalProperties = false; foreach (KeyValuePair createdFile in nfd.CreatedFiles) { FileProjectItem item = CreateNewFile(node, createdFile.Key); + if (!FileUtility.IsEqualFileName(node.Directory, Path.GetDirectoryName(createdFile.Key))) { + additionalProperties = true; + } if (createdFile.Value.PropertyCount > 0) { additionalProperties = true; item.Properties.Merge(createdFile.Value); diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/SolutionNodeCommands.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/SolutionNodeCommands.cs index 498deaffc3..7a19671a69 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/SolutionNodeCommands.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/SolutionNodeCommands.cs @@ -50,9 +50,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands IProject newProject = LanguageBindingService.LoadProject(fileName, Path.GetFileNameWithoutExtension(fileName)); if (newProject != null) { newProject.Location = FileUtility.GetRelativePath(solutionFolderNode.Solution.Directory, fileName); - ParserService.CreateProjectContentForAddedProject(newProject); - solutionFolderNode.Container.AddFolder(newProject); - solutionFolderNode.Solution.FixSolutionConfiguration(new IProject[] { newProject }); + ProjectService.AddProject(solutionFolderNode, newProject); NodeBuilders.AddProjectNode((TreeNode)solutionFolderNode, newProject).EnsureVisible(); solutionFolderNode.Solution.ApplySolutionConfigurationToProjects(); solutionFolderNode.Solution.ApplySolutionPlatformToProjects(); diff --git a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs index fbf40b329e..6dea583738 100644 --- a/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs +++ b/src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/ProjectBrowserControl.cs @@ -70,6 +70,31 @@ namespace ICSharpCode.SharpDevelop.Project ProjectService.ProjectItemAdded += ProjectServiceProjectItemAdded; ProjectService.SolutionFolderRemoved += ProjectServiceSolutionFolderRemoved; treeView.DrawNode += TreeViewDrawNode; + treeView.DragDrop += TreeViewDragDrop; + } + + void TreeViewDragDrop(object sender, DragEventArgs e) + { + Point clientcoordinate = PointToClient(new Point(e.X, e.Y)); + ExtTreeNode node = treeView.GetNodeAt(clientcoordinate) as ExtTreeNode; + if (node == null) { + // did not drag onto any node + if (e.Data.GetDataPresent(DataFormats.FileDrop)) { + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + foreach (string file in files) { + try { + IProjectLoader loader = ProjectService.GetProjectLoader(file); + if (loader != null) { + FileUtility.ObservedLoad(new NamedFileOperationDelegate(loader.Load), file); + } else { + FileService.OpenFile(file); + } + } catch (Exception ex) { + MessageService.ShowError(ex, "unable to open file " + file); + } + } + } + } } void TreeViewDrawNode(object sender, DrawTreeNodeEventArgs e) diff --git a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs index af520e1e91..fbcc51865b 100644 --- a/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs +++ b/src/Main/Base/Project/Src/Gui/Workbench/Layouts/SdiWorkspaceLayout.cs @@ -122,13 +122,23 @@ namespace ICSharpCode.SharpDevelop.Gui void TrackFullscreenPropertyChanges(object sender, PropertyChangedEventArgs e) { - if (e.OldValue != e.NewValue && wbForm.FullScreen) { + if (!Boolean.Equals(e.OldValue, e.NewValue) && wbForm.FullScreen) { switch (e.Key) { case "HideMainMenu": + case "ShowMainMenuOnMouseMove": + RedrawMainMenu(); + break; case "HideToolbars": + RedrawToolbars(); + break; + //case "HideTabs": + //case "HideVerticalScrollbar": + //case "HideHorizontalScrollbar": case "HideStatusBar": - RedrawAllComponents(); + case "ShowStatusBarOnMouseMove": + RedrawStatusBar(); break; + //case "HideWindowsTaskbar": } } } @@ -222,6 +232,7 @@ namespace ICSharpCode.SharpDevelop.Gui if (dockPanel != null) { LockWindowUpdate(wbForm.Handle); try { + IViewContent activeView = GetActiveView(); dockPanel.ActiveDocumentChanged -= new EventHandler(ActiveMdiChanged); DetachPadContents(true); @@ -231,6 +242,9 @@ namespace ICSharpCode.SharpDevelop.Gui LoadLayoutConfiguration(); ShowPads(); ShowViewContents(); + if (activeView != null && activeView.WorkbenchWindow != null) { + activeView.WorkbenchWindow.SelectWindow(); + } } finally { LockWindowUpdate(IntPtr.Zero); } @@ -560,6 +574,15 @@ namespace ICSharpCode.SharpDevelop.Gui OnActiveWorkbenchWindowChanged(e); } + static IViewContent GetActiveView() + { + IWorkbenchWindow activeWindow = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; + if (activeWindow != null) { + return activeWindow.ViewContent; + } + return null; + } + IWorkbenchWindow oldSelectedWindow = null; public virtual void OnActiveWorkbenchWindowChanged(EventArgs e) { diff --git a/src/Main/Base/Project/Src/Internal/Templates/File/FileDescriptionTemplate.cs b/src/Main/Base/Project/Src/Internal/Templates/File/FileDescriptionTemplate.cs index 899d6dfcf2..6145f2c11d 100644 --- a/src/Main/Base/Project/Src/Internal/Templates/File/FileDescriptionTemplate.cs +++ b/src/Main/Base/Project/Src/Internal/Templates/File/FileDescriptionTemplate.cs @@ -31,7 +31,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates } } - public FileDescriptionTemplate(XmlElement xml) + public FileDescriptionTemplate(XmlElement xml, string hintPath) { name = xml.GetAttribute("name"); language = xml.GetAttribute("language"); @@ -39,7 +39,17 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates copyToOutputDirectory = xml.GetAttribute("copyToOutputDirectory"); dependentUpon = xml.GetAttribute("dependentUpon"); subType = xml.GetAttribute("subType"); - content = xml.InnerText; + if (xml.HasAttribute("src")) { + string fileName = Path.Combine(hintPath, StringParser.Parse(xml.GetAttribute("src"))); + try { + content = File.ReadAllText(fileName); + } catch (Exception e) { + content = "Error reading content from " + fileName + ":\n" + e.ToString(); + LoggingService.Warn(content); + } + } else { + content = xml.InnerText; + } } /// diff --git a/src/Main/Base/Project/Src/Internal/Templates/File/FileTemplate.cs b/src/Main/Base/Project/Src/Internal/Templates/File/FileTemplate.cs index 934354ea9b..2d7a624433 100644 --- a/src/Main/Base/Project/Src/Internal/Templates/File/FileTemplate.cs +++ b/src/Main/Base/Project/Src/Internal/Templates/File/FileTemplate.cs @@ -311,7 +311,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates XmlNodeList nodes = files.ChildNodes; foreach (XmlNode filenode in nodes) { if (filenode is XmlElement) { - this.files.Add(new FileDescriptionTemplate((XmlElement)filenode)); + this.files.Add(new FileDescriptionTemplate((XmlElement)filenode, Path.GetDirectoryName(filename))); } } diff --git a/src/Main/Base/Project/Src/Internal/Templates/Project/CombineDescriptor.cs b/src/Main/Base/Project/Src/Internal/Templates/Project/CombineDescriptor.cs index 9af2f46313..f4903b2134 100644 --- a/src/Main/Base/Project/Src/Internal/Templates/Project/CombineDescriptor.cs +++ b/src/Main/Base/Project/Src/Internal/Templates/Project/CombineDescriptor.cs @@ -28,17 +28,17 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates internal List projectDescriptors = new List(); internal List solutionFoldersDescriptors = new List(); - internal void Read(XmlElement element) + internal void Read(XmlElement element, string hintPath) { name = element.GetAttribute("name"); foreach (XmlNode node in element.ChildNodes) { if (node != null) { switch (node.Name) { case "Project": - projectDescriptors.Add(ProjectDescriptor.CreateProjectDescriptor((XmlElement)node)); + projectDescriptors.Add(ProjectDescriptor.CreateProjectDescriptor((XmlElement)node, hintPath)); break; case "SolutionFolder": - solutionFoldersDescriptors.Add(new SolutionFolderDescriptor((XmlElement)node)); + solutionFoldersDescriptors.Add(new SolutionFolderDescriptor((XmlElement)node, hintPath)); break; } } @@ -64,9 +64,9 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates return true; } - public SolutionFolderDescriptor(XmlElement element) + public SolutionFolderDescriptor(XmlElement element, string hintPath) { - Read(element); + Read(element, hintPath); } public SolutionFolderDescriptor(string name) @@ -143,7 +143,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates return combineLocation; } - public static CombineDescriptor CreateCombineDescriptor(XmlElement element) + public static CombineDescriptor CreateCombineDescriptor(XmlElement element, string hintPath) { CombineDescriptor combineDescriptor = new CombineDescriptor(element.Attributes["name"].InnerText); @@ -155,7 +155,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates combineDescriptor.startupProject = element["Options"]["StartupProject"].InnerText; } - combineDescriptor.mainFolder.Read(element); + combineDescriptor.mainFolder.Read(element, hintPath); return combineDescriptor; } } diff --git a/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectCreateInformation.cs b/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectCreateInformation.cs index 7fb86d9f42..64c82fb95d 100644 --- a/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectCreateInformation.cs +++ b/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectCreateInformation.cs @@ -30,6 +30,18 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates public List CreatedProjects = new List(); + public ProjectCreateInformation() + { + SetDefaultCreateProjectOptions(); + } + + internal bool CreateProjectWithDefaultOutputPath; + + internal void SetDefaultCreateProjectOptions() + { + CreateProjectWithDefaultOutputPath = true; + } + public string OutputProjectFileName { get { return outputProjectFileName; diff --git a/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs b/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs index e4aedfccb8..11c10418b6 100644 --- a/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs +++ b/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectDescriptor.cs @@ -108,6 +108,12 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates string projectLocation = FileUtility.Combine(projectCreateInformation.ProjectBasePath, newProjectName + LanguageBindingService.GetProjectFileExtension(language)); projectCreateInformation.OutputProjectFileName = projectLocation; + projectCreateInformation.SetDefaultCreateProjectOptions(); + foreach (PropertyGroup pg in propertyGroups) { + if (pg.IsSet("OutputPath")) { + projectCreateInformation.CreateProjectWithDefaultOutputPath = false; + } + } IProject project = languageinfo.CreateProject(projectCreateInformation, projectOptions); StringBuilder standardNamespace = new StringBuilder(); @@ -215,7 +221,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates } } - public static ProjectDescriptor CreateProjectDescriptor(XmlElement element) + public static ProjectDescriptor CreateProjectDescriptor(XmlElement element, string hintPath) { ProjectDescriptor projectDescriptor = new ProjectDescriptor(element.Attributes["name"].InnerText, element.Attributes["directory"].InnerText); @@ -228,7 +234,7 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates foreach (XmlNode node in element["Files"].ChildNodes) { if (node != null && node.Name == "File") { XmlElement filenode = (XmlElement)node; - projectDescriptor.files.Add(new FileDescriptionTemplate(filenode)); + projectDescriptor.files.Add(new FileDescriptionTemplate(filenode, hintPath)); } } } diff --git a/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs b/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs index 0f420ed7ba..fe410d890d 100644 --- a/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs +++ b/src/Main/Base/Project/Src/Internal/Templates/Project/ProjectTemplate.cs @@ -199,13 +199,13 @@ namespace ICSharpCode.SharpDevelop.Internal.Templates } if (doc.DocumentElement["Solution"] != null) { - combineDescriptor = CombineDescriptor.CreateCombineDescriptor(doc.DocumentElement["Solution"]); + combineDescriptor = CombineDescriptor.CreateCombineDescriptor(doc.DocumentElement["Solution"], Path.GetDirectoryName(fileName)); } else if (doc.DocumentElement["Combine"] != null) { - combineDescriptor = CombineDescriptor.CreateCombineDescriptor(doc.DocumentElement["Combine"]); + combineDescriptor = CombineDescriptor.CreateCombineDescriptor(doc.DocumentElement["Combine"], Path.GetDirectoryName(fileName)); } if (doc.DocumentElement["Project"] != null) { - projectDescriptor = ProjectDescriptor.CreateProjectDescriptor(doc.DocumentElement["Project"]); + projectDescriptor = ProjectDescriptor.CreateProjectDescriptor(doc.DocumentElement["Project"], Path.GetDirectoryName(fileName)); } // Read Actions; diff --git a/src/Main/Base/Project/Src/Project/MSBuildProject.cs b/src/Main/Base/Project/Src/Project/MSBuildProject.cs index 77c0399122..42ccf20c81 100644 --- a/src/Main/Base/Project/Src/Project/MSBuildProject.cs +++ b/src/Main/Base/Project/Src/Project/MSBuildProject.cs @@ -46,7 +46,9 @@ namespace ICSharpCode.SharpDevelop.Project configurations["Debug|*"] = new PropertyGroup(); configurations["Debug|*"]["BaseIntermediateOutputPath"] = @"obj\"; configurations["Debug|*"]["IntermediateOutputPath"] = @"obj\Debug\"; - configurations["Debug|*"]["OutputPath"] = @"bin\Debug\"; + if (information.CreateProjectWithDefaultOutputPath) { + configurations["Debug|*"]["OutputPath"] = @"bin\Debug\"; + } configurations["Debug|*"]["Optimize"] = "False"; configurations["Debug|*"]["DefineConstants"] = "DEBUG" + BuildConstantSeparator + "TRACE"; configurations["Debug|*"]["DebugSymbols"] = "True"; @@ -55,7 +57,9 @@ namespace ICSharpCode.SharpDevelop.Project configurations["Release|*"] = new PropertyGroup(); configurations["Release|*"]["BaseIntermediateOutputPath"] = @"obj\"; configurations["Release|*"]["IntermediateOutputPath"] = @"obj\Release\"; - configurations["Release|*"]["OutputPath"] = @"bin\Release\"; + if (information.CreateProjectWithDefaultOutputPath) { + configurations["Release|*"]["OutputPath"] = @"bin\Release\"; + } configurations["Release|*"]["Optimize"] = "True"; configurations["Release|*"]["DefineConstants"] = "TRACE"; configurations["Release|*"]["DebugSymbols"] = "False"; diff --git a/src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs b/src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs index 7ad565d8fe..a008eee964 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/DebuggerGridControl.cs @@ -93,6 +93,15 @@ namespace ICSharpCode.Core frm.ClientSize = new Size(frm.ClientSize.Width, row.Height + 2); } + public bool IsMouseOver { + get { + if (frm != null && !frm.IsDisposed) { + return frm.ClientRectangle.Contains(frm.PointToClient(Control.MousePosition)); + } + return false; + } + } + void OnTextAreaClick(object sender, EventArgs e) { ((ICSharpCode.TextEditor.TextArea)sender).KeyDown -= OnTextAreaClick; diff --git a/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs b/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs index 00bd216562..20e4b33553 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs @@ -208,7 +208,7 @@ namespace ICSharpCode.Core } } - static void ToggleBreakpointAt(IDocument document, string fileName, int lineNumber) + public static void ToggleBreakpointAt(IDocument document, string fileName, int lineNumber) { foreach (Bookmark m in document.BookmarkManager.Marks) { BreakpointBookmark breakpoint = m as BreakpointBookmark; @@ -222,6 +222,8 @@ namespace ICSharpCode.Core foreach (char ch in document.GetText(document.GetLineSegment(lineNumber))) { if (!char.IsWhiteSpace(ch)) { document.BookmarkManager.AddMark(new BreakpointBookmark(fileName, document, lineNumber)); + document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, lineNumber)); + document.CommitUpdate(); break; } } @@ -240,6 +242,7 @@ namespace ICSharpCode.Core textArea.IconBarMargin.MouseDown += IconBarMouseDown; textArea.ToolTipRequest += TextAreaToolTipRequest; + textArea.MouseLeave += TextAreaMouseLeave; } } @@ -250,6 +253,7 @@ namespace ICSharpCode.Core textArea.IconBarMargin.MouseDown -= IconBarMouseDown; textArea.ToolTipRequest -= TextAreaToolTipRequest; + textArea.MouseLeave -= TextAreaMouseLeave; } } @@ -284,6 +288,7 @@ namespace ICSharpCode.Core /// static void TextAreaToolTipRequest(object sender, ToolTipRequestEventArgs e) { + DebuggerGridControl toolTipControl = null; try { TextArea textArea = (TextArea)sender; if (e.ToolTipShown) return; @@ -312,7 +317,6 @@ namespace ICSharpCode.Core ResolveResult result = ParserService.Resolve(expressionResult, logicPos.Y + 1, logicPos.X + 1, textArea.MotherTextEditorControl.FileName, textContent); bool debuggerCanShowValue; string toolTipText = GetText(result, expression, out debuggerCanShowValue); - DebuggerGridControl toolTipControl = null; if (toolTipText != null) { if (Control.ModifierKeys == Keys.Control) { toolTipText = "expr: " + expressionResult.ToString() + "\n" + toolTipText; @@ -324,10 +328,7 @@ namespace ICSharpCode.Core if (toolTipText != null) { e.ShowToolTip(toolTipText); } - if (oldToolTipControl != null) { - Form frm = oldToolTipControl.FindForm(); - if (frm != null) frm.Close(); - } + CloseOldToolTip(); if (toolTipControl != null) { toolTipControl.ShowForm(textArea, logicPos); } @@ -336,9 +337,33 @@ namespace ICSharpCode.Core } } catch (Exception ex) { ICSharpCode.Core.MessageService.ShowError(ex); + } finally { + if (toolTipControl == null && CanCloseOldToolTip) + CloseOldToolTip(); + } + } + + static bool CanCloseOldToolTip { + get { + return oldToolTipControl != null && oldToolTipControl.AllowClose; + } + } + + static void CloseOldToolTip() + { + if (oldToolTipControl != null) { + Form frm = oldToolTipControl.FindForm(); + if (frm != null) frm.Close(); + oldToolTipControl = null; } } + static void TextAreaMouseLeave(object source, EventArgs e) + { + if (CanCloseOldToolTip && !oldToolTipControl.IsMouseOver) + CloseOldToolTip(); + } + static string GetText(ResolveResult result, string expression, out bool debuggerCanShowValue) { debuggerCanShowValue = false; diff --git a/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs b/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs index 97c4d8ed6c..a21a3805b6 100644 --- a/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs +++ b/src/Main/Base/Project/Src/Services/ParserService/ParserService.cs @@ -184,7 +184,7 @@ namespace ICSharpCode.Core newContent.Initialize2(); } - public static IProjectContent CreateProjectContentForAddedProject(IProject project) + internal static IProjectContent CreateProjectContentForAddedProject(IProject project) { lock (projectContents) { ParseProjectContent newContent = project.CreateProjectContent(); diff --git a/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs b/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs index d1e6b567da..6104cf820e 100644 --- a/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs +++ b/src/Main/Base/Project/Src/Services/ProjectService/ProjectService.cs @@ -192,6 +192,14 @@ namespace ICSharpCode.SharpDevelop.Project CurrentProject = OpenSolution.FindProjectContainingFile(fileName) ?? CurrentProject; } + public static void AddProject(ISolutionFolderNode solutionFolderNode, IProject newProject) + { + solutionFolderNode.Container.AddFolder(newProject); + ParserService.CreateProjectContentForAddedProject(newProject); + solutionFolderNode.Solution.FixSolutionConfiguration(new IProject[] { newProject }); + OnProjectAdded(new ProjectEventArgs(newProject)); + } + /// /// Adds a project item to the project, raising the ProjectItemAdded event. /// Make sure you call project.Save() after adding new items! @@ -483,7 +491,14 @@ namespace ICSharpCode.SharpDevelop.Project ProjectItemRemoved(null, e); } } + static void OnProjectAdded(ProjectEventArgs e) + { + if (ProjectAdded != null) { + ProjectAdded(null, e); + } + } + public static event ProjectEventHandler ProjectAdded; public static event SolutionFolderEventHandler SolutionFolderRemoved; public static event EventHandler StartBuild; diff --git a/src/Main/Base/Project/Src/Services/ProjectService/SolutionFolderEventHandler.cs b/src/Main/Base/Project/Src/Services/ProjectService/SolutionFolderEventHandler.cs index 6a32bfd324..72ad672e20 100644 --- a/src/Main/Base/Project/Src/Services/ProjectService/SolutionFolderEventHandler.cs +++ b/src/Main/Base/Project/Src/Services/ProjectService/SolutionFolderEventHandler.cs @@ -11,7 +11,7 @@ namespace ICSharpCode.SharpDevelop.Project { public delegate void SolutionFolderEventHandler(object sender, SolutionFolderEventArgs e); - public class SolutionFolderEventArgs + public class SolutionFolderEventArgs : EventArgs { ISolutionFolder solutionFolder; diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs b/src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs index a91d8780e6..4711f8923a 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs @@ -143,7 +143,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring res.ProvidedDocumentInformation = GetDocumentInformation(r.FileName); results.Add(res); } - SearchReplaceInFilesManager.ShowSearchResults(pattern, results); + SearchInFilesManager.ShowSearchResults(pattern, results); } public static void RenameReferences(List list, string newName) diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringMenuBuilder.cs b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringMenuBuilder.cs index 47545386d9..534c64a989 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringMenuBuilder.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringMenuBuilder.cs @@ -70,7 +70,9 @@ namespace ICSharpCode.SharpDevelop.Refactoring // Include menu for member that has been clicked on ResolveResult rr = ResolveAtCaret(textEditorControl, textArea); item = null; - if (rr is MemberResolveResult) { + if (rr is MethodResolveResult) { + item = MakeItem(definitions, ((MethodResolveResult)rr).GetMethodIfSingleOverload()); + } else if (rr is MemberResolveResult) { item = MakeItem(definitions, ((MemberResolveResult)rr).ResolvedMember); } else if (rr is TypeResolveResult) { item = MakeItem(definitions, ((TypeResolveResult)rr).ResolvedClass); diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs index 36cbb14e50..a3ececceda 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs @@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring /// If true, gets only the classes that derive directly from . public static List FindDerivedClasses(IClass baseClass, IEnumerable projectContents, bool directDerivationOnly) { - baseClass = FixClass(baseClass); + baseClass = baseClass.GetCompoundClass(); string baseClassName = baseClass.Name; string baseClassFullName = baseClass.FullyQualifiedName; List list = new List(); @@ -109,7 +109,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring files = new List(); files.Add(FindItem(ownerClass.CompilationUnit.FileName)); } else { - ownerClass = FixClass(ownerClass); + ownerClass = ownerClass.GetCompoundClass(); files = GetPossibleFiles(ownerClass, member); } ParseableFileContentEnumerator enumerator = new ParseableFileContentEnumerator(files.ToArray()); @@ -236,14 +236,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring return new Point(column, line); } - /// - /// Gets the compound class if the class was partial. - /// - static IClass FixClass(IClass c) - { - return c.DefaultReturnType.GetUnderlyingClass(); - } - public static List GetFileNames(IClass c) { List list = new List(); diff --git a/src/Main/Base/Project/Src/TextEditor/Codons/AddInTreeSyntaxModeProvider.cs b/src/Main/Base/Project/Src/TextEditor/Codons/AddInTreeSyntaxModeProvider.cs index c33c944d33..8d2d084b57 100644 --- a/src/Main/Base/Project/Src/TextEditor/Codons/AddInTreeSyntaxModeProvider.cs +++ b/src/Main/Base/Project/Src/TextEditor/Codons/AddInTreeSyntaxModeProvider.cs @@ -8,7 +8,7 @@ using System; using System.Diagnostics; using System.Xml; -using System.Collections; +using System.Collections.Generic; using ICSharpCode.Core; using ICSharpCode.TextEditor.Document; namespace ICSharpCode.SharpDevelop.DefaultEditor.Codons @@ -20,9 +20,9 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Codons { const string syntaxModePath = "/SharpDevelop/ViewContent/DefaultTextEditor/SyntaxModes"; - ArrayList syntaxModes; + List syntaxModes; - public ArrayList SyntaxModes { + public ICollection SyntaxModes { get { return syntaxModes; } @@ -30,11 +30,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Codons public AddInTreeSyntaxModeProvider() { - try { - syntaxModes = AddInTree.GetTreeNode(syntaxModePath).BuildChildItems(this); - } catch (TreePathNotFoundException) { - syntaxModes = new ArrayList(); - } + syntaxModes = AddInTree.BuildItems(syntaxModePath, this, false); } public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode) diff --git a/src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs b/src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs index d0fbab4ccb..a892c11567 100644 --- a/src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs +++ b/src/Main/Base/Project/Src/TextEditor/Commands/ClassBookmarkMenuBuilder.cs @@ -147,7 +147,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands public static void RenameClass(IClass c, string newName) { - c = c.DefaultReturnType.GetUnderlyingClass(); // get compound class if class is partial + c = c.GetCompoundClass(); // get compound class if class is partial List list = RefactoringService.FindReferences(c, null); if (list == null) return; @@ -213,7 +213,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands res.ProvidedDocumentInformation = FindReferencesAndRenameHelper.GetDocumentInformation(derivedClass.CompilationUnit.FileName); results.Add(res); } - SearchReplaceInFilesManager.ShowSearchResults("Classes deriving from " + c.Name, results); + SearchInFilesManager.ShowSearchResults("Classes deriving from " + c.Name, results); } void FindReferences(object sender, EventArgs e) diff --git a/src/Main/Base/Project/Src/TextEditor/Commands/ClassMemberMenuBuilder.cs b/src/Main/Base/Project/Src/TextEditor/Commands/ClassMemberMenuBuilder.cs index 47c040c76b..e0977b4926 100644 --- a/src/Main/Base/Project/Src/TextEditor/Commands/ClassMemberMenuBuilder.cs +++ b/src/Main/Base/Project/Src/TextEditor/Commands/ClassMemberMenuBuilder.cs @@ -217,7 +217,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands results.Add(res); } } - SearchReplaceInFilesManager.ShowSearchResults("Overrides of " + member.Name, results); + SearchInFilesManager.ShowSearchResults("Overrides of " + member.Name, results); } void FindReferences(object sender, EventArgs e) diff --git a/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/CodeGenerator.cs b/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/CodeGenerator.cs index eb8c690152..5e25785d87 100644 --- a/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/CodeGenerator.cs +++ b/src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/CodeGenerator.cs @@ -27,7 +27,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands public void Initialize(IClass currentClass) { - this.currentClass = currentClass.DefaultReturnType.GetUnderlyingClass(); + this.currentClass = currentClass.GetCompoundClass(); this.codeGen = currentClass.ProjectContent.Language.CodeGenerator; this.classFinderContext = new ClassFinder(currentClass, currentClass.Region.BeginLine + 1, 0); this.InitContent(); diff --git a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs index 28187a5f57..56161ae14e 100644 --- a/src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs +++ b/src/Main/Base/Project/Src/TextEditor/Gui/Editor/QuickClassBrowserPanel.cs @@ -338,7 +338,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor bool partialMode = false; IClass currentPart = c; if (c.IsPartial) { - CompoundClass cc = c.DefaultReturnType.GetUnderlyingClass() as CompoundClass; + CompoundClass cc = c.GetCompoundClass() as CompoundClass; if (cc != null && cc.Parts.Count > 0) { partialMode = true; c = cc; diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs index 5511552e58..fa39e25058 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Commands/SearchMainMenuCommands.cs @@ -32,12 +32,10 @@ namespace SearchAndReplace public static void SetSearchPattern() { // Get Highlighted value and set it to FindDialog.searchPattern - IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; - - if (window != null && (window.ViewContent is ITextEditorControlProvider)) { - TextEditorControl textarea = ((ITextEditorControlProvider)window.ViewContent).TextEditorControl; - string selectedText = textarea.ActiveTextAreaControl.TextArea.SelectionManager.SelectedText; - if (selectedText != null && selectedText.Length > 0) { + TextEditorControl textArea = SearchReplaceUtilities.GetActiveTextEditor(); + if (textArea != null) { + string selectedText = textArea.ActiveTextAreaControl.TextArea.SelectionManager.SelectedText; + if (selectedText != null && selectedText.Length > 0 && !IsMultipleLines(selectedText)) { SearchOptions.CurrentFindPattern = selectedText; } } @@ -48,13 +46,23 @@ namespace SearchAndReplace SetSearchPattern(); SearchAndReplaceDialog.ShowSingleInstance(SearchAndReplaceMode.Search); } + + static bool IsMultipleLines(string text) + { + return text.IndexOf('\n') != -1; + } } public class FindNext : AbstractMenuCommand { public override void Run() { - SearchReplaceManager.FindNext(); + if (SearchOptions.CurrentFindPattern.Length > 0) { + SearchReplaceManager.FindNext(); + } else { + Find find = new Find(); + find.Run(); + } } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs index 7ad01b5a94..2505d82edb 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/Search.cs @@ -119,5 +119,37 @@ namespace SearchAndReplace } return null; } + + public SearchResult FindNext(int offset, int length) + { + if (info != null && textIterator != null && documentIterator.CurrentFileName != null) { + if (info.FileName != documentIterator.CurrentFileName) { // create new iterator, if document changed + info = documentIterator.Current; + textIterator = textIteratorBuilder.BuildTextIterator(info); + } else { // old document -> initialize iterator position to caret pos + textIterator.Position = info.CurrentOffset; + } + + SearchResult result = CreateNamedSearchResult(searchStrategy.FindNext(textIterator, offset, length)); + if (result != null) { + info.CurrentOffset = textIterator.Position; + return result; + } + } + + // not found or first start -> move forward to the next document + if (documentIterator.MoveForward()) { + info = documentIterator.Current; + // document is valid for searching -> set iterator & fileName + if (info != null && info.TextBuffer != null && info.EndOffset >= 0 && info.EndOffset < info.TextBuffer.Length) { + textIterator = textIteratorBuilder.BuildTextIterator(info); + } else { + textIterator = null; + } + + return FindNext(offset, length); + } + return null; + } } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs index 6fd4816d9e..7b77c0e71b 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceInFilesManager.cs @@ -20,7 +20,7 @@ using ICSharpCode.TextEditor.Document; namespace SearchAndReplace { - public static class SearchReplaceInFilesManager + public static class SearchInFilesManager { static Search find = new Search(); @@ -33,7 +33,7 @@ namespace SearchAndReplace } } - static SearchReplaceInFilesManager() + static SearchInFilesManager() { find.TextIteratorBuilder = new ForwardTextIteratorBuilder(); } @@ -63,7 +63,7 @@ namespace SearchAndReplace public static void ShowSearchResults(string pattern, List results) { - SearchAndReplace.SearchAllFinishedEventArgs e = + SearchAndReplace.SearchAllFinishedEventArgs e = new SearchAllFinishedEventArgs(pattern, results); OnSearchAllFinished(e); @@ -76,31 +76,24 @@ namespace SearchAndReplace } } - public static void ReplaceAll() + public static void FindAll() { if (!InitializeSearchInFiles()) { return; } List results = new List(); - while (true) { SearchResult result = find.FindNext(); if (result == null) { break; } - - find.Replace(result.Offset, - result.Length, - result.TransformReplacePattern(SearchOptions.ReplacePattern)); - results.Add(result); } - FinishSearchInFiles(results); } - public static void FindAll() + public static void FindAll(int offset, int length) { if (!InitializeSearchInFiles()) { return; @@ -108,7 +101,7 @@ namespace SearchAndReplace List results = new List(); while (true) { - SearchResult result = find.FindNext(); + SearchResult result = find.FindNext(offset, length); if (result == null) { break; } @@ -116,7 +109,7 @@ namespace SearchAndReplace } FinishSearchInFiles(results); } - + static void OnSearchAllFinished(SearchAllFinishedEventArgs e) { lastSearches.Insert(0, e); @@ -124,7 +117,7 @@ namespace SearchAndReplace SearchAllFinished(null, e); } } - + public static event SearchAllFinishedEventHandler SearchAllFinished; } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs index 9a084d4aab..9aa2a76a23 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceManager.cs @@ -63,6 +63,42 @@ namespace SearchAndReplace FindNext(); } + static TextSelection textSelection; + + public static void ReplaceFirstInSelection(int offset, int length) + { + SetSearchOptions(); + FindFirstInSelection(offset, length); + } + + public static bool ReplaceNextInSelection() + { + if (lastResult != null && WorkbenchSingleton.Workbench.ActiveWorkbenchWindow != null) { + ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent as ITextEditorControlProvider; + if (provider != null) { + TextEditorControl textarea = provider.TextEditorControl; + SelectionManager selectionManager = textarea.ActiveTextAreaControl.TextArea.SelectionManager; + + if (selectionManager.SelectionCollection.Count == 1 + && selectionManager.SelectionCollection[0].Offset == lastResult.Offset + && selectionManager.SelectionCollection[0].Length == lastResult.Length + && lastResult.FileName == textarea.FileName) + { + string replacePattern = lastResult.TransformReplacePattern(SearchOptions.ReplacePattern); + + textarea.BeginUpdate(); + selectionManager.ClearSelection(); + textarea.Document.Replace(lastResult.Offset, lastResult.Length, replacePattern); + textarea.ActiveTextAreaControl.Caret.Position = textarea.Document.OffsetToPosition(lastResult.Offset + replacePattern.Length); + textarea.EndUpdate(); + + textSelection.Length -= lastResult.Length - replacePattern.Length; + } + } + } + return FindNextInSelection(); + } + public static void MarkAll() { SetSearchOptions(); @@ -74,31 +110,81 @@ namespace SearchAndReplace find.Reset(); if (!find.SearchStrategy.CompilePattern()) return; - for (int count = 0;; count++) { + List textAreas = new List(); + int count; + for (count = 0;; count++) { SearchResult result = SearchReplaceManager.find.FindNext(); if (result == null) { - if (count == 0) { - ShowNotFoundMessage(); - } else { - MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.MarkAllDone}", "${res:Global.FinishedCaptionText}"); - } - find.Reset(); - return; + break; } else { - textArea = OpenTextArea(result.FileName); - if (textArea != null) { - textArea.ActiveTextAreaControl.Caret.Position = textArea.Document.OffsetToPosition(result.Offset); - int lineNr = textArea.Document.GetLineNumberForOffset(result.Offset); - - if (!textArea.Document.BookmarkManager.IsMarked(lineNr)) { - textArea.Document.BookmarkManager.ToggleMarkAt(lineNr); - } - } else { - count--; - } + MarkResult(textAreas, result); } } + find.Reset(); + foreach (TextEditorControl ctl in textAreas) { + ctl.Refresh(); + } + ShowMarkDoneMessage(count); + } + + public static void MarkAll(int offset, int length) + { + SetSearchOptions(); + find.Reset(); + + if (!find.SearchStrategy.CompilePattern()) + return; + + List textAreas = new List(); + int count; + for (count = 0;; count++) { + SearchResult result = find.FindNext(offset, length); + if (result == null) { + break; + } else { + MarkResult(textAreas, result); + } + } + find.Reset(); + foreach (TextEditorControl ctl in textAreas) { + ctl.Refresh(); + } + ShowMarkDoneMessage(count); + } + + static void MarkResult(List textAreas, SearchResult result) + { + TextEditorControl textArea = OpenTextArea(result.FileName); + if (textArea != null) { + if (!textAreas.Contains(textArea)) { + textAreas.Add(textArea); + } + textArea.ActiveTextAreaControl.Caret.Position = textArea.Document.OffsetToPosition(result.Offset); + int lineNr = textArea.Document.GetLineNumberForOffset(result.Offset); + + if (!textArea.Document.BookmarkManager.IsMarked(lineNr)) { + textArea.Document.BookmarkManager.ToggleMarkAt(lineNr); + } + } + } + + static void ShowMarkDoneMessage(int count) + { + if (count == 0) { + ShowNotFoundMessage(); + } else { + MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.MarkAllDone}", "${res:Global.FinishedCaptionText}"); + } + } + + static void ShowReplaceDoneMessage(int count) + { + if (count == 0) { + ShowNotFoundMessage(); + } else { + MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.ReplaceAllDone}", "${res:Global.FinishedCaptionText}"); + } } public static void ReplaceAll() @@ -119,15 +205,13 @@ namespace SearchAndReplace SearchResult result = SearchReplaceManager.find.FindNext(); if (result == null) { - if (count == 0) { - ShowNotFoundMessage(); - } else { + if (count != 0) { foreach (TextEditorControl textArea in textAreas) { textArea.EndUpdate(); textArea.Refresh(); } - MessageService.ShowMessage("${res:ICSharpCode.TextEditor.Document.SearchReplaceManager.ReplaceAllDone}", "${res:Global.FinishedCaptionText}"); } + ShowReplaceDoneMessage(count); find.Reset(); return; } else { @@ -151,6 +235,35 @@ namespace SearchAndReplace } } + public static void ReplaceAll(int offset, int length) + { + SetSearchOptions(); + find.Reset(); + + if (!find.SearchStrategy.CompilePattern()) + return; + + for (int count = 0;; count++) { + SearchResult result = find.FindNext(offset, length); + if (result == null) { + ShowReplaceDoneMessage(count); + return; + } + + string replacement = result.TransformReplacePattern(SearchOptions.ReplacePattern); + find.Replace(result.Offset, + result.Length, + replacement); + length -= result.Length - replacement.Length; + + // HACK - Move the cursor to the correct offset - the caret gets + // moved before the replace range if we replace a string with a + // single character. The ProvidedDocInfo.Replace method assumes that + // the current offset is at the end of the found text which it is not. + find.CurrentDocumentInformation.CurrentOffset = result.Offset + replacement.Length - 1; + } + } + static SearchResult lastResult = null; public static void FindNext() { @@ -185,15 +298,65 @@ namespace SearchAndReplace int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset)); int endPos = Math.Min(textArea.Document.TextLength, startPos + result.Length); - textArea.ActiveTextAreaControl.Caret.Position = textArea.Document.OffsetToPosition(endPos); - textArea.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection(); - textArea.ActiveTextAreaControl.TextArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, textArea.Document.OffsetToPosition(startPos), - textArea.Document.OffsetToPosition(endPos))); - textArea.Refresh(); + SearchReplaceUtilities.SelectText(textArea, startPos, endPos); + lastResult = result; + } + } + } + } + + static bool foundAtLeastOneItem = false; + + public static void FindFirstInSelection(int offset, int length) + { + foundAtLeastOneItem = false; + textSelection = null; + SetSearchOptions(); + + if (find == null || + SearchOptions.FindPattern == null || + SearchOptions.FindPattern.Length == 0) { + return; + } + + if (!find.SearchStrategy.CompilePattern()) { + find.Reset(); + lastResult = null; + return; + } + + textSelection = new TextSelection(offset, length); + FindNextInSelection(); + } + + public static bool FindNextInSelection() + { + TextEditorControl textArea = null; + while (textArea == null) { + SearchResult result = find.FindNext(textSelection.Offset, textSelection.Length); + if (result == null) { + if (!foundAtLeastOneItem) { + ShowNotFoundMessage(); + } + find.Reset(); + lastResult = null; + foundAtLeastOneItem = false; + return false; + } else { + textArea = OpenTextArea(result.FileName); + if (textArea != null) { + foundAtLeastOneItem = true; + if (lastResult != null && lastResult.FileName == result.FileName && + textArea.ActiveTextAreaControl.Caret.Offset != lastResult.Offset + lastResult.Length) { + } + int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset)); + int endPos = Math.Min(textArea.Document.TextLength, startPos + result.Length); + SearchReplaceUtilities.SelectText(textArea, startPos, endPos); lastResult = result; } } } + return true; } static void ShowNotFoundMessage() @@ -213,10 +376,10 @@ namespace SearchAndReplace } else { textEditorProvider = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ViewContent as ITextEditorControlProvider; } - + if (textEditorProvider != null) { return textEditorProvider.TextEditorControl; - } + } return null; } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceUtilities.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceUtilities.cs index 446f784d73..9225144ce2 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceUtilities.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchReplaceUtilities.cs @@ -26,6 +26,15 @@ namespace SearchAndReplace } } + public static TextEditorControl GetActiveTextEditor() + { + IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; + if (window != null && (window.ViewContent is ITextEditorControlProvider)) { + return ((ITextEditorControlProvider)window.ViewContent).TextEditorControl; + } + return null; + } + public static bool IsWholeWordAt(ITextBufferStrategy document, int offset, int length) { return (offset - 1 < 0 || Char.IsWhiteSpace(document.GetCharAt(offset - 1))) && @@ -95,5 +104,18 @@ namespace SearchAndReplace } return true; } + + public static void SelectText(TextEditorControl textArea, int offset, int endOffset) + { + int textLength = textArea.ActiveTextAreaControl.Document.TextLength; + if (textLength < endOffset) { + endOffset = textLength - 1; + } + textArea.ActiveTextAreaControl.Caret.Position = textArea.Document.OffsetToPosition(endOffset); + textArea.ActiveTextAreaControl.TextArea.SelectionManager.ClearSelection(); + textArea.ActiveTextAreaControl.TextArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, textArea.Document.OffsetToPosition(offset), + textArea.Document.OffsetToPosition(endOffset))); + textArea.Refresh(); + } } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs index e58f079faf..857156e65d 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/BruteForceSearchStrategy.cs @@ -58,6 +58,22 @@ namespace SearchAndReplace return -1; } + int InternalFindNext(ITextIterator textIterator, int offset, int length) + { + while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length)) { + if (SearchOptions.MatchCase ? MatchCaseSensitive(textIterator.TextBuffer, textIterator.Position, searchPattern) : MatchCaseInsensitive(textIterator.TextBuffer, textIterator.Position, searchPattern)) { + if (!SearchOptions.MatchWholeWord || IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, searchPattern.Length)) { + if (TextSelection.IsInsideRange(textIterator.Position + searchPattern.Length - 1, offset, length)) { + return textIterator.Position; + } else { + return -1; + } + } + } + } + return -1; + } + public bool CompilePattern() { searchPattern = SearchOptions.MatchCase ? SearchOptions.FindPattern : SearchOptions.FindPattern.ToUpper(); @@ -67,6 +83,17 @@ namespace SearchAndReplace public SearchResult FindNext(ITextIterator textIterator) { int offset = InternalFindNext(textIterator); + return GetSearchResult(offset); + } + + public SearchResult FindNext(ITextIterator textIterator, int offset, int length) + { + int foundOffset = InternalFindNext(textIterator, offset, length); + return GetSearchResult(foundOffset); + } + + SearchResult GetSearchResult(int offset) + { return offset >= 0 ? new SearchResult(offset, searchPattern.Length) : null; } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs index 1f84f7bf45..6f2d4e061c 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/ISearchStrategy.cs @@ -31,5 +31,10 @@ namespace SearchAndReplace /// compiled pattern in the text using the textIterator and options. /// SearchResult FindNext(ITextIterator textIterator); + + /// + /// Find only in the specified range. + /// + SearchResult FindNext(ITextIterator textIterator, int offset, int length); } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs index a6d09517b0..657787fce2 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/RegExSearchStrategy.cs @@ -53,6 +53,31 @@ namespace SearchAndReplace return null; } + public SearchResult FindNext(ITextIterator textIterator, int offset, int length) + { + string document = textIterator.TextBuffer.GetText(0, textIterator.TextBuffer.Length); + + while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length)) { + Match m = regex.Match(document, textIterator.Position); + if (m == null || m.Index <= 0 || m.Length <= 0) { + + } else { + int delta = m.Index - textIterator.Position; + if (delta <= 0 || textIterator.MoveAhead(delta)) { + if (TextSelection.IsInsideRange(m.Index + m.Length - 1, offset, length)) { + return new RegexSearchResult(m); + } else { + return null; + } + } else { + return null; + } + } + } + + return null; + } + private class RegexSearchResult : SearchResult { Match m; diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs index 5f606ff318..18d9e383d1 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/SearchStrategy/WildcardSearchStrategy.cs @@ -144,6 +144,22 @@ namespace SearchAndReplace return -1; } + int InternalFindNext(ITextIterator textIterator, int offset, int length) + { + while (textIterator.MoveAhead(1) && TextSelection.IsInsideRange(textIterator.Position, offset, length)) { + if (Match(textIterator.TextBuffer, textIterator.Position, !SearchOptions.MatchCase, 0)) { + if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, textIterator.Position, curMatchEndOffset - textIterator.Position)) { + if (TextSelection.IsInsideRange(curMatchEndOffset - 1, offset, length)) { + return textIterator.Position; + } else { + return -1; + } + } + } + } + return -1; + } + public bool CompilePattern() { CompilePattern(SearchOptions.FindPattern, !SearchOptions.MatchCase); @@ -153,6 +169,17 @@ namespace SearchAndReplace public SearchResult FindNext(ITextIterator textIterator) { int offset = InternalFindNext(textIterator); + return GetSearchResult(offset); + } + + public SearchResult FindNext(ITextIterator textIterator, int offset, int length) + { + int foundOffset = InternalFindNext(textIterator, offset, length); + return GetSearchResult(foundOffset); + } + + SearchResult GetSearchResult(int offset) + { return offset >= 0 ? new SearchResult(offset, curMatchEndOffset - offset) : null; } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/TextSelection.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/TextSelection.cs new file mode 100644 index 0000000000..9d570f389b --- /dev/null +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Engine/TextSelection.cs @@ -0,0 +1,49 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace SearchAndReplace +{ + public class TextSelection + { + int offset; + int length; + + public TextSelection(int offset, int length) + { + this.offset = offset; + this.length = length; + } + + public int Length { + get { + return length; + } + set { + length = value; + } + } + + public int Offset { + get { + return offset; + } + set { + offset = value; + } + } + + /// + /// Checks whether a position is in a specified range. + /// + public static bool IsInsideRange(int position, int offset, int length) + { + return position >= offset && position < offset + length; + } + } +} diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs index 374184669d..5d478636dc 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplaceDialog.cs @@ -11,6 +11,7 @@ using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.TextEditor.Document; namespace SearchAndReplace { @@ -21,8 +22,8 @@ namespace SearchAndReplace public class SearchAndReplaceDialog : Form { - public static string SearchPattern = ""; - public static string ReplacePattern = ""; + public static string SearchPattern = String.Empty; + public static string ReplacePattern = String.Empty; static SearchAndReplaceDialog Instance; @@ -45,7 +46,7 @@ namespace SearchAndReplace ToolStripButton replaceButton = new ToolStripButton(); SearchAndReplacePanel searchAndReplacePanel; - + public SearchAndReplaceDialog(SearchAndReplaceMode searchAndReplaceMode) { this.Owner = WorkbenchSingleton.MainForm; @@ -96,7 +97,6 @@ namespace SearchAndReplace } } - void SearchButtonClick(object sender, EventArgs e) { if (!searchButton.Checked) { @@ -126,6 +126,5 @@ namespace SearchAndReplace this.ClientSize = new Size(430, 385); } } - } } diff --git a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs index e5e4a411c8..8145a6f708 100644 --- a/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs +++ b/src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Gui/SearchAndReplacePanel.cs @@ -24,6 +24,10 @@ namespace SearchAndReplace public class SearchAndReplacePanel : BaseSharpDevelopUserControl { SearchAndReplaceMode searchAndReplaceMode; + ISelection selection; + TextEditorControl textEditor; + bool ignoreSelectionChanges; + bool findFirst; public SearchAndReplaceMode SearchAndReplaceMode { get { @@ -36,12 +40,13 @@ namespace SearchAndReplace switch (searchAndReplaceMode) { case SearchAndReplaceMode.Search: SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("Resources.FindPanel.xfrm")); - Get