From 8247fde3313f8aa7edd18021e074e2f5dc4e2f23 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Thu, 26 Jun 2014 20:09:32 +0200 Subject: [PATCH 001/146] Cleanup - FxCop --- .../src/Designer/ReportRootDesigner.cs | 4 ++-- .../src/Globals/StringWriterWithEncoding.cs | 2 +- .../src/TypeProvider/AbstractItemTypeProvider.cs | 16 +++++----------- .../src/TypeProvider/CircleItemTypeProvider.cs | 6 +++--- .../src/TypeProvider/DataItemTypeProvider.cs | 8 ++++---- .../src/TypeProvider/GroupedRowTypeProvider.cs | 15 ++++----------- .../src/TypeProvider/LineItemTypeProvider.cs | 11 ++++------- .../TypeProvider/RectangleItemTypeProvider.cs | 8 ++++---- .../src/TypeProvider/RowItemTypeProvider.cs | 14 ++++---------- .../src/TypeProvider/SectionItemTypeProvider.cs | 4 ++-- .../src/TypeProvider/TextItemTypeProvider.cs | 6 ++---- .../src/Views/DesignerView.cs | 2 +- .../src/XML/MycroWriter.cs | 3 ++- .../src/XML/ReportDefinitionParser.cs | 14 +++++++------- .../src/XML/ReportDesignerWriter.cs | 9 ++++----- .../Src/DataSource/ExtendedTypeDescriptor.cs | 2 +- .../ICSharpCode.Reporting/Src/Xml/MycroParser.cs | 7 ++++--- 17 files changed, 54 insertions(+), 77 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/ReportRootDesigner.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/ReportRootDesigner.cs index 21f779209a..d7da7e7886 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/ReportRootDesigner.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Designer/ReportRootDesigner.cs @@ -24,6 +24,7 @@ using System.ComponentModel.Design; using System.Drawing; using System.Drawing.Design; using System.Drawing.Printing; +using System.Globalization; using System.Windows.Forms; using System.Windows.Forms.Design; using ICSharpCode.Core; @@ -217,7 +218,6 @@ namespace ICSharpCode.Reporting.Addin.Designer if (section != null) { sections.Add(section); section.SizeChanged += new EventHandler( OnSectionSizeChanged); - Console.Write("reportRootDesigner:OnComponentAdded"); foreach (Control ctrl in section.Controls) { AddToHost(ctrl); host.Container.Add(ctrl); @@ -240,7 +240,7 @@ namespace ICSharpCode.Reporting.Addin.Designer private void OnComponentChanged(object sender, ComponentChangedEventArgs ce) { LoggingService.InfoFormatted("RootDesigner:OnComponentChanged"); - String str = String.Format("RootDesigner:OnComponentChanged <{0}> from <{1}> to <{2}>",ce.Component.ToString(),ce.OldValue,ce.NewValue); + var str = String.Format(CultureInfo.CurrentCulture,"RootDesigner:OnComponentChanged <{0}> from <{1}> to <{2}>",ce.Component.ToString(),ce.OldValue,ce.NewValue); LoggingService.InfoFormatted(str); var section = ce.Component as BaseSection; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/StringWriterWithEncoding.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/StringWriterWithEncoding.cs index ece8f2e807..7cbb7e2694 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/StringWriterWithEncoding.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/StringWriterWithEncoding.cs @@ -16,7 +16,7 @@ namespace ICSharpCode.Reporting.Addin.Globals /// class StringWriterWithEncoding:System.IO.StringWriter { - private readonly Encoding encoding; + readonly Encoding encoding; public StringWriterWithEncoding(Encoding encoding) { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/AbstractItemTypeProvider.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/AbstractItemTypeProvider.cs index 1a3175bfd2..fae180edad 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/AbstractItemTypeProvider.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/AbstractItemTypeProvider.cs @@ -22,26 +22,20 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider { } -// public AbstractItemTypeProvider(TypeDescriptionProvider parent): base(parent) -// { -// } - public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType, instance); - return new AbstractItemTypeDescriptor(td, instance); + return new AbstractItemTypeDescriptor(td); } } - internal class AbstractItemTypeDescriptor : CustomTypeDescriptor + class AbstractItemTypeDescriptor : CustomTypeDescriptor { -// private AbstractItem _instance; - public AbstractItemTypeDescriptor(ICustomTypeDescriptor parent, object instance) + public AbstractItemTypeDescriptor(ICustomTypeDescriptor parent) : base(parent) { -// _instance = instance as AbstractItem; } @@ -54,8 +48,8 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { - PropertyDescriptorCollection props = base.GetProperties(attributes); - List allProperties = new List(); + var props = base.GetProperties(attributes); + var allProperties = new List(); foreach (PropertyDescriptor p in props) { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/CircleItemTypeProvider.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/CircleItemTypeProvider.cs index bb84b9472c..9f86469b8d 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/CircleItemTypeProvider.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/CircleItemTypeProvider.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); - return new CircleItemTypeDescriptor(td, instance); + return new CircleItemTypeDescriptor(td); } } @@ -34,7 +34,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider class CircleItemTypeDescriptor : CustomTypeDescriptor { - public CircleItemTypeDescriptor(ICustomTypeDescriptor parent, object instance): base(parent) + public CircleItemTypeDescriptor(ICustomTypeDescriptor parent): base(parent) { } @@ -48,7 +48,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { PropertyDescriptorCollection props = base.GetProperties(attributes); - List allProperties = new List(); + var allProperties = new List(); TypeProviderHelper.AddDefaultProperties(allProperties,props); TypeProviderHelper.AddGraphicProperties(allProperties,props); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/DataItemTypeProvider.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/DataItemTypeProvider.cs index dbaabc703d..d92f052fd6 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/DataItemTypeProvider.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/DataItemTypeProvider.cs @@ -27,7 +27,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); - return new DataItemTypeDescriptor(td, instance); + return new DataItemTypeDescriptor(td); } } @@ -36,7 +36,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider class DataItemTypeDescriptor : CustomTypeDescriptor { - public DataItemTypeDescriptor(ICustomTypeDescriptor parent, object instance) + public DataItemTypeDescriptor(ICustomTypeDescriptor parent) : base(parent) { } @@ -50,8 +50,8 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { - PropertyDescriptorCollection props = base.GetProperties(attributes); - List allProperties = new List(); + var props = base.GetProperties(attributes); + var allProperties = new List(); TypeProviderHelper.AddDefaultProperties(allProperties,props); TypeProviderHelper.AddTextBasedProperties(allProperties,props); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/GroupedRowTypeProvider.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/GroupedRowTypeProvider.cs index d1e32d1ee2..b900e3e324 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/GroupedRowTypeProvider.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/GroupedRowTypeProvider.cs @@ -26,14 +26,14 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); - return new GroupedRowItemTypeDescriptor(td, instance); + return new GroupedRowItemTypeDescriptor(td); } } class GroupedRowItemTypeDescriptor : CustomTypeDescriptor { - public GroupedRowItemTypeDescriptor(ICustomTypeDescriptor parent, object instance) + public GroupedRowItemTypeDescriptor(ICustomTypeDescriptor parent) : base(parent) { } @@ -47,8 +47,8 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { - PropertyDescriptorCollection props = base.GetProperties(attributes); - List allProperties = new List(); + var props = base.GetProperties(attributes); + var allProperties = new List(); TypeProviderHelper.AddDefaultProperties(allProperties,props); @@ -69,16 +69,9 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider prop = props.Find("Controls",true); allProperties.Add(prop); -// prop = props.Find("AlternateBackColor",true); -// allProperties.Add(prop); -// -// prop = props.Find("ChangeBackColorEveryNRow",true); -// allProperties.Add(prop); - prop = props.Find("PageBreakOnGroupChange",true); allProperties.Add(prop); - return new PropertyDescriptorCollection(allProperties.ToArray()); } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/LineItemTypeProvider.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/LineItemTypeProvider.cs index 00929e7a2a..359e11def0 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/LineItemTypeProvider.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/LineItemTypeProvider.cs @@ -25,7 +25,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); - return new LineItemTypeDescriptor(td, instance); + return new LineItemTypeDescriptor(td); } } @@ -35,7 +35,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider { - public LineItemTypeDescriptor(ICustomTypeDescriptor parent, object instance) + public LineItemTypeDescriptor(ICustomTypeDescriptor parent) : base(parent) { @@ -50,8 +50,8 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { - PropertyDescriptorCollection props = base.GetProperties(attributes); - List allProperties = new List(); + var props = base.GetProperties(attributes); + var allProperties = new List(); TypeProviderHelper.AddDefaultProperties(allProperties,props); @@ -71,9 +71,6 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider prop = props.Find("EndLineCap",true); allProperties.Add(prop); -// prop = props.Find("DashLineCap",true); -// allProperties.Add(prop); - prop = props.Find("DashStyle",true); allProperties.Add(prop); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RectangleItemTypeProvider.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RectangleItemTypeProvider.cs index 34371541f2..45229f76c4 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RectangleItemTypeProvider.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RectangleItemTypeProvider.cs @@ -25,7 +25,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); - return new RectangleItemTypeDescriptor(td, instance); + return new RectangleItemTypeDescriptor(td); } } @@ -33,7 +33,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider class RectangleItemTypeDescriptor : CustomTypeDescriptor { - public RectangleItemTypeDescriptor(ICustomTypeDescriptor parent, object instance) + public RectangleItemTypeDescriptor(ICustomTypeDescriptor parent) : base(parent) { } @@ -47,8 +47,8 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { - PropertyDescriptorCollection props = base.GetProperties(attributes); - List allProperties = new List(); + var props = base.GetProperties(attributes); + var allProperties = new List(); TypeProviderHelper.AddDefaultProperties(allProperties,props); TypeProviderHelper.AddGraphicProperties(allProperties,props); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RowItemTypeProvider.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RowItemTypeProvider.cs index 1eeec71092..89245e2e48 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RowItemTypeProvider.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/RowItemTypeProvider.cs @@ -26,14 +26,14 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); - return new RowItemTypeDescriptor(td, instance); + return new RowItemTypeDescriptor(td); } } internal class RowItemTypeDescriptor : CustomTypeDescriptor { - public RowItemTypeDescriptor(ICustomTypeDescriptor parent, object instance) + public RowItemTypeDescriptor(ICustomTypeDescriptor parent) : base(parent) { } @@ -47,8 +47,8 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { - PropertyDescriptorCollection props = base.GetProperties(attributes); - List allProperties = new List(); + var props = base.GetProperties(attributes); + var allProperties = new List(); TypeProviderHelper.AddDefaultProperties(allProperties,props); @@ -69,12 +69,6 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider prop = props.Find("Controls",true); allProperties.Add(prop); -// prop = props.Find("AlternateBackColor",true); -// allProperties.Add(prop); -// -// prop = props.Find("ChangeBackColorEveryNRow",true); -// allProperties.Add(prop); - return new PropertyDescriptorCollection(allProperties.ToArray()); } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/SectionItemTypeProvider.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/SectionItemTypeProvider.cs index a3521a9622..6e96413e35 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/SectionItemTypeProvider.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/SectionItemTypeProvider.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); - return new SectionItemDescriptor(td, instance); + return new SectionItemDescriptor(td); } } @@ -35,7 +35,7 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider { - public SectionItemDescriptor(ICustomTypeDescriptor parent, object instance) + public SectionItemDescriptor(ICustomTypeDescriptor parent) : base(parent) { } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/TextItemTypeProvider.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/TextItemTypeProvider.cs index f00be1b76c..6bbab5ee08 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/TextItemTypeProvider.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/TypeProvider/TextItemTypeProvider.cs @@ -26,19 +26,17 @@ namespace ICSharpCode.Reporting.Addin.TypeProvider public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { ICustomTypeDescriptor td = base.GetTypeDescriptor(objectType,instance); - return new TextItemTypeDescriptor(td, instance); + return new TextItemTypeDescriptor(td); } } class TextItemTypeDescriptor : CustomTypeDescriptor { -// BaseTextItem instance; - public TextItemTypeDescriptor(ICustomTypeDescriptor parent, object instance) + public TextItemTypeDescriptor(ICustomTypeDescriptor parent) : base(parent) { -// instance = instance as BaseTextItem; } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Views/DesignerView.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Views/DesignerView.cs index 14704122d8..bfa4dad25d 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Views/DesignerView.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Views/DesignerView.cs @@ -212,7 +212,7 @@ namespace ICSharpCode.Reporting.Addin.Views abstractItem.Site.Name = abstractItem.Name; } } - UpdatePropertyPadSelection((ISelectionService)sender); + UpdatePropertyPadSelection(selectionService); } #endregion diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/MycroWriter.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/MycroWriter.cs index 5db3ffea39..e6935aa763 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/MycroWriter.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/MycroWriter.cs @@ -9,6 +9,7 @@ using System; using System.Collections; using System.ComponentModel; +using System.Globalization; using System.Reflection; using System.Xml; using System.Xml.Serialization; @@ -53,7 +54,7 @@ namespace ICSharpCode.Reporting.Addin.XML if (val is ICollection) { // PropertyInfo pinfo = t.GetProperty(info.Name); // Console.WriteLine("pinfo {0}",pinfo.Name); - if (info.Name.StartsWith("Contr")) { + if (info.Name.StartsWith("Contr",true,CultureInfo.CurrentCulture)) { writer.WriteStartElement("Items"); } else { writer.WriteStartElement(info.Name); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/ReportDefinitionParser.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/ReportDefinitionParser.cs index 209e6f5951..8042fc0041 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/ReportDefinitionParser.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/ReportDefinitionParser.cs @@ -20,6 +20,7 @@ using System; using System.Collections; using System.ComponentModel; using System.Diagnostics; +using System.Globalization; using System.Reflection; using System.Xml; using System.Xml.XPath; @@ -118,7 +119,7 @@ namespace ICSharpCode.Reporting.Addin.XML // Special case--we're going to assume that the child is a class instance // not associated with the parent object // Trace.Fail("Unsupported property: "+pname); - System.Console.WriteLine("Unsupported property: "+pname); + Console.WriteLine("Unsupported property: "+pname); continue; } @@ -134,8 +135,8 @@ namespace ICSharpCode.Reporting.Addin.XML { object propObject=pi.GetValue(parent, null); object obj=ProcessNode(grandChild, propObject); - System.Windows.Forms.Control parentControl = parent as System.Windows.Forms.Control; - System.Windows.Forms.Control childControl = obj as System.Windows.Forms.Control; + var parentControl = parent as System.Windows.Forms.Control; + var childControl = obj as System.Windows.Forms.Control; // we have the Items Section if ((parentControl != null) && (childControl != null)){ parentControl.Controls.Add(childControl); @@ -228,8 +229,7 @@ namespace ICSharpCode.Reporting.Addin.XML { if (tc.CanConvertFrom(typeof(string))) { - object val=tc.ConvertFromInvariantString(value); -// Console.WriteLine("\tRDP -> SetPropertyToString {0} - {1}",pi.Name,value.ToString()); + object val=tc.ConvertFromInvariantString(value); pi.SetValue(obj, val, null); } else if (pi.PropertyType == typeof(Type)) { pi.SetValue(obj, Type.GetType(value), null); @@ -237,9 +237,9 @@ namespace ICSharpCode.Reporting.Addin.XML } catch(Exception e) { - String s = String.Format("Property setter for {0} failed {1}\r\n",pi.Name, + var s = String.Format(CultureInfo.CurrentCulture,"Property setter for {0} failed {1}\r\n",pi.Name, e.Message); - System.Console.WriteLine("MycroParser : {0}",s); + Console.WriteLine("MycroParser : {0}",s); } } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/ReportDesignerWriter.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/ReportDesignerWriter.cs index ff91334c1e..6b592f9717 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/ReportDesignerWriter.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/XML/ReportDesignerWriter.cs @@ -7,6 +7,7 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using System.Globalization; namespace ICSharpCode.Reporting.Addin.XML { @@ -15,13 +16,11 @@ namespace ICSharpCode.Reporting.Addin.XML /// class ReportDesignerWriter:MycroWriter { - public ReportDesignerWriter() { - Console.WriteLine("ReportDesignerWriter"); - Console.WriteLine(); - } protected override string GetTypeName(Type t) { - if (t.BaseType != null && t.BaseType.Name.StartsWith("Base",StringComparison.InvariantCultureIgnoreCase)) { + if (t.BaseType != null && t.BaseType.Name.StartsWith("Base", StringComparison.OrdinalIgnoreCase)) { + + // return t.BaseType.Name; } return t.Name; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ExtendedTypeDescriptor.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ExtendedTypeDescriptor.cs index 0611f8ac7a..64fd1dc6d4 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ExtendedTypeDescriptor.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ExtendedTypeDescriptor.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.Reporting.DataSource /// class ExtendedTypeDescriptor { - static Hashtable collections = new Hashtable(); + static readonly Hashtable collections = new Hashtable(); static bool IsAllowedProperty(string name) { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Xml/MycroParser.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Xml/MycroParser.cs index 5a3e5946ee..6095b99535 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Xml/MycroParser.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Xml/MycroParser.cs @@ -21,6 +21,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Collections; using System.Collections.Generic; +using System.Globalization; using System.Xml; using System.Reflection; @@ -223,7 +224,7 @@ namespace ICSharpCode.Reporting.Xml static void SetPropertyToString(object obj, PropertyInfo pi, string value) { // it's string, so use a type converter. - TypeConverter tc=TypeDescriptor.GetConverter(pi.PropertyType); + var tc=TypeDescriptor.GetConverter(pi.PropertyType); try { if (tc.CanConvertFrom(typeof(string))) @@ -236,9 +237,9 @@ namespace ICSharpCode.Reporting.Xml } catch(Exception e) { - String s = String.Format("Property setter for {0} failed {1}\r\n",pi.Name, + var s = String.Format(CultureInfo.CurrentCulture,"Property setter for {0} failed {1}\r\n",pi.Name, e.Message); - System.Console.WriteLine("MycroParser : {0}",s); + Console.WriteLine("MycroParser : {0}",s); } } From 97677677c53503a4ad8d6f452bb20a7a45abf2ba Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Thu, 24 Jul 2014 20:39:12 +0200 Subject: [PATCH 002/146] Remove GlobalEnums.cs, start work on Wizard --- .../ICSharpCode.Reporting.Addin.csproj | 25 ++++++- .../src/DesignableItems/ReportSettings.cs | 8 +-- .../src/DesignerBinding/DesignerBinding.cs | 23 +++++-- .../ReportWizard/Dialog/BaseSettingsPage.xaml | 66 +++++++++++++++++++ .../Dialog/BaseSettingsPage.xaml.cs | 63 ++++++++++++++++++ .../src/ReportWizard/Dialog/IHasContext.cs | 22 +++++++ .../src/ReportWizard/Dialog/ReportWizard.xaml | 33 ++++++++++ .../ReportWizard/Dialog/ReportWizard.xaml.cs | 63 ++++++++++++++++++ .../src/ReportWizard/ReportGenerator.cs | 31 +++++++++ .../src/ReportWizard/ReportWizardCommand.cs | 48 ++++++++++++++ .../ReportWizard/ViewModels/PageOneContext.cs | 26 ++++++++ .../ViewModels/ReportWizardContext.cs | 39 +++++++++++ .../Src/Factories/ReportCreatorFactory.cs | 6 +- .../Src/Factories/ReportModelFactory.cs | 2 +- .../Src/Globals/GlobalEnums.cs | 53 +++++++++++---- .../Src/Items/ReportSettings.cs | 8 +-- .../Reportingfactory/GeneralReportLoading.cs | 2 +- 17 files changed, 485 insertions(+), 33 deletions(-) create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/IHasContext.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportWizardCommand.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/PageOneContext.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/ReportWizardContext.cs diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj index 19879aca23..a5181ece13 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj @@ -73,9 +73,13 @@ 3.0 + + ..\..\..\..\Libraries\WPFExtendedToolkit\Xceed.Wpf.Toolkit.dll + + @@ -84,8 +88,10 @@ + + - + @@ -140,6 +146,19 @@ + + + BaseSettingsPage.xaml + Code + + + ReportWizard.xaml + Code + + + + + @@ -210,5 +229,9 @@ EditorDialog.cs + + + + \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs index e50e4043e7..50861beb18 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs @@ -34,9 +34,9 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems // this.GraphicsUnit = GraphicsUnit.Pixel; // this.Padding = new Padding(5); // this.DefaultFont = GlobalValues.DefaultFont; - this.ReportType = GlobalEnums.ReportType.FormSheet; + this.ReportType = ReportType.FormSheet; // - this.DataModel = GlobalEnums.PushPullModel.FormSheet; + this.DataModel = PushPullModel.FormSheet; // // this.CommandType = System.Data.CommandType.Text; // this.ConnectionString = String.Empty; @@ -130,11 +130,11 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems public bool Landscape {get;set;} // [Category("Data")] - public GlobalEnums.PushPullModel DataModel {get;set;} + public PushPullModel DataModel {get;set;} // [Browsable(true), Category("Base Settings")] - public GlobalEnums.ReportType ReportType {get;set;} + public ReportType ReportType {get;set;} // [Category("Parameters")] diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs index caa01485ba..e7a716d31c 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs @@ -13,10 +13,10 @@ using System.Xml; using ICSharpCode.Core; using ICSharpCode.Reporting.Factories; using ICSharpCode.Reporting.Items; -using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Workbench; using ICSharpCode.Reporting.Addin.Commands; using ICSharpCode.Reporting.Addin.Factory; +using ICSharpCode.Reporting.Addin.ReportWizard; namespace ICSharpCode.Reporting.Addin.DesignerBinding { @@ -44,6 +44,21 @@ namespace ICSharpCode.Reporting.Addin.DesignerBinding { public IViewContent CreateContentForFile(OpenedFile file) { + if (file.IsDirty) { + var cmd = new ReportWizardCommand(file); + cmd.Run(); + if (cmd.Canceled) { + LoggingService.Info("reportWizard canceled"); + return null; + } + } + + var viewCmd = new CreateDesignerCommand(file); + viewCmd.Run(); + LoggingService.Info("return DesignerView"); + return viewCmd.DesignerView; + + /* if (file.IsDirty) { var reportModel = ReportModelFactory.Create(); @@ -55,10 +70,8 @@ namespace ICSharpCode.Reporting.Addin.DesignerBinding { file.SetData(ar); } - var viewCmd = new CreateDesignerCommand(file); - viewCmd.Run(); - LoggingService.Info("return DesignerView"); - return viewCmd.DesignerView; + + */ } static byte[] XmlToArray(XmlDocument doc) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml new file mode 100644 index 0000000000..bf2a81e6da --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs new file mode 100644 index 0000000000..126262eb96 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs @@ -0,0 +1,63 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 08.07.2014 + * Time: 20:26 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Windows; +using Xceed.Wpf.Toolkit; +using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; + +namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog{ + + /// + /// Interaction logic for PageOne.xamlWizardPage,IHasContext + /// + public partial class BaseSettingsPage : WizardPage,IHasContext + { + PageOneContext context; + + public BaseSettingsPage() + { + InitializeComponent(); + this.context = new PageOneContext(); + } + + + public IWizardContext Context { + get{ + UpdateContext(); + return context;} + } + + public int PageNumber { + get {return 1;} + } + + + void WizardPage_Enter(object sender, RoutedEventArgs e) + { + + Console.Write("Create Context for PageOne"); + } + + void WizardPage_Leave(object sender, RoutedEventArgs e) + { +// NewMethod(); + } + + void UpdateContext() + { +// context.FormSheet = this._FormSheet.IsChecked == true; +// context.PushModel = this._PushModel.IsChecked == true; + context.ReportName = this._ReportName.Text; + context.FileName = this._Filename.Text; + context.Legal = _Legal.IsChecked == true; + ; + context.Landscape = _Landscape.IsChecked == true; + } + } +} \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/IHasContext.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/IHasContext.cs new file mode 100644 index 0000000000..d2479d2600 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/IHasContext.cs @@ -0,0 +1,22 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 16.07.2014 + * Time: 20:41 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; + +namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog +{ + /// + /// Description of IHasContext. + /// + public interface IHasContext + { + IWizardContext Context {get;} + int PageNumber {get;} + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml new file mode 100644 index 0000000000..8e3d9916e0 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs new file mode 100644 index 0000000000..736ae0ee53 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs @@ -0,0 +1,63 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 07.07.2014 + * Time: 20:18 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Windows; +using Xceed.Wpf.Toolkit; +using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; +using System.Linq; + +namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog +{ + /// + /// Interaction logic for Window1.xaml + /// + public partial class ReportWizard : Window + { + ReportWizardContext context; + BaseSettingsPage baseSettingsPage; + + public ReportWizard(ReportWizardContext context) + { + InitializeComponent(); + this.context = context; + baseSettingsPage = new BaseSettingsPage(); + _wizard.Items.Insert(2,baseSettingsPage); + + } + + + void _wizard_Next(object sender, Xceed.Wpf.Toolkit.Core.CancelRoutedEventArgs e) + { + } + + + void _wizard_PageChanged(object sender, RoutedEventArgs e) + { + + } + + void _wizard_Finish(object sender, RoutedEventArgs e) + { + var x = _wizard.Items; + + foreach (var element in this._wizard.Items) { + var isHasContext = element is IHasContext; + if (isHasContext) { + + var hasContext = (IHasContext) element; + Console.WriteLine(" {0} - {1}",hasContext.PageNumber,element.ToString()); + } + } + + context.PageOneContext = baseSettingsPage.Context; + + } + + } +} \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs new file mode 100644 index 0000000000..8f99a5e582 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs @@ -0,0 +1,31 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 22.07.2014 + * Time: 19:37 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using ICSharpCode.Reporting.Interfaces; +using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; + +namespace ICSharpCode.Reporting.Addin.ReportWizard +{ + /// + /// Description of ReportGenerator. + /// + public class ReportGenerator + { + ReportWizardContext context; + + public ReportGenerator(ReportWizardContext context) + { + if (context == null) + throw new ArgumentNullException("context"); + this.context = context; + } + + + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportWizardCommand.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportWizardCommand.cs new file mode 100644 index 0000000000..ba524408af --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportWizardCommand.cs @@ -0,0 +1,48 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 08.07.2014 + * Time: 19:47 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using ICSharpCode.Core; +using ICSharpCode.Reporting.Interfaces; +using ICSharpCode.SharpDevelop.Workbench; +using ICSharpCode.Reporting.Addin.ReportWizard.Dialog; +using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; + +namespace ICSharpCode.Reporting.Addin.ReportWizard +{ + /// + /// Description of ReportWizardCommand. + /// + class ReportWizardCommand: AbstractMenuCommand + { + readonly OpenedFile file; + + public ReportWizardCommand (OpenedFile file) { + if (file == null) + throw new ArgumentNullException("file"); + this.file = file; + } + + public override void Run() + { + var wizardViewModel = new ReportWizardContext(); + var reportWizard = new ICSharpCode.Reporting.Addin.ReportWizard.Dialog.ReportWizard(wizardViewModel); + + reportWizard.ShowDialog(); + if (reportWizard.DialogResult.HasValue && reportWizard.DialogResult.Value){ + LoggingService.Info("ReportWizard - CreateReport"); + var rg = new ReportGenerator(wizardViewModel); + + } else { + Canceled = true; + } + } + + public bool Canceled {get; private set;} + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/PageOneContext.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/PageOneContext.cs new file mode 100644 index 0000000000..a012d040eb --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/PageOneContext.cs @@ -0,0 +1,26 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 07/12/2014 + * Time: 18:20 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using Xceed.Wpf.Toolkit; + +namespace ICSharpCode.Reporting.Addin.ReportWizard.ViewModels +{ + /// + /// Description of PageOneViewModel. + /// + public class PageOneContext:IWizardContext + { + public bool FormSheet {get;set;} + public bool PushModel {get;set;} + public string ReportName {get;set;} + public string FileName {get;set;} + public bool Legal {get;set;} + public bool Landscape {get;set;} + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/ReportWizardContext.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/ReportWizardContext.cs new file mode 100644 index 0000000000..074f032a60 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/ReportWizardContext.cs @@ -0,0 +1,39 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 07/12/2014 + * Time: 18:10 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; + +namespace ICSharpCode.Reporting.Addin.ReportWizard.ViewModels +{ + + public interface IWizardContext { + + } + /// + /// Description of ReportWizardViewModel. + /// + public class ReportWizardContext:IWizardContext + { + + + public string Title { + get{ return "das ist der Title";} + } + + IWizardContext pageOneContext; + + public IWizardContext PageOneContext { + get { + return pageOneContext; + } + set { + pageOneContext = value; + } + } + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/ReportCreatorFactory.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/ReportCreatorFactory.cs index 6ce850bbb8..7b87fe03d2 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/ReportCreatorFactory.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/ReportCreatorFactory.cs @@ -32,18 +32,18 @@ namespace ICSharpCode.Reporting.Factories { IReportCreator reportCreator = null; switch (reportModel.ReportSettings.DataModel) { - case GlobalEnums.PushPullModel.FormSheet: + case PushPullModel.FormSheet: { reportCreator = new FormPageBuilder(reportModel); break; } - case GlobalEnums.PushPullModel.PullData: + case PushPullModel.PullData: { break; } - case GlobalEnums.PushPullModel.PushData: + case PushPullModel.PushData: { break; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/ReportModelFactory.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/ReportModelFactory.cs index b6fa62ec5e..ded5abbdbc 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/ReportModelFactory.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/ReportModelFactory.cs @@ -22,7 +22,7 @@ namespace ICSharpCode.Reporting.Factories { var reportModel = new ReportModel(); - foreach (var section in Enum.GetValues(typeof(GlobalEnums.ReportSection))) { + foreach (var section in Enum.GetValues(typeof(ReportSection))) { reportModel.SectionCollection.Add (SectionFactory.Create(section.ToString())); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs index accba07f91..15be41d41e 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs @@ -23,12 +23,30 @@ namespace ICSharpCode.Reporting.Globals /// /// Description of GlobalEnums. /// - public sealed class GlobalEnums - { - private GlobalEnums() { - } - public enum ReportSection { + ///Technics to get the data + /// Push : report get's a ready filld dataset or something tah implements IList + /// Pull : report has to fill data by themself + /// FormSheet : FormSheet report, just labels and images are allowed + /// + /// + public enum PushPullModel { + PushData, + PullData, + FormSheet + } + + /// + /// FormSheet means a blank form with Labels, Lines and Checkboxes + /// DataReport handles all Reports with Data + /// + public enum ReportType { + FormSheet, + DataReport, + } + + +public enum ReportSection { ReportHeader, ReportPageHeader, ReportDetail, @@ -36,27 +54,34 @@ namespace ICSharpCode.Reporting.Globals ReportFooter } + public sealed class GlobalEnums + { + private GlobalEnums() { + } + + + ///Technics to get the data /// Push : report get's a ready filld dataset or something tah implements IList /// Pull : report has to fill data by themself /// FormSheet : FormSheet report, just labels and images are allowed /// /// - public enum PushPullModel { - PushData, - PullData, - FormSheet - } +// public enum PushPullModel { +// PushData, +// PullData, +// FormSheet +// } /// /// FormSheet means a blank form with Labels, Lines and Checkboxes /// DataReport handles all Reports with Data /// - public enum ReportType { - FormSheet, - DataReport, - } +// public enum ReportType { +// FormSheet, +// DataReport, +// } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs index 5193420945..ac960a1dd2 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs @@ -65,9 +65,9 @@ namespace ICSharpCode.Reporting.Items // this.GraphicsUnit = GraphicsUnit.Pixel; // this.Padding = new Padding(5); // this.DefaultFont = GlobalValues.DefaultFont; - ReportType = GlobalEnums.ReportType.FormSheet; + ReportType = ReportType.FormSheet; // - this.DataModel = GlobalEnums.PushPullModel.FormSheet; + this.DataModel = PushPullModel.FormSheet; // // this.CommandType = System.Data.CommandType.Text; // this.ConnectionString = String.Empty; @@ -125,11 +125,11 @@ namespace ICSharpCode.Reporting.Items [Browsable(true), Category("Base Settings")] - public GlobalEnums.ReportType ReportType {get;set;} + public ReportType ReportType {get;set;} [Browsable(true), Category("Base Settings")] - public GlobalEnums.PushPullModel DataModel {get;set;} + public PushPullModel DataModel {get;set;} #endregion diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/GeneralReportLoading.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/GeneralReportLoading.cs index b1c1d5d25c..f19e89df84 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/GeneralReportLoading.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/GeneralReportLoading.cs @@ -68,7 +68,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory { var rf = new ReportingFactory(); var model = rf.LoadReportModel(stream); - Assert.That(model.ReportSettings.DataModel,Is.EqualTo(GlobalEnums.PushPullModel.FormSheet)); + Assert.That(model.ReportSettings.DataModel,Is.EqualTo(PushPullModel.FormSheet)); } From 9f847f624fec3d0f6ebcb72defd67a77c57e55b7 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Tue, 29 Jul 2014 21:00:53 +0200 Subject: [PATCH 003/146] First, very basic implementation for FormSheet Wizard --- .../ICSharpCode.Reporting.Addin.csproj | 1 - .../src/DesignableItems/ReportSettings.cs | 45 ++++++----- .../src/DesignerBinding/DesignerBinding.cs | 13 +++- .../src/DesignerBinding/DesignerGenerator.cs | 7 +- .../ReportWizard/Dialog/BaseSettingsPage.xaml | 65 +++++++++------- .../Dialog/BaseSettingsPage.xaml.cs | 19 ++--- .../src/ReportWizard/Dialog/ReportWizard.xaml | 7 +- .../ReportWizard/Dialog/ReportWizard.xaml.cs | 18 +---- .../src/ReportWizard/ReportGenerator.cs | 45 +++++++++++ .../src/ReportWizard/ReportWizardCommand.cs | 4 + .../ReportWizard/ViewModels/PageOneContext.cs | 5 +- .../Src/Globals/GlobalEnums.cs | 76 +++++-------------- .../Src/Items/BaseSection.cs | 2 +- .../Src/Items/BaseTextItem.cs | 1 + .../Src/Items/PrintableItem.cs | 1 + 15 files changed, 162 insertions(+), 147 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj index a5181ece13..c1cdc982e4 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj @@ -79,7 +79,6 @@ - diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs index 50861beb18..43a4f72fdf 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs @@ -42,10 +42,10 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems // this.ConnectionString = String.Empty; // this.CommandText = String.Empty; // -// this.TopMargin = GlobalValues.DefaultPageMargin.Left; -// this.BottomMargin = GlobalValues.DefaultPageMargin.Bottom; -// this.LeftMargin = GlobalValues.DefaultPageMargin.Left; -// this.RightMargin = GlobalValues.DefaultPageMargin.Right; + this.TopMargin = GlobalValues.DefaultPageMargin.Left; + this.BottomMargin = GlobalValues.DefaultPageMargin.Bottom; + this.LeftMargin = GlobalValues.DefaultPageMargin.Left; + this.RightMargin = GlobalValues.DefaultPageMargin.Right; // // this.availableFields = new AvailableFieldsCollection(); // this.groupingsCollection = new GroupColumnCollection(); @@ -57,10 +57,9 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems } - private string reportName; + string reportName; -// [Category("Base Settings")] -// [DefaultValueAttribute ("")] + [Category("Base Settings")] public string ReportName { get { @@ -76,8 +75,9 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems } } - private string fileName; -// [Category("Base Settings")] + + string fileName; + [Category("Base Settings")] // [XmlIgnoreAttribute] public string FileName { @@ -93,25 +93,28 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems } -// [Category("Page Settings")] + [Browsable(true), Category("Base Settings")] + public ReportType ReportType {get;set;} + + + [Category("Page Settings")] public int BottomMargin {get;set;} -// [Category("Page Settings")] + [Category("Page Settings")] public int TopMargin {get;set;} - -// [Category("Page Settings")] + [Category("Page Settings")] public int LeftMargin {get;set;} - -// [Category("Page Settings")] + [Category("Page Settings")] public int RightMargin {get;set;} - private Size pageSize; + Size pageSize; + [Category("Page Settings")] public Size PageSize { get { if (!Landscape) { @@ -123,19 +126,15 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems set { pageSize = value; } } -// [Category("Page Settings")] -// public Size PageSize {get;set;} + -// [Category("Page Settings")] + [Category("Page Settings")] public bool Landscape {get;set;} -// [Category("Data")] + [Category("Data")] public PushPullModel DataModel {get;set;} -// [Browsable(true), Category("Base Settings")] - public ReportType ReportType {get;set;} - // [Category("Parameters")] // [EditorAttribute ( typeof(ParameterCollectionEditor), diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs index e7a716d31c..93df61f344 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs @@ -47,8 +47,17 @@ namespace ICSharpCode.Reporting.Addin.DesignerBinding { if (file.IsDirty) { var cmd = new ReportWizardCommand(file); cmd.Run(); - if (cmd.Canceled) { + if (!cmd.Canceled) { LoggingService.Info("reportWizard canceled"); + //return null; + var reportModel = cmd.ReportModel; + + var xml = CreateFormSheetFromModel.ToXml(reportModel); + var doc = new XmlDocument(); + doc.LoadXml(xml.ToString()); + var ar = XmlToArray(doc); + file.SetData(ar); + } else { return null; } } @@ -71,7 +80,7 @@ namespace ICSharpCode.Reporting.Addin.DesignerBinding { } - */ + */ } static byte[] XmlToArray(XmlDocument doc) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerGenerator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerGenerator.cs index ea4dcfa3d4..6cde4855fa 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerGenerator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerGenerator.cs @@ -78,9 +78,10 @@ namespace ICSharpCode.Reporting.Addin.DesignerBinding // we look only for Sections foreach (var component in viewContent.Host.Container.Components) { - var b = component as BaseSection; - if (b != null) { - reportDesignerWriter.Save(component,xml); + var section = component as BaseSection; + if (section != null) { +// reportDesignerWriter.Save(component,xml); + reportDesignerWriter.Save(section,xml); } } //SectionCollection diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml index bf2a81e6da..3fd65a42db 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml @@ -2,27 +2,31 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" - xmlns:System="clr-namespace:System;assembly=mscorlib" -xmlns:aa="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Reporting" - xmlns:ics="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Reporting" + xmlns:System="clr-namespace:System;assembly=mscorlib" + xmlns:sdr="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Reporting" + Title="Base Settings" Description="Basic Settings and Layout" - Background="LightGray"> + Background="LightGray" + CanFinish="true"> - - - - - - - - + + + + + + + + + + + - - + + @@ -30,10 +34,10 @@ xmlns:aa="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Repor - - - - + + + + @@ -43,14 +47,17 @@ xmlns:aa="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Repor - - - + + + - - + + + @@ -59,8 +66,8 @@ xmlns:aa="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Repor - - + + \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs index 126262eb96..191c6cb858 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs @@ -8,6 +8,7 @@ */ using System; using System.Windows; +using ICSharpCode.Reporting.Globals; using Xceed.Wpf.Toolkit; using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; @@ -23,6 +24,8 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog{ public BaseSettingsPage() { InitializeComponent(); + _DataModel.SelectedItem = PushPullModel.FormSheet; + _ReportType.SelectedItem = ReportType.FormSheet; this.context = new PageOneContext(); } @@ -38,21 +41,11 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog{ } - void WizardPage_Enter(object sender, RoutedEventArgs e) - { - - Console.Write("Create Context for PageOne"); - } - - void WizardPage_Leave(object sender, RoutedEventArgs e) - { -// NewMethod(); - } - void UpdateContext() { -// context.FormSheet = this._FormSheet.IsChecked == true; -// context.PushModel = this._PushModel.IsChecked == true; + + context.DataModel = (PushPullModel) _DataModel.SelectedItem; + context.ReportType = (ReportType) _ReportType.SelectedItem; context.ReportName = this._ReportName.Text; context.FileName = this._Filename.Text; context.Legal = _Legal.IsChecked == true; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml index 8e3d9916e0..59ba6244b3 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml @@ -20,14 +20,15 @@ - + \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs index 736ae0ee53..cc0460698d 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs @@ -19,16 +19,15 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog /// public partial class ReportWizard : Window { - ReportWizardContext context; - BaseSettingsPage baseSettingsPage; + readonly ReportWizardContext context; + readonly BaseSettingsPage baseSettingsPage; public ReportWizard(ReportWizardContext context) { InitializeComponent(); this.context = context; baseSettingsPage = new BaseSettingsPage(); - _wizard.Items.Insert(2,baseSettingsPage); - + _wizard.Items.Insert(1,baseSettingsPage); } @@ -44,17 +43,6 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog void _wizard_Finish(object sender, RoutedEventArgs e) { - var x = _wizard.Items; - - foreach (var element in this._wizard.Items) { - var isHasContext = element is IHasContext; - if (isHasContext) { - - var hasContext = (IHasContext) element; - Console.WriteLine(" {0} - {1}",hasContext.PageNumber,element.ToString()); - } - } - context.PageOneContext = baseSettingsPage.Context; } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs index 8f99a5e582..807be02f9b 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs @@ -7,7 +7,13 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using System.Drawing; +using ICSharpCode.Reporting.Factories; +using ICSharpCode.Reporting.Globals; using ICSharpCode.Reporting.Interfaces; + + +using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; namespace ICSharpCode.Reporting.Addin.ReportWizard @@ -18,14 +24,53 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard public class ReportGenerator { ReportWizardContext context; + public ReportGenerator(ReportWizardContext context) { if (context == null) throw new ArgumentNullException("context"); this.context = context; + ReportModel = ReportModelFactory.Create(); + } + + + public void Generate() { + PageOneGenerate(); + CreateReportHeader(); + } + + void PageOneGenerate() + { + var pageOne = (PageOneContext)context.PageOneContext; + var reportSettings = ReportModel.ReportSettings; + reportSettings.DataModel = pageOne.DataModel; + reportSettings.FileName = pageOne.FileName; + if (pageOne.Legal) { + reportSettings.Landscape = false; + } else { + reportSettings.Landscape = true; + } + reportSettings.ReportName = pageOne.ReportName; + reportSettings.ReportType = pageOne.ReportType; + } + + + void CreateReportHeader() + { + var headerText = new BaseTextItem(); + headerText.Text = "Header"; + headerText.Size = GlobalValues.PreferedSize; + var printableWith = ReportModel.ReportSettings.PageSize.Width - ReportModel.ReportSettings.LeftMargin - ReportModel.ReportSettings.RightMargin; + var x = (int)(printableWith - headerText.Size.Width) / 2; + + headerText.Location = new Point(x,4); + ReportModel.ReportHeader.Items.Add(headerText); + Console.WriteLine(""); + Console.WriteLine("Createreportheader Size {0}",ReportModel.ReportHeader.Size); } + public IReportModel ReportModel {get;private set;} } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportWizardCommand.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportWizardCommand.cs index ba524408af..387ca1acb5 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportWizardCommand.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportWizardCommand.cs @@ -38,11 +38,15 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard LoggingService.Info("ReportWizard - CreateReport"); var rg = new ReportGenerator(wizardViewModel); + rg.Generate(); + ReportModel = rg.ReportModel; } else { Canceled = true; } } public bool Canceled {get; private set;} + + public IReportModel ReportModel {get;private set;} } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/PageOneContext.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/PageOneContext.cs index a012d040eb..c6fc2d92df 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/PageOneContext.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/PageOneContext.cs @@ -7,6 +7,7 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using ICSharpCode.Reporting.Globals; using Xceed.Wpf.Toolkit; namespace ICSharpCode.Reporting.Addin.ReportWizard.ViewModels @@ -16,8 +17,8 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.ViewModels /// public class PageOneContext:IWizardContext { - public bool FormSheet {get;set;} - public bool PushModel {get;set;} + public PushPullModel DataModel {get;set;} + public ReportType ReportType {get;set;} public string ReportName {get;set;} public string FileName {get;set;} public bool Legal {get;set;} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs index 15be41d41e..e3c34f027e 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs @@ -20,69 +20,35 @@ using System; namespace ICSharpCode.Reporting.Globals { - /// - /// Description of GlobalEnums. - /// ///Technics to get the data - /// Push : report get's a ready filld dataset or something tah implements IList - /// Pull : report has to fill data by themself - /// FormSheet : FormSheet report, just labels and images are allowed - /// - /// + /// Push : report get's a ready filld dataset or something tah implements IList + /// Pull : report has to fill data by themself + /// FormSheet : FormSheet report, just labels and images are allowed + /// + public enum PushPullModel { - PushData, - PullData, - FormSheet + PushData, + PullData, + FormSheet } - + /// - /// FormSheet means a blank form with Labels, Lines and Checkboxes - /// DataReport handles all Reports with Data - /// + /// FormSheet means a blank form with Labels, Lines and Checkboxes + /// DataReport handles all Reports with Data + /// public enum ReportType { - FormSheet, - DataReport, + FormSheet, + DataReport, } -public enum ReportSection { - ReportHeader, - ReportPageHeader, - ReportDetail, - ReportPageFooter, - ReportFooter - } - - public sealed class GlobalEnums - { - private GlobalEnums() { - } - - - - ///Technics to get the data - /// Push : report get's a ready filld dataset or something tah implements IList - /// Pull : report has to fill data by themself - /// FormSheet : FormSheet report, just labels and images are allowed - /// - /// -// public enum PushPullModel { -// PushData, -// PullData, -// FormSheet -// } - - - /// - /// FormSheet means a blank form with Labels, Lines and Checkboxes - /// DataReport handles all Reports with Data - /// -// public enum ReportType { -// FormSheet, -// DataReport, -// } - - + public enum ReportSection { + ReportHeader, + ReportPageHeader, + ReportDetail, + ReportPageFooter, + ReportFooter } + } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseSection.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseSection.cs index a57b3614cd..2bfa2a8455 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseSection.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseSection.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.Reporting.Items /// Description of BaseSection. /// - public class BaseSection:ReportContainer,IReportContainer + public class BaseSection:ReportContainer { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseTextItem.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseTextItem.cs index 242c524eed..571d00b4a0 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseTextItem.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseTextItem.cs @@ -45,6 +45,7 @@ namespace ICSharpCode.Reporting.Items public BaseTextItem(){ Name = "BaseTextItem"; Font = GlobalValues.DefaultFont; + } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/PrintableItem.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/PrintableItem.cs index ec72ea1005..4be5b87cf5 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/PrintableItem.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/PrintableItem.cs @@ -18,6 +18,7 @@ using System; using System.Drawing; +using ICSharpCode.Reporting.Globals; using ICSharpCode.Reporting.Interfaces; using ICSharpCode.Reporting.Interfaces.Export; From a8a3391f2575f7d1da63b009408555fb3645342a Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 29 Jul 2014 21:53:49 +0200 Subject: [PATCH 004/146] fix problem with captured/local variables in a generic context while debugging --- src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs | 4 +++- src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs b/src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs index fec6bd7158..75b0441eef 100644 --- a/src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs +++ b/src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs @@ -232,7 +232,9 @@ namespace Debugger { var info = GetInfo(method.ParentAssembly); var variableTypes = info.GetLocalVariableTypes(method.UnresolvedMember); - return variableTypes[index].Resolve(new SimpleTypeResolveContext(method)); + return variableTypes[index] + .Resolve(new SimpleTypeResolveContext(method)) + .AcceptVisitor(method.Substitution); } #endregion diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs index 218178354b..24a89a5cb8 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpySymbolSource.cs @@ -106,7 +106,7 @@ namespace ICSharpCode.ILSpyAddIn return symbols.LocalVariables.Where(v => v.OriginalVariable != null).Select( v => new Debugger.ILLocalVariable() { Index = v.OriginalVariable.Index, - Type = loader.ReadTypeReference(v.Type).Resolve(context), + Type = loader.ReadTypeReference(v.Type).Resolve(context).AcceptVisitor(method.Substitution), Name = v.Name, IsCompilerGenerated = false, ILRanges = new [] { new ILRange(0, int.MaxValue) } From 8063942775eedd7242edc7f771052ff6f03558df Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 30 Jul 2014 20:09:01 +0200 Subject: [PATCH 005/146] close #296: ArgumentNullException when debugging and pdb points to missing file + show StackFrames without file name as unreachable in CallStackPad --- src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.cs index 4e0006a4d2..18b1f83dd2 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Pads/CallStackPad.cs @@ -150,7 +150,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads { bool showExternalMethods = DebuggingOptions.Instance.ShowExternalMethods; var symSource = WindowsDebugger.PdbSymbolSource; - bool hasSymbols = symSource.Handles(frame.MethodInfo) && !symSource.IsCompilerGenerated(frame.MethodInfo); + bool hasSymbols = symSource.Handles(frame.MethodInfo) + && !symSource.IsCompilerGenerated(frame.MethodInfo) + && frame.NextStatement != null && !string.IsNullOrWhiteSpace(frame.NextStatement.Filename); if (showExternalMethods || hasSymbols) { // Show the method in the list previousItemIsExternalMethod = false; From 466aa3a986bdd83167c8b60d9d3329619840ae35 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 31 Jul 2014 20:41:49 +0200 Subject: [PATCH 006/146] fix #371: No code completion in Razor .cshtml files --- .../AspNet.Mvc/Project/AspNet.Mvc.addin | 2 +- .../AspNet.Mvc/Project/AspNet.Mvc.csproj | 5 + .../RazorCSharpCompletionBinding.cs | 143 +++++++++++++++--- .../Project/Src/CSharpLanguageBinding.cs | 29 ++-- .../Src/Completion/CSharpCompletionBinding.cs | 9 +- .../Src/Completion/CSharpCompletionContext.cs | 24 +-- .../Pads/AutoCompleteTextBox.cs | 2 +- .../Debugger.AddIn/Pads/ConsolePad.cs | 2 +- .../Pads/DebuggerDotCompletion.cs | 8 +- .../LanguageBinding/DefaultLanguageBinding.cs | 2 +- .../LanguageBinding/ILanguageBinding.cs | 2 +- 11 files changed, 152 insertions(+), 76 deletions(-) diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.addin b/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.addin index 8f012b7a71..2b878a57fb 100644 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.addin +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.addin @@ -130,7 +130,7 @@ - + diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj b/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj index a6d3b5fd9d..0ac77f3dba 100644 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj @@ -285,6 +285,11 @@ ICSharpCode.AvalonEdit False + + {53DCA265-3C3C-42F9-B647-F72BA678122B} + ICSharpCode.NRefactory.CSharp + False + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} ICSharpCode.NRefactory diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs index 4401cdb541..38b0020cb6 100644 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs @@ -16,27 +16,122 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//using System; -//using ICSharpCode.SharpDevelop.Editor; -//using ICSharpCode.SharpDevelop.Editor.CodeCompletion; -// -//namespace ICSharpCode.AspNet.Mvc.Completion -//{ -// public class RazorCSharpCompletionBinding : DefaultCodeCompletionBinding -// { -// public RazorCSharpCompletionBinding() -// { -// } -// -// public override CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch) -// { -// if (ch == '.') { -// new RazorCSharpDotCompletionDataProvider().ShowCompletion(editor); -// return CodeCompletionKeyPressResult.Completed; -// } else if (ch == '(') { -// return base.HandleKeyPress(editor, ch); -// } -// return CodeCompletionKeyPressResult.None; -// } -// } -//} +using System; +using System.IO; +using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.CSharp.Resolver; +using ICSharpCode.NRefactory.CSharp.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem.Implementation; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Editor; +using ICSharpCode.SharpDevelop.Editor.CodeCompletion; + +namespace ICSharpCode.AspNet.Mvc.Completion +{ + public class RazorCSharpCompletionBinding : ICodeCompletionBinding + { + public bool HandleKeyPressed(ITextEditor editor, char ch) + { + if (ch == '.') { + var binding = CreateBinding(editor); + return binding.HandleKeyPressed(editor, ch); + } + return false; + } + + public bool CtrlSpace(ITextEditor editor) + { + return false; + } + + public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch) + { + // We use HandleKeyPressed instead. + return CodeCompletionKeyPressResult.None; + } + + ICodeCompletionBinding CreateBinding(ITextEditor editor) + { + return SD.LanguageService.GetLanguageByExtension(".cs") + .CreateCompletionBinding(FindExpressionToComplete(editor), CreateContext(editor)); + } + + string FindExpressionToComplete(ITextEditor editor) + { + int endOffset = editor.Caret.Offset; + int startOffset = endOffset; + while (startOffset > 0 && IsValidCharacter(editor.Document.GetCharAt(startOffset - 1))) + startOffset--; + return editor.Document.GetText(startOffset, endOffset - startOffset); + } + + bool IsValidCharacter(char ch) + { + return Char.IsLetterOrDigit(ch) || + (ch == '.') || + (ch == '_'); + } + + ICodeContext CreateContext(ITextEditor editor) + { + var compilation = SD.ParserService.GetCompilationForFile(editor.FileName); + var project = SD.ProjectService.FindProjectContainingFile(editor.FileName); + + var resolveContext = new SimpleTypeResolveContext(compilation.MainAssembly); + + var currentTypeDefinition = new DefaultUnresolvedTypeDefinition(project.RootNamespace, Path.GetFileNameWithoutExtension(editor.FileName)); + ITypeReference baseTypeReference = new GetClassTypeReference("System.Web.Mvc", "WebViewPage", 1); + baseTypeReference = new ParameterizedTypeReference(baseTypeReference, new[] { KnownTypeReference.Object }); + currentTypeDefinition.BaseTypes.Add(baseTypeReference); + + var currentMethod = new DefaultUnresolvedMethod(currentTypeDefinition, "__ContextStub__"); + currentMethod.ReturnType = KnownTypeReference.Void; + currentTypeDefinition.Members.Add(currentMethod); + + var currentResolvedTypeDef = new DefaultResolvedTypeDefinition(resolveContext, currentTypeDefinition); + + var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent; + + var currentFile = new CSharpUnresolvedFile(); + + currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc"); + currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Ajax"); + currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Html"); + currentFile.RootUsingScope.AddSimpleUsing("System.Web.Routing"); + + currentFile.TopLevelTypeDefinitions.Add(currentTypeDefinition); + + if (projectContent != null) { + compilation = projectContent.AddOrUpdateFiles(currentFile).CreateCompilation(SD.ParserService.GetCurrentSolutionSnapshot()); + } + + var context = new CSharpTypeResolveContext(compilation.MainAssembly, + currentFile.RootUsingScope.Resolve(compilation), + currentResolvedTypeDef, + currentMethod.CreateResolved(resolveContext.WithCurrentTypeDefinition(currentResolvedTypeDef))); + return new CSharpResolver(context); + } + } + + static class NRUtils + { + /// Does not support type arguments! + public static void AddSimpleUsing(this UsingScope scope, string fullName) + { + if (scope == null) + throw new ArgumentNullException("scope"); + string[] parts = fullName.Trim().Split('.'); + TypeOrNamespaceReference reference = null; + foreach (var part in parts) { + if (reference != null) { + reference = new MemberTypeOrNamespaceReference(reference, part, EmptyList.Instance); + } else { + reference = new SimpleTypeOrNamespaceReference(part, EmptyList.Instance); + } + } + + scope.Usings.AddIfNotNull(reference); + } + } +} diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpLanguageBinding.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpLanguageBinding.cs index 548fddd585..8921e09daf 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpLanguageBinding.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpLanguageBinding.cs @@ -55,35 +55,26 @@ namespace CSharpBinding this.container.AddService(typeof(System.CodeDom.Compiler.CodeDomProvider), new Microsoft.CSharp.CSharpCodeProvider()); } - public override ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, FileName fileName, TextLocation location, ICodeContext context) + public override ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, ICodeContext context) { - if (fileName == null) - throw new ArgumentNullException("fileName"); if (context == null) throw new ArgumentNullException("context"); - string content = GeneratePartialClassContextStub(fileName, location, context); + string content = GeneratePartialClassContextStub(context); const string caretPoint = "$__Caret_Point__$;"; int caretOffset = content.IndexOf(caretPoint, StringComparison.Ordinal) + expressionToComplete.Length; SD.Log.DebugFormatted("context used for dot completion: {0}", content.Replace(caretPoint, "$" + expressionToComplete + "|$")); var doc = new ReadOnlyDocument(content.Replace(caretPoint, expressionToComplete)); - return new CSharpCompletionBinding(fileName, doc.GetLocation(caretOffset), doc.CreateSnapshot()); + return new CSharpCompletionBinding(context, doc.GetLocation(caretOffset), doc.CreateSnapshot()); } - static string GeneratePartialClassContextStub(FileName fileName, TextLocation location, ICodeContext context) + static string GeneratePartialClassContextStub(ICodeContext context) { - var compilation = SD.ParserService.GetCompilationForFile(fileName); - var file = SD.ParserService.GetExistingUnresolvedFile(fileName); - if (compilation == null || file == null) - return ""; - var unresolvedMember = file.GetMember(location); - if (unresolvedMember == null) - return ""; - var member = unresolvedMember.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly)); + var member = context.CurrentMember; if (member == null) return ""; var builder = new TypeSystemAstBuilder(); MethodDeclaration decl; - if (unresolvedMember is IMethod) { + if (member is IMethod) { // If it's a method, convert it directly (including parameters + type parameters) decl = (MethodDeclaration)builder.ConvertEntity(member); } else { @@ -97,11 +88,11 @@ namespace CSharpBinding } decl.Name = "__DebuggerStub__"; decl.ReturnType = builder.ConvertType(member.ReturnType); - decl.Modifiers = unresolvedMember.IsStatic ? Modifiers.Static : Modifiers.None; + decl.Modifiers = member.IsStatic ? Modifiers.Static : Modifiers.None; // Make the method look like an explicit interface implementation so that it doesn't appear in CC decl.PrivateImplementationType = new SimpleType("__DummyType__"); decl.Body = GenerateBodyFromContext(builder, context.LocalVariables.ToArray()); - return WrapInType(unresolvedMember.DeclaringTypeDefinition, decl).ToString(); + return WrapInType(context.CurrentTypeDefinition, decl).ToString(); } static BlockStatement GenerateBodyFromContext(TypeSystemAstBuilder builder, IVariable[] variables) @@ -113,7 +104,7 @@ namespace CSharpBinding return body; } - static AstNode WrapInType(IUnresolvedTypeDefinition entity, EntityDeclaration decl) + static AstNode WrapInType(ITypeDefinition entity, EntityDeclaration decl) { if (entity == null) return decl; @@ -137,7 +128,7 @@ namespace CSharpBinding }; } - static ClassType GetClassType(IUnresolvedTypeDefinition entity) + static ClassType GetClassType(ITypeDefinition entity) { switch (entity.Kind) { case TypeKind.Interface: diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs index 1e9943d962..11bbd494da 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionBinding.cs @@ -26,6 +26,7 @@ using ICSharpCode.NRefactory.CSharp.Resolver; using ICSharpCode.NRefactory.Completion; using ICSharpCode.NRefactory.CSharp.Completion; using ICSharpCode.NRefactory.Editor; +using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor.CodeCompletion; @@ -35,7 +36,7 @@ namespace CSharpBinding.Completion { public class CSharpCompletionBinding : ICodeCompletionBinding { - FileName contextFileName; + ICodeContext context; TextLocation currentLocation; ITextSource fileContent; @@ -44,9 +45,9 @@ namespace CSharpBinding.Completion { } - public CSharpCompletionBinding(FileName contextFileName, TextLocation currentLocation, ITextSource fileContent) + public CSharpCompletionBinding(ICodeContext context, TextLocation currentLocation, ITextSource fileContent) { - this.contextFileName = contextFileName; + this.context = context; this.currentLocation = currentLocation; this.fileContent = fileContent; } @@ -75,7 +76,7 @@ namespace CSharpBinding.Completion if (fileContent == null) { completionContext = CSharpCompletionContext.Get(editor); } else { - completionContext = CSharpCompletionContext.Get(editor, fileContent, currentLocation, contextFileName); + completionContext = CSharpCompletionContext.Get(editor, context, currentLocation, fileContent); } if (completionContext == null) return false; diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionContext.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionContext.cs index ae654a0d81..2f4623dcf7 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionContext.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionContext.cs @@ -61,38 +61,24 @@ namespace CSharpBinding.Completion return new CSharpCompletionContext(editor, parseInfo.SyntaxTree.ConditionalSymbols, compilation, projectContent, editor.Document, parseInfo.UnresolvedFile, editor.Caret.Location); } - public static CSharpCompletionContext Get(ITextEditor editor, ITextSource fileContent, TextLocation currentLocation, FileName fileName) + public static CSharpCompletionContext Get(ITextEditor editor, ICodeContext context, TextLocation currentLocation, ITextSource fileContent) { IDocument document = new ReadOnlyDocument(fileContent); - // Don't require the very latest parse information, an older cached version is OK. - var parseInfo = SD.ParserService.GetCachedParseInformation(fileName) as CSharpFullParseInformation; - if (parseInfo == null) { - parseInfo = SD.ParserService.Parse(fileName) as CSharpFullParseInformation; - } - if (parseInfo == null) - return null; - - - var project = SD.ProjectService.FindProjectContainingFile(fileName)as CSharpProject; - if (project == null) - return null; - - var solutionSnapshot = SD.ParserService.GetCurrentSolutionSnapshot(); - var projectContent = solutionSnapshot.GetProjectContent(project); + var projectContent = context.Compilation.MainAssembly.UnresolvedAssembly as IProjectContent; if (projectContent == null) return null; - CSharpParser parser = new CSharpParser(project.CompilerSettings); + CSharpParser parser = new CSharpParser(); parser.GenerateTypeSystemMode = false; SyntaxTree cu = parser.Parse(fileContent, Path.GetRandomFileName() + ".cs"); cu.Freeze(); CSharpUnresolvedFile unresolvedFile = cu.ToTypeSystem(); - ICompilation compilation = projectContent.AddOrUpdateFiles(unresolvedFile).CreateCompilation(solutionSnapshot); + ICompilation compilation = projectContent.AddOrUpdateFiles(unresolvedFile).CreateCompilation(SD.ParserService.GetCurrentSolutionSnapshot()); - return new CSharpCompletionContext(editor, parseInfo.SyntaxTree.ConditionalSymbols, compilation, projectContent, document, unresolvedFile, currentLocation); + return new CSharpCompletionContext(editor, EmptyList.Instance, compilation, projectContent, document, unresolvedFile, currentLocation); } private CSharpCompletionContext(ITextEditor editor, IList conditionalSymbols, ICompilation compilation, IProjectContent projectContent, IDocument document, CSharpUnresolvedFile unresolvedFile, TextLocation caretLocation) diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/AutoCompleteTextBox.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/AutoCompleteTextBox.cs index aca8f0c0b6..b931e96c10 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/AutoCompleteTextBox.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Pads/AutoCompleteTextBox.cs @@ -134,7 +134,7 @@ namespace Debugger.AddIn.Pads.Controls ContextTextLocation = new TextLocation(frame.NextStatement.StartLine, frame.NextStatement.StartColumn); } if (ContextFileName == null) return; - var binding = DebuggerDotCompletion.PrepareDotCompletion(editor.Text.Substring(0, editor.CaretOffset), ContextFileName, ContextTextLocation, SD.ParserService.ResolveContext(ContextFileName, ContextTextLocation)); + var binding = DebuggerDotCompletion.PrepareDotCompletion(editor.Text.Substring(0, editor.CaretOffset), SD.ParserService.ResolveContext(ContextFileName, ContextTextLocation)); if (binding == null) return; binding.HandleKeyPressed(editorAdapter, '.'); } else { diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/ConsolePad.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/ConsolePad.cs index c88df18834..76c3341a9d 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/ConsolePad.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Pads/ConsolePad.cs @@ -88,7 +88,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads { var fileName = new ICSharpCode.Core.FileName(frame.NextStatement.Filename); var textLocation = new TextLocation(frame.NextStatement.StartLine, frame.NextStatement.StartColumn); - var binding = DebuggerDotCompletion.PrepareDotCompletion(currentText, fileName, textLocation, SD.ParserService.ResolveContext(fileName, textLocation)); + var binding = DebuggerDotCompletion.PrepareDotCompletion(currentText, SD.ParserService.ResolveContext(fileName, textLocation)); if (binding == null) return; binding.HandleKeyPressed(console.TextEditor, '.'); } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Pads/DebuggerDotCompletion.cs b/src/AddIns/Debugger/Debugger.AddIn/Pads/DebuggerDotCompletion.cs index 854abc5cca..9370726b9d 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Pads/DebuggerDotCompletion.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Pads/DebuggerDotCompletion.cs @@ -41,12 +41,10 @@ namespace Debugger.AddIn.Pads.Controls return !errors.Any(); } - public static ICodeCompletionBinding PrepareDotCompletion(string expressionToComplete, FileName fileName, TextLocation location, ICodeContext context) + public static ICodeCompletionBinding PrepareDotCompletion(string expressionToComplete, ICodeContext context) { - var lang = SD.LanguageService.GetLanguageByFileName(fileName); - if (lang == null) - return null; - return lang.CreateCompletionBinding(expressionToComplete, fileName, location, context); + return SD.LanguageService.GetLanguageByExtension(".cs") + .CreateCompletionBinding(expressionToComplete, context); } } } diff --git a/src/Main/Base/Project/Src/Services/LanguageBinding/DefaultLanguageBinding.cs b/src/Main/Base/Project/Src/Services/LanguageBinding/DefaultLanguageBinding.cs index c1b1bf7216..f48211e1d1 100644 --- a/src/Main/Base/Project/Src/Services/LanguageBinding/DefaultLanguageBinding.cs +++ b/src/Main/Base/Project/Src/Services/LanguageBinding/DefaultLanguageBinding.cs @@ -75,7 +75,7 @@ namespace ICSharpCode.SharpDevelop } } - public virtual ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, FileName fileName, TextLocation location, ICodeContext context) + public virtual ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, ICodeContext context) { throw new NotSupportedException(); } diff --git a/src/Main/Base/Project/Src/Services/LanguageBinding/ILanguageBinding.cs b/src/Main/Base/Project/Src/Services/LanguageBinding/ILanguageBinding.cs index 49ad72abea..56528c08cc 100644 --- a/src/Main/Base/Project/Src/Services/LanguageBinding/ILanguageBinding.cs +++ b/src/Main/Base/Project/Src/Services/LanguageBinding/ILanguageBinding.cs @@ -65,6 +65,6 @@ namespace ICSharpCode.SharpDevelop /// /// Creates a completion binding for a given expression and context. /// - ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, FileName fileName, TextLocation location, ICodeContext context); + ICodeCompletionBinding CreateCompletionBinding(string expressionToComplete, ICodeContext context); } } From 0c84517c9c966719eca9df5d60a6fbaa684ff939 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 31 Jul 2014 21:27:02 +0200 Subject: [PATCH 007/146] remove old RazorCSharp completion code --- .../AspNet.Mvc/Project/AspNet.Mvc.csproj | 5 - .../RazorCSharpDotCompletionDataProvider.cs | 26 ---- .../Completion/RazorCSharpExpressionFinder.cs | 58 --------- .../Src/Completion/RazorCSharpParser.cs | 68 ---------- .../Src/Completion/RazorCSharpResolver.cs | 119 ------------------ .../Src/Completion/RazorCompilationUnit.cs | 50 -------- 6 files changed, 326 deletions(-) delete mode 100644 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpDotCompletionDataProvider.cs delete mode 100644 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpExpressionFinder.cs delete mode 100644 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpParser.cs delete mode 100644 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpResolver.cs delete mode 100644 src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCompilationUnit.cs diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj b/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj index 0ac77f3dba..95273c0e26 100644 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/AspNet.Mvc.csproj @@ -134,14 +134,9 @@ - - - - - diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpDotCompletionDataProvider.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpDotCompletionDataProvider.cs deleted file mode 100644 index e5a321335d..0000000000 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpDotCompletionDataProvider.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//using System; -// -//namespace ICSharpCode.AspNet.Mvc.Completion -//{ -// public class RazorCSharpDotCompletionDataProvider : DotCodeCompletionItemProvider -// { -// } -//} diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpExpressionFinder.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpExpressionFinder.cs deleted file mode 100644 index 11aae7c710..0000000000 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpExpressionFinder.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//using System; -//using ICSharpCode.SharpDevelop.Dom; -// -//namespace ICSharpCode.AspNet.Mvc.Completion -//{ -// public class RazorCSharpExpressionFinder : IExpressionFinder -// { -// public RazorCSharpExpressionFinder() -// { -// } -// -// public ExpressionResult FindExpression(string text, int offset) -// { -// int position = offset - 1; -// while (position > 0 && IsValidCharacter(text[position])) { -// position--; -// } -// position++; -// string expression = text.Substring(position, offset - position); -// return new ExpressionResult(expression); -// } -// -// bool IsValidCharacter(char ch) -// { -// return Char.IsLetterOrDigit(ch) || -// (ch == '.') || -// (ch == '_'); -// } -// -// public ExpressionResult FindFullExpression(string text, int offset) -// { -// return ExpressionResult.Empty; -// } -// -// public string RemoveLastPart(string expression) -// { -// return expression; -// } -// } -//} diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpParser.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpParser.cs deleted file mode 100644 index cce64fb643..0000000000 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpParser.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//using System; -//using System.IO; -//using ICSharpCode.SharpDevelop; -//using ICSharpCode.SharpDevelop.Dom; -//using ICSharpCode.SharpDevelop.Dom.CSharp; -//using ICSharpCode.SharpDevelop.Project; -// -//namespace ICSharpCode.AspNet.Mvc.Completion -//{ -// public class RazorCSharpParser : IParser -// { -// public RazorCSharpParser() -// { -// } -// -// public string[] LexerTags { get; set; } -// -// public LanguageProperties Language { -// get { return LanguageProperties.CSharp; } -// } -// -// public IExpressionFinder CreateExpressionFinder(string fileName) -// { -// return new RazorCSharpExpressionFinder(); -// } -// -// public bool CanParse(string fileName) -// { -// return Path.GetExtension(fileName).Equals(".cshtml", StringComparison.OrdinalIgnoreCase); -// } -// -// public bool CanParse(IProject project) -// { -// return project.Language == "C#"; -// } -// -// public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ITextBuffer fileContent) -// { -// var modelTypeLocater = new RazorCSharpModelTypeLocater(fileContent); -// return new RazorCompilationUnit(projectContent) { -// ModelTypeName = modelTypeLocater.ModelTypeName -// }; -// } -// -// public IResolver CreateResolver() -// { -// return new RazorCSharpResolver(); -// } -// } -//} diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpResolver.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpResolver.cs deleted file mode 100644 index 1ce97c8dc5..0000000000 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpResolver.cs +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//using System; -//using System.Collections.Generic; -//using ICSharpCode.NRefactory.TypeSystem; -// -//namespace ICSharpCode.AspNet.Mvc.Completion -//{ -// public class RazorCSharpResolver : IResolver -// { -// NRefactoryResolver resolver = new NRefactoryResolver(LanguageProperties.CSharp); -// -// public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent) -// { -// ParseInformation parseInfoWithWebViewPageClass = CreateParseInformationWithWebViewPageClass(parseInfo); -// expressionResult.Region = GetRegionInMiddleOfWebViewPageClass(); -// return resolver.Resolve(expressionResult, parseInfoWithWebViewPageClass, fileContent); -// } -// -// ParseInformation CreateParseInformationWithWebViewPageClass(ParseInformation parseInfo) -// { -// RazorCompilationUnit compilationUnit = RazorCompilationUnit.CreateFromParseInfo(parseInfo); -// AddDefaultUsings(compilationUnit); -// AddWebViewPageClass(compilationUnit); -// return new ParseInformation(compilationUnit); -// } -// -// void AddDefaultUsings(ICompilationUnit compilationUnit) -// { -// AddUsing("System.Web.Mvc", compilationUnit); -// AddUsing("System.Web.Mvc.Ajax", compilationUnit); -// AddUsing("System.Web.Mvc.Html", compilationUnit); -// AddUsing("System.Web.Routing", compilationUnit); -// } -// -// void AddUsing(string name, ICompilationUnit compilationUnit) -// { -// DefaultUsing defaultUsing = CreateUsing(name, compilationUnit.ProjectContent); -// compilationUnit.UsingScope.Usings.Add(defaultUsing); -// } -// -// DefaultUsing CreateUsing(string namespaceName, IProjectContent projectContent) -// { -// var defaultUsing = new DefaultUsing(projectContent); -// defaultUsing.Usings.Add(namespaceName); -// return defaultUsing; -// } -// -// void AddWebViewPageClass(RazorCompilationUnit compilationUnit) -// { -// DefaultClass webViewPageClass = CreateWebViewPageClass(compilationUnit); -// compilationUnit.Classes.Add(webViewPageClass); -// } -// -// DefaultClass CreateWebViewPageClass(RazorCompilationUnit compilationUnit) -// { -// var webViewPageClass = new DefaultClass(compilationUnit, "RazorWebViewPage") { -// Region = new DomRegion(1, 0, 3, 0) -// }; -// IReturnType modelType = GetModelReturnType(compilationUnit); -// AddWebViewPageBaseClass(webViewPageClass, modelType); -// return webViewPageClass; -// } -// -// IReturnType GetModelReturnType(RazorCompilationUnit compilationUnit) -// { -// IClass modelType = GetClassIfTypeNameIsNotEmpty(compilationUnit.ProjectContent, compilationUnit.ModelTypeName); -// if (modelType != null) { -// return modelType.DefaultReturnType; -// } -// return new DynamicReturnType(compilationUnit.ProjectContent); -// } -// -// IClass GetClassIfTypeNameIsNotEmpty(IProjectContent projectContent, string modelTypeName) -// { -// if (!String.IsNullOrEmpty(modelTypeName)) { -// return projectContent.GetClass(modelTypeName, 0); -// } -// return null; -// } -// -// void AddWebViewPageBaseClass(DefaultClass webViewPageClass, IReturnType modelType) -// { -// IClass webViewPageBaseClass = webViewPageClass.ProjectContent.GetClass("System.Web.Mvc.WebViewPage", 1); -// if (webViewPageBaseClass != null) { -// IReturnType returnType = GetWebViewPageBaseClassReturnType(webViewPageBaseClass, modelType); -// webViewPageClass.BaseTypes.Add(returnType); -// } -// } -// -// IReturnType GetWebViewPageBaseClassReturnType(IClass webViewPageBaseClass, IReturnType modelType) -// { -// var typeArguments = new List(); -// typeArguments.Add(modelType); -// return new ConstructedReturnType(webViewPageBaseClass.DefaultReturnType, typeArguments); -// } -// -// DomRegion GetRegionInMiddleOfWebViewPageClass() -// { -// return new DomRegion(2, 0, 2, 0); -// } -// } -//} diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCompilationUnit.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCompilationUnit.cs deleted file mode 100644 index 9672f4df56..0000000000 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCompilationUnit.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this -// software and associated documentation files (the "Software"), to deal in the Software -// without restriction, including without limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons -// to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR -// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//using System; -//using ICSharpCode.NRefactory.TypeSystem; -//using ICSharpCode.SharpDevelop.Parser; -// -//namespace ICSharpCode.AspNet.Mvc.Completion -//{ -// public class RazorCompilationUnit : DefaultCompilationUnit -// { -// public RazorCompilationUnit(IProjectContent projectContent) -// : base(projectContent) -// { -// } -// -// public static RazorCompilationUnit CreateFromParseInfo(ParseInformation parseInformation) -// { -// return new RazorCompilationUnit(parseInformation.CompilationUnit.ProjectContent) { -// ModelTypeName = GetModelTypeName(parseInformation.CompilationUnit) -// }; -// } -// -// static string GetModelTypeName(ICompilationUnit compilationUnit) -// { -// var originalRazorCompilationUnit = compilationUnit as RazorCompilationUnit; -// if (originalRazorCompilationUnit != null) { -// return originalRazorCompilationUnit.ModelTypeName; -// } -// return String.Empty; -// } -// -// public string ModelTypeName { get; set; } -// } -//} From d68d30151934109d28991ca4fe3437d07945c898 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 31 Jul 2014 21:27:53 +0200 Subject: [PATCH 008/146] reimplement support for @model ModelTypeName --- .../RazorCSharpCompletionBinding.cs | 35 +++++++++-- .../Completion/RazorCSharpModelTypeLocater.cs | 62 +++++++++---------- 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs index 38b0020cb6..1ab287f0cb 100644 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpCompletionBinding.cs @@ -18,9 +18,12 @@ using System; using System.IO; +using System.Web.Razor; using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.CSharp.Resolver; using ICSharpCode.NRefactory.CSharp.TypeSystem; +using ICSharpCode.NRefactory.Editor; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem.Implementation; using ICSharpCode.SharpDevelop; @@ -82,7 +85,7 @@ namespace ICSharpCode.AspNet.Mvc.Completion var currentTypeDefinition = new DefaultUnresolvedTypeDefinition(project.RootNamespace, Path.GetFileNameWithoutExtension(editor.FileName)); ITypeReference baseTypeReference = new GetClassTypeReference("System.Web.Mvc", "WebViewPage", 1); - baseTypeReference = new ParameterizedTypeReference(baseTypeReference, new[] { KnownTypeReference.Object }); + baseTypeReference = new ParameterizedTypeReference(baseTypeReference, new[] { FindModelType(editor) }); currentTypeDefinition.BaseTypes.Add(baseTypeReference); var currentMethod = new DefaultUnresolvedMethod(currentTypeDefinition, "__ContextStub__"); @@ -107,11 +110,35 @@ namespace ICSharpCode.AspNet.Mvc.Completion } var context = new CSharpTypeResolveContext(compilation.MainAssembly, - currentFile.RootUsingScope.Resolve(compilation), - currentResolvedTypeDef, - currentMethod.CreateResolved(resolveContext.WithCurrentTypeDefinition(currentResolvedTypeDef))); + currentFile.RootUsingScope.Resolve(compilation), + currentResolvedTypeDef, + currentMethod.CreateResolved(resolveContext.WithCurrentTypeDefinition(currentResolvedTypeDef))); return new CSharpResolver(context); } + + ITypeReference FindModelType(ITextEditor editor) + { + ParserResults results = ParseTemplate(editor.Document); + string typeName = GetModelTypeName(results); + if (string.IsNullOrWhiteSpace(typeName)) + return KnownTypeReference.Object; + return new CSharpParser().ParseTypeReference(typeName) + .ToTypeReference(NameLookupMode.BaseTypeReference); + } + + ParserResults ParseTemplate(ITextSource textBuffer) + { + var host = new RazorEngineHost(new CSharpRazorCodeLanguage()); + var engine = new RazorTemplateEngine(host); + return engine.ParseTemplate(textBuffer.CreateReader()); + } + + string GetModelTypeName(ParserResults results) + { + var visitor = new RazorCSharpParserModelTypeVisitor(); + results.Document.Accept(visitor); + return visitor.ModelTypeName; + } } static class NRUtils diff --git a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpModelTypeLocater.cs b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpModelTypeLocater.cs index e45bc69574..a5cc0ea8be 100644 --- a/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpModelTypeLocater.cs +++ b/src/AddIns/BackendBindings/AspNet.Mvc/Project/Src/Completion/RazorCSharpModelTypeLocater.cs @@ -16,34 +16,34 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -//using System; -//using System.Web.Razor; -//using ICSharpCode.SharpDevelop; -// -//namespace ICSharpCode.AspNet.Mvc.Completion -//{ -// public class RazorCSharpModelTypeLocater -// { -// public RazorCSharpModelTypeLocater(ITextBuffer textBuffer) -// { -// ParserResults results = ParseTemplate(textBuffer); -// ModelTypeName = GetModelTypeName(results); -// } -// -// ParserResults ParseTemplate(ITextBuffer textBuffer) -// { -// var host = new RazorEngineHost(new CSharpRazorCodeLanguage()); -// var engine = new RazorTemplateEngine(host); -// return engine.ParseTemplate(textBuffer.CreateReader()); -// } -// -// string GetModelTypeName(ParserResults results) -// { -// var visitor = new RazorCSharpParserModelTypeVisitor(); -// results.Document.Accept(visitor); -// return visitor.ModelTypeName; -// } -// -// public string ModelTypeName { get; private set; } -// } -//} +using System; +using System.Web.Razor; +using ICSharpCode.NRefactory.Editor; + +namespace ICSharpCode.AspNet.Mvc.Completion +{ + public class RazorCSharpModelTypeLocater + { + public RazorCSharpModelTypeLocater(ITextSource textBuffer) + { + ParserResults results = ParseTemplate(textBuffer); + ModelTypeName = GetModelTypeName(results); + } + + ParserResults ParseTemplate(ITextSource textBuffer) + { + var host = new RazorEngineHost(new CSharpRazorCodeLanguage()); + var engine = new RazorTemplateEngine(host); + return engine.ParseTemplate(textBuffer.CreateReader()); + } + + string GetModelTypeName(ParserResults results) + { + var visitor = new RazorCSharpParserModelTypeVisitor(); + results.Document.Accept(visitor); + return visitor.ModelTypeName; + } + + public string ModelTypeName { get; private set; } + } +} From e152b747ddd56a604480379d5762df7ffc22f398 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 1 Aug 2014 16:57:29 +0200 Subject: [PATCH 009/146] fix calculation of sequence points for breakpoints in pdb files --- .../Debugger/Debugger.Core/Breakpoint.cs | 2 +- .../Debugger/Debugger.Core/PdbSymbolSource.cs | 58 +++++++++++++++---- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.Core/Breakpoint.cs b/src/AddIns/Debugger/Debugger.Core/Breakpoint.cs index 2e170818cc..f6b1e8a034 100644 --- a/src/AddIns/Debugger/Debugger.Core/Breakpoint.cs +++ b/src/AddIns/Debugger/Debugger.Core/Breakpoint.cs @@ -84,7 +84,7 @@ namespace Debugger public void SetBreakpoint(Module module) { - foreach(var symbolSource in module.Process.Debugger.SymbolSources) { + foreach (var symbolSource in module.Process.Debugger.SymbolSources) { foreach (var seq in symbolSource.GetSequencePoints(module, this.FileName, this.Line, this.Column)) { ICorDebugFunction corFunction = module.CorModule.GetFunctionFromToken(seq.MethodDefToken); ICorDebugFunctionBreakpoint corBreakpoint = corFunction.GetILCode().CreateBreakpoint((uint)seq.ILOffset); diff --git a/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs b/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs index 5715fa7443..aad518a400 100644 --- a/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs +++ b/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs @@ -48,6 +48,14 @@ namespace Debugger this.StartLine, this.StartColumn, this.EndLine, this.EndColumn); } + + public bool ContainsLocation(int line, int column = 0) + { + if (column == 0) + return line >= StartLine && line <= EndLine; + return (StartLine < line || (StartLine == line && StartColumn <= column)) + && (line < EndLine || (line == EndLine && column <= EndColumn)); + } } public struct ILRange @@ -185,14 +193,14 @@ namespace Debugger var realSeqPoints = sequencePoints.Where(p => p.StartLine != 0xFEEFEE); // Find point for which (ilstart <= iloffset < ilend) or fallback to the next valid sequence point - var sequencePoint = realSeqPoints.FirstOrDefault(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To)) ?? - realSeqPoints.FirstOrDefault(p => iloffset <= p.ILOffset); + var sequencePoint = realSeqPoints.FirstOrDefault(p => p.ILRanges.Any(r => r.From <= iloffset && iloffset < r.To)) + ?? realSeqPoints.FirstOrDefault(p => iloffset <= p.ILOffset); if (sequencePoint != null) { // VB.NET sometimes produces temporary files which it then deletes // (eg 17d14f5c-a337-4978-8281-53493378c1071.vb) string name = Path.GetFileName(sequencePoint.Filename); - if (name.Length == 40 && name.EndsWith(".vb")) { + if (name.Length == 40 && name.EndsWith(".vb", StringComparison.OrdinalIgnoreCase)) { if (name.Substring(0, name.Length - 3).All(c => ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F') || (c == '-'))) { return null; } @@ -232,19 +240,47 @@ namespace Debugger foreach (ISymUnmanagedMethod symMethod in symMethods) { var corFunction = module.CorModule.GetFunctionFromToken(symMethod.GetToken()); - int codesize = (int)corFunction.GetILCode().GetSize(); - var seqPoints = symMethod.GetSequencePoints(codesize).Where(s => s.StartLine != 0xFEEFEE); - SequencePoint seqPoint = null; - if (column != 0) { - seqPoint = seqPoints.FirstOrDefault(s => (s.StartLine < line || (s.StartLine == line && s.StartColumn <= column)) && - (line < s.EndLine || (line == s.EndLine && column <= s.EndColumn))); - } - seqPoint = seqPoint ?? seqPoints.FirstOrDefault(s => line <= s.StartLine); + int codeSize = (int)corFunction.GetILCode().GetSize(); + var seqPoints = symMethod.GetSequencePoints(codeSize).Where(s => s.StartLine != 0xFEEFEE).OrderBy(s => s.StartLine).ToArray(); + SequencePoint seqPoint = FindNearestMatchingSequencePoint(seqPoints, line, column); if (seqPoint != null) yield return seqPoint; } } + SequencePoint FindNearestMatchingSequencePoint(SequencePoint[] seqPoints, int line, int column) + { + // value is nearest offset in lines; + // negative numbers: (Start|End)Line is same as line, value is offset in columns + int nearestOffset = 0; + SequencePoint bestMatch = null; + for (int i = 0; i < seqPoints.Length; i++) { + var s = seqPoints[i]; + if (s.ContainsLocation(line, column)) + return seqPoints[i]; + + if (bestMatch == null) { + bestMatch = s; + nearestOffset = GetOffsetValue(s, line, column); + } else { + int newOffset = GetOffsetValue(s, line, column); + if ((newOffset < 0 && nearestOffset < 0 && newOffset > nearestOffset) || (newOffset < nearestOffset)) { + bestMatch = s; + nearestOffset = newOffset; + } + } + } + + return bestMatch; + } + + static int GetOffsetValue(SequencePoint s, int line, int column) + { + if (line == s.StartLine || s.EndLine == line) + return -Math.Min(Math.Abs(s.StartColumn - column), Math.Abs(s.EndColumn - column)); + return Math.Min(Math.Abs(s.StartLine - line), Math.Abs(s.EndLine - line)); + } + public IEnumerable GetIgnoredILRanges(IMethod method) { var symMethod = method.GetSymMethod(); From 7a6df89318ffbbcc7c9f9f447eaa5e4127204a78 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 1 Aug 2014 17:24:36 +0200 Subject: [PATCH 010/146] fix build --- .../Debugger/Debugger.Core/PdbSymbolSource.cs | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs b/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs index aad518a400..945242fbe3 100644 --- a/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs +++ b/src/AddIns/Debugger/Debugger.Core/PdbSymbolSource.cs @@ -234,6 +234,8 @@ namespace Debugger try { uint validLine = symDoc.FindClosestLine((uint)line); symMethods = symReader.GetMethodsFromDocumentPosition(symDoc, validLine, (uint)column); + if (validLine > 0) + line = (int)validLine; } catch { yield break; //Not found } @@ -250,35 +252,14 @@ namespace Debugger SequencePoint FindNearestMatchingSequencePoint(SequencePoint[] seqPoints, int line, int column) { - // value is nearest offset in lines; - // negative numbers: (Start|End)Line is same as line, value is offset in columns - int nearestOffset = 0; - SequencePoint bestMatch = null; for (int i = 0; i < seqPoints.Length; i++) { var s = seqPoints[i]; if (s.ContainsLocation(line, column)) - return seqPoints[i]; - - if (bestMatch == null) { - bestMatch = s; - nearestOffset = GetOffsetValue(s, line, column); - } else { - int newOffset = GetOffsetValue(s, line, column); - if ((newOffset < 0 && nearestOffset < 0 && newOffset > nearestOffset) || (newOffset < nearestOffset)) { - bestMatch = s; - nearestOffset = newOffset; - } - } + return s; + if (s.StartLine > line) + return s; } - - return bestMatch; - } - - static int GetOffsetValue(SequencePoint s, int line, int column) - { - if (line == s.StartLine || s.EndLine == line) - return -Math.Min(Math.Abs(s.StartColumn - column), Math.Abs(s.EndColumn - column)); - return Math.Min(Math.Abs(s.StartLine - line), Math.Abs(s.EndLine - line)); + return null; } public IEnumerable GetIgnoredILRanges(IMethod method) From af0cc60416d5c40528f3c2b36b3dca0f6446ede2 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sat, 2 Aug 2014 14:35:19 +0100 Subject: [PATCH 011/146] Fix Check with StyleCop menu not returning any StyleCop warnings. --- .../SharpDevelop/Project/Build/MSBuildEngine/MSBuildEngine.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Main/SharpDevelop/Project/Build/MSBuildEngine/MSBuildEngine.cs b/src/Main/SharpDevelop/Project/Build/MSBuildEngine/MSBuildEngine.cs index f4c9f5af5c..6142d601f2 100644 --- a/src/Main/SharpDevelop/Project/Build/MSBuildEngine/MSBuildEngine.cs +++ b/src/Main/SharpDevelop/Project/Build/MSBuildEngine/MSBuildEngine.cs @@ -94,6 +94,7 @@ namespace ICSharpCode.SharpDevelop.Project throw new ArgumentNullException("feedbackSink"); var additionalTargetFileList = additionalTargetFiles != null ? additionalTargetFiles.ToList() : new List(); + additionalTargetFileList.AddRange(AdditionalTargetFiles.Select(fileName => fileName.ToString())); if (project.MinimumSolutionVersion >= SolutionFormatVersion.VS2010) { additionalTargetFileList.Add(Path.Combine(Path.GetDirectoryName(typeof(MSBuildEngine).Assembly.Location), "SharpDevelop.TargetingPack.targets")); } From e5dde6f4aceae2e77957258307597c97cb90862d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 3 Aug 2014 19:37:25 +0200 Subject: [PATCH 012/146] Don't use lazy loading for built-in WPF commands. --- src/Main/Core/Project/Src/Util/CommandWrapper.cs | 11 +++++++++++ .../Menu/MenuCommand.cs | 7 ++----- .../Menu/MenuService.cs | 3 +-- .../ToolBar/ToolBarButton.cs | 7 ++----- .../ToolBar/ToolBarService.cs | 4 +--- .../ICSharpCode.Core.WinForms/Menu/MenuCommand.cs | 12 +----------- .../ICSharpCode.Core.WinForms/Menu/MenuService.cs | 2 +- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/Main/Core/Project/Src/Util/CommandWrapper.cs b/src/Main/Core/Project/Src/Util/CommandWrapper.cs index 70009c5366..b2adc9479f 100644 --- a/src/Main/Core/Project/Src/Util/CommandWrapper.cs +++ b/src/Main/Core/Project/Src/Util/CommandWrapper.cs @@ -44,6 +44,17 @@ namespace ICSharpCode.Core /// public static ICommand CreateLazyCommand(Codon codon, IReadOnlyCollection conditions) { + if (codon.Properties["loadclasslazy"] == "false") { + // if lazy loading was explicitly disabled, create the actual command now + return CreateCommand(codon, conditions); + } + if (codon.Properties.Contains("command") && !codon.Properties.Contains("loadclasslazy")) { + // If we're using the 'command=' syntax, this is most likely a built-in command + // where lazy loading isn't useful (and hurts if CanExecute is used). + // Don't use lazy loading unless loadclasslazy is set explicitly. + return CreateCommand(codon, conditions); + } + // Create the wrapper that lazily loads the actual command. return new CommandWrapper(codon, conditions); } diff --git a/src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs b/src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs index c96ed51a2b..d134811d71 100644 --- a/src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs +++ b/src/Main/ICSharpCode.Core.Presentation/Menu/MenuCommand.cs @@ -32,13 +32,10 @@ namespace ICSharpCode.Core.Presentation { readonly string ActivationMethod; - public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand, string activationMethod, IReadOnlyCollection conditions) : base(codon, caller, conditions) + public MenuCommand(UIElement inputBindingOwner, Codon codon, object caller, string activationMethod, IReadOnlyCollection conditions) : base(codon, caller, conditions) { this.ActivationMethod = activationMethod; - if (createCommand) - this.Command = CommandWrapper.CreateCommand(codon, conditions); - else - this.Command = CommandWrapper.CreateLazyCommand(codon, conditions); + this.Command = CommandWrapper.CreateLazyCommand(codon, conditions); this.CommandParameter = caller; if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) { diff --git a/src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs b/src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs index efdfb4209f..7f68990b38 100644 --- a/src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs +++ b/src/Main/ICSharpCode.Core.Presentation/Menu/MenuService.cs @@ -211,7 +211,6 @@ namespace ICSharpCode.Core.Presentation { Codon codon = descriptor.Codon; string type = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command"; - bool createCommand = codon.Properties["loadclasslazy"] == "false"; switch (type) { case "Separator": @@ -220,7 +219,7 @@ namespace ICSharpCode.Core.Presentation return new MenuCheckBox(context.InputBindingOwner, codon, descriptor.Parameter, descriptor.Conditions); case "Item": case "Command": - return new MenuCommand(context.InputBindingOwner, codon, descriptor.Parameter, createCommand, context.ActivationMethod, descriptor.Conditions); + return new MenuCommand(context.InputBindingOwner, codon, descriptor.Parameter, context.ActivationMethod, descriptor.Conditions); case "Menu": var item = new CoreMenuItem(codon, descriptor.Parameter, descriptor.Conditions) { ItemsSource = new object[1], diff --git a/src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs b/src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs index 094a150956..4b4e4663ab 100644 --- a/src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs +++ b/src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarButton.cs @@ -36,16 +36,13 @@ namespace ICSharpCode.Core.Presentation readonly string inputGestureText; readonly IEnumerable conditions; - public ToolBarButton(UIElement inputBindingOwner, Codon codon, object caller, bool createCommand, IReadOnlyCollection conditions) + public ToolBarButton(UIElement inputBindingOwner, Codon codon, object caller, IReadOnlyCollection conditions) { ToolTipService.SetShowOnDisabled(this, true); this.codon = codon; this.caller = caller; - if (createCommand) - this.Command = CommandWrapper.CreateCommand(codon, conditions); - else - this.Command = CommandWrapper.CreateLazyCommand(codon, conditions); + this.Command = CommandWrapper.CreateLazyCommand(codon, conditions); this.CommandParameter = caller; this.Content = ToolBarService.CreateToolBarItemContent(codon); this.conditions = conditions; diff --git a/src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs b/src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs index 9c0d128fe8..dce695ec80 100644 --- a/src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs +++ b/src/Main/ICSharpCode.Core.Presentation/ToolBar/ToolBarService.cs @@ -65,15 +65,13 @@ namespace ICSharpCode.Core.Presentation object caller = descriptor.Parameter; string type = codon.Properties.Contains("type") ? codon.Properties["type"] : "Item"; - bool createCommand = codon.Properties["loadclasslazy"] == "false"; - switch (type) { case "Separator": return new ConditionalSeparator(codon, caller, true, descriptor.Conditions); case "CheckBox": return new ToolBarCheckBox(codon, caller, descriptor.Conditions); case "Item": - return new ToolBarButton(inputBindingOwner, codon, caller, createCommand, descriptor.Conditions); + return new ToolBarButton(inputBindingOwner, codon, caller, descriptor.Conditions); case "DropDownButton": return new ToolBarDropDownButton( codon, caller, MenuService.CreateUnexpandedMenuItems( diff --git a/src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs b/src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs index b8d2fc061f..92169ca890 100644 --- a/src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs +++ b/src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs @@ -43,23 +43,13 @@ namespace ICSharpCode.Core.WinForms } public MenuCommand(Codon codon, object caller, IReadOnlyCollection conditions) - : this(codon, caller, false, conditions) - { - - } - - public MenuCommand(Codon codon, object caller, bool createCommand, IReadOnlyCollection conditions) { this.RightToLeft = RightToLeft.Inherit; this.caller = caller; this.codon = codon; this.conditions = conditions; - if (createCommand) { - this.command = CommandWrapper.CreateCommand(codon, conditions); - } else { - this.command = CommandWrapper.CreateLazyCommand(codon, conditions); - } + this.command = CommandWrapper.CreateLazyCommand(codon, conditions); UpdateText(); } diff --git a/src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs b/src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs index d6237501a1..f82aa51fb2 100644 --- a/src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs +++ b/src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs @@ -62,7 +62,7 @@ namespace ICSharpCode.Core.WinForms return new MenuCheckBox(codon, descriptor.Parameter, descriptor.Conditions); case "Item": case "Command": - return new MenuCommand(codon, descriptor.Parameter, createCommand, descriptor.Conditions); + return new MenuCommand(codon, descriptor.Parameter, descriptor.Conditions); case "Menu": return new Menu(codon, descriptor.Parameter, ConvertSubItems(descriptor.SubItems), descriptor.Conditions); case "Builder": From 904373afe228f7340d3136a24ac18fa419c55e82 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 3 Aug 2014 20:06:12 +0200 Subject: [PATCH 013/146] fix #234: Short cuts/toolbar actions do not always work in non-WPF view contents --- .../Project/Src/View/HexEditContainer.cs | 4 --- .../HexEditor/Project/Src/View/HexEditView.cs | 25 ++++++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs b/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs index 3d06983640..2f4b077f7b 100644 --- a/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs +++ b/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs @@ -34,10 +34,6 @@ namespace HexEditor.View get { return hexEditControl.HasSomethingSelected; } } - public bool EditorFocused { - get { return hexEditControl.Focused; } - } - public bool CanUndo { get { return hexEditControl.CanUndo; } } diff --git a/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditView.cs b/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditView.cs index 63e4e00b04..bfe4d78981 100644 --- a/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditView.cs +++ b/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditView.cs @@ -18,10 +18,8 @@ using System; using System.IO; -using ICSharpCode.Core; -using ICSharpCode.Core.WinForms; +using System.Windows.Input; using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.WinForms; using ICSharpCode.SharpDevelop.Workbench; @@ -34,7 +32,8 @@ namespace HexEditor.View public HexEditView(OpenedFile file) { hexEditContainer = new HexEditContainer(); - hexEditContainer.hexEditControl.DocumentChanged += new EventHandler(DocumentChanged); + hexEditContainer.hexEditControl.DocumentChanged += DocumentChanged; + hexEditContainer.hexEditControl.Selection.SelectionChanged += SelectionChanged; this.Files.Add(file); @@ -67,23 +66,23 @@ namespace HexEditor.View #region IClipboardHandler public bool EnableCut { - get { return hexEditContainer.HasSomethingSelected & hexEditContainer.EditorFocused; } + get { return hexEditContainer.HasSomethingSelected; } } public bool EnableCopy { - get { return hexEditContainer.HasSomethingSelected & hexEditContainer.EditorFocused; } + get { return hexEditContainer.HasSomethingSelected; } } public bool EnablePaste { - get { return hexEditContainer.EditorFocused; } + get { return true; } } public bool EnableDelete { - get { return hexEditContainer.HasSomethingSelected & hexEditContainer.EditorFocused; } + get { return hexEditContainer.HasSomethingSelected; } } public bool EnableSelectAll { - get { return hexEditContainer.EditorFocused; } + get { return true; } } public void Cut() @@ -137,10 +136,12 @@ namespace HexEditor.View void DocumentChanged(object sender, EventArgs e) { if (PrimaryFile != null) PrimaryFile.MakeDirty(); + CommandManager.InvalidateRequerySuggested(); } - - public override bool IsDirty { - get { return base.IsDirty; } + + void SelectionChanged(object sender, System.EventArgs e) + { + CommandManager.InvalidateRequerySuggested(); } } } From 6c0d5d256102e7fe724899306d1abc5201744db5 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 9 Aug 2014 14:33:20 +0200 Subject: [PATCH 014/146] Remove weird extension method that was only used in a single place. --- .../FormsDesigner/Project/Src/ToolboxProvider.cs | 9 ++++++++- src/Main/Base/Project/Util/SharpDevelopExtensions.cs | 11 ----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs index 149daee471..2260b563ee 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/ToolboxProvider.cs @@ -136,6 +136,13 @@ namespace ICSharpCode.FormsDesigner toolboxService.SetSelectedToolboxItem(null); } + static ICompilation GetCompilationForCurrentProject() + { + IProject project = SD.ProjectService.CurrentProject; + if (project == null) return null; + return SD.ParserService.GetCompilation(project); + } + static void SelectedToolUsedHandler(object sender, EventArgs e) { SD.Log.Debug("SelectedToolUsedHandler"); @@ -148,7 +155,7 @@ namespace ICSharpCode.FormsDesigner if (selectedItem != null && selectedItem.TypeName != null) { SD.Log.Debug("Checking for reference to CustomComponent: " + selectedItem.TypeName); // Check current project has the custom component first. - ICompilation currentCompilation = SD.ParserService.GetCompilationForCurrentProject(); + ICompilation currentCompilation = GetCompilationForCurrentProject(); var typeName = new FullTypeName(selectedItem.TypeName); if (currentCompilation != null && currentCompilation.FindType(typeName).Kind == TypeKind.Unknown) { // Check other projects in the solution. diff --git a/src/Main/Base/Project/Util/SharpDevelopExtensions.cs b/src/Main/Base/Project/Util/SharpDevelopExtensions.cs index 6f320ecf9f..81e1afb7a0 100644 --- a/src/Main/Base/Project/Util/SharpDevelopExtensions.cs +++ b/src/Main/Base/Project/Util/SharpDevelopExtensions.cs @@ -902,17 +902,6 @@ namespace ICSharpCode.SharpDevelop } #endregion - #region Service Extensions - public static ICompilation GetCompilationForCurrentProject(this IParserService svc) - { - if (svc == null) - throw new ArgumentNullException("svc"); - IProject project = SD.ProjectService.CurrentProject; - if (project == null) return null; - return SD.ParserService.GetCompilation(project); - } - #endregion - #region Resource Service Extensions /// /// Gets an from a resource. From e98a46da008e1b0a5c8a3f8b06873ee7ea943ddb Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 9 Aug 2014 08:22:55 +0200 Subject: [PATCH 015/146] allow public use of indentation-alignment logic from TextMarkerToolTipProvider --- .../Src/TextMarkerToolTipProvider.cs | 59 +------------ src/Main/Base/Project/Editor/ToolTipUtils.cs | 86 +++++++++++++++++++ .../Project/ICSharpCode.SharpDevelop.csproj | 1 + 3 files changed, 88 insertions(+), 58 deletions(-) create mode 100644 src/Main/Base/Project/Editor/ToolTipUtils.cs diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerToolTipProvider.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerToolTipProvider.cs index 3ca357cbca..75f85d8011 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerToolTipProvider.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/TextMarkerToolTipProvider.cs @@ -67,64 +67,7 @@ namespace ICSharpCode.AvalonEdit.AddIn string GetTooltipTextForCollapsedSection(ToolTipRequestEventArgs args, FoldingSection foldingSection) { - // This fixes SD-1394: - // Each line is checked for leading indentation whitespaces. If - // a line has the same or more indentation than the first line, - // it is reduced. If a line is less indented than the first line - // the indentation is removed completely. - // - // See the following example: - // line 1 - // line 2 - // line 3 - // line 4 - // - // is reduced to: - // line 1 - // line 2 - // line 3 - // line 4 - - const int maxLineCount = 15; - - TextDocument document = (TextDocument)args.Editor.Document; - int startOffset = foldingSection.StartOffset; - int endOffset = foldingSection.EndOffset; - - DocumentLine startLine = document.GetLineByOffset(startOffset); - DocumentLine endLine = document.GetLineByOffset(endOffset); - StringBuilder builder = new StringBuilder(); - - DocumentLine current = startLine; - ISegment startIndent = TextUtilities.GetLeadingWhitespace(document, startLine); - int lineCount = 0; - while (current != endLine.NextLine && lineCount < maxLineCount) { - ISegment currentIndent = TextUtilities.GetLeadingWhitespace(document, current); - - if (current == startLine && current == endLine) - builder.Append(document.GetText(startOffset, endOffset - startOffset)); - else if (current == startLine) { - if (current.EndOffset - startOffset > 0) - builder.AppendLine(document.GetText(startOffset, current.EndOffset - startOffset).TrimStart()); - } else if (current == endLine) { - if (startIndent.Length <= currentIndent.Length) - builder.Append(document.GetText(current.Offset + startIndent.Length, endOffset - current.Offset - startIndent.Length)); - else - builder.Append(document.GetText(current.Offset + currentIndent.Length, endOffset - current.Offset - currentIndent.Length)); - } else { - if (startIndent.Length <= currentIndent.Length) - builder.AppendLine(document.GetText(current.Offset + startIndent.Length, current.Length - startIndent.Length)); - else - builder.AppendLine(document.GetText(current.Offset + currentIndent.Length, current.Length - currentIndent.Length)); - } - - current = current.NextLine; - lineCount++; - } - if (current != endLine.NextLine) - builder.Append("..."); - - return builder.ToString(); + return ToolTipUtils.GetAlignedText(args.Editor.Document, foldingSection.StartOffset, foldingSection.EndOffset); } } } diff --git a/src/Main/Base/Project/Editor/ToolTipUtils.cs b/src/Main/Base/Project/Editor/ToolTipUtils.cs new file mode 100644 index 0000000000..34ab466ce1 --- /dev/null +++ b/src/Main/Base/Project/Editor/ToolTipUtils.cs @@ -0,0 +1,86 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +using System; +using System.Text; +using ICSharpCode.AvalonEdit.Document; +using ICSharpCode.NRefactory.Editor; + +namespace ICSharpCode.SharpDevelop.Editor +{ + public static class ToolTipUtils + { + public static string GetAlignedText(IDocument document, int startOffset, int endOffset, int maxLineCount = 15) + { + // This fixes SD-1394: + // Each line is checked for leading indentation whitespaces. If + // a line has the same or more indentation than the first line, + // it is reduced. If a line is less indented than the first line + // the indentation is removed completely. + // + // See the following example: + // line 1 + // line 2 + // line 3 + // line 4 + // + // is reduced to: + // line 1 + // line 2 + // line 3 + // line 4 + + if (maxLineCount < 1) + maxLineCount = int.MaxValue; + + IDocumentLine startLine = document.GetLineByOffset(startOffset); + IDocumentLine endLine = document.GetLineByOffset(endOffset); + StringBuilder builder = new StringBuilder(); + + IDocumentLine current = startLine; + ISegment startIndent = TextUtilities.GetWhitespaceAfter(document, startLine.Offset); + int lineCount = 0; + while (current != endLine.NextLine && lineCount < maxLineCount) { + ISegment currentIndent = TextUtilities.GetWhitespaceAfter(document, current.Offset); + + if (current == startLine && current == endLine) + builder.Append(document.GetText(startOffset, endOffset - startOffset)); + else if (current == startLine) { + if (current.EndOffset - startOffset > 0) + builder.AppendLine(document.GetText(startOffset, current.EndOffset - startOffset).TrimStart()); + } else if (current == endLine) { + if (startIndent.Length <= currentIndent.Length) + builder.Append(document.GetText(current.Offset + startIndent.Length, endOffset - current.Offset - startIndent.Length)); + else + builder.Append(document.GetText(current.Offset + currentIndent.Length, endOffset - current.Offset - currentIndent.Length)); + } else { + if (startIndent.Length <= currentIndent.Length) + builder.AppendLine(document.GetText(current.Offset + startIndent.Length, current.Length - startIndent.Length)); + else + builder.AppendLine(document.GetText(current.Offset + currentIndent.Length, current.Length - currentIndent.Length)); + } + + current = current.NextLine; + lineCount++; + } + if (current != endLine.NextLine) + builder.Append("..."); + + return builder.ToString(); + } + } +} diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index ee778929a9..8013c235ff 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -171,6 +171,7 @@ ToolTipService.cs + From 07870409a3a5a1840b2f0f1ae3e1af345e7a7fc8 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 10 Aug 2014 16:53:25 +0200 Subject: [PATCH 016/146] use "git add --intent-to-add" --- src/AddIns/VersionControl/GitAddIn/Src/Git.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AddIns/VersionControl/GitAddIn/Src/Git.cs b/src/AddIns/VersionControl/GitAddIn/Src/Git.cs index a7480c487f..d2a0e063fa 100644 --- a/src/AddIns/VersionControl/GitAddIn/Src/Git.cs +++ b/src/AddIns/VersionControl/GitAddIn/Src/Git.cs @@ -59,7 +59,7 @@ namespace ICSharpCode.GitAddIn string wcRoot = FindWorkingCopyRoot(fileName); if (wcRoot == null) return Task.FromResult(false); - return RunGitAsync(wcRoot, "add", AdaptFileName(wcRoot, fileName)); + return RunGitAsync(wcRoot, "add", "--intent-to-add", AdaptFileName(wcRoot, fileName)); } public static Task RemoveAsync(string fileName, bool indexOnly) From 5810bb51e036e13bccc17e78576a99834baee3b5 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 10 Aug 2014 18:22:43 +0200 Subject: [PATCH 017/146] Fix #529: CC item creating an event handler has confusing name 'HandleHandleClick' Because EventCreationCompletionData uses a new SDRefactoringContext with a different compilation, import the delegateType into the new compilation so that CreateShortType() works as expected. --- .../Completion/EventCreationCompletionData.cs | 44 ++++++------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EventCreationCompletionData.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EventCreationCompletionData.cs index 01ab271a64..6c9af001b8 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EventCreationCompletionData.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EventCreationCompletionData.cs @@ -19,6 +19,7 @@ using System; using System.Linq; using System.Threading; +using System.Windows.Controls; using ICSharpCode.SharpDevelop; using CSharpBinding.Parser; using CSharpBinding.Refactoring; @@ -35,46 +36,27 @@ namespace CSharpBinding.Completion /// class EventCreationCompletionData : CompletionData { - IEvent eventDefinition; - string varName; - IType delegateType; - string parameterList; - IUnresolvedMember callingMember; - IUnresolvedTypeDefinition declaringType; - CSharpResolver contextAtCaret; + readonly string handlerName; + readonly ITypeReference delegateTypeReference; + readonly bool isStatic; - public EventCreationCompletionData(string varName, IType delegateType, IEvent evt, string parameterList, IUnresolvedMember callingMember, IUnresolvedTypeDefinition declaringType, CSharpResolver contextAtCaret) + public EventCreationCompletionData(string handlerName, IType delegateType, IEvent evt, string parameterList, IUnresolvedMember callingMember, IUnresolvedTypeDefinition declaringType, CSharpResolver contextAtCaret) { - if (string.IsNullOrEmpty(varName)) { - this.DisplayText = ""; + if (string.IsNullOrEmpty(handlerName)) { + handlerName = (evt != null ? evt.Name : "Handle"); } - else { - this.DisplayText = "Handle" + char.ToUpper(varName[0]) + varName.Substring(1) + (evt != null ? evt.Name : ""); - } - - this.varName = varName; - this.eventDefinition = evt; - this.delegateType = delegateType; - this.parameterList = parameterList; - this.callingMember = callingMember; - this.declaringType = declaringType; - this.contextAtCaret = contextAtCaret; + this.handlerName = handlerName; + this.DisplayText = ""; + this.delegateTypeReference = delegateType.ToTypeReference(); + this.isStatic = callingMember != null && callingMember.IsStatic; } public override void Complete(CompletionContext context) { - var invokeSignature = delegateType.GetMethods(m => m.Name == "Invoke").Single(); var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None); + var delegateType = delegateTypeReference.Resolve(refactoringContext.Compilation); + var invokeSignature = delegateType.GetMethods(m => m.Name == "Invoke").Single(); var builder = refactoringContext.CreateTypeSystemAstBuilder(); - string handlerName; - bool isStatic; - if (eventDefinition != null) { - handlerName = eventDefinition.Name; - isStatic = eventDefinition.IsStatic; - } else { - handlerName = varName; - isStatic = callingMember.IsStatic; - } var throwStatement = new ThrowStatement(); var decl = new MethodDeclaration { From 71e2387f0d91d58be4cba011fece6975ff066b59 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 10 Aug 2014 21:46:55 +0200 Subject: [PATCH 018/146] Fix part of #525 --- .../Project/Src/DesignerViewContent.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs index d96f5f47fc..7713964875 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerViewContent.cs @@ -50,6 +50,7 @@ namespace ICSharpCode.FormsDesigner readonly Control pleaseWaitLabel = new Label() { Text = StringParser.Parse("${res:Global.PleaseWait}"), TextAlign=ContentAlignment.MiddleCenter }; DesignSurface designSurface; bool disposing; + Timer timer = new Timer { Interval = 200 }; readonly IViewContent primaryViewContent; readonly IDesignerLoaderProvider loaderProvider; @@ -142,10 +143,11 @@ namespace ICSharpCode.FormsDesigner this.IsActiveViewContentChanged += this.IsActiveViewContentChangedHandler; + timer.Tick += Timer_Tick; FileService.FileRemoving += this.FileServiceFileRemoving; SD.Debugger.DebugStarting += this.DebugStarting; } - + public FormsDesignerViewContent(IViewContent primaryViewContent, IDesignerLoaderProvider loaderProvider) : this(primaryViewContent) { @@ -168,6 +170,20 @@ namespace ICSharpCode.FormsDesigner this.Files.Add(primaryViewContent.PrimaryFile); } + void Timer_Tick(object sender, System.EventArgs e) + { + // The WinForms designer internally relies on Application.Idle for some actions, e.g. 'Show Code' + // This event does not get raised in a WPF application. + // While we do forward WPF's equivalent idle event to WinForms (see WorkbenchStartup.cs), + // it doesn't happen often enough -- in particular, it doesn't get raised while the mouse + // is over the WinForms design surface. + // This caused the bug: https://github.com/icsharpcode/SharpDevelop/issues/525 + // As a workaround, we use a timer to raise the event while the designer is open. + // Note: this timer is implemented in the WinForms designer and not globally in SharpDevelop + // so that we don't wake up the CPU unnecessarily when the designer is not in use. + Application.RaiseIdle(e); + } + bool inMasterLoadOperation; protected override void LoadInternal(OpenedFile file, System.IO.Stream stream) @@ -344,6 +360,7 @@ namespace ICSharpCode.FormsDesigner UpdatePropertyPad(); hasUnmergedChanges = false; + timer.Start(); LoggingService.Info("Form Designer: END INITIALIZE"); } @@ -404,6 +421,7 @@ namespace ICSharpCode.FormsDesigner { LoggingService.Debug("FormsDesigner unloading, setting ActiveDesignSurface to null"); designSurfaceManager.ActiveDesignSurface = null; + timer.Stop(); bool savedIsDirty = (this.DesignerCodeFile == null) ? false : this.DesignerCodeFile.IsDirty; this.UserContent = this.pleaseWaitLabel; From 4be799023b71f80306fe5ae7d8b128bcafb077e2 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 10 Aug 2014 22:31:43 +0200 Subject: [PATCH 019/146] Fix #533: Use a mutex to prevent concurrent git add/rm calls. --- src/AddIns/VersionControl/GitAddIn/Src/Git.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/AddIns/VersionControl/GitAddIn/Src/Git.cs b/src/AddIns/VersionControl/GitAddIn/Src/Git.cs index d2a0e063fa..48b2f66ff3 100644 --- a/src/AddIns/VersionControl/GitAddIn/Src/Git.cs +++ b/src/AddIns/VersionControl/GitAddIn/Src/Git.cs @@ -18,6 +18,7 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; @@ -79,14 +80,24 @@ namespace ICSharpCode.GitAddIn return relFileName.Replace('\\', '/'); } - public static Task RunGitAsync(string workingDir, params string[] arguments) + static SemaphoreSlim gitMutex = new SemaphoreSlim(1); + + public static async Task RunGitAsync(string workingDir, params string[] arguments) { string git = FindGit(); if (git == null) - return Task.FromResult(9009); - ProcessRunner p = new ProcessRunner(); - p.WorkingDirectory = workingDir; - return p.RunInOutputPadAsync(GitMessageView.Category, git, arguments); + return 9009; + // Wait until other git calls have finished running + // This prevents git from failing due to a locked index when several files + // are added concurrently + await gitMutex.WaitAsync(); + try { + ProcessRunner p = new ProcessRunner(); + p.WorkingDirectory = workingDir; + await p.RunInOutputPadAsync(GitMessageView.Category, git, arguments); + } finally { + gitMutex.Release(); + } } /// From 582d996f284414c86e09de58d533dfef56019a44 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 10 Aug 2014 21:38:56 +0200 Subject: [PATCH 020/146] fix #530: Missing whitespace in XML Doc tooltips --- src/Main/Base/Project/Editor/DocumentationUIBuilder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Main/Base/Project/Editor/DocumentationUIBuilder.cs b/src/Main/Base/Project/Editor/DocumentationUIBuilder.cs index d26efceae3..5934abaa8f 100644 --- a/src/Main/Base/Project/Editor/DocumentationUIBuilder.cs +++ b/src/Main/Base/Project/Editor/DocumentationUIBuilder.cs @@ -453,6 +453,7 @@ namespace ICSharpCode.SharpDevelop.Editor AddBlock(para); } inlineCollection.Add(inline); + ignoreWhitespace = false; } public void AddBlock(Block block) From 2256606360b56a7a87b21fac65dd22275b145991 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 10 Aug 2014 22:29:00 +0200 Subject: [PATCH 021/146] raise FileCreated events for all newly-created files when creating a new solution/project --- src/Main/Base/Project/Templates/ProjectTemplate.cs | 1 + src/Main/SharpDevelop/Templates/Project/ProjectDescriptor.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/Main/Base/Project/Templates/ProjectTemplate.cs b/src/Main/Base/Project/Templates/ProjectTemplate.cs index bd02c5197f..9f27029185 100644 --- a/src/Main/Base/Project/Templates/ProjectTemplate.cs +++ b/src/Main/Base/Project/Templates/ProjectTemplate.cs @@ -70,6 +70,7 @@ namespace ICSharpCode.SharpDevelop.Templates if (SD.ProjectService.OpenSolution(createdSolution)) { solutionOpened = true; SD.GetRequiredService().RaiseSolutionCreated(new SolutionEventArgs(createdSolution)); + FileService.FireFileCreated(solutionFileName, false); return result; } else { return null; diff --git a/src/Main/SharpDevelop/Templates/Project/ProjectDescriptor.cs b/src/Main/SharpDevelop/Templates/Project/ProjectDescriptor.cs index 4b4a49761a..9804a08ef6 100644 --- a/src/Main/SharpDevelop/Templates/Project/ProjectDescriptor.cs +++ b/src/Main/SharpDevelop/Templates/Project/ProjectDescriptor.cs @@ -514,6 +514,7 @@ namespace ICSharpCode.SharpDevelop.Templates file.SetProjectItemProperties(projectFile); project.Items.Add(projectFile); + FileService.FireFileCreated(fileName, false); } } @@ -535,6 +536,7 @@ namespace ICSharpCode.SharpDevelop.Templates project.ProjectLoaded(); SD.GetRequiredService().RaiseProjectCreated(new ProjectEventArgs(project)); + FileService.FireFileCreated(project.FileName, false); templateResults.NewProjects.Add(project); success = true; return true; From 8ae347fd0ae218d2f2fff853dec2a4859165cd5b Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 10 Aug 2014 22:43:13 +0200 Subject: [PATCH 022/146] Fix build. --- src/AddIns/VersionControl/GitAddIn/Src/Git.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AddIns/VersionControl/GitAddIn/Src/Git.cs b/src/AddIns/VersionControl/GitAddIn/Src/Git.cs index 48b2f66ff3..8c2740fbe7 100644 --- a/src/AddIns/VersionControl/GitAddIn/Src/Git.cs +++ b/src/AddIns/VersionControl/GitAddIn/Src/Git.cs @@ -94,7 +94,7 @@ namespace ICSharpCode.GitAddIn try { ProcessRunner p = new ProcessRunner(); p.WorkingDirectory = workingDir; - await p.RunInOutputPadAsync(GitMessageView.Category, git, arguments); + return await p.RunInOutputPadAsync(GitMessageView.Category, git, arguments); } finally { gitMutex.Release(); } From a1fd70e664f1be2fa77b47ecd20a4be9c7e31971 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Mon, 11 Aug 2014 20:46:07 +0200 Subject: [PATCH 023/146] PushDataWizard --- .../ICSharpCode.Reporting.Addin.csproj | 11 ++++++ .../ReportWizard/Dialog/BaseSettingsPage.xaml | 39 ++++++++++++------- .../Dialog/BaseSettingsPage.xaml.cs | 31 ++++++++++++--- .../ReportWizard/Dialog/PushDataReport.xaml | 33 ++++++++++++++++ .../src/ReportWizard/Dialog/ReportWizard.xaml | 32 +++++++++++---- .../ReportWizard/Dialog/ReportWizard.xaml.cs | 11 ++++-- .../src/ReportWizard/Dialog/WelcomePage.xaml | 18 +++++++++ .../src/ReportWizard/WizardHelper.cs | 25 ++++++++++++ .../Src/BaseClasses/AbstractColumn.cs | 6 +-- 9 files changed, 172 insertions(+), 34 deletions(-) create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/WelcomePage.xaml create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/WizardHelper.cs diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj index c1cdc982e4..9fec4e1330 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj @@ -150,14 +150,23 @@ BaseSettingsPage.xaml Code + + PushDataReport.xaml + Code + ReportWizard.xaml Code + + WelcomePage.xaml + Code + + @@ -230,7 +239,9 @@ + + \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml index 3fd65a42db..4f200abc5b 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml @@ -4,11 +4,17 @@ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:sdr="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Reporting" - + Name="Base" Title="Base Settings" Description="Basic Settings and Layout" + PageType="Interior" Background="LightGray" - CanFinish="true"> + CanFinish="true" + CanSelectNextPage="false"> + + + + - + @@ -40,34 +46,37 @@ - + - + - + - - + + - - + + - - - + + + + + \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs index 191c6cb858..ec357aff60 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs @@ -7,8 +7,14 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; using System.Windows; +using System.Windows.Controls; +using System.Windows.Media.Imaging; using ICSharpCode.Reporting.Globals; +using ICSharpCode.SharpDevelop; using Xceed.Wpf.Toolkit; using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; @@ -26,9 +32,11 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog{ InitializeComponent(); _DataModel.SelectedItem = PushPullModel.FormSheet; _ReportType.SelectedItem = ReportType.FormSheet; - this.context = new PageOneContext(); + this.context = new PageOneContext(); + this._DataModel.SelectedItem = PushPullModel.FormSheet; + _image.Source = WizardHelper.GetWizardIcon(); } - + public IWizardContext Context { get{ @@ -41,16 +49,29 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog{ } - void UpdateContext() - { + void UpdateContext(){ context.DataModel = (PushPullModel) _DataModel.SelectedItem; context.ReportType = (ReportType) _ReportType.SelectedItem; context.ReportName = this._ReportName.Text; context.FileName = this._Filename.Text; context.Legal = _Legal.IsChecked == true; - ; context.Landscape = _Landscape.IsChecked == true; } + + + void _DataModel_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e){ + var cbo = (ComboBox) sender; + + if (((PushPullModel)cbo.SelectedItem) == PushPullModel.FormSheet) { + this.CanFinish = true; + this.CanSelectNextPage = false; + this._ReportType.SelectedItem = ReportType.FormSheet; + } else { + this._ReportType.SelectedItem = ReportType.DataReport; + this.CanFinish = false; + this.CanSelectNextPage = true; + } + } } } \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml new file mode 100644 index 0000000000..4d17ce77b6 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml index 59ba6244b3..4632743569 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml @@ -4,25 +4,41 @@ xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:local="clr-namespace:ICSharpCode.Reporting.Addin.ReportWizard.Dialog" Title="{Binding Title}" - Height="600" Width="600"> + Height="600" Width="800"> + + + + + + + + + + + --> + - - + + + - - - - - - - - - \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs index 448dcceea5..19489041ab 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs @@ -12,6 +12,7 @@ using System.Drawing.Imaging; using System.IO; using System.Windows; using System.Windows.Media.Imaging; +using ICSharpCode.Reporting.Globals; using ICSharpCode.SharpDevelop; using Xceed.Wpf.Toolkit; using ICSharpCode.Reporting.Addin.ReportWizard.Dialog; @@ -46,7 +47,6 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog void UpdateContext(IHasContext hc) { - switch (hc.ReportPageType) { case WizardPageType.BaseSettingsPage:{ context.PageOneContext = hc.Context; @@ -59,5 +59,39 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog } } } + + + void _wizard_Next(object sender, Xceed.Wpf.Toolkit.Core.CancelRoutedEventArgs e) + { + var current = this._wizard.CurrentPage; + if (current.Name.Equals("BaseSettings")) { + var hasContext = current as IHasContext; + if (hasContext != null) { + var pushPullModel = ((PageOneContext)hasContext.Context).DataModel; + switch (pushPullModel) { + case PushPullModel.PushData: { + current.NextPage = (WizardPage)_wizard.Items[2]; + break; + } + + case PushPullModel.PullData: { + current.NextPage = (WizardPage)_wizard.Items[3]; + break; + } + + case PushPullModel.FormSheet: { + break; + } + } + } + } + + Console.WriteLine("CurrentPage {0}",current.Name); + + } + void _wizard_PageChanged(object sender, RoutedEventArgs e) + { + var x = _wizard.CurrentPage; + } } } \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/WelcomePage.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/WelcomePage.xaml index d1ac41d115..83b4d4a1e4 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/WelcomePage.xaml +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/WelcomePage.xaml @@ -13,6 +13,9 @@ CancelButtonVisibility="Visible"> - + + + + \ No newline at end of file From 2a0600761d347629da7ae89be62f1370879eb554 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Fri, 22 Aug 2014 23:03:09 +0200 Subject: [PATCH 052/146] Update WizardPages --- .../ReportWizard/Dialog/BaseSettingsPage.xaml | 9 +++--- .../Dialog/BaseSettingsPage.xaml.cs | 4 +-- .../src/ReportWizard/Dialog/ReportWizard.xaml | 14 +++----- .../ReportWizard/Dialog/ReportWizard.xaml.cs | 10 ++---- .../src/ReportWizard/Dialog/WelcomePage.xaml | 18 +++++++---- .../src/ReportWizard/ReportGenerator.cs | 32 +++++++++++++++---- .../Src/Items/ReportSettings.cs | 13 +++----- .../Src/Wpf/Visitor/FixedDocumentCreator.cs | 1 - 8 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml index 77b5cb1baf..94bcfec0b7 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml @@ -6,14 +6,13 @@ xmlns:sdr="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Reporting" Title="Base Settings" Description="Basic Settings and Layout" - PageType="Interior" - Background="LightGray" + PageType="Interior" CanFinish="true" CanSelectNextPage="false"> - - - + - + - + - + - + - \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs index 19489041ab..bcb53c0d1f 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/ReportWizard.xaml.cs @@ -7,13 +7,8 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; -using System.Drawing; -using System.Drawing.Imaging; -using System.IO; using System.Windows; -using System.Windows.Media.Imaging; using ICSharpCode.Reporting.Globals; -using ICSharpCode.SharpDevelop; using Xceed.Wpf.Toolkit; using ICSharpCode.Reporting.Addin.ReportWizard.Dialog; using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; @@ -85,10 +80,9 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog } } } - - Console.WriteLine("CurrentPage {0}",current.Name); - } + + void _wizard_PageChanged(object sender, RoutedEventArgs e) { var x = _wizard.CurrentPage; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/WelcomePage.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/WelcomePage.xaml index 83b4d4a1e4..d464312050 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/WelcomePage.xaml +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/WelcomePage.xaml @@ -1,4 +1,4 @@ - - - - - + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs index b9787e1cd8..2c01bb8749 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs @@ -34,11 +34,27 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard public void Generate(ReportWizardContext context) { if (context == null) throw new ArgumentNullException("context"); + + var poc = (PageOneContext)context.PageOneContext; + if (IsDataReport(poc)) { + CreateDataReport (context); + } else { + CreateFormSheetReport(context); + } + } + + void CreateFormSheetReport(ReportWizardContext context) + { GenerateBaseSettings(context); - GeneratePushModel(context); CreateReportHeader(context); } - + + void CreateDataReport(ReportWizardContext context) + { + GenerateBaseSettings(context); + CreateReportHeader(context); + GeneratePushModel(context); + } void GenerateBaseSettings (ReportWizardContext context) { var pageOneContext = (PageOneContext)context.PageOneContext; @@ -51,6 +67,7 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard } + void GeneratePushModel(ReportWizardContext context){ var pushModelContext = (PushModelContext)context.PushModelContext; var xLocation = 5; @@ -83,14 +100,17 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard headerText.Size = GlobalValues.PreferedSize; var printableWith = ReportModel.ReportSettings.PageSize.Width - ReportModel.ReportSettings.LeftMargin - ReportModel.ReportSettings.RightMargin; - var x = (int)(printableWith - headerText.Size.Width) / 2; + var x = (int)(printableWith - headerText.Size.Width) / 2; headerText.Location = new Point(x,4); ReportModel.ReportHeader.Items.Add(headerText); - Console.WriteLine(""); - Console.WriteLine("Createreportheader Size {0}",ReportModel.ReportHeader.Size); + + } + + static bool IsDataReport(PageOneContext poc) + { + return poc.ReportType.Equals(ReportType.DataReport); } - public IReportModel ReportModel {get;private set;} } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs index ac960a1dd2..c10f13ffe3 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs @@ -82,14 +82,15 @@ namespace ICSharpCode.Reporting.Items SortColumnsCollection = new SortColumnCollection(); GroupColumnsCollection = new GroupColumnCollection(); -// this.sqlParameters = new SqlParameterCollection(); ParameterCollection = new ParameterCollection(); +// this.sqlParameters = new SqlParameterCollection(); + // this.NoDataMessage = "No Data for this Report"; } #region BaseSettings - private string reportName; + string reportName; [Category("Base Settings")] [DefaultValueAttribute ("")] @@ -154,7 +155,7 @@ namespace ICSharpCode.Reporting.Items public int RightMargin {get;set;} - private Size pageSize; + Size pageSize; [Category("Page Settings")] public Size PageSize { @@ -177,14 +178,8 @@ namespace ICSharpCode.Reporting.Items #region - // [Category("Data")] - - - - - // [Category("Parameters")] // [EditorAttribute ( typeof(ParameterCollectionEditor), // typeof(System.Drawing.Design.UITypeEditor) )] diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/FixedDocumentCreator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/FixedDocumentCreator.cs index 13524e669d..b91b31deee 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/FixedDocumentCreator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/FixedDocumentCreator.cs @@ -64,7 +64,6 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor { var culture = CultureInfo.CurrentCulture; var flowDirection = culture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; - var emSize = ExtensionMethodes.ToPoints((int)exportText.Font.SizeInPoints +1); var formattedText = new FormattedText(exportText.Text, From 6c2f0f432053ef4ab7b7e7d8183ff3c3d9f3b73d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 23 Aug 2014 10:57:33 +0200 Subject: [PATCH 053/146] Avoid unnecessary access to entity.Documentation. Improves code completion performance. --- .../Project/Src/Completion/EntityCompletionData.cs | 3 ++- .../Project/Src/Completion/TypeCompletionData.cs | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs index 65ea84fc1b..9eee9b02f4 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs @@ -37,8 +37,9 @@ namespace CSharpBinding.Completion public EntityCompletionData(IEntity entity) : base(entity.Name) { this.entity = entity; - this.Description = entity.Documentation; this.Image = ClassBrowserIconService.GetIcon(entity); + // don't set this.Description -- we use CreateFancyDescription() instead, + // and accessing entity.Documentation in the constructor is too slow } protected override object CreateFancyDescription() diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/TypeCompletionData.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/TypeCompletionData.cs index e2351811c4..dcedf8519d 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/TypeCompletionData.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/TypeCompletionData.cs @@ -35,10 +35,9 @@ namespace CSharpBinding.Completion public TypeCompletionData(IType type) : base(type.Name) { this.type = type; - ITypeDefinition typeDef = type.GetDefinition(); - if (typeDef != null) - this.Description = typeDef.Documentation; this.Image = ClassBrowserIconService.GetIcon(type); + // don't set this.Description -- we use CreateFancyDescription() instead, + // and accessing entity.Documentation in the constructor is too slow } protected override object CreateFancyDescription() From a0d84c9cc88584773f84590c21152b5dbf60abbb Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Aug 2014 08:13:32 +0200 Subject: [PATCH 054/146] fix bug in code completion: space should trigger insertion --- .../Project/Src/Services/ParserService/CodeCompletionOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main/Base/Project/Src/Services/ParserService/CodeCompletionOptions.cs b/src/Main/Base/Project/Src/Services/ParserService/CodeCompletionOptions.cs index 730bb2ac95..61c81972e7 100644 --- a/src/Main/Base/Project/Src/Services/ParserService/CodeCompletionOptions.cs +++ b/src/Main/Base/Project/Src/Services/ParserService/CodeCompletionOptions.cs @@ -84,7 +84,7 @@ namespace ICSharpCode.SharpDevelop } public static string CompletionCharList { - get { return properties.Get("CompletionCharList", @"{}[]().,:;+-*/%&|^!~=<>?@#'""\"); } + get { return properties.Get("CompletionCharList", @" {}[]().,:;+-*/%&|^!~=<>?@#'""\"); } set { properties.Set("CompletionCharList", value); } } From 4170e41ea8af3edd4ac2b4f8fcc523b7df4eb9b9 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Aug 2014 08:21:04 +0200 Subject: [PATCH 055/146] fix #542: Code completion window description tooltip missing --- .../CodeCompletion/CompletionWindow.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindow.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindow.cs index 3a81b86a0f..bf1c8ac678 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindow.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindow.cs @@ -64,8 +64,6 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion } #region ToolTip handling - public bool ShowDocumentationTooltips { get; set; } - void toolTip_Closed(object sender, RoutedEventArgs e) { // Clear content after tooltip is closed. @@ -77,11 +75,6 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion void completionList_SelectionChanged(object sender, SelectionChangedEventArgs e) { - if (!ShowDocumentationTooltips) { - toolTip.IsOpen = false; - return; - } - var item = completionList.SelectedItem; if (item == null) return; From d41e13e16434fa55ed9a17fb911cb3ef74f6e5ac Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Aug 2014 11:40:28 +0200 Subject: [PATCH 056/146] fix #543: Ctrl+Space Code completion description tooltip for classes should include namespace name --- .../Project/Src/Completion/EntityCompletionData.cs | 2 +- .../CSharpBinding/Project/Src/Completion/TypeCompletionData.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs index 9eee9b02f4..16d627ef43 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EntityCompletionData.cs @@ -45,7 +45,7 @@ namespace CSharpBinding.Completion protected override object CreateFancyDescription() { return new FlowDocumentScrollViewer { - Document = XmlDocFormatter.CreateTooltip(entity, false), + Document = XmlDocFormatter.CreateTooltip(entity, entity is ITypeDefinition), VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; } diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/TypeCompletionData.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/TypeCompletionData.cs index dcedf8519d..a60836e910 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/TypeCompletionData.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/TypeCompletionData.cs @@ -43,7 +43,7 @@ namespace CSharpBinding.Completion protected override object CreateFancyDescription() { return new FlowDocumentScrollViewer { - Document = XmlDocFormatter.CreateTooltip(type, false), + Document = XmlDocFormatter.CreateTooltip(type), VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; } From 2bdddf31366acc674968fb3f2f34210974fd4fe6 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Aug 2014 14:11:04 +0200 Subject: [PATCH 057/146] add special handling for enum member completion data --- .../Project/CSharpBinding.csproj | 1 + .../Completion/CSharpCompletionDataFactory.cs | 3 +- .../Completion/EnumMemberCompletionData.cs | 52 +++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EnumMemberCompletionData.cs diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj b/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj index 970be27a88..848785d6fb 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj @@ -78,6 +78,7 @@ + diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs index c3f005e892..9396dc084c 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/CSharpCompletionDataFactory.cs @@ -86,8 +86,7 @@ namespace CSharpBinding.Completion ICompletionData ICompletionDataFactory.CreateMemberCompletionData(IType type, IEntity member) { - string typeName = builder.ConvertType(type).ToString(); - return new CompletionData(typeName + "." + member.Name); + return new EnumMemberCompletionData(type, member, builder); } ICompletionData ICompletionDataFactory.CreateLiteralCompletionData(string title, string description, string insertText) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EnumMemberCompletionData.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EnumMemberCompletionData.cs new file mode 100644 index 0000000000..9d0b2c9d33 --- /dev/null +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EnumMemberCompletionData.cs @@ -0,0 +1,52 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Linq; +using System.Windows.Controls; +using ICSharpCode.NRefactory.CSharp.Refactoring; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Editor; +namespace CSharpBinding.Completion +{ + class EnumMemberCompletionData : CompletionData + { + IType enumType; + + IEntity member; + + public EnumMemberCompletionData(IType enumType, IEntity member, TypeSystemAstBuilder builder) : base(enumType.Name + "." + member.Name) + { + this.enumType = enumType; + this.member = member; + this.Image = ClassBrowserIconService.Const; + this.CompletionText = builder.ConvertType(enumType).ToString() + "." + member.Name; + } + + protected override object CreateFancyDescription() + { + return new FlowDocumentScrollViewer { + Document = XmlDocFormatter.CreateTooltip(member, false), + VerticalScrollBarVisibility = ScrollBarVisibility.Auto + }; + } + } +} + + From a81b6c234937c4b17fc906bf91a6c52529bb1e88 Mon Sep 17 00:00:00 2001 From: julodnik Date: Sun, 29 Jun 2014 14:06:13 +0200 Subject: [PATCH 058/146] Add Underline attribute in syntax highlighting --- data/resources/StringResources.resx | 3 +++ .../Src/CustomizedHighlightingColor.cs | 1 + .../Src/Options/CustomizedHighlightingItem.cs | 17 ++++++++++++++--- .../Src/Options/HighlightingOptions.xaml | 2 ++ .../Src/Options/IHighlightingItem.cs | 5 +++++ .../Src/Options/NamedColorHighlightingItem.cs | 16 +++++++++++++++- .../Src/Options/SimpleHighlightingItem.cs | 1 + .../CustomizingHighlighter.cs | 3 ++- .../Src/View/HexEditOptionsPanel.xaml.cs | 2 ++ .../Highlighting/HighlightedInlineBuilder.cs | 2 +- .../Highlighting/HighlightingColor.cs | 15 +++++++++++++++ .../Highlighting/HighlightingColorizer.cs | 8 ++++++-- .../Highlighting/Xshd/V2Loader.cs | 1 + .../Xshd/XmlHighlightingDefinition.cs | 1 + .../Highlighting/Xshd/XshdColor.cs | 8 ++++++++ 15 files changed, 77 insertions(+), 8 deletions(-) diff --git a/data/resources/StringResources.resx b/data/resources/StringResources.resx index 0be935f412..0fd83c63fb 100644 --- a/data/resources/StringResources.resx +++ b/data/resources/StringResources.resx @@ -1729,6 +1729,9 @@ Examples: "120", "MainClass", "Main.cs, 120". Italic + + Underlined + Export highlighting colors diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingColor.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingColor.cs index a5df6f78c6..c113ed576c 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingColor.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CustomizedHighlightingColor.cs @@ -43,6 +43,7 @@ namespace ICSharpCode.AvalonEdit.AddIn public bool Bold { get; set; } public bool Italic { get; set; } + public bool Underline { get; set; } public Color? Foreground { get; set; } public Color? Background { get; set; } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CustomizedHighlightingItem.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CustomizedHighlightingItem.cs index ce076196b5..e18c5be58a 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CustomizedHighlightingItem.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/CustomizedHighlightingItem.cs @@ -66,6 +66,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options { OnPropertyChanged("Bold"); OnPropertyChanged("Italic"); + OnPropertyChanged("Underline"); OnPropertyChanged("Foreground"); OnPropertyChanged("UseDefaultForeground"); OnPropertyChanged("Background"); @@ -73,7 +74,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options OnPropertyChanged("IsCustomized"); } - void SetCustomization(bool? bold = null, bool? italic = null, + void SetCustomization(bool? bold = null, bool? italic = null, bool? underline = null, Color? foreground = null, bool? useDefaultForeground = null, Color? background = null, bool? useDefaultBackground = null) { @@ -82,6 +83,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options newColor.Name = this.Name; newColor.Bold = bold ?? this.Bold; newColor.Italic = italic ?? this.Italic; + newColor.Underline = underline ?? this.Underline; if (useDefaultBackground ?? this.UseDefaultBackground) newColor.Background = null; @@ -99,7 +101,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options else if (customization != null) customizationList.Remove(customization); - if (newColor.Bold == original.Bold && newColor.Italic == original.Italic && + if (newColor.Bold == original.Bold && newColor.Italic == original.Italic && newColor.Underline == original.Underline && (newColor.Background == null) == original.UseDefaultBackground && (newColor.Background == null || newColor.Background == original.Background) && (newColor.Foreground == null) == original.UseDefaultForeground && @@ -140,6 +142,15 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options } } + public bool Underline { + get { + return (customization != null) ? customization.Underline : original.Underline; + } + set { + SetCustomization(underline: value); + } + } + public Color Foreground { get { return (customization != null) ? (customization.Foreground ?? original.Foreground) : original.Foreground; @@ -191,7 +202,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options public void Reset() { original.Reset(); - SetCustomization(original.Bold, original.Italic, original.Foreground, original.UseDefaultForeground, original.Background, original.UseDefaultBackground); + SetCustomization(original.Bold, original.Italic, original.Underline, original.Foreground, original.UseDefaultForeground, original.Background, original.UseDefaultBackground); AllPropertiesChanged(); } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml index 93508d4370..b78fff3c35 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml @@ -44,6 +44,8 @@ Content="{core:Localize Dialog.HighlightingEditor.ColorDlg.Bold}"/> + bool Italic { get; set; } + /// + /// Gets/Sets whether the element uses an underlined font. + /// + bool Underline { get; set; } + Color Foreground { get; set; } bool UseDefaultForeground { get; set; } Color Background { get; set; } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs index c2e158f526..5bc0f4cd7f 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs @@ -68,6 +68,15 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options } } + public bool Underline { + get { + return color.Underline; + } + set { + throw new NotSupportedException(); + } + } + public Color Foreground { get { Color? c = color.Foreground != null ? color.Foreground.GetColor(null) : null; @@ -161,7 +170,12 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options marker.ForegroundColor = item.Foreground; marker.FontStyle = item.Italic ? FontStyles.Italic : FontStyles.Normal; marker.FontWeight = item.Bold ? FontWeights.Bold : FontWeights.Normal; - }); + if(item.Underline) + { + marker.MarkerColor = item.Foreground; + marker.MarkerTypes = TextMarkerTypes.NormalUnderline; + } + }); } } else { exampleTextArea.Document.Text = exampleText; diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/SimpleHighlightingItem.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/SimpleHighlightingItem.cs index 99376357d7..8c165207ec 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/SimpleHighlightingItem.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/SimpleHighlightingItem.cs @@ -40,6 +40,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options public string Name { get; private set; } public bool Bold { get; set; } public bool Italic { get; set; } + public bool Underline { get; set; } public Color Foreground { get; set; } public bool UseDefaultForeground { get; set; } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/CustomizingHighlighter.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/CustomizingHighlighter.cs index 0ababb9de6..8f70e0b457 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/CustomizingHighlighter.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SyntaxHighlighting/CustomizingHighlighter.cs @@ -267,7 +267,8 @@ namespace ICSharpCode.AvalonEdit.AddIn Background = CreateBrush(customization.Background), Foreground = CreateBrush(customization.Foreground), FontWeight = customization.Bold ? FontWeights.Bold : FontWeights.Normal, - FontStyle = customization.Italic ? FontStyles.Italic : FontStyles.Normal + FontStyle = customization.Italic ? FontStyles.Italic : FontStyles.Normal, + Underline = customization.Underline }; } } diff --git a/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditOptionsPanel.xaml.cs b/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditOptionsPanel.xaml.cs index f1978f6747..8026d1672c 100644 --- a/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditOptionsPanel.xaml.cs +++ b/src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditOptionsPanel.xaml.cs @@ -103,6 +103,8 @@ namespace HexEditor.View preview.FontWeight = FontWeights.Bold; else preview.FontWeight = FontWeights.Normal; + if (font.Underline) + preview.TextDecorations = TextDecorations.Underline; } } } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs index e5f2e24bba..97ada1628a 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightedInlineBuilder.cs @@ -113,7 +113,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting { if (color == null) throw new ArgumentNullException("color"); - if (color.Foreground == null && color.Background == null && color.FontStyle == null && color.FontWeight == null) { + if (color.Foreground == null && color.Background == null && color.FontStyle == null && color.FontWeight == null && color.Underline == null) { // Optimization: don't split the HighlightingState when we're not changing // any property. For example, the "Punctuation" color in C# is // empty by default. diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs index f8f13182a7..2acaf80a8d 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs @@ -38,6 +38,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting string name; FontWeight? fontWeight; FontStyle? fontStyle; + bool? underline; HighlightingBrush foreground; HighlightingBrush background; bool frozen; @@ -84,6 +85,20 @@ namespace ICSharpCode.AvalonEdit.Highlighting } } + /// + /// Gets/sets the underline flag. Null if the underline status does not change the font style. + /// + public bool? Underline { + get { + return underline; + } + set { + if (frozen) + throw new InvalidOperationException(); + underline = value; + } + } + /// /// Gets/sets the foreground color applied by the highlighting. /// diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs index 68a625745e..10527b3843 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs @@ -18,6 +18,7 @@ using System; using System.Diagnostics; +using System.Windows; using System.Windows.Media; using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Rendering; @@ -231,7 +232,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting if (color == null) return true; return color.Background == null && color.Foreground == null - && color.FontStyle == null && color.FontWeight == null; + && color.FontStyle == null && color.FontWeight == null + && color.Underline == null; } /// @@ -254,7 +256,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting if (b != null) element.BackgroundBrush = b; } - if (color.FontStyle != null || color.FontWeight != null) { + if (color.FontStyle != null || color.FontWeight != null || color.Underline != null) { Typeface tf = element.TextRunProperties.Typeface; element.TextRunProperties.SetTypeface(new Typeface( tf.FontFamily, @@ -263,6 +265,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting tf.Stretch )); } + if(color.Underline ?? false) + element.TextRunProperties.SetTextDecorations(TextDecorations.Underline); } /// diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs index 7a239d8196..70b2539dc8 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs @@ -297,6 +297,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd color.Background = ParseColor(position, reader.GetAttribute("background")); color.FontWeight = ParseFontWeight(reader.GetAttribute("fontWeight")); color.FontStyle = ParseFontStyle(reader.GetAttribute("fontStyle")); + color.Underline = reader.GetAttribute("underline") == "true"; return color; } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs index 62128c81fa..9743277ba8 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XmlHighlightingDefinition.cs @@ -204,6 +204,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd c.Name = color.Name; c.Foreground = color.Foreground; c.Background = color.Background; + c.Underline = color.Underline; c.FontStyle = color.FontStyle; c.FontWeight = color.FontWeight; return c; diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs index 3812a57e71..7ec202641e 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs @@ -49,6 +49,11 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd /// public FontWeight? FontWeight { get; set; } + /// + /// Gets/sets the underline flag + /// + public bool Underline { get; set; } + /// /// Gets/sets the font style. /// @@ -81,6 +86,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd if (info.GetBoolean("HasStyle")) this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style")); this.ExampleText = info.GetString("ExampleText"); + this.Underline = info.GetBoolean("Underline"); } /// @@ -99,6 +105,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd info.AddValue("Foreground", this.Foreground); info.AddValue("Background", this.Background); info.AddValue("HasWeight", this.FontWeight.HasValue); + if (this.Underline) + info.AddValue("Underline", this.Underline); if (this.FontWeight.HasValue) info.AddValue("Weight", this.FontWeight.Value.ToOpenTypeWeight()); info.AddValue("HasStyle", this.FontStyle.HasValue); From fe37b3b004ee87cda47da7c4bbd5da73d79c51ef Mon Sep 17 00:00:00 2001 From: julodnik Date: Fri, 11 Jul 2014 22:37:00 +0200 Subject: [PATCH 059/146] Some small fixes --- .../Highlighting/HighlightingColorizer.cs | 2 +- .../ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs index 10527b3843..6867f87c24 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColorizer.cs @@ -256,7 +256,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting if (b != null) element.BackgroundBrush = b; } - if (color.FontStyle != null || color.FontWeight != null || color.Underline != null) { + if (color.FontStyle != null || color.FontWeight != null) { Typeface tf = element.TextRunProperties.Typeface; element.TextRunProperties.SetTypeface(new Typeface( tf.FontFamily, diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd index 047ef38a19..171a1eb88d 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd @@ -24,6 +24,7 @@ + @@ -35,6 +36,7 @@ + From a5fee39851fdbc050ff42b8b2aa8d1db5dad243a Mon Sep 17 00:00:00 2001 From: julodnik Date: Fri, 11 Jul 2014 22:43:55 +0200 Subject: [PATCH 060/146] Fixed mixed tab and spaces --- .../ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs | 4 ++-- .../ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs index 2acaf80a8d..163444c111 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs @@ -88,8 +88,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting /// /// Gets/sets the underline flag. Null if the underline status does not change the font style. /// - public bool? Underline { - get { + public bool? Underline { + get { return underline; } set { diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs index 7ec202641e..5213eeee34 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs @@ -106,7 +106,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd info.AddValue("Background", this.Background); info.AddValue("HasWeight", this.FontWeight.HasValue); if (this.Underline) - info.AddValue("Underline", this.Underline); + info.AddValue("Underline", this.Underline); if (this.FontWeight.HasValue) info.AddValue("Weight", this.FontWeight.Value.ToOpenTypeWeight()); info.AddValue("HasStyle", this.FontStyle.HasValue); From 293edbf7310a0bf71a4339349947d4cd8e787183 Mon Sep 17 00:00:00 2001 From: julodnik Date: Fri, 11 Jul 2014 22:50:35 +0200 Subject: [PATCH 061/146] Still a wrong indentation (spaces instead of tabs) --- .../ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd index 171a1eb88d..1a9c463960 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd @@ -36,7 +36,7 @@ - + From 8ace2341fb6babcb202708c8d887ffb913142a3e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 23 Aug 2014 14:06:05 +0200 Subject: [PATCH 062/146] Fix bugs in #505 --- .../Src/Options/NamedColorHighlightingItem.cs | 2 +- .../Highlighting/HighlightingColor.cs | 26 +++++++++++++++---- .../Highlighting/Resources/ModeV2.xsd | 1 - .../Highlighting/Xshd/V2Loader.cs | 2 +- .../Highlighting/Xshd/XshdColor.cs | 10 ++++--- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs index 5bc0f4cd7f..e5176fdc80 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/NamedColorHighlightingItem.cs @@ -70,7 +70,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options public bool Underline { get { - return color.Underline; + return color.Underline == true; } set { throw new NotSupportedException(); diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs index 163444c111..6dfb652d05 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HighlightingColor.cs @@ -86,8 +86,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting } /// - /// Gets/sets the underline flag. Null if the underline status does not change the font style. - /// + /// Gets/sets the underline flag. Null if the underline status does not change the font style. + /// public bool? Underline { get { return underline; @@ -97,7 +97,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting throw new InvalidOperationException(); underline = value; } - } + } /// /// Gets/sets the foreground color applied by the highlighting. @@ -146,6 +146,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting this.FontWeight = System.Windows.FontWeight.FromOpenTypeWeight(info.GetInt32("Weight")); if (info.GetBoolean("HasStyle")) this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style")); + if (info.GetBoolean("HasUnderline")) + this.Underline = info.GetBoolean("Underline"); this.Foreground = (HighlightingBrush)info.GetValue("Foreground", typeof(HighlightingBrush)); this.Background = (HighlightingBrush)info.GetValue("Background", typeof(HighlightingBrush)); } @@ -169,6 +171,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting info.AddValue("HasStyle", this.FontStyle.HasValue); if (this.FontStyle.HasValue) info.AddValue("Style", this.FontStyle.Value.ToString()); + info.AddValue("HasUnderline", this.Underline.HasValue); + if (this.Underline.HasValue) + info.AddValue("Underline", this.Underline.Value); info.AddValue("Foreground", this.Foreground); info.AddValue("Background", this.Background); } @@ -196,6 +201,12 @@ namespace ICSharpCode.AvalonEdit.Highlighting b.Append(FontStyle.Value.ToString().ToLowerInvariant()); b.Append("; "); } + if (Underline != null) + { + b.Append("text-decoration: "); + b.Append(Underline.Value ? "underline" : "none"); + b.Append("; "); + } return b.ToString(); } @@ -247,7 +258,9 @@ namespace ICSharpCode.AvalonEdit.Highlighting { if (other == null) return false; - return this.name == other.name && this.fontWeight == other.fontWeight && this.fontStyle == other.fontStyle && object.Equals(this.foreground, other.foreground) && object.Equals(this.background, other.background); + return this.name == other.name && this.fontWeight == other.fontWeight + && this.fontStyle == other.fontStyle && this.underline == other.underline + && object.Equals(this.foreground, other.foreground) && object.Equals(this.background, other.background); } /// @@ -282,11 +295,14 @@ namespace ICSharpCode.AvalonEdit.Highlighting this.foreground = color.foreground; if (color.background != null) this.background = color.background; + if (color.underline != null) + this.underline = color.underline; } internal bool IsEmptyForMerge { get { - return fontWeight == null && fontStyle == null && foreground == null && background == null; + return fontWeight == null && fontStyle == null && underline == null + && foreground == null && background == null; } } } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd index 1a9c463960..c2e242ac28 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Resources/ModeV2.xsd @@ -24,7 +24,6 @@ - diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs index 70b2539dc8..b9b81d1dec 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/V2Loader.cs @@ -297,7 +297,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd color.Background = ParseColor(position, reader.GetAttribute("background")); color.FontWeight = ParseFontWeight(reader.GetAttribute("fontWeight")); color.FontStyle = ParseFontStyle(reader.GetAttribute("fontStyle")); - color.Underline = reader.GetAttribute("underline") == "true"; + color.Underline = reader.GetBoolAttribute("underline"); return color; } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs index 5213eeee34..a6968508b8 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/Xshd/XshdColor.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd /// /// Gets/sets the underline flag /// - public bool Underline { get; set; } + public bool? Underline { get; set; } /// /// Gets/sets the font style. @@ -86,7 +86,8 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd if (info.GetBoolean("HasStyle")) this.FontStyle = (FontStyle?)new FontStyleConverter().ConvertFromInvariantString(info.GetString("Style")); this.ExampleText = info.GetString("ExampleText"); - this.Underline = info.GetBoolean("Underline"); + if (info.GetBoolean("HasUnderline")) + this.Underline = info.GetBoolean("Underline"); } /// @@ -104,9 +105,10 @@ namespace ICSharpCode.AvalonEdit.Highlighting.Xshd info.AddValue("Name", this.Name); info.AddValue("Foreground", this.Foreground); info.AddValue("Background", this.Background); + info.AddValue("HasUnderline", this.Underline.HasValue); + if (this.Underline.HasValue) + info.AddValue("Underline", this.Underline.Value); info.AddValue("HasWeight", this.FontWeight.HasValue); - if (this.Underline) - info.AddValue("Underline", this.Underline); if (this.FontWeight.HasValue) info.AddValue("Weight", this.FontWeight.Value.ToOpenTypeWeight()); info.AddValue("HasStyle", this.FontStyle.HasValue); From c62179725a20f5c9d2c4c500032fbff051d147e3 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Aug 2014 14:40:27 +0200 Subject: [PATCH 063/146] fix #541: Allow configuring color for interfaces (etc.) in C# semantic highlighting --- .../CSharpBinding/Project/Resources/CSharp-Semantic.xshd | 4 ++++ .../Project/Src/CSharpSemanticHighlighterVisitor.cs | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Resources/CSharp-Semantic.xshd b/src/AddIns/BackendBindings/CSharpBinding/Project/Resources/CSharp-Semantic.xshd index 157dc9e717..3e1bba50c7 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Resources/CSharp-Semantic.xshd +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Resources/CSharp-Semantic.xshd @@ -32,7 +32,11 @@ + + + + diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighterVisitor.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighterVisitor.cs index 8e4765c939..f50df9abb3 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighterVisitor.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighterVisitor.cs @@ -58,10 +58,10 @@ namespace CSharpBinding //this.defaultTextColor = ???; this.referenceTypeColor = highlighting.GetNamedColor("ReferenceTypes"); this.valueTypeColor = highlighting.GetNamedColor("ValueTypes"); - this.interfaceTypeColor = this.referenceTypeColor; - this.enumerationTypeColor = this.valueKeywordColor; - this.typeParameterTypeColor = this.referenceTypeColor; - this.delegateTypeColor = this.referenceTypeColor; + this.interfaceTypeColor = highlighting.GetNamedColor("InterfaceTypes"); + this.enumerationTypeColor = highlighting.GetNamedColor("EnumTypes"); + this.typeParameterTypeColor = highlighting.GetNamedColor("TypeParameters"); + this.delegateTypeColor = highlighting.GetNamedColor("DelegateType"); this.methodDeclarationColor = this.methodCallColor = highlighting.GetNamedColor("MethodCall"); //this.eventDeclarationColor = this.eventAccessColor = defaultTextColor; //this.propertyDeclarationColor = this.propertyAccessColor = defaultTextColor; From 40e5ec6116300cc42d5ebbce9f28532a8787b416 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 23 Aug 2014 16:10:32 +0200 Subject: [PATCH 064/146] Fix #518 by re-using the insight window. --- .../Src/CodeCompletionEditorAdapter.cs | 24 +- .../Src/SharpDevelopInsightWindow.cs | 205 ++++++++++++++---- .../Src/SharpDevelopTextEditor.cs | 2 +- .../CodeCompletion/OverloadInsightWindow.cs | 2 +- 4 files changed, 181 insertions(+), 52 deletions(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeCompletionEditorAdapter.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeCompletionEditorAdapter.cs index 4c21ee704e..16ef070ad6 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeCompletionEditorAdapter.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeCompletionEditorAdapter.cs @@ -55,20 +55,30 @@ namespace ICSharpCode.AvalonEdit.AddIn { if (items == null) return null; - var insightWindow = new SharpDevelopInsightWindow(this.TextEditor.TextArea); - insightWindow.Items.AddRange(items); - if (insightWindow.Items.Count > 0) { - insightWindow.SelectedItem = insightWindow.Items[0]; + var insightWindow = textEditor.ActiveInsightWindow; + bool isNewWindow = false; + if (insightWindow == null) { + insightWindow = new SharpDevelopInsightWindow(this.TextEditor.TextArea); + isNewWindow = true; + } + var adapter = new SharpDevelopInsightWindowAdapter(insightWindow); + adapter.Items.AddRange(items); + if (adapter.Items.Count > 0) { + adapter.SelectedItem = adapter.Items[0]; } else { // don't open insight window when there are no items return null; } - textEditor.ShowInsightWindow(insightWindow); - return insightWindow; + insightWindow.SetActiveAdapter(adapter, isNewWindow); + if (isNewWindow) + { + textEditor.ShowInsightWindow(insightWindow); + } + return adapter; } public override IInsightWindow ActiveInsightWindow { - get { return textEditor.ActiveInsightWindow; } + get { return textEditor.ActiveInsightWindow.activeAdapter; } } public override ICompletionListWindow ActiveCompletionWindow { diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs index e2a26ad1d5..0bed5d79f2 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs @@ -22,6 +22,7 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; +using System.Windows.Threading; using ICSharpCode.AvalonEdit.CodeCompletion; using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Editing; @@ -30,17 +31,94 @@ using ICSharpCode.SharpDevelop.Editor.CodeCompletion; namespace ICSharpCode.AvalonEdit.AddIn { + class SharpDevelopInsightWindow : OverloadInsightWindow + { + public SharpDevelopInsightWindow(TextArea textArea) : base(textArea) + { + this.Style = ICSharpCode.Core.Presentation.GlobalStyles.WindowStyle; + AttachEvents(); + } + + internal SharpDevelopInsightWindowAdapter activeAdapter; + + public void SetActiveAdapter(SharpDevelopInsightWindowAdapter adapter, bool isNewWindow) + { + if (activeAdapter != null) { + // tell the previous adapter that its window was closed, + // but actually reuse the window for the new adapter + activeAdapter.OnClosed(); + } + activeAdapter = adapter; + this.Provider = adapter.Provider; + if (!isNewWindow) { + // reset insight window to initial state + CloseAutomatically = true; + StartOffset = EndOffset = this.TextArea.Caret.Offset; + Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(SetPositionToStartOffset)); + } + } + + void SetPositionToStartOffset() + { + if (document != null && this.StartOffset != this.TextArea.Caret.Offset) { + SetPosition(new TextViewPosition(document.GetLocation(this.StartOffset))); + } else { + SetPosition(this.TextArea.Caret.Position); + } + } + + TextDocument document; + Caret caret; + + void AttachEvents() + { + document = this.TextArea.Document; + caret = this.TextArea.Caret; + if (document != null) + document.Changed += document_Changed; + if (caret != null) + caret.PositionChanged += caret_PositionChanged; + this.Closed += OnClosed; + } + + /// + protected override void DetachEvents() + { + if (document != null) + document.Changed -= document_Changed; + if (caret != null) + caret.PositionChanged -= caret_PositionChanged; + this.Closed -= OnClosed; + base.DetachEvents(); + } + + void OnClosed(object sender, EventArgs e) + { + activeAdapter.OnClosed(); + } + + void caret_PositionChanged(object sender, EventArgs e) + { + activeAdapter.OnCaretPositionChanged(e); + } + + void document_Changed(object sender, DocumentChangeEventArgs e) + { + activeAdapter.OnDocumentChanged(e); + } + } + /// /// Adapter between AvalonEdit InsightWindow and SharpDevelop IInsightWindow interface. /// - public class SharpDevelopInsightWindow : OverloadInsightWindow, IInsightWindow + class SharpDevelopInsightWindowAdapter : IInsightWindow { sealed class SDItemProvider : IOverloadProvider { - readonly SharpDevelopInsightWindow insightWindow; + readonly SharpDevelopInsightWindowAdapter insightWindow; int selectedIndex; - public SDItemProvider(SharpDevelopInsightWindow insightWindow) + public SDItemProvider(SharpDevelopInsightWindowAdapter insightWindow) { this.insightWindow = insightWindow; insightWindow.items.CollectionChanged += insightWindow_items_CollectionChanged; @@ -103,16 +181,21 @@ namespace ICSharpCode.AvalonEdit.AddIn } readonly ObservableCollection items = new ObservableCollection(); + SharpDevelopInsightWindow insightWindow; + readonly SDItemProvider provider; - public SharpDevelopInsightWindow(TextArea textArea) : base(textArea) + internal IOverloadProvider Provider { + get { return provider; } + } + + internal SharpDevelopInsightWindowAdapter(SharpDevelopInsightWindow insightWindow) { - this.Provider = new SDItemProvider(this); - this.Provider.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { + this.insightWindow = insightWindow; + provider = new SDItemProvider(this); + provider.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "SelectedIndex") OnSelectedItemChanged(EventArgs.Empty); }; - this.Style = ICSharpCode.Core.Presentation.GlobalStyles.WindowStyle; - AttachEvents(); } public IList Items { @@ -121,55 +204,28 @@ namespace ICSharpCode.AvalonEdit.AddIn public IInsightItem SelectedItem { get { - int index = this.Provider.SelectedIndex; + int index = provider.SelectedIndex; if (index < 0 || index >= items.Count) return null; else return items[index]; } set { - this.Provider.SelectedIndex = items.IndexOf(value); + provider.SelectedIndex = items.IndexOf(value); OnSelectedItemChanged(EventArgs.Empty); } } - TextDocument document; - Caret caret; IInsightItem oldSelectedItem; - void AttachEvents() - { - document = this.TextArea.Document; - caret = this.TextArea.Caret; - if (document != null) - document.Changed += document_Changed; - if (caret != null) - caret.PositionChanged += caret_PositionChanged; - } + public event EventHandler DocumentChanged; - void caret_PositionChanged(object sender, EventArgs e) - { - OnCaretPositionChanged(e); - } - - /// - protected override void DetachEvents() - { - if (document != null) - document.Changed -= document_Changed; - if (caret != null) - caret.PositionChanged -= caret_PositionChanged; - base.DetachEvents(); - } - - void document_Changed(object sender, DocumentChangeEventArgs e) + internal void OnDocumentChanged(DocumentChangeEventArgs e) { if (DocumentChanged != null) DocumentChanged(this, e); } - public event EventHandler DocumentChanged; - public event EventHandler SelectedItemChanged; protected virtual void OnSelectedItemChanged(EventArgs e) @@ -186,8 +242,6 @@ namespace ICSharpCode.AvalonEdit.AddIn void SelectedItemPropertyChanged(object sender, PropertyChangedEventArgs e) { - var provider = Provider as SDItemProvider; - if (provider == null) return; switch (e.PropertyName) { case "Header": provider.OnPropertyChanged("CurrentHeader"); @@ -199,12 +253,77 @@ namespace ICSharpCode.AvalonEdit.AddIn } public event EventHandler CaretPositionChanged; - - protected virtual void OnCaretPositionChanged(EventArgs e) + + internal void OnCaretPositionChanged(EventArgs e) { if (CaretPositionChanged != null) { CaretPositionChanged(this, e); } } + + public event EventHandler Closed; + + internal void OnClosed() + { + if (Closed != null) + Closed(this, EventArgs.Empty); + insightWindow = null; + } + + public void Close() + { + if (insightWindow != null) + insightWindow.Close(); + } + + public double Width { + get { + return insightWindow != null ? insightWindow.Width : 0; + } + set { + if (insightWindow != null) + insightWindow.Width = value; + } + } + + public double Height { + get { + return insightWindow != null ? insightWindow.Height : 0; + } + set { + if (insightWindow != null) + insightWindow.Height = value; + } + } + + public bool CloseAutomatically { + get { + return insightWindow != null && insightWindow.CloseAutomatically; + } + set { + if (insightWindow != null) + insightWindow.CloseAutomatically = value; + } + } + + public int StartOffset { + get { + return insightWindow != null ? insightWindow.StartOffset : 0; + } + set { + if (insightWindow != null) + insightWindow.StartOffset = value; + } + } + + public int EndOffset { + get { + return insightWindow != null ? insightWindow.EndOffset : 0; + } + set { + if (insightWindow != null) + insightWindow.EndOffset = value; + } + } } } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopTextEditor.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopTextEditor.cs index ead5adfe6c..07294e8ff6 100755 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopTextEditor.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopTextEditor.cs @@ -97,7 +97,7 @@ namespace ICSharpCode.AvalonEdit.AddIn get { return completionWindow; } } - public SharpDevelopInsightWindow ActiveInsightWindow { + internal SharpDevelopInsightWindow ActiveInsightWindow { get { return insightWindow; } } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/OverloadInsightWindow.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/OverloadInsightWindow.cs index ac192835b4..2ec182ce44 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/OverloadInsightWindow.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CodeCompletion/OverloadInsightWindow.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); - if (!e.Handled && this.Provider.Count > 1) { + if (!e.Handled && this.Provider != null && this.Provider.Count > 1) { switch (e.Key) { case Key.Up: e.Handled = true; From 9f7b8f44b8659cce44d4ce7b52bb9404e4dd92c0 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 23 Aug 2014 16:24:01 +0200 Subject: [PATCH 065/146] PushModel generation --- .../ICSharpCode.Reporting.Addin.csproj | 5 ++ .../src/DesignableItems/ReportSettings.cs | 2 + .../src/Globals/GlobalLists.cs | 2 +- .../Dialog/BaseSettingsPage.xaml.cs | 4 +- .../ReportWizard/Dialog/PushDataReport.xaml | 18 +++++-- .../Dialog/PushDataReport.xaml.cs | 47 ++++++++++++++++++- .../src/ReportWizard/ReportGenerator.cs | 31 ++++++------ .../Src/BaseClasses/AbstractColumn.cs | 29 ++---------- .../Src/BaseClasses/ExtensionMethods.cs | 9 +++- .../Src/Items/BaseTextItem.cs | 2 +- .../Src/ReportingFactory.cs | 19 +++++++- 11 files changed, 115 insertions(+), 53 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj index 6213368704..35fdf67bba 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.Addin.csproj @@ -213,6 +213,11 @@ + + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} + ICSharpCode.NRefactory + False + {2748AD25-9C63-4E12-877B-4DCE96FBED54} ICSharpCode.SharpDevelop diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs index 43a4f72fdf..ff04752a03 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignableItems/ReportSettings.cs @@ -145,5 +145,7 @@ namespace ICSharpCode.Reporting.Addin.DesignableItems public SortColumnCollection SortColumnsCollection {get;private set;} public GroupColumnCollection GroupColumnsCollection {get;private set;} + + } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs index c6ad60e79a..684d501278 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.Reporting.Addin.Globals "System.DateTime", "System.TimeSpan", "System.Decimal", - "System.Int"}; + "System.Int32"}; #endregion diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs index adacd5af0d..2061e2316f 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/BaseSettingsPage.xaml.cs @@ -56,12 +56,12 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog{ var cbo = (ComboBox) sender; var pushPullModel = (PushPullModel)cbo.SelectedItem; - + switch (pushPullModel) { case PushPullModel.PushData: { this._ReportType.SelectedItem = ReportType.DataReport; this.CanFinish = false; - this.CanSelectNextPage = true; + this.CanSelectNextPage = true; break; } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml index 9a30f432ee..65c71efe10 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml @@ -6,7 +6,7 @@ xmlns:sdr="clr-namespace:ICSharpCode.Reporting.Globals;assembly=ICSharpCode.Reporting" Name="PushData" Title="SharpDevelop Reporting" - Description="Create Columns for a PusData Report" + PageType="Interior" CanFinish="true" CancelButtonVisibility="Visible" @@ -14,20 +14,28 @@ CanSelectNextPage="false"> + + + + + + + + + + AutoGenerateColumns="False" Grid.Row="1" Grid.RowSpan="2" Margin="30,10,30,5" Width="400" Grid.Column="1"> - - + + diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml.cs index d08ce70bd8..51cc316010 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/Dialog/PushDataReport.xaml.cs @@ -8,9 +8,12 @@ */ using System; using System.Collections.Generic; +using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.Reporting.BaseClasses; using Xceed.Wpf.Toolkit; +using ICSharpCode.Reporting.Addin.Globals; using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; +using System.Linq; namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog { @@ -20,21 +23,59 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog public partial class PushDataReport : WizardPage,IHasContext { List items; + List types; + PushModelContext context; public PushDataReport() { InitializeComponent(); items = new List(); + types = new List(); _DataGrid.ItemsSource = items; this.context = new PushModelContext(); var data = new AbstractColumn("MyColumn",typeof(string)); items.Add(data); + cboType.ItemsSource = GlobalLists.DataTypeList(); + var definitions = GetTypeDefinitions(); + + if (definitions != null) { + _cboTypes.Visibility = System.Windows.Visibility.Visible; + _cboTypes.ItemsSource = definitions; + _cboTypes.SelectedIndex = 0; + } + } - - void UpdateContext() + static IEnumerable GetTypeDefinitions() { + var currentProject = SharpDevelop.SD.ProjectService.CurrentProject; + var compilation = SharpDevelop.SD.ParserService.GetCompilation(currentProject); + var definitions = compilation.MainAssembly.TopLevelTypeDefinitions.Where(x => x.Properties.Any()); + return definitions; + } + + + #region Combo + + void _cboTypes_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e){ + + var s = (ITypeDefinition)e.AddedItems[0]; + var l = CreateItemsSource(s); + if (l.Count > 0) { + _DataGrid.ItemsSource = l; + } + } + + static List CreateItemsSource(ITypeDefinition s){ + return s.Properties.Select(p => new AbstractColumn(){ + ColumnName = p.Name, + DataTypeName = p.ReturnType.ReflectionName + }).ToList(); + } + #endregion + + void UpdateContext(){ context.Items = (List)_DataGrid.ItemsSource; } @@ -51,6 +92,8 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.Dialog public WizardPageType ReportPageType { get {return WizardPageType.PushModelPage;} } + + #endregion } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs index 2c01bb8749..42947cd5e2 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs @@ -11,7 +11,7 @@ using System.Drawing; using ICSharpCode.Reporting.Factories; using ICSharpCode.Reporting.Globals; using ICSharpCode.Reporting.Interfaces; - +using ICSharpCode.Reporting.BaseClasses; using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.Addin.ReportWizard.ViewModels; @@ -35,8 +35,8 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard if (context == null) throw new ArgumentNullException("context"); - var poc = (PageOneContext)context.PageOneContext; - if (IsDataReport(poc)) { + + if (IsDataReport(context)) { CreateDataReport (context); } else { CreateFormSheetReport(context); @@ -90,25 +90,28 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard void CreateReportHeader(ReportWizardContext context){ var pageOneContext = (PageOneContext)context.PageOneContext; - var headerText = new BaseTextItem(); - if (String.IsNullOrEmpty(pageOneContext.ReportName)) { - headerText.Text = GlobalValues.DefaultReportName; - } else { - headerText.Text = pageOneContext.ReportName; - } + var headerText = new BaseTextItem(); - headerText.Size = GlobalValues.PreferedSize; - var printableWith = ReportModel.ReportSettings.PageSize.Width - ReportModel.ReportSettings.LeftMargin - ReportModel.ReportSettings.RightMargin; + headerText.Text = String.IsNullOrEmpty(pageOneContext.ReportName) ? GlobalValues.DefaultReportName : pageOneContext.ReportName; - var x = (int)(printableWith - headerText.Size.Width) / 2; - headerText.Location = new Point(x,4); + var xLoc = (ReportModel.ReportSettings.PrintableWidth() - headerText.Size.Width) / 2; + headerText.Location = new Point(xLoc,4); ReportModel.ReportHeader.Items.Add(headerText); + xLoc = ReportModel.ReportSettings.PrintableWidth() - GlobalValues.PreferedSize.Width - 20; + + var dateText = new BaseTextItem(){ + Text ="= Today.Today", + Location = new Point(xLoc ,10) + }; + ReportModel.ReportHeader.Items.Add(dateText); } - static bool IsDataReport(PageOneContext poc) + + static bool IsDataReport(ReportWizardContext context) { + var poc = (PageOneContext)context.PageOneContext; return poc.ReportType.Equals(ReportType.DataReport); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/AbstractColumn.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/AbstractColumn.cs index ed3bff6643..616cb28d72 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/AbstractColumn.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/AbstractColumn.cs @@ -26,42 +26,19 @@ namespace ICSharpCode.Reporting.BaseClasses /// public class AbstractColumn { - Type dataType; - string dataTypeName; public AbstractColumn() { - this.dataType = typeof(System.String); + this.DataTypeName = typeof(String).FullName; } - public AbstractColumn(string columnName, Type dataType){ this.ColumnName = columnName; - this.dataType = dataType; + this.DataTypeName = dataType.FullName; } public string ColumnName {get;set;} + public string DataTypeName {get;set;} - - public string DataTypeName { - get { - return this.dataType.ToString(); - } - set { - dataTypeName = value; - this.dataType = Type.GetType(dataTypeName,true,true); - } - } - -// [XmlIgnoreAttribute] - public Type DataType { - get { - return dataType; - } - set { - dataType = value; - } - } - } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/ExtensionMethods.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/ExtensionMethods.cs index a73d3984fc..e47c5d5f2e 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/ExtensionMethods.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/ExtensionMethods.cs @@ -20,6 +20,8 @@ using System; using System.Collections.Generic; using System.Windows; using System.Windows.Media; +using ICSharpCode.Reporting.Items; + namespace ICSharpCode.Reporting.BaseClasses { /// @@ -28,7 +30,7 @@ namespace ICSharpCode.Reporting.BaseClasses /// /// Date: Sat, 23 Aug 2014 16:39:13 +0200 Subject: [PATCH 066/146] Simplify AddOptionalParameterToInvocationAction. This should fix UDC crash 5207. --- .../AddOptionalParameterToInvocationAction.cs | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeActions/AddOptionalParameterToInvocationAction.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeActions/AddOptionalParameterToInvocationAction.cs index e7a91c2a05..49157a040e 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeActions/AddOptionalParameterToInvocationAction.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeActions/AddOptionalParameterToInvocationAction.cs @@ -23,9 +23,11 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System; using ICSharpCode.NRefactory.CSharp; using System.Collections.Generic; using System.Linq; +using ICSharpCode.NRefactory.CSharp.Resolver; using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory.Xml; using ICSharpCode.NRefactory.Documentation; @@ -43,44 +45,28 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring if (invocationExpression == null) yield break; - var resolveResult = context.Resolve(invocationExpression) as InvocationResolveResult; + var resolveResult = context.Resolve(invocationExpression) as CSharpInvocationResolveResult; if (resolveResult == null) { yield break; } - + var method = (IMethod)resolveResult.Member; - - bool foundOptionalParameter = false; - foreach (var parameter in method.Parameters) { - if (parameter.IsParams) { - yield break; - } - - if (parameter.IsOptional) { - foundOptionalParameter = true; - break; + bool[] parameterIsSpecified = new bool[method.Parameters.Count]; + var argumentToParameterMap = resolveResult.GetArgumentToParameterMap(); + if (argumentToParameterMap != null) { + foreach (int paramIndex in argumentToParameterMap) + parameterIsSpecified[paramIndex] = true; + } else { + for (int i = 0; i < Math.Min(resolveResult.Arguments.Count, parameterIsSpecified.Length); i++) { + parameterIsSpecified[i] = true; } } - - if (!foundOptionalParameter) { - yield break; + var missingParameters = new List(); + for (int i = 0; i < method.Parameters.Count; i++) { + if (!parameterIsSpecified[i] && method.Parameters[i].IsOptional) + missingParameters.Add(method.Parameters[i]); } - - //Basic sanity checks done, now see if there are any missing optional arguments - var missingParameters = new List(method.Parameters); - if (resolveResult.Arguments.Count != invocationExpression.Arguments.Count) { - //Extension method - missingParameters.RemoveAt (0); - } - foreach (var argument in invocationExpression.Arguments) { - var namedArgument = argument as NamedArgumentExpression; - if (namedArgument == null) { - missingParameters.RemoveAt(0); - } else { - missingParameters.RemoveAll(parameter => parameter.Name == namedArgument.Name); - } - } - + foreach (var parameterToAdd in missingParameters) { //Add specific parameter yield return new CodeAction(string.Format(context.TranslateString("Add optional parameter \"{0}\""), From cd9a09027ec0494bfbdc8adb4e92550c0551d189 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 23 Aug 2014 17:08:58 +0200 Subject: [PATCH 067/146] Strip "I" from type name when generating a variable name. --- .../CodeActions/CreateMethodDeclarationAction.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeActions/CreateMethodDeclarationAction.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeActions/CreateMethodDeclarationAction.cs index d325fe7ff9..b1b22360a4 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeActions/CreateMethodDeclarationAction.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp.Refactoring/CodeActions/CreateMethodDeclarationAction.cs @@ -363,7 +363,10 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring case "System.Action": return "action"; } - return returnType.Name; + if (returnType.Kind == TypeKind.Interface && returnType.Name.StartsWith("I", System.StringComparison.Ordinal)) + return returnType.Name.Substring(1); + else + return returnType.Name; } string GetMethodName(InvocationExpression invocation) From 681576a29616b7fe542534ec6f20a6245895dc4f Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 23 Aug 2014 17:27:29 +0200 Subject: [PATCH 068/146] Generate PageHeader --- .../src/ReportWizard/ReportGenerator.cs | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs index 42947cd5e2..88e6fa425e 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs @@ -7,6 +7,7 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using System.Collections.Generic; using System.Drawing; using ICSharpCode.Reporting.Factories; using ICSharpCode.Reporting.Globals; @@ -24,7 +25,7 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard public class ReportGenerator { const int gap = 10; - + const int startLocation = 5; public ReportGenerator() { ReportModel = ReportModelFactory.Create(); @@ -53,6 +54,7 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard { GenerateBaseSettings(context); CreateReportHeader(context); + CreatePageHeader(context); GeneratePushModel(context); } @@ -70,7 +72,6 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard void GeneratePushModel(ReportWizardContext context){ var pushModelContext = (PushModelContext)context.PushModelContext; - var xLocation = 5; foreach (var element in pushModelContext.Items) { var dataItem = new BaseDataItem(){ Name = element.ColumnName, @@ -78,13 +79,9 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard ColumnName = element.ColumnName, DataType = element.DataTypeName }; - - var location = new Point(xLocation,4); - dataItem.Location = location; - dataItem.Size = GlobalValues.PreferedSize; - xLocation = xLocation + GlobalValues.PreferedSize.Width + gap; ReportModel.DetailSection.Items.Add(dataItem); } + AdjustItems(ReportModel.DetailSection.Items,startLocation); } @@ -105,10 +102,44 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard Text ="= Today.Today", Location = new Point(xLoc ,10) }; + ReportModel.ReportHeader.Items.Add(dateText); } + void CreatePageHeader(ReportWizardContext context) + { + var pushModelContext = (PushModelContext)context.PushModelContext; + foreach (var element in pushModelContext.Items) { + var dataItem = new BaseTextItem(){ + Name = element.ColumnName, + Text = element.ColumnName + }; + ReportModel.PageHeader.Items.Add(dataItem); + } + + AdjustItems(ReportModel.PageHeader.Items,startLocation); + + var line = new BaseLineItem(){ + Location = new Point(2,35), + FromPoint = new Point(1,1), + ToPoint = new Point(ReportModel.ReportSettings.PrintableWidth() -10,1), + Size = new Size (ReportModel.ReportSettings.PrintableWidth() -5,5) + }; + + ReportModel.PageHeader.Items.Add(line); + + } + + void AdjustItems (List list,int startValue ) { + + var xLocation = startValue; + foreach (var element in list) { + element.Location = new Point(xLocation,6); + xLocation = xLocation + GlobalValues.PreferedSize.Width + gap; + } + } + static bool IsDataReport(ReportWizardContext context) { var poc = (PageOneContext)context.PageOneContext; From 2d373d8bb12b610f02645d9644e5bd4ab3529657 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Aug 2014 15:06:19 +0200 Subject: [PATCH 069/146] fix 'unreachable code' compiler warning in mcs/cs-tokenizer.cs --- .../ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs index 9b692bf46c..44a83ce8bf 100644 --- a/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs +++ b/src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Parser/mcs/cs-tokenizer.cs @@ -3104,7 +3104,6 @@ namespace Mono.CSharp value_builder[pos++] = (char) c; } - recordNewLine = true; } private int consume_identifier (int s) From bec0f8f8f76d97b66600bfa5c315491e737bee7c Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Aug 2014 15:07:12 +0200 Subject: [PATCH 070/146] fix compiler warnings --- .../PackageManagement/SharpDevelop.EnvDTE/Src/CodeElements.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AddIns/Misc/PackageManagement/SharpDevelop.EnvDTE/Src/CodeElements.vb b/src/AddIns/Misc/PackageManagement/SharpDevelop.EnvDTE/Src/CodeElements.vb index 6fb8e69228..f702090600 100644 --- a/src/AddIns/Misc/PackageManagement/SharpDevelop.EnvDTE/Src/CodeElements.vb +++ b/src/AddIns/Misc/PackageManagement/SharpDevelop.EnvDTE/Src/CodeElements.vb @@ -24,6 +24,6 @@ Namespace EnvDTE Function Item(index As Object) As CodeElement - Function GetEnumerator() As IEnumerator + Shadows Function GetEnumerator() As IEnumerator End Interface End Namespace \ No newline at end of file From 048134be8ff41dbaee5fe4afd820fdc829f3bcf5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Aug 2014 15:14:13 +0200 Subject: [PATCH 071/146] fix #538: WPF Commands do not work properly in Windows Forms ContextMenus --- .../Menu/MenuCommand.cs | 3 ++- .../Menu/MenuService.cs | 1 + src/Main/SharpDevelop/Workbench/WpfWorkbench.cs | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs b/src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs index 92169ca890..677ed62619 100644 --- a/src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs +++ b/src/Main/ICSharpCode.Core.WinForms/Menu/MenuCommand.cs @@ -100,7 +100,8 @@ namespace ICSharpCode.Core.WinForms } catch (ResourceNotFoundException) {} } Visible = GetVisible(); - Enabled = command != null && command.CanExecute(caller); + command = CommandWrapper.Unwrap(command); + Enabled = command != null && MenuService.CanExecuteCommand(command, caller); } } diff --git a/src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs b/src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs index f82aa51fb2..295649edf0 100644 --- a/src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs +++ b/src/Main/ICSharpCode.Core.WinForms/Menu/MenuService.cs @@ -28,6 +28,7 @@ namespace ICSharpCode.Core.WinForms public static class MenuService { public static Action ExecuteCommand; + public static Func CanExecuteCommand; public static void AddItemsToMenu(ToolStripItemCollection collection, object owner, string addInTreePath) { diff --git a/src/Main/SharpDevelop/Workbench/WpfWorkbench.cs b/src/Main/SharpDevelop/Workbench/WpfWorkbench.cs index 07dae61df2..2dab222965 100644 --- a/src/Main/SharpDevelop/Workbench/WpfWorkbench.cs +++ b/src/Main/SharpDevelop/Workbench/WpfWorkbench.cs @@ -137,6 +137,7 @@ namespace ICSharpCode.SharpDevelop.Workbench dockPanel.Children.Insert(dockPanel.Children.Count - 2, statusBar); Core.WinForms.MenuService.ExecuteCommand = ExecuteCommand; + Core.WinForms.MenuService.CanExecuteCommand = CanExecuteCommand; UpdateMenu(); AddHandler(Hyperlink.RequestNavigateEvent, new RequestNavigateEventHandler(OnRequestNavigate)); @@ -160,9 +161,9 @@ namespace ICSharpCode.SharpDevelop.Workbench { ServiceSingleton.GetRequiredService() .TrackFeature(command.GetType().FullName, "Menu"); - var routedCommand = command as System.Windows.Input.RoutedCommand; + var routedCommand = command as RoutedCommand; if (routedCommand != null) { - var target = System.Windows.Input.FocusManager.GetFocusedElement(this); + var target = FocusManager.GetFocusedElement(this); if (routedCommand.CanExecute(caller, target)) routedCommand.Execute(caller, target); } else { @@ -171,6 +172,17 @@ namespace ICSharpCode.SharpDevelop.Workbench } } + bool CanExecuteCommand(ICommand command, object caller) + { + var routedCommand = command as RoutedCommand; + if (routedCommand != null) { + var target = FocusManager.GetFocusedElement(this); + return routedCommand.CanExecute(caller, target); + } else { + return command.CanExecute(caller); + } + } + // keep a reference to the event handler to prevent it from being garbage collected // (CommandManager.RequerySuggested only keeps weak references to the event handlers) EventHandler requerySuggestedEventHandler; From 1a4979491a63d8a886c5765222abbdc7d0b9d164 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 23 Aug 2014 16:44:13 +0200 Subject: [PATCH 072/146] rename StringListEditorXaml to StringListEditor --- .../Src/AnalysisProjectOptionsPanel.xaml.cs | 2 +- .../CppBinding/Project/LinkerOptions.xaml.cs | 2 +- .../Options/DebuggingSymbolsPanel.xaml | 2 +- .../Project/ICSharpCode.SharpDevelop.csproj | 6 +++--- ...tEditorXaml.xaml => StringListEditor.xaml} | 4 ++-- ...rXaml.xaml.cs => StringListEditor.xaml.cs} | 18 ++++++++++-------- .../Components/StringListEditorDialog.xaml | 2 +- .../Components/StringListEditorDialog.xaml.cs | 19 ++++++++----------- .../ProjectOptions/ReferencePaths.xaml | 2 +- .../ProjectOptions/ReferencePaths.xaml.cs | 2 +- 10 files changed, 29 insertions(+), 30 deletions(-) rename src/Main/Base/Project/Src/Gui/Components/{StringListEditorXaml.xaml => StringListEditor.xaml} (94%) rename src/Main/Base/Project/Src/Gui/Components/{StringListEditorXaml.xaml.cs => StringListEditor.xaml.cs} (95%) diff --git a/src/AddIns/Analysis/CodeAnalysis/Src/AnalysisProjectOptionsPanel.xaml.cs b/src/AddIns/Analysis/CodeAnalysis/Src/AnalysisProjectOptionsPanel.xaml.cs index 8129f06798..d620fdec43 100644 --- a/src/AddIns/Analysis/CodeAnalysis/Src/AnalysisProjectOptionsPanel.xaml.cs +++ b/src/AddIns/Analysis/CodeAnalysis/Src/AnalysisProjectOptionsPanel.xaml.cs @@ -276,7 +276,7 @@ namespace ICSharpCode.CodeAnalysis private void ChangeRuleAssembliesButtonClick( object sender, RoutedEventArgs e) { var stringListDialog = new StringListEditorDialog(); - stringListDialog.BrowseForDirectory = true; + stringListDialog.ShowBrowse = true; stringListDialog.TitleText = StringParser.Parse("${res:ICSharpCode.CodeAnalysis.ProjectOptions.ChooseRuleAssemblyDirectory}"); stringListDialog.LoadList(GetRuleAssemblyList(false)); stringListDialog.ShowDialog(); diff --git a/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/LinkerOptions.xaml.cs b/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/LinkerOptions.xaml.cs index cd9130db9a..655b18c2c2 100644 --- a/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/LinkerOptions.xaml.cs +++ b/src/AddIns/BackendBindings/CppBinding/CppBinding/Project/LinkerOptions.xaml.cs @@ -165,7 +165,7 @@ namespace ICSharpCode.CppBinding.Project var stringListDialog = new StringListEditorDialog(); stringListDialog.TitleText = title; stringListDialog.ListCaption = listCaption; - stringListDialog.BrowseForDirectory = browseForDirectoty; + stringListDialog.ShowBrowse = browseForDirectoty; string[] strings = textBox.Text.Split(';'); stringListDialog.LoadList (strings); stringListDialog.ShowDialog(); diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingSymbolsPanel.xaml b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingSymbolsPanel.xaml index b2b9894ce9..d0c1bf005d 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingSymbolsPanel.xaml +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingSymbolsPanel.xaml @@ -5,6 +5,6 @@ xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"> - + \ No newline at end of file diff --git a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj index 1b58b2e940..61a29f8d26 100644 --- a/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj +++ b/src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj @@ -279,8 +279,8 @@ StringListEditorDialog.xaml - - StringListEditorXaml.xaml + + StringListEditor.xaml Code @@ -896,7 +896,7 @@ - + diff --git a/src/Main/Base/Project/Src/Gui/Components/StringListEditorXaml.xaml b/src/Main/Base/Project/Src/Gui/Components/StringListEditor.xaml similarity index 94% rename from src/Main/Base/Project/Src/Gui/Components/StringListEditorXaml.xaml rename to src/Main/Base/Project/Src/Gui/Components/StringListEditor.xaml index 98dde7281b..809f08a024 100644 --- a/src/Main/Base/Project/Src/Gui/Components/StringListEditorXaml.xaml +++ b/src/Main/Base/Project/Src/Gui/Components/StringListEditor.xaml @@ -1,6 +1,6 @@ diff --git a/src/Main/Base/Project/Src/Gui/Components/StringListEditorXaml.xaml.cs b/src/Main/Base/Project/Src/Gui/Components/StringListEditor.xaml.cs similarity index 95% rename from src/Main/Base/Project/Src/Gui/Components/StringListEditorXaml.xaml.cs rename to src/Main/Base/Project/Src/Gui/Components/StringListEditor.xaml.cs index f934970d7f..0aff2e32c0 100644 --- a/src/Main/Base/Project/Src/Gui/Components/StringListEditorXaml.xaml.cs +++ b/src/Main/Base/Project/Src/Gui/Components/StringListEditor.xaml.cs @@ -26,14 +26,14 @@ using ICSharpCode.Core.Presentation; namespace ICSharpCode.SharpDevelop.Gui { /// - /// Interaction logic for StringListEditorXaml.xaml + /// Interaction logic for StringListEditor.xaml /// - public partial class StringListEditorXaml : UserControl + public partial class StringListEditor : UserControl { - bool browseForDirectory; + bool showBrowse; public event EventHandler ListChanged; - public StringListEditorXaml() + public StringListEditor() { InitializeComponent(); moveUpButton.Content = new Image { Height = 16, Source = PresentationResourceService.GetBitmapSource("Icons.16x16.ArrowUp") }; @@ -44,16 +44,18 @@ namespace ICSharpCode.SharpDevelop.Gui public string TitleText {get;set;} + public string AddButtonText { get; set; } + public string ListCaption {get;set;} - public bool BrowseForDirectory { + public bool ShowBrowse { get { - return browseForDirectory; + return showBrowse; } set { - browseForDirectory = value; - if (browseForDirectory) { + showBrowse = value; + if (showBrowse) { browseButton.Visibility = Visibility.Visible; } else { browseButton.Visibility = Visibility.Hidden; diff --git a/src/Main/Base/Project/Src/Gui/Components/StringListEditorDialog.xaml b/src/Main/Base/Project/Src/Gui/Components/StringListEditorDialog.xaml index 6f2b011f88..127051a381 100644 --- a/src/Main/Base/Project/Src/Gui/Components/StringListEditorDialog.xaml +++ b/src/Main/Base/Project/Src/Gui/Components/StringListEditorDialog.xaml @@ -22,7 +22,7 @@ - + diff --git a/src/Main/Base/Project/Src/Gui/Components/StringListEditorDialog.xaml.cs b/src/Main/Base/Project/Src/Gui/Components/StringListEditorDialog.xaml.cs index 71d3f54136..ed0350e016 100644 --- a/src/Main/Base/Project/Src/Gui/Components/StringListEditorDialog.xaml.cs +++ b/src/Main/Base/Project/Src/Gui/Components/StringListEditorDialog.xaml.cs @@ -39,9 +39,9 @@ namespace ICSharpCode.SharpDevelop.Gui } - public bool BrowseForDirectory { - get {return stringListEditor.BrowseForDirectory;} - set {stringListEditor.BrowseForDirectory = value;} + public bool ShowBrowse { + get {return stringListEditor.ShowBrowse;} + set {stringListEditor.ShowBrowse = value;} } public string ListCaption { @@ -54,6 +54,11 @@ namespace ICSharpCode.SharpDevelop.Gui set {stringListEditor.TitleText = value;} } + public string AddButtonText { + get {return stringListEditor.AddButtonText;} + set {stringListEditor.AddButtonText = value;} + } + public string[] GetList() { return stringListEditor.GetList(); } @@ -66,13 +71,5 @@ namespace ICSharpCode.SharpDevelop.Gui { DialogResult = true; } - - - public string AddButtonText - { - get {return stringListEditor.Content.ToString();} - set {stringListEditor.addButton.Content = value;} - } - } } diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.xaml b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.xaml index 928a2e762c..0d68a04533 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.xaml +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.xaml @@ -21,7 +21,7 @@ - + diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.xaml.cs index 45edb802a5..18231567b1 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.xaml.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.xaml.cs @@ -31,7 +31,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels { InitializeComponent(); - editor.BrowseForDirectory = true; + editor.ShowBrowse = true; editor.TitleText = StringParser.Parse("${res:Global.Folder}:"); editor.ListCaption = StringParser.Parse("${res:Dialog.ProjectOptions.ReferencePaths}:"); editor.ListChanged += delegate { IsDirty = true; }; From 99e9fad8385233bd7b770225c2e73de29af5bb1e Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 23 Aug 2014 18:34:09 +0200 Subject: [PATCH 073/146] Generate PageFooter --- .../src/ReportWizard/ReportGenerator.cs | 18 +++++- .../Src/Expressions/Irony/Ast/GlobalsNode.cs | 3 + .../IntegrationTests/GlobalsFixture.cs | 9 +++ .../src/TestReports/TestForGlobals.srd | 60 ++++++++----------- 4 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs index 88e6fa425e..b138338cf5 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ReportGenerator.cs @@ -55,7 +55,8 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard GenerateBaseSettings(context); CreateReportHeader(context); CreatePageHeader(context); - GeneratePushModel(context); + CreateDetailsSection(context); + CreatePageFooter (context); } void GenerateBaseSettings (ReportWizardContext context) { @@ -70,7 +71,7 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard - void GeneratePushModel(ReportWizardContext context){ + void CreateDetailsSection(ReportWizardContext context){ var pushModelContext = (PushModelContext)context.PushModelContext; foreach (var element in pushModelContext.Items) { var dataItem = new BaseDataItem(){ @@ -130,6 +131,19 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard ReportModel.PageHeader.Items.Add(line); } +// + void CreatePageFooter(ReportWizardContext context) + { + var pageOneContext = (PageOneContext)context.PageOneContext; + var lineNrField = new BaseTextItem() { + Text = "='Page : ' + Globals!PageNumber + ' of ' + Globals!Pages + ' Page(s)'", + Name = "LineNumber", + Location = new Point(300,10), + Size = new Size (GlobalValues.PreferedSize.Width * 2,GlobalValues.PreferedSize.Height) + }; + ReportModel.PageFooter.Items.Add(lineNrField); + } + void AdjustItems (List list,int startValue ) { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs index 51e6239e82..a49b85ab04 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs @@ -47,6 +47,9 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast var pi = thread.GetPageInfo(); var test = globalNode.AsString.ToLower(); + if (test.Contains(":")) { + Console.WriteLine(""); + } if ( test == "pagenumber") { return pi.PageNumber; } else if (test == "pages") { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs index c1a7bd2949..359cf57a8c 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs @@ -45,6 +45,15 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests Assert.That(s.Text.Contains("Page")); } + [Test] + public void CanEvaluateComplexStatement () { + reportCreator.BuildExportList(); + var page = reportCreator.Pages[0]; + var sec = (ExportContainer)page.ExportedItems[4]; + var s = (ExportText)sec.ExportedItems[0]; + Assert.That (s.Text.Contains("1")); + Assert.That(s.Text.Contains("Page")); + } [Test] public void CanEvaluateTotalPages () { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/TestForGlobals.srd b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/TestForGlobals.srd index 3581112111..62b5abb9be 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/TestForGlobals.srd +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/TestForGlobals.srd @@ -4,26 +4,16 @@ Report1 FormSheet + FormSheet 50 50 50 50 827, 1169 False - Millimeter - 5, 5, 5, 5 - + - - - - - Text - FormSheet - No Data for this Report - Microsoft Sans Serif, 10pt - True @@ -31,10 +21,7 @@ 50, 50 727, 60 White - 0 - 0 False - False 383, 17 @@ -43,9 +30,9 @@ Segoe UI, 9pt None TopLeft + Left False False - No = 'ReportFileName : ' + Globals!reportfilename False Black @@ -59,10 +46,10 @@ Microsoft Sans Serif, 10pt None TopLeft + Left False False System.String - No = 'ReportFolder :' + Globals!ReportFolder False Black @@ -77,10 +64,7 @@ 50, 125 727, 60 White - 0 - 0 False - False 16, 4 @@ -89,9 +73,9 @@ Segoe UI, 9pt None TopLeft + Left False False - No ='Pages ' + Globals!Pages False Black @@ -106,10 +90,7 @@ 50, 200 727, 60 White - 0 - 0 False - False 16, 4 @@ -118,9 +99,9 @@ Segoe UI, 9pt None TopLeft + Left False False - No = 'ReportName : ' + Globals!ReportName False Black @@ -135,10 +116,7 @@ 50, 275 727, 60 White - 0 - 0 False - False 16, 4 @@ -147,9 +125,9 @@ Segoe UI, 9pt None TopLeft + Left False False - No =Globals!SyntaxError False Black @@ -163,10 +141,10 @@ Microsoft Sans Serif, 10pt None TopLeft + Left False False System.String - No ='Page ' + Globals!PageNumber False Black @@ -181,11 +159,25 @@ 50, 350 727, 60 White - 0 - 0 False - False - + + + 16, 16 + 393, 20 + White + Segoe UI, 9pt + None + TopLeft + Left + False + False + ='Page : ' + Globals!PageNumber + 'Pages :' + Globals!Pages + False + Black + ControlText + BaseTextItem2147483646 + + Black ReportFooter From 2184c84e514f420dca87d92eaa8c42a032b03ca0 Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Sat, 23 Aug 2014 19:06:56 +0200 Subject: [PATCH 074/146] Migrated some basic functions of ResourceEditor to WPF. --- .../Project/ResourceEditor.csproj | 52 ++- .../Project/Src/BitmapExtensions.cs | 50 +++ .../Project/Src/Commands/AddNewFileCommand.cs | 102 +++-- .../Src/Commands/AddStringEntryCommand.cs | 44 +- .../Src/Commands/CopyResourceNameCommand.cs | 10 +- .../Src/Commands/EditCommentCommand.cs | 25 +- .../Src/Commands/RenameEntryCommand.cs | 10 +- .../Src/Commands/SaveEntryAsCommand.cs | 113 ++--- .../Src/ResourceEditorDisplayBinding.cs | 213 ++------- .../Src/ViewModels/ResourceEditorViewModel.cs | 421 ++++++++++++++++++ .../Project/Src/ViewModels/ResourceItem.cs | 229 ++++++++++ .../Project/Src/Views/BinaryView.xaml | 7 + .../Project/Src/Views/BinaryView.xaml.cs | 41 ++ .../Project/Src/Views/BooleanView.xaml | 7 + .../Project/Src/Views/BooleanView.xaml.cs | 41 ++ .../Project/Src/Views/IResourceEditorView.cs | 55 +++ .../IResourceItemView.cs} | 21 +- .../Project/Src/Views/ImageViewBase.xaml | 13 + .../Project/Src/Views/ImageViewBase.xaml.cs | 101 +++++ .../Project/Src/Views/ResourceEditorView.xaml | 146 ++++++ .../Src/Views/ResourceEditorView.xaml.cs | 128 ++++++ .../Project/Src/Views/ResourceItemIcons.cs | 76 ++++ .../Project/Src/Views/TextView.xaml | 12 + .../Project/Src/Views/TextView.xaml.cs | 56 +++ 24 files changed, 1636 insertions(+), 337 deletions(-) create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/BitmapExtensions.cs create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml.cs create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml.cs create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs rename src/AddIns/DisplayBindings/ResourceEditor/Project/Src/{Commands/ClipboardCommands.cs => Views/IResourceItemView.cs} (80%) create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml.cs create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml.cs create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceItemIcons.cs create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/TextView.xaml create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/TextView.xaml.cs diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj b/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj index 58b4161739..4f4746dc44 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj @@ -40,16 +40,26 @@ ..\..\..\..\..\AddIns\DisplayBindings\ResourceEditor\ + + 3.0 + + + 3.0 + + + 4.0 + + + - @@ -84,6 +94,31 @@ Component + + + + BinaryView.xaml + Code + + + BooleanView.xaml + Code + + + ImageViewBase.xaml + Code + + + + + ResourceEditorView.xaml + Code + + + + TextView.xaml + Code + Always @@ -108,6 +143,10 @@ ICSharpCode.Core False + + {7E4A7172-7FF5-48D0-B719-7CD959DD1AC9} + ICSharpCode.Core.Presentation + {857CA1A3-FC88-4BE0-AB6A-D1EE772AB288} ICSharpCode.Core.WinForms @@ -119,5 +158,16 @@ False + + + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/BitmapExtensions.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/BitmapExtensions.cs new file mode 100644 index 0000000000..f5348e36e2 --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/BitmapExtensions.cs @@ -0,0 +1,50 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Interop; +using System.Windows.Media.Imaging; + +namespace ResourceEditor +{ + /// + /// Bitmap conversion extensions for WinForms -> WPF + /// + public static class BitmapExtensions + { + [DllImport("gdi32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool DeleteObject(IntPtr hObject); + + public static BitmapSource ToBitmapSource(this System.Drawing.Bitmap bitmap) + { + BitmapSource bs; + IntPtr hBitmap = bitmap.GetHbitmap(); + try { + bs = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, + Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); + bs.Freeze(); + } finally { + DeleteObject(hBitmap); + } + return bs; + } + } +} diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs index 29672f20a0..db9ef94670 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs @@ -17,14 +17,14 @@ // DEALINGS IN THE SOFTWARE. using System; -using System.Drawing; using System.IO; using System.Runtime.Serialization.Formatters.Binary; -using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; +using Microsoft.Win32; +using ResourceEditor.ViewModels; namespace ResourceEditor { @@ -32,47 +32,49 @@ namespace ResourceEditor { public override void Run() { - ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; + ResourceEditorViewModel editor = ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor; - if(editor.ResourceList.WriteProtected) { - return; - } + // TODO Reactivate this +// if (editor.ResourceList.WriteProtected) { +// return; +// } - using (OpenFileDialog fdiag = new OpenFileDialog()) { - fdiag.AddExtension = true; - fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*"); - fdiag.Multiselect = true; - fdiag.CheckFileExists = true; - - if (fdiag.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) { - foreach (string filename in fdiag.FileNames) { - string oresname = Path.ChangeExtension(Path.GetFileName(filename), null); - if (oresname == "") oresname = "new"; - - string resname = oresname; - - int i = 0; - TestName: - if (editor.ResourceList.Resources.ContainsKey(resname)) { - if (i == 10) { - continue; - } - i++; - resname = oresname + "_" + i.ToString(); - goto TestName; - } - - object tmp = loadResource(filename); - if (tmp == null) { - continue; - } - editor.ResourceList.Resources.Add(resname, new ResourceItem(resname, tmp)); - - } - editor.ResourceList.InitializeListView(); - } - } - editor.ResourceList.OnChanged(); +// using (OpenFileDialog fdiag = new OpenFileDialog()) { +// fdiag.AddExtension = true; +// fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*"); +// fdiag.Multiselect = true; +// fdiag.CheckFileExists = true; +// +// if (fdiag.ShowDialog()) { +// foreach (string filename in fdiag.FileNames) { +// string oresname = Path.ChangeExtension(Path.GetFileName(filename), null); +// if (oresname == "") +// oresname = "new"; +// +// string resname = oresname; +// +// int i = 0; +// TestName: +// if (editor.ResourceList.Resources.ContainsKey(resname)) { +// if (i == 10) { +// continue; +// } +// i++; +// resname = oresname + "_" + i.ToString(); +// goto TestName; +// } +// +// object tmp = loadResource(filename); +// if (tmp == null) { +// continue; +// } +// editor.ResourceList.Resources.Add(resname, new ResourceItem(resname, tmp)); +// +// } +// editor.ResourceList.InitializeListView(); +// } +// } +// editor.ResourceList.OnChanged(); } object loadResource(string name) @@ -80,21 +82,22 @@ namespace ResourceEditor switch (Path.GetExtension(name).ToUpperInvariant()) { case ".CUR": try { - return new Cursor(name); + return new System.Windows.Forms.Cursor(name); } catch { return null; } case ".ICO": try { - return new Icon(name); + return new System.Drawing.Icon(name); } catch { return null; } default: // try to read a bitmap try { - return new Bitmap(name); - } catch {} + return new System.Drawing.Bitmap(name); + } catch { + } // try to read a serialized object try { @@ -104,8 +107,11 @@ namespace ResourceEditor object o = c.Deserialize(r); r.Close(); return o; - } catch { r.Close(); } - } catch { } + } catch { + r.Close(); + } + } catch { + } // try to read a byte array :) try { @@ -115,7 +121,7 @@ namespace ResourceEditor d = r.ReadBytes((int) s.Length); s.Close(); return d; - } catch(Exception) { + } catch (Exception) { string message = ResourceService.GetString("ResourceEditor.Messages.CantLoadResource"); diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs index 8b5b4fa376..f36780a98e 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs @@ -20,6 +20,7 @@ using System; using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; +using ResourceEditor.ViewModels; namespace ResourceEditor { @@ -27,28 +28,29 @@ namespace ResourceEditor { public override void Run() { - ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; + ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - if(editor.ResourceList.WriteProtected) { - return; - } - - int count = 1; - string newNameBase = " new string entry "; - string newName = newNameBase + count.ToString(); - string type = "System.String"; - - while(editor.ResourceList.Resources.ContainsKey(newName)) { - count++; - newName = newNameBase + count.ToString(); - } - - ResourceItem item = new ResourceItem(newName, ""); - editor.ResourceList.Resources.Add(newName, item); - ListViewItem lv = new ListViewItem(new string[] { newName, type, "" }, item.ImageIndex); - editor.ResourceList.Items.Add(lv); - editor.ResourceList.OnChanged(); - lv.BeginEdit(); + // TODO Reactivate this +// if(editor.ResourceList.WriteProtected) { +// return; +// } +// +// int count = 1; +// string newNameBase = " new string entry "; +// string newName = newNameBase + count.ToString(); +// string type = "System.String"; +// +// while(editor.ResourceList.Resources.ContainsKey(newName)) { +// count++; +// newName = newNameBase + count.ToString(); +// } +// +// ResourceItem item = new ResourceItem(newName, ""); +// editor.ResourceList.Resources.Add(newName, item); +// ListViewItem lv = new ListViewItem(new string[] { newName, type, "" }, item.ImageIndex); +// editor.ResourceList.Items.Add(lv); +// editor.ResourceList.OnChanged(); +// lv.BeginEdit(); } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs index 93de120f94..8cbe918ce1 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs @@ -21,6 +21,7 @@ using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; +using ResourceEditor.ViewModels; namespace ResourceEditor { @@ -28,11 +29,12 @@ namespace ResourceEditor { public override void Run() { - ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; + ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - if(editor.ResourceList.SelectedItems.Count > 0) { - Clipboard.SetText(editor.ResourceList.SelectedItems[0].Text); - } + // TODO Reactivate this +// if(editor.ResourceList.SelectedItems.Count > 0) { +// Clipboard.SetText(editor.ResourceList.SelectedItems[0].Text); +// } } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs index 9ca56f1a82..6d32310cd1 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs @@ -19,6 +19,7 @@ using System; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; +using ResourceEditor.ViewModels; namespace ResourceEditor { @@ -26,17 +27,19 @@ namespace ResourceEditor { public override void Run() { - ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; - if (editor.ResourceList.SelectedItems.Count != 0) { - var item = editor.ResourceList.SelectedItems[0].SubItems[3]; - string resourceName = editor.ResourceList.SelectedItems[0].Text; - string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}", - "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}", - item.Text); - if (newValue != null && newValue != item.Text) { - editor.ResourceList.SetCommentValue(resourceName, newValue); - } - } + ResourceEditorViewModel editor = ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor; + + // TODO Reactivate this +// if (editor.ResourceList.SelectedItems.Count != 0) { +// var item = editor.ResourceList.SelectedItems[0].SubItems[3]; +// string resourceName = editor.ResourceList.SelectedItems[0].Text; +// string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}", +// "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}", +// item.Text); +// if (newValue != null && newValue != item.Text) { +// editor.ResourceList.SetCommentValue(resourceName, newValue); +// } +// } } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs index a374788e8b..e033aed956 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs @@ -19,6 +19,7 @@ using System; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; +using ResourceEditor.ViewModels; namespace ResourceEditor { @@ -26,11 +27,12 @@ namespace ResourceEditor { public override void Run() { - ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; + ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - if(editor.ResourceList.SelectedItems.Count != 0) { - editor.ResourceList.SelectedItems[0].BeginEdit(); - } + // TODO Reactivate this +// if(editor.ResourceList.SelectedItems.Count != 0) { +// editor.ResourceList.SelectedItems[0].BeginEdit(); +// } } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs index e6cf8a4a99..8a4f2897b2 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs @@ -24,6 +24,7 @@ using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; +using ResourceEditor.ViewModels; namespace ResourceEditor { @@ -31,62 +32,64 @@ namespace ResourceEditor { public override void Run() { - ResourceEditorControl editor = ((ResourceEditWrapper)SD.Workbench.ActiveViewContent).ResourceEditor; - ResourceList list = editor.ResourceList; + ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - if(list.SelectedItems.Count != 1) { - return; - } - - string key = list.SelectedItems[0].Text; - if(! list.Resources.ContainsKey(key)) { - return; - } - - ResourceItem item = list.Resources[key]; - SaveFileDialog sdialog = new SaveFileDialog(); - sdialog.AddExtension = true; - sdialog.FileName = key; - - if (item.ResourceValue is Bitmap) { - sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.ImageFiles} (*.png)|*.png"); - sdialog.DefaultExt = ".png"; - } else if (item.ResourceValue is Icon) { - sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.Icons}|*.ico"); - sdialog.DefaultExt = ".ico"; - } else if (item.ResourceValue is Cursor) { - sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.CursorFiles} (*.cur)|*.cur"); - sdialog.DefaultExt = ".cur"; - } else if (item.ResourceValue is byte[]){ - sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.BinaryFiles} (*.*)|*.*"); - sdialog.DefaultExt = ".bin"; - } else { - return; - } - - DialogResult dr = sdialog.ShowDialog(SD.WinForms.MainWin32Window); - sdialog.Dispose(); - if (dr != DialogResult.OK) { - return; - } - - try { - if (item.ResourceValue is Icon) { - FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); - ((Icon)item.ResourceValue).Save(fstr); - fstr.Close(); - } else if(item.ResourceValue is Image) { - Image img = (Image)item.ResourceValue; - img.Save(sdialog.FileName); - } else { - FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); - BinaryWriter wr = new BinaryWriter(fstr); - wr.Write((byte[])item.ResourceValue); - fstr.Close(); - } - } catch(Exception ex) { - MessageBox.Show(ex.Message, "Can't save resource to " + sdialog.FileName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - } + // TODO Reactivate this +// ResourceList list = editor.ResourceList; +// +// if(list.SelectedItems.Count != 1) { +// return; +// } +// +// string key = list.SelectedItems[0].Text; +// if(! list.Resources.ContainsKey(key)) { +// return; +// } +// +// ResourceItem item = list.Resources[key]; +// SaveFileDialog sdialog = new SaveFileDialog(); +// sdialog.AddExtension = true; +// sdialog.FileName = key; +// +// if (item.ResourceValue is Bitmap) { +// sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.ImageFiles} (*.png)|*.png"); +// sdialog.DefaultExt = ".png"; +// } else if (item.ResourceValue is Icon) { +// sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.Icons}|*.ico"); +// sdialog.DefaultExt = ".ico"; +// } else if (item.ResourceValue is Cursor) { +// sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.CursorFiles} (*.cur)|*.cur"); +// sdialog.DefaultExt = ".cur"; +// } else if (item.ResourceValue is byte[]){ +// sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.BinaryFiles} (*.*)|*.*"); +// sdialog.DefaultExt = ".bin"; +// } else { +// return; +// } +// +// DialogResult dr = sdialog.ShowDialog(SD.WinForms.MainWin32Window); +// sdialog.Dispose(); +// if (dr != DialogResult.OK) { +// return; +// } +// +// try { +// if (item.ResourceValue is Icon) { +// FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); +// ((Icon)item.ResourceValue).Save(fstr); +// fstr.Close(); +// } else if(item.ResourceValue is Image) { +// Image img = (Image)item.ResourceValue; +// img.Save(sdialog.FileName); +// } else { +// FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); +// BinaryWriter wr = new BinaryWriter(fstr); +// wr.Write((byte[])item.ResourceValue); +// fstr.Close(); +// } +// } catch(Exception ex) { +// MessageBox.Show(ex.Message, "Can't save resource to " + sdialog.FileName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); +// } } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEditorDisplayBinding.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEditorDisplayBinding.cs index 6fc0f754c0..6b38c9f829 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEditorDisplayBinding.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ResourceEditorDisplayBinding.cs @@ -27,6 +27,8 @@ using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.WinForms; using ICSharpCode.SharpDevelop.Workbench; +using ResourceEditor.ViewModels; +using ResourceEditor.Views; namespace ResourceEditor { @@ -39,7 +41,7 @@ namespace ResourceEditor public IViewContent CreateContentForFile(OpenedFile file) { - return new ResourceEditWrapper(file); + return new ResourceEditViewContent(file); } public bool IsPreferredBindingForFile(FileName fileName) @@ -53,211 +55,60 @@ namespace ResourceEditor } } - public class ResourceEditWrapper : AbstractViewContentHandlingLoadErrors, IClipboardHandler + public class ResourceEditViewContent : AbstractViewContentHandlingLoadErrors { - ResourceEditorControl resourceEditor = new ResourceEditorControl(); + readonly ResourceEditorViewModel resourceEditor = new ResourceEditorViewModel(); + readonly ResourceEditorView resourceEditorView = new ResourceEditorView(); - public ResourceEditorControl ResourceEditor { - get { return resourceEditor; } + public ResourceEditViewContent(OpenedFile file) + { + this.TabPageText = "Resource editor"; + resourceEditor.View = resourceEditorView; + + // Register different resource item viewers + resourceEditor.AddItemView(ResourceItemEditorType.String, new Views.TextView()); + resourceEditor.AddItemView(ResourceItemEditorType.Bitmap, new Views.ImageViewBase()); + resourceEditor.DirtyStateChanged += (sender, e) => { + if (e.IsDirty) + SetDirty(sender, new EventArgs()); + }; + + UserContent = resourceEditorView; +// resourceEditor.ResourceList.Changed += SetDirty; +// resourceEditor.ResourceList.ItemSelectionChanged += (sender, e) => SD.WinForms.InvalidateCommands(); + this.Files.Add(file); } + public ResourceEditorViewModel ResourceEditor { + get { return resourceEditor; } + } + public override bool IsReadOnly { get { return false; } } - + void SetDirty(object sender, EventArgs e) { PrimaryFile.MakeDirty(); - SD.WinForms.InvalidateCommands(); - } - - public ResourceEditWrapper(OpenedFile file) - { - this.TabPageText = "Resource editor"; - UserContent = resourceEditor; - resourceEditor.ResourceList.Changed += SetDirty; - resourceEditor.ResourceList.ItemSelectionChanged += (sender, e) => SD.WinForms.InvalidateCommands(); - this.Files.Add(file); +// SD.WinForms.InvalidateCommands(); } public override void Dispose() { base.Dispose(); - resourceEditor.Dispose(); +// resourceEditor.Dispose(); } protected override void LoadInternal(OpenedFile file, Stream stream) { - resourceEditor.ResourceList.LoadFile(file.FileName, stream); + resourceEditor.LoadFile(file.FileName, stream); } protected override void SaveInternal(OpenedFile file, Stream stream) { - resourceEditor.ResourceList.SaveFile(file.FileName, stream); - } - - - public bool EnableCut - { - get { - if (resourceEditor.ResourceList.IsEditing) { - return false; - } - return resourceEditor.ResourceList.SelectedItems.Count > 0; - } - } - - public bool EnableCopy - { - get { - if (resourceEditor.ResourceList.IsEditing) { - return false; - } - return resourceEditor.ResourceList.SelectedItems.Count > 0; - } - } - - public bool EnablePaste - { - get { - if (resourceEditor.ResourceList.IsEditing) { - return false; - } - return true; - } - } - - public bool EnableDelete - { - get { - if (resourceEditor.ResourceList.IsEditing) { - return false; - } - return resourceEditor.ResourceList.SelectedItems.Count > 0; - } - } - - public bool EnableSelectAll - { - get { - if (resourceEditor.ResourceList.IsEditing) { - return false; - } - return true; - } - } - - public void Cut() - { - if (resourceEditor.ResourceList.WriteProtected || resourceEditor.ResourceList.SelectedItems.Count < 1) - return; - - Hashtable tmphash = new Hashtable(); - foreach (ListViewItem item in resourceEditor.ResourceList.SelectedItems) { - tmphash.Add(item.Text, resourceEditor.ResourceList.Resources[item.Text].ResourceValue); - resourceEditor.ResourceList.Resources.Remove(item.Text); - resourceEditor.ResourceList.Items.Remove(item); - } - resourceEditor.ResourceList.OnChanged(); - SD.Clipboard.SetDataObject(tmphash); - } - - public void Copy() - { - if (resourceEditor.ResourceList.SelectedItems.Count < 1) { - return; - } - - Hashtable tmphash = new Hashtable(); - foreach (ListViewItem item in resourceEditor.ResourceList.SelectedItems) { - object resourceValue = GetClonedResource(resourceEditor.ResourceList.Resources[item.Text].ResourceValue); - tmphash.Add(item.Text, resourceValue); // copy a clone to clipboard - } - SD.Clipboard.SetDataObject(tmphash); - } - - public void Paste() - { - if (resourceEditor.ResourceList.WriteProtected) { - return; - } - - IDataObject dob = Clipboard.GetDataObject(); - if (dob == null) - return; - - if (dob.GetDataPresent(typeof(Hashtable).FullName)) { - Hashtable tmphash = (Hashtable)dob.GetData(typeof(Hashtable)); - foreach (DictionaryEntry entry in tmphash) { - - object resourceValue = GetClonedResource(entry.Value); - ResourceItem item; - - if (!resourceEditor.ResourceList.Resources.ContainsKey((string)entry.Key)) { - item = new ResourceItem(entry.Key.ToString(), resourceValue); - } else { - int count = 1; - string newNameBase = entry.Key.ToString() + " "; - string newName = newNameBase + count.ToString(); - - while(resourceEditor.ResourceList.Resources.ContainsKey(newName)) { - count++; - newName = newNameBase + count.ToString(); - } - item = new ResourceItem(newName, resourceValue); - } - resourceEditor.ResourceList.Resources.Add(item.Name, item); - resourceEditor.ResourceList.OnChanged(); - } - resourceEditor.ResourceList.InitializeListView(); - } - } - - /// - /// Clones a resource if the - /// is cloneable. - /// - /// A resource to clone. - /// A cloned resource if the object implements - /// the ICloneable interface, otherwise the - /// object. - object GetClonedResource(object resource) - { - object clonedResource = null; - - ICloneable cloneableResource = resource as ICloneable; - if (cloneableResource != null) { - clonedResource = cloneableResource.Clone(); - } else { - clonedResource = resource; - } - - return clonedResource; - } - - public void Delete() - { - var resourceList = resourceEditor.ResourceList; - if (resourceList.WriteProtected || resourceList.SelectedItems.Count == 0) - return; - if (!SD.MessageService.AskQuestion("${res:ResourceEditor.DeleteEntry.Confirm}", "${res:ResourceEditor.DeleteEntry.Title}")) - return; - - foreach (ListViewItem item in resourceList.SelectedItems) { - resourceList.Resources.Remove(item.Text); - resourceList.Items.Remove(item); - // and set dirty flag - resourceList.OnChanged(); - } - } - - public void SelectAll() - { - foreach (ListViewItem i in resourceEditor.ResourceList.Items) { - i.Selected=true; - } + resourceEditor.SaveFile(file.FileName, stream); } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs new file mode 100644 index 0000000000..6983c545c7 --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs @@ -0,0 +1,421 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.IO; +using System.Linq; +using System.Resources; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using ICSharpCode.Core; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Project; +using ICSharpCode.SharpDevelop.Project.Commands; +using ResourceEditor.Views; + +namespace ResourceEditor.ViewModels +{ + public class ChangedDirtyStateEventArgs : EventArgs + { + public ChangedDirtyStateEventArgs(bool isDirty) + { + this.IsDirty = isDirty; + } + + public bool IsDirty { + get; + private set; + } + } + + /// + /// Main view model for resource editor. + /// + public class ResourceEditorViewModel : DependencyObject + { + readonly ObservableCollection resourceItems; + readonly HashSet resourceItemNames; + readonly ObservableCollection metadataItems; + readonly Dictionary itemViews; + bool longUpdateRunning; + + IResourceEditorView view; + + public event EventHandler DirtyStateChanged; + + public static readonly DependencyProperty SearchTermProperty = + DependencyProperty.Register("SearchTerm", typeof(string), typeof(ResourceEditorViewModel), + new FrameworkPropertyMetadata()); + + public string SearchTerm { + get { return (string)GetValue(SearchTermProperty); } + set { SetValue(SearchTermProperty, value); } + } + + public IList SelectedItems { + get { + if (view != null) { + return view.SelectedItems; + } + + return null; + } + } + + public ResourceEditorViewModel() + { + resourceItems = new ObservableCollection(); + resourceItemNames = new HashSet(); + metadataItems = new ObservableCollection(); + itemViews = new Dictionary(); + } + + public ObservableCollection ResourceItems { + get { + return resourceItems; + } + } + + public void AddItemView(ResourceItemEditorType itemType, IResourceItemView view) + { + itemViews[itemType] = view; + } + + public IResourceEditorView View { + get { + return view; + } + set { + if (view != null) { + view.SelectionChanged += View_SelectionChanged; + ResourceItems.CollectionChanged -= ResourceItems_CollectionChanged; + } + + view = value; + if (view != null) { + // Bind this model to new view + view.DataContext = this; + view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, (s, e) => Cut(), (s, e) => e.CanExecute = EnableCut)); + view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (s, e) => Copy(), (s, e) => e.CanExecute = EnableCopy)); + view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, (s, e) => Paste(), (s, e) => e.CanExecute = EnablePaste)); + view.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, (s, e) => Delete(), (s, e) => e.CanExecute = EnableDelete)); + view.CommandBindings.Add(new CommandBinding(ApplicationCommands.SelectAll, (s, e) => SelectAll(), (s, e) => e.CanExecute = EnableSelectAll)); + + view.FilterPredicate = resourceItem => { + if (SearchTerm != null) + return resourceItem.Name.IndexOf(SearchTerm, StringComparison.OrdinalIgnoreCase) >= 0; + return true; + }; + view.SelectionChanged += View_SelectionChanged; + ResourceItems.CollectionChanged += ResourceItems_CollectionChanged; + } + } + } + + void ResourceItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + switch (e.Action) { + case NotifyCollectionChangedAction.Remove: + if (e.OldItems != null) { + var oldItems = e.OldItems.OfType(); + foreach (var item in oldItems) { + resourceItemNames.Remove(item.Name); + } + } + break; + case NotifyCollectionChangedAction.Add: + if (e.NewItems != null) { + var newItems = e.NewItems.OfType(); + foreach (var item in newItems) { + if (!resourceItemNames.Contains(item.Name)) + resourceItemNames.Add(item.Name); + } + } + break; + case NotifyCollectionChangedAction.Reset: + resourceItemNames.Clear(); + break; + } + + // Changes in collection of ResourceItems => make dirty + MakeDirty(); + } + + void View_SelectionChanged(object sender, EventArgs e) + { + if (longUpdateRunning) + return; + + ResourceItem selectedItem = SelectedItems.OfType().FirstOrDefault(); + if (selectedItem != null) { + if (itemViews.ContainsKey(selectedItem.ResourceType)) { + var itemView = itemViews[selectedItem.ResourceType]; + itemView.ResourceItem = selectedItem; + view.SetItemView(itemView); + } + } + } + + void OnChangedDirtyState(bool isDirty) + { + if (DirtyStateChanged != null) { + DirtyStateChanged(this, new ChangedDirtyStateEventArgs(isDirty)); + } + } + + public void MakeDirty() + { + OnChangedDirtyState(true); + } + + void StartUpdate() + { + // When loading many items at once, temporarily unbind view from model + view.DataContext = null; + } + + void EndUpdate() + { + view.DataContext = this; + } + + public void LoadFile(FileName filename, Stream stream) + { + StartUpdate(); + + resourceItems.Clear(); + metadataItems.Clear(); + switch (Path.GetExtension(filename).ToLowerInvariant()) { + case ".resx": + ResXResourceReader rx = new ResXResourceReader(stream); + ITypeResolutionService typeResolver = null; + rx.BasePath = Path.GetDirectoryName(filename); + rx.UseResXDataNodes = true; + IDictionaryEnumerator n = rx.GetEnumerator(); + while (n.MoveNext()) { + ResXDataNode node = (ResXDataNode)n.Value; + resourceItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver), node.Comment)); + } + + n = rx.GetMetadataEnumerator(); + while (n.MoveNext()) { + ResXDataNode node = (ResXDataNode)n.Value; + metadataItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver))); + } + + rx.Close(); + break; + case ".resources": + ResourceReader rr = null; + try { + rr = new ResourceReader(stream); + foreach (DictionaryEntry entry in rr) { + resourceItems.Add(new ResourceItem(this, entry.Key.ToString(), entry.Value)); + } + } finally { + if (rr != null) { + rr.Close(); + } + } + break; + } + + EndUpdate(); + } + + public void SaveFile(FileName filename, Stream stream) + { + switch (Path.GetExtension(filename).ToLowerInvariant()) { + case ".resx": + // write XML resource + ResXResourceWriter rxw = new ResXResourceWriter(stream, t => ResXConverter.ConvertTypeName(t, filename)); + foreach (ResourceItem entry in resourceItems) { + if (entry != null) { + rxw.AddResource(entry.ToResXDataNode(t => ResXConverter.ConvertTypeName(t, filename))); + } + } + foreach (ResourceItem entry in metadataItems) { + if (entry != null) { + rxw.AddMetadata(entry.Name, entry.ResourceValue); + } + } + rxw.Generate(); + rxw.Close(); + break; + default: + // write default resource + ResourceWriter rw = new ResourceWriter(stream); + foreach (ResourceItem entry in resourceItems) { + rw.AddResource(entry.Name, entry.ResourceValue); + } + rw.Generate(); + rw.Close(); + break; + } + } + + #region Standard clipboard commands + + public bool EnableCut { + get { + return SelectedItems.Count > 0; + } + } + + public bool EnableCopy { + get { + return SelectedItems.Count > 0; + } + } + + public bool EnablePaste { + get { + return true; + } + } + + public bool EnableDelete { + get { + return SelectedItems.Count > 0; + } + } + + public bool EnableSelectAll { + get { + return true; + } + } + + public void Cut() + { + // if (resourceEditor.ResourceList.WriteProtected || resourceEditor.ResourceList.SelectedItems.Count < 1) + // return; + if (SelectedItems.Count == 0) + return; + + Hashtable tmphash = new Hashtable(); + foreach (var selectedItem in SelectedItems.OfType().ToList()) { + tmphash.Add(selectedItem.Name, selectedItem.ResourceValue); + resourceItems.Remove(selectedItem); + } + SD.Clipboard.SetDataObject(tmphash); + } + + public void Copy() + { + if (SelectedItems.Count == 0) + return; + + Hashtable tmphash = new Hashtable(); + foreach (var selectedItem in SelectedItems.OfType().ToList()) { + object resourceValue = GetClonedResource(selectedItem.ResourceValue); + tmphash.Add(selectedItem.Name, resourceValue); + } + SD.Clipboard.SetDataObject(tmphash); + } + + public void Paste() + { + // if (resourceEditor.ResourceList.WriteProtected) { + // return; + // } + + IDataObject dob = Clipboard.GetDataObject(); + if (dob == null) + return; + + if (dob.GetDataPresent(typeof(Hashtable).FullName)) { + Hashtable tmphash = (Hashtable)dob.GetData(typeof(Hashtable)); + foreach (DictionaryEntry entry in tmphash) { + object resourceValue = GetClonedResource(entry.Value); + ResourceItem item; + + if (!resourceItemNames.Contains((string)entry.Key)) { + item = new ResourceItem(this, entry.Key.ToString(), resourceValue); + } else { + int count = 1; + string newNameBase = entry.Key + " "; + string newName = newNameBase + count; + + while (resourceItemNames.Contains(newName)) { + count++; + newName = newNameBase + count; + } + item = new ResourceItem(this, newName, resourceValue); + } + resourceItems.Add(item); + // TODO Set selection to new element? + } + } + } + + /// + /// Clones a resource if the + /// is cloneable. + /// + /// A resource to clone. + /// A cloned resource if the object implements + /// the ICloneable interface, otherwise the + /// object. + object GetClonedResource(object resource) + { + object clonedResource = null; + + ICloneable cloneableResource = resource as ICloneable; + if (cloneableResource != null) { + clonedResource = cloneableResource.Clone(); + } else { + clonedResource = resource; + } + + return clonedResource; + } + + public void Delete() + { +// if (resourceList.WriteProtected || resourceList.SelectedItems.Count == 0) +// return; + + if (SelectedItems.Count > 0) { + if (!SD.MessageService.AskQuestion("${res:ResourceEditor.DeleteEntry.Confirm}", "${res:ResourceEditor.DeleteEntry.Title}")) + return; + + foreach (var item in SelectedItems.OfType().ToList()) { + resourceItems.Remove(item); + } + } + } + + public void SelectAll() + { + longUpdateRunning = true; + foreach (var i in resourceItems) + SelectedItems.Add(i); + longUpdateRunning = false; + } + + #endregion + } +} diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs new file mode 100644 index 0000000000..f24fa6de6a --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs @@ -0,0 +1,229 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.ComponentModel; +using System.Drawing; +using System.Resources; +using System.Windows.Forms; +using ICSharpCode.SharpDevelop; + +namespace ResourceEditor.ViewModels +{ + /// + /// Defines the type of resource item supported by editor. + /// + public enum ResourceItemEditorType + { + Unknown, + String, + Boolean, + Bitmap, + Icon, + Cursor, + Binary + } + + public class ResourceItem : INotifyPropertyChanged + { + string name; + object resourceValue; + string comment; + ResourceItemEditorType resourceType; + ResourceEditorViewModel resourceEditor; + + public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue) + { + this.resourceEditor = resourceEditor; + this.name = name; + this.resourceValue = resourceValue; + this.resourceType = GetResourceTypeFromValue(resourceValue); + } + + public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue, string comment) + { + this.resourceEditor = resourceEditor; + this.name = name; + this.resourceValue = resourceValue; + this.resourceType = GetResourceTypeFromValue(resourceValue); + this.comment = comment; + } + + #region INotifyPropertyChanged implementation + + public event PropertyChangedEventHandler PropertyChanged; + + void OnPropertyChanged(string propertyName) + { + if (PropertyChanged != null) { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + + #endregion + + public string Name { + get { + return name; + } + set { + name = value; + OnPropertyChanged("Name"); + } + } + + public object ResourceValue { + get { + return resourceValue; + } + set { + resourceValue = value; + OnPropertyChanged("ResourceValue"); + OnPropertyChanged("ResourceType"); + OnPropertyChanged("Content"); + resourceEditor.MakeDirty(); + } + } + + public string DisplayedResourceType { + get { + return ResourceValue == null ? "(Nothing/null)" : ResourceValue.GetType().FullName; + } + } + + public ResourceItemEditorType ResourceType { + get { + return resourceType; + } + } + + ResourceItemEditorType GetResourceTypeFromValue(object val) + { + if (this.ResourceValue == null) { + return ResourceItemEditorType.Unknown; + } + switch (this.ResourceValue.GetType().ToString()) { + case "System.String": + return ResourceItemEditorType.String; + case "System.Drawing.Bitmap": + return ResourceItemEditorType.Bitmap; + case "System.Drawing.Icon": + return ResourceItemEditorType.Icon; + case "System.Windows.Forms.Cursor": + return ResourceItemEditorType.Cursor; + case "System.Byte[]": + return ResourceItemEditorType.Binary; + case "System.Boolean": + return ResourceItemEditorType.Boolean; + default: + return ResourceItemEditorType.Unknown; + } + } + + public string Content { + get { + return ToString(); + } + } + + public string Comment { + get { + return comment; + } + set { + comment = value; + OnPropertyChanged("Comment"); + } + } + + public override string ToString() + { + if (ResourceValue == null) { + return "(Nothing/null)"; + } + + string type = ResourceValue.GetType().FullName; + string tmp = String.Empty; + + switch (type) { + case "System.String": + tmp = ResourceValue.ToString(); + break; + case "System.Byte[]": + tmp = "[Size = " + ((byte[])ResourceValue).Length + "]"; + break; + case "System.Drawing.Bitmap": + Bitmap bmp = ResourceValue as Bitmap; + tmp = "[Width = " + bmp.Size.Width + ", Height = " + bmp.Size.Height + "]"; + break; + case "System.Drawing.Icon": + Icon icon = ResourceValue as Icon; + tmp = "[Width = " + icon.Size.Width + ", Height = " + icon.Size.Height + "]"; + break; + case "System.Windows.Forms.Cursor": + Cursor c = ResourceValue as Cursor; + tmp = "[Width = " + c.Size.Width + ", Height = " + c.Size.Height + "]"; + break; + case "System.Boolean": + tmp = ResourceValue.ToString(); + break; + default: + tmp = ResourceValue.ToString(); + break; + } + return tmp; + } + + public ResXDataNode ToResXDataNode(Func typeNameConverter = null) + { + var node = new ResXDataNode(Name, ResourceValue, typeNameConverter) { + Comment = Comment + }; + return node; + } + + public bool UpdateFromFile() + { + var fileDialog = new Microsoft.Win32.OpenFileDialog(); + fileDialog.AddExtension = true; + fileDialog.Filter = "All files (*.*)|*.*"; + fileDialog.CheckFileExists = true; + + if (fileDialog.ShowDialog().Value) { + object newValue = null; + switch (resourceType) { + case ResourceItemEditorType.Bitmap: + try { + newValue = new Bitmap(fileDialog.FileName); + } catch { + SD.MessageService.ShowWarning("Can't load bitmap file."); + return false; + } + break; + } + + if (newValue != null) { + ResourceValue = newValue; + return true; + } + } + + return false; + } + } +} diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml new file mode 100644 index 0000000000..bbf7b5621b --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml.cs new file mode 100644 index 0000000000..cc310d86ec --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BinaryView.xaml.cs @@ -0,0 +1,41 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; + +namespace ResourceEditor.Views +{ + /// + /// Interaction logic for BinaryView.xaml + /// + public partial class BinaryView : UserControl + { + public BinaryView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml new file mode 100644 index 0000000000..fb14f41549 --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml.cs new file mode 100644 index 0000000000..f5055919ac --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/BooleanView.xaml.cs @@ -0,0 +1,41 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; + +namespace ResourceEditor.Views +{ + /// + /// Interaction logic for BooleanView.xaml + /// + public partial class BooleanView : UserControl + { + public BooleanView() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs new file mode 100644 index 0000000000..4517b1ba38 --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs @@ -0,0 +1,55 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Windows; +using System.Windows.Input; + +namespace ResourceEditor.Views +{ + /// + /// Base interface for resource editor main views. + /// + public interface IResourceEditorView + { + CommandBindingCollection CommandBindings { + get; + } + + event EventHandler SelectionChanged; + IList SelectedItems { + get; + } + + void SetItemView(IResourceItemView view); + + object DataContext { + get; + set; + } + + Predicate FilterPredicate + { + get; + set; + } + } +} diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ClipboardCommands.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceItemView.cs similarity index 80% rename from src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ClipboardCommands.cs rename to src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceItemView.cs index 835846c92f..9e8a7a9163 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ClipboardCommands.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceItemView.cs @@ -16,21 +16,18 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. + using System; -using ICSharpCode.Core; -using ICSharpCode.SharpDevelop; +using System.Windows; -namespace ResourceEditor +namespace ResourceEditor.Views { - - class SelectAllCommand : AbstractMenuCommand + /// + /// Interface for resource item views. + /// + public interface IResourceItemView { - public override void Run() - { - ResourceEditWrapper editor = (ResourceEditWrapper)SD.Workbench.ActiveViewContent; - - editor.SelectAll(); - } + ResourceEditor.ViewModels.ResourceItem ResourceItem { get; set; } + FrameworkElement UIControl { get; } } - } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml new file mode 100644 index 0000000000..8e7e41dd9d --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml @@ -0,0 +1,13 @@ + + + + + + + + class ReportWizardCommand: AbstractMenuCommand { - readonly OpenedFile file; - - public ReportWizardCommand (OpenedFile file) { - if (file == null) - throw new ArgumentNullException("file"); - this.file = file; - } public override void Run() { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/ReportWizardContext.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/ReportWizardContext.cs index bf663356b8..b3e22560b9 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/ReportWizardContext.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/ReportWizard/ViewModels/ReportWizardContext.cs @@ -19,32 +19,10 @@ namespace ICSharpCode.Reporting.Addin.ReportWizard.ViewModels /// public class ReportWizardContext:IWizardContext { - - - public string Title { - get{ return "das ist der Title";} - } - - IWizardContext pageOneContext; - public IWizardContext PageOneContext { - get { - return pageOneContext; - } - set { - pageOneContext = value; - } - } + public IWizardContext PageOneContext {get;set;} + + public IWizardContext PushModelContext {get;set;} - IWizardContext pushModelContext; - - public IWizardContext PushModelContext { - get { - return pushModelContext; - } - set { - pushModelContext = value; - } - } } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Services/ToolboxService.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Services/ToolboxService.cs index f8313da331..a129caebc3 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Services/ToolboxService.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Services/ToolboxService.cs @@ -189,13 +189,6 @@ namespace ICSharpCode.Reporting.Addin.Services if (serializedObject is System.Windows.Forms.IDataObject) { if (((System.Windows.Forms.IDataObject)serializedObject).GetDataPresent(typeof(ToolboxItem))) { var item = (ToolboxItem) ((System.Windows.Forms.IDataObject)serializedObject).GetData(typeof(ToolboxItem)); -// if (host != null) { -// ArrayList list = (ArrayList)toolboxByHost[host]; -// if (list != null && list.Contains(item)) { -// return true; -// } -// list = (ArrayList)toolboxByHost[ALL_HOSTS]; -// if (list != null && list.Contains(item)) { return true; // } // } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs index a49b85ab04..c4aca3d2cd 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs @@ -17,6 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Globalization; using System.Linq; using ICSharpCode.Reporting.PageBuilder.ExportColumns; using Irony.Ast; @@ -63,7 +64,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast } else { - return String.Format("Syntaxerror in Globals <{0}>",globalNode.AsString); + return String.Format(CultureInfo.CurrentCulture,"Syntaxerror in Globals <{0}>",globalNode.AsString); } } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs index 359cf57a8c..59138a0b1c 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs @@ -45,6 +45,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests Assert.That(s.Text.Contains("Page")); } + [Test] public void CanEvaluateComplexStatement () { reportCreator.BuildExportList(); @@ -53,6 +54,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests var s = (ExportText)sec.ExportedItems[0]; Assert.That (s.Text.Contains("1")); Assert.That(s.Text.Contains("Page")); + Assert.That(s.Text.Contains("Pages")); } [Test] From 3b6892c319d129f48a375d98e1da4ef38073a7d6 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 23 Aug 2014 22:40:13 +0200 Subject: [PATCH 079/146] Merge+squash #521 changed implementation of PanelSelectionHandler --- .../Extensions/PanelSelectionHandler.cs | 15 ++- .../PartialPanelSelectionHandler.cs | 108 ++++++++++++++++++ .../Project/WpfDesign.Designer.csproj | 1 + 3 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelSelectionHandler.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelSelectionHandler.cs index ddd3bb9d0b..3dce10d8ee 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelSelectionHandler.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelSelectionHandler.cs @@ -52,13 +52,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } } - sealed class RangeSelectionGesture : ClickOrDragMouseGesture + internal class RangeSelectionGesture : ClickOrDragMouseGesture { - DesignItem container; - AdornerPanel adornerPanel; - SelectionFrame selectionFrame; + protected DesignItem container; + protected AdornerPanel adornerPanel; + protected SelectionFrame selectionFrame; - GrayOutDesignerExceptActiveArea grayOut; + protected GrayOutDesignerExceptActiveArea grayOut; public RangeSelectionGesture(DesignItem container) { @@ -100,7 +100,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions Math.Abs(startPoint.Y - endPoint.Y) ); - ICollection items = GetChildDesignItemsInContainer(container, new RectangleGeometry(frameRect)); + ICollection items = GetChildDesignItemsInContainer(new RectangleGeometry(frameRect)); if (items.Count == 0) { items.Add(container); } @@ -109,8 +109,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions Stop(); } - static ICollection GetChildDesignItemsInContainer( - DesignItem container, Geometry geometry) + protected virtual ICollection GetChildDesignItemsInContainer(Geometry geometry) { HashSet resultItems = new HashSet(); ViewService viewService = container.Services.View; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs new file mode 100644 index 0000000000..26159e559d --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs @@ -0,0 +1,108 @@ +/* + * Created by SharpDevelop. + * User: trubra + * Date: 2014-08-06 + * Time: 14:13 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; + +using ICSharpCode.WpfDesign.Adorners; +using ICSharpCode.WpfDesign.Designer.Controls; +using ICSharpCode.WpfDesign.Designer.Services; +using ICSharpCode.WpfDesign.Extensions; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + public class PartialPanelSelectionHandler : BehaviorExtension, IHandlePointerToolMouseDown + { + protected override void OnInitialized() + { + base.OnInitialized(); + this.ExtendedItem.AddBehavior(typeof(IHandlePointerToolMouseDown), this); + } + + public new void HandleSelectionMouseDown(IDesignPanel designPanel, MouseButtonEventArgs e, DesignPanelHitTestResult result) + { + if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) + { + e.Handled = true; + new PartialRangeSelectionGesture(result.ModelHit).Start(designPanel, e); + } + } + } + + /// + /// + /// + internal class PartialRangeSelectionGesture : RangeSelectionGesture + { + public PartialRangeSelectionGesture(DesignItem container) + : base(container) + { + } + + protected override ICollection GetChildDesignItemsInContainer(Geometry geometry) + { + HashSet resultItems = new HashSet(); + ViewService viewService = container.Services.View; + + HitTestFilterCallback filterCallback = delegate(DependencyObject potentialHitTestTarget) + { + FrameworkElement element = potentialHitTestTarget as FrameworkElement; + if (element != null) + { + // ensure we are able to select elements with width/height=0 + if (element.ActualWidth == 0 || element.ActualHeight == 0) + { + DependencyObject tmp = element; + DesignItem model = null; + while (tmp != null) + { + model = viewService.GetModel(tmp); + if (model != null) break; + tmp = VisualTreeHelper.GetParent(tmp); + } + if (model != container) + { + resultItems.Add(model); + return HitTestFilterBehavior.ContinueSkipChildren; + } + } + } + return HitTestFilterBehavior.Continue; + }; + + HitTestResultCallback resultCallback = delegate(HitTestResult result) + { + if (((GeometryHitTestResult)result).IntersectionDetail == IntersectionDetail.FullyInside || (Mouse.RightButton== MouseButtonState.Pressed && ((GeometryHitTestResult)result).IntersectionDetail == IntersectionDetail.Intersects)) + { + // find the model for the visual contained in the selection area + DependencyObject tmp = result.VisualHit; + DesignItem model = null; + while (tmp != null) + { + model = viewService.GetModel(tmp); + if (model != null) break; + tmp = VisualTreeHelper.GetParent(tmp); + } + if (model != container) + { + resultItems.Add(model); + } + } + return HitTestResultBehavior.Continue; + }; + + VisualTreeHelper.HitTest(container.View, filterCallback, resultCallback, new GeometryHitTestParameters(geometry)); + return resultItems; + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index 5b38b78d68..ebbffae7ed 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -84,6 +84,7 @@ Configuration\GlobalAssemblyInfo.cs + RightClickContextMenu.xaml Code From 6c46af6b41828aa0c3420a3cc4659b07d3cf45a5 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 24 Aug 2014 10:51:41 +0200 Subject: [PATCH 080/146] Fix NullReferenceException in SharpDevelopInsightWindow --- .../Src/CodeCompletionEditorAdapter.cs | 7 ++++++- .../Src/SharpDevelopInsightWindow.cs | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeCompletionEditorAdapter.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeCompletionEditorAdapter.cs index 16ef070ad6..024b45eeee 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeCompletionEditorAdapter.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeCompletionEditorAdapter.cs @@ -78,7 +78,12 @@ namespace ICSharpCode.AvalonEdit.AddIn } public override IInsightWindow ActiveInsightWindow { - get { return textEditor.ActiveInsightWindow.activeAdapter; } + get { + if (textEditor.ActiveInsightWindow != null) + return textEditor.ActiveInsightWindow.activeAdapter; + else + return null; + } } public override ICompletionListWindow ActiveCompletionWindow { diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs index 0bed5d79f2..6e0da85587 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/SharpDevelopInsightWindow.cs @@ -94,17 +94,24 @@ namespace ICSharpCode.AvalonEdit.AddIn void OnClosed(object sender, EventArgs e) { - activeAdapter.OnClosed(); + if (activeAdapter != null) + activeAdapter.OnClosed(); } void caret_PositionChanged(object sender, EventArgs e) { - activeAdapter.OnCaretPositionChanged(e); + // It is possible that the insight window is not initialized correctly + // due to an exception, and then caret_PositionChanged is called in a finally block + // during exception handling. + // Check for a null adapter to avoid a NullReferenceException that hides the first exception. + if (activeAdapter != null) + activeAdapter.OnCaretPositionChanged(e); } void document_Changed(object sender, DocumentChangeEventArgs e) { - activeAdapter.OnDocumentChanged(e); + if (activeAdapter != null) + activeAdapter.OnDocumentChanged(e); } } From 8bdcedaa75927ae5a3bb8eed2040705bb79dc336 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 24 Aug 2014 10:28:31 +0200 Subject: [PATCH 081/146] make TreeViewOptionsDialog remember the last selection --- .../Gui/Dialogs/TreeViewOptionsDialog.xaml.cs | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptionsDialog.xaml.cs b/src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptionsDialog.xaml.cs index ed1c9afc9c..45a7df78ac 100644 --- a/src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptionsDialog.xaml.cs +++ b/src/Main/Base/Project/Src/Gui/Dialogs/TreeViewOptionsDialog.xaml.cs @@ -46,13 +46,10 @@ namespace ICSharpCode.SharpDevelop.Gui throw new ArgumentNullException("optionPanels"); InitializeComponent(); - ICSharpCode.SharpDevelop.Gui.FormLocationHelper.ApplyWindow(this, "TreeViewOptionsDialog.WindowBounds", true); + FormLocationHelper.ApplyWindow(this, "TreeViewOptionsDialog.WindowBounds", true); var list = optionPanels.Select(op => new OptionPanelNode(op, this)).ToList(); treeView.ItemsSource = list; - if (list.Count > 0) { - list[0].IsSelected = true; - } } void okButtonClick(object sender, RoutedEventArgs e) @@ -71,9 +68,42 @@ namespace ICSharpCode.SharpDevelop.Gui Close(); } + protected override void OnSourceInitialized(EventArgs e) + { + base.OnSourceInitialized(e); + string[] lastOpenedPanelID = SD.PropertyService.Get("TreeViewOptionsDialog.LastOpenedPanelID", "UIOptions/SelectCulture").Split('/'); + + OptionPanelNode lastOpenedPanelNode = null; + for (int i = 0; i < lastOpenedPanelID.Length; i++) { + IEnumerable currentList; + if (lastOpenedPanelNode == null) { + currentList = (IEnumerable)treeView.ItemsSource; + } else { + currentList = lastOpenedPanelNode.Children; + } + var nextNode = currentList.FirstOrDefault(op => lastOpenedPanelID[i].Equals(op.ID, StringComparison.Ordinal)); + if (nextNode == null) + break; + lastOpenedPanelNode = nextNode; + } + if (lastOpenedPanelNode != null) + lastOpenedPanelNode.IsSelected = true; + } + protected override void OnClosed(EventArgs e) { base.OnClosed(e); + var selectedPanelNode = treeView.SelectedItem as OptionPanelNode; + string openedPanelID = ""; + while (selectedPanelNode != null) { + if (openedPanelID.Length > 0) + openedPanelID = "/" + openedPanelID; + openedPanelID = selectedPanelNode.ID + openedPanelID; + selectedPanelNode = selectedPanelNode.Parent; + } + if (openedPanelID == "") + openedPanelID = "UIOptions/SelectCulture"; + SD.PropertyService.Set("TreeViewOptionsDialog.LastOpenedPanelID", openedPanelID); foreach (IDisposable op in optionPanels.OfType()) { op.Dispose(); } @@ -128,10 +158,12 @@ namespace ICSharpCode.SharpDevelop.Gui this.dialog = parent.dialog; } + public string ID { + get { return OptionPanelDescriptor.ID; } + } + public string Title { - get { - return OptionPanelDescriptor.Label; - } + get { return OptionPanelDescriptor.Label; } } IOptionPanel optionPanel; From 0759063d55a234b7a01ed8d33dfe267c746bd5a2 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 24 Aug 2014 11:49:26 +0200 Subject: [PATCH 082/146] add ChooseExceptionsDialog for PauseOnHandledException feature --- data/resources/StringResources.resx | 12 +++++ .../Debugger.AddIn/Debugger.AddIn.csproj | 5 ++ .../Options/ChooseExceptionsDialog.xaml | 45 ++++++++++++++++ .../Options/ChooseExceptionsDialog.xaml.cs | 49 +++++++++++++++++ .../Options/DebuggingOptions.cs | 5 ++ .../Options/DebuggingOptionsPanel.xaml | 5 ++ .../Options/DebuggingOptionsPanel.xaml.cs | 22 ++++++++ .../Debugger/Debugger.Core/ManagedCallback.cs | 51 +++++++++++++++++- src/AddIns/Debugger/Debugger.Core/Options.cs | 53 +++++++++++++++++++ .../Project/Debugging/IDebuggerService.cs | 6 ++- 10 files changed, 250 insertions(+), 3 deletions(-) create mode 100644 src/AddIns/Debugger/Debugger.AddIn/Options/ChooseExceptionsDialog.xaml create mode 100644 src/AddIns/Debugger/Debugger.AddIn/Options/ChooseExceptionsDialog.xaml.cs diff --git a/data/resources/StringResources.resx b/data/resources/StringResources.resx index 0fd83c63fb..aebaee76a4 100644 --- a/data/resources/StringResources.resx +++ b/data/resources/StringResources.resx @@ -8204,4 +8204,16 @@ a line break Only insert selected code completion entry by typing <Tab> or <Enter>. + + Choose exceptions you want the debugger to break on + + + Break on + + + Exception name expression (wildcards are allowed) + + + Choose exceptions + \ No newline at end of file diff --git a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj index ddaadde216..1815ee4e71 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj +++ b/src/AddIns/Debugger/Debugger.AddIn/Debugger.AddIn.csproj @@ -105,6 +105,10 @@ + + ChooseExceptionsDialog.xaml + Code + DebuggingOptionsPanel.xaml Code @@ -319,6 +323,7 @@ + diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/ChooseExceptionsDialog.xaml b/src/AddIns/Debugger/Debugger.AddIn/Options/ChooseExceptionsDialog.xaml new file mode 100644 index 0000000000..1522cee9c6 --- /dev/null +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/ChooseExceptionsDialog.xaml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/ChooseExceptionsDialog.xaml.cs b/src/AddIns/Debugger/Debugger.AddIn/Options/ChooseExceptionsDialog.xaml.cs new file mode 100644 index 0000000000..e96cc000d0 --- /dev/null +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/ChooseExceptionsDialog.xaml.cs @@ -0,0 +1,49 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Windows; +using ICSharpCode.SharpDevelop.Gui; + +namespace Debugger.AddIn.Options +{ + /// + /// Interaction logic for ChooseExceptionsDialog.xaml + /// + public partial class ChooseExceptionsDialog : Window + { + public ChooseExceptionsDialog(IEnumerable entries) + { + InitializeComponent(); + + FormLocationHelper.ApplyWindow(this, "Debugger.ChooseExceptionsDialog", true); + + ExceptionFilterList = new ObservableCollection(entries); + dataGrid.ItemsSource = ExceptionFilterList; + } + + public IList ExceptionFilterList { get; set; } + + void Button_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + } + } +} \ No newline at end of file diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs index 6fe518e798..4af0fabf3e 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptions.cs @@ -85,6 +85,11 @@ namespace ICSharpCode.SharpDevelop.Services set { PS.Set("Debugger.PauseOnHandledExceptions", value); } } + public override IEnumerable ExceptionFilterList { + get { return PS.GetList("Debugger.ExceptionFilterList"); } + set { PS.SetList("Debugger.ExceptionFilterList", value); } + } + public bool AskForArguments { get { return PS.Get("Debugger.AskForArguments", false); } set { PS.Set("Debugger.AskForArguments", value); } diff --git a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml index 9a6b7c713c..95432a91a1 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml +++ b/src/AddIns/Debugger/Debugger.AddIn/Options/DebuggingOptionsPanel.xaml @@ -19,7 +19,12 @@ + public partial class DebuggingOptionsPanel : OptionPanel { + IList exceptionFilterList; + public DebuggingOptionsPanel() { InitializeComponent(); @@ -47,7 +50,26 @@ namespace Debugger.AddIn.Options bool result = base.SaveOptions(); if (WindowsDebugger.CurrentDebugger != null) WindowsDebugger.CurrentDebugger.ReloadOptions(); + DebuggingOptions.Instance.ExceptionFilterList = exceptionFilterList; return result; } + + public override void LoadOptions() + { + base.LoadOptions(); + exceptionFilterList = DebuggingOptions.Instance.ExceptionFilterList.ToList(); + + if (exceptionFilterList.Count == 0) { + exceptionFilterList.Add(new ExceptionFilterEntry("*")); + } + } + + void ChooseExceptionsClick(object sender, RoutedEventArgs e) + { + var dialog = new ChooseExceptionsDialog(exceptionFilterList); + if (dialog.ShowDialog() == true) { + exceptionFilterList = dialog.ExceptionFilterList; + } + } } } \ No newline at end of file diff --git a/src/AddIns/Debugger/Debugger.Core/ManagedCallback.cs b/src/AddIns/Debugger/Debugger.Core/ManagedCallback.cs index 489001dc40..87c5d1936b 100644 --- a/src/AddIns/Debugger/Debugger.Core/ManagedCallback.cs +++ b/src/AddIns/Debugger/Debugger.Core/ManagedCallback.cs @@ -19,7 +19,11 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Runtime.InteropServices; +using System.Text; +using System.Text.RegularExpressions; +using ICSharpCode.NRefactory.TypeSystem; using Debugger.Interop; using Debugger.Interop.CorDebug; @@ -540,19 +544,62 @@ namespace Debugger ExceptionType exceptionType = (ExceptionType)_exceptionType; bool pauseOnHandled = !process.Evaluating && process.Options != null && process.Options.PauseOnHandledExceptions; + Thread thread = process.GetThread(pThread); - if (exceptionType == ExceptionType.Unhandled || (pauseOnHandled && exceptionType == ExceptionType.CatchHandlerFound)) { + if (exceptionType == ExceptionType.Unhandled || (pauseOnHandled && exceptionType == ExceptionType.CatchHandlerFound && BreakOnException(thread))) { // Multiple exceptions can happen at the same time on multiple threads // (I have managed to create a test application to trigger it) - Thread thread = process.GetThread(pThread); thread.CurrentExceptionType = exceptionType; RequestPause(thread).ExceptionsThrown.Add(thread); } ExitCallback(); } + + Regex filterRegex; + + static string ConvertWildcardsToRegex(string searchPattern) + { + if (string.IsNullOrEmpty(searchPattern)) + return ""; + + StringBuilder builder = new StringBuilder(); + + foreach (char ch in searchPattern) { + switch (ch) { + case '?': + builder.Append("."); + break; + case '*': + builder.Append(".*"); + break; + default: + builder.Append(Regex.Escape(ch.ToString())); + break; + } + } + + return builder.ToString(); + } + bool BreakOnException(Thread thread) + { + IType exceptionType = thread.CurrentException.Type; + + if (filterRegex == null) { + var exceptionFilterList = thread.Process.Options.ExceptionFilterList.Where(i => i.IsActive).Select(s => "(" + ConvertWildcardsToRegex(s.Expression) + ")"); + filterRegex = new Regex(string.Join("|", exceptionFilterList), RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.ExplicitCapture); + } + + foreach (var baseType in exceptionType.GetNonInterfaceBaseTypes()) { + if (filterRegex.IsMatch(baseType.ReflectionName)) + return true; + } + + return false; + } + public void ExceptionUnwind(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, CorDebugExceptionUnwindCallbackType dwEventType, uint dwFlags) { EnterCallback("ExceptionUnwind", pThread); diff --git a/src/AddIns/Debugger/Debugger.Core/Options.cs b/src/AddIns/Debugger/Debugger.Core/Options.cs index ffe613908c..a556603629 100644 --- a/src/AddIns/Debugger/Debugger.Core/Options.cs +++ b/src/AddIns/Debugger/Debugger.Core/Options.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; namespace Debugger { @@ -32,5 +33,57 @@ namespace Debugger public virtual bool StepOverFieldAccessProperties { get; set; } public virtual IEnumerable SymbolsSearchPaths { get; set; } public virtual bool PauseOnHandledExceptions { get; set; } + public virtual IEnumerable ExceptionFilterList { get; set; } + } + + [Serializable] + public class ExceptionFilterEntry : INotifyPropertyChanged + { + string expression; + bool isActive; + + public ExceptionFilterEntry() + { + this.IsActive = true; + } + + public ExceptionFilterEntry(string expression) + { + this.IsActive = true; + this.Expression = expression; + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected virtual void OnPropertyChanged(string propertyName) + { + var propertyChanged = PropertyChanged; + if (propertyChanged != null) + propertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + + public string Expression { + get { + return expression; + } + set { + if (expression != value) { + expression = value; + OnPropertyChanged("Expression"); + } + } + } + + public bool IsActive { + get { + return isActive; + } + set { + if (isActive != value) { + isActive = value; + OnPropertyChanged("IsActive"); + } + } + } } } diff --git a/src/Main/Base/Project/Debugging/IDebuggerService.cs b/src/Main/Base/Project/Debugging/IDebuggerService.cs index 1529a45773..b097a7f5f5 100644 --- a/src/Main/Base/Project/Debugging/IDebuggerService.cs +++ b/src/Main/Base/Project/Debugging/IDebuggerService.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using ICSharpCode.Core; +using ICSharpCode.NRefactory; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; @@ -217,11 +218,14 @@ namespace ICSharpCode.SharpDevelop.Debugging get { return false; } } public IEnumerable SymbolsSearchPaths { - get { return Enumerable.Empty(); } + get { return EmptyList.Instance; } } public bool PauseOnHandledExceptions { get { return false; } } + public IEnumerable ExceptionFilterList { + get { return EmptyList.Instance; } + } public static readonly DummyDebuggerOptions Instance = new DummyDebuggerOptions(); } From 30b7002e33acaf495af419ce723ec03e37799d47 Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Sun, 24 Aug 2014 11:52:58 +0200 Subject: [PATCH 083/146] Porting ResourceEditor context menu commands. --- .../Project/ResourceEditor.addin | 32 +++-- .../Project/Src/Commands/AddNewFileCommand.cs | 6 +- .../Src/Commands/AddStringEntryCommand.cs | 6 +- .../Src/Commands/CopyResourceNameCommand.cs | 6 +- .../Src/Commands/EditCommentCommand.cs | 29 +++-- .../Src/Commands/RenameEntryCommand.cs | 12 +- .../Src/Commands/SaveEntryAsCommand.cs | 115 +++++++++--------- .../Src/ViewModels/ResourceEditorViewModel.cs | 45 ++++++- .../Project/Src/ViewModels/ResourceItem.cs | 12 ++ .../Project/Src/Views/IResourceEditorView.cs | 7 +- .../Project/Src/Views/ResourceEditorView.xaml | 31 ++++- .../Src/Views/ResourceEditorView.xaml.cs | 25 ++-- 12 files changed, 205 insertions(+), 121 deletions(-) diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.addin b/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.addin index 1d3c34c203..b688d29433 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.addin +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.addin @@ -30,30 +30,28 @@ + class="ResourceEditor.Commands.AddNewFileCommand" /> - - - - - - + + + + diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs index db9ef94670..28b3a62ac5 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs @@ -26,11 +26,11 @@ using ICSharpCode.SharpDevelop.Gui; using Microsoft.Win32; using ResourceEditor.ViewModels; -namespace ResourceEditor +namespace ResourceEditor.Commands { - class AddNewFileCommand : AbstractMenuCommand + class AddNewFileCommand : SimpleCommand { - public override void Run() + public override void Execute(object parameter) { ResourceEditorViewModel editor = ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor; diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs index f36780a98e..199ac36c9e 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs @@ -22,11 +22,11 @@ using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ResourceEditor.ViewModels; -namespace ResourceEditor +namespace ResourceEditor.Commands { - class AddStringCommand : AbstractMenuCommand + class AddStringCommand : SimpleCommand { - public override void Run() + public override void Execute(object parameter) { ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs index 8cbe918ce1..7073ea16bc 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs @@ -23,11 +23,11 @@ using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; using ResourceEditor.ViewModels; -namespace ResourceEditor +namespace ResourceEditor.Commands { - class CopyResourceNameCommand : AbstractMenuCommand + class CopyResourceNameCommand : SimpleCommand { - public override void Run() + public override void Execute(object parameter) { ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs index 6d32310cd1..36c0254e3a 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs @@ -17,29 +17,28 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Linq; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ResourceEditor.ViewModels; -namespace ResourceEditor +namespace ResourceEditor.Commands { - class EditCommentCommand : AbstractMenuCommand + class EditCommentCommand : SimpleCommand { - public override void Run() + public override void Execute(object parameter) { - ResourceEditorViewModel editor = ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor; + ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - // TODO Reactivate this -// if (editor.ResourceList.SelectedItems.Count != 0) { -// var item = editor.ResourceList.SelectedItems[0].SubItems[3]; -// string resourceName = editor.ResourceList.SelectedItems[0].Text; -// string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}", -// "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}", -// item.Text); -// if (newValue != null && newValue != item.Text) { -// editor.ResourceList.SetCommentValue(resourceName, newValue); -// } -// } + if (editor.SelectedItems.Count != 0) { + var selectedItem = editor.SelectedItems.OfType().FirstOrDefault(); + string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}", + "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}", + selectedItem.Comment); + if (newValue != null && newValue != selectedItem.Comment) { + selectedItem.Comment = newValue; + } + } } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs index e033aed956..21f20b630a 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs @@ -21,18 +21,14 @@ using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ResourceEditor.ViewModels; -namespace ResourceEditor +namespace ResourceEditor.Commands { - class RenameEntryCommand : AbstractMenuCommand + class RenameEntryCommand : SimpleCommand { - public override void Run() + public override void Execute(object parameter) { ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - - // TODO Reactivate this -// if(editor.ResourceList.SelectedItems.Count != 0) { -// editor.ResourceList.SelectedItems[0].BeginEdit(); -// } + editor.StartEditing(); } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs index 8a4f2897b2..f9f10807be 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs @@ -19,77 +19,72 @@ using System; using System.Drawing; using System.IO; -using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; +using Microsoft.Win32; using ResourceEditor.ViewModels; -namespace ResourceEditor +namespace ResourceEditor.Commands { - class SaveEntryAsCommand : AbstractMenuCommand + class SaveEntryAsCommand : SimpleCommand { - public override void Run() + public override void Execute(object parameter) { ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - // TODO Reactivate this -// ResourceList list = editor.ResourceList; -// -// if(list.SelectedItems.Count != 1) { -// return; -// } -// -// string key = list.SelectedItems[0].Text; -// if(! list.Resources.ContainsKey(key)) { -// return; -// } -// -// ResourceItem item = list.Resources[key]; -// SaveFileDialog sdialog = new SaveFileDialog(); -// sdialog.AddExtension = true; -// sdialog.FileName = key; -// -// if (item.ResourceValue is Bitmap) { -// sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.ImageFiles} (*.png)|*.png"); -// sdialog.DefaultExt = ".png"; -// } else if (item.ResourceValue is Icon) { -// sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.Icons}|*.ico"); -// sdialog.DefaultExt = ".ico"; -// } else if (item.ResourceValue is Cursor) { -// sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.CursorFiles} (*.cur)|*.cur"); -// sdialog.DefaultExt = ".cur"; -// } else if (item.ResourceValue is byte[]){ -// sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.BinaryFiles} (*.*)|*.*"); -// sdialog.DefaultExt = ".bin"; -// } else { -// return; -// } -// -// DialogResult dr = sdialog.ShowDialog(SD.WinForms.MainWin32Window); -// sdialog.Dispose(); -// if (dr != DialogResult.OK) { -// return; -// } -// -// try { -// if (item.ResourceValue is Icon) { -// FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); -// ((Icon)item.ResourceValue).Save(fstr); -// fstr.Close(); -// } else if(item.ResourceValue is Image) { -// Image img = (Image)item.ResourceValue; -// img.Save(sdialog.FileName); -// } else { -// FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); -// BinaryWriter wr = new BinaryWriter(fstr); -// wr.Write((byte[])item.ResourceValue); -// fstr.Close(); -// } -// } catch(Exception ex) { -// MessageBox.Show(ex.Message, "Can't save resource to " + sdialog.FileName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); -// } + if (editor.SelectedItems.Count != 1) { + return; + } + + ResourceItem firstSelectedItem = (editor.SelectedItems[0] as ResourceItem); + if (firstSelectedItem == null) { + return; + } + + var sdialog = new Microsoft.Win32.SaveFileDialog(); + sdialog.AddExtension = true; + sdialog.FileName = firstSelectedItem.Name; + + if (firstSelectedItem.ResourceValue is System.Drawing.Bitmap) { + sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.ImageFiles} (*.png)|*.png"); + sdialog.DefaultExt = ".png"; + } else if (firstSelectedItem.ResourceValue is System.Drawing.Icon) { + sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.Icons}|*.ico"); + sdialog.DefaultExt = ".ico"; + } else if (firstSelectedItem.ResourceValue is System.Windows.Forms.Cursor) { + sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.CursorFiles} (*.cur)|*.cur"); + sdialog.DefaultExt = ".cur"; + } else if (firstSelectedItem.ResourceValue is byte[]) { + sdialog.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.BinaryFiles} (*.*)|*.*"); + sdialog.DefaultExt = ".bin"; + } else { + return; + } + + bool? dr = sdialog.ShowDialog(); + if (dr.HasValue && dr.Value) { + return; + } + + try { + if (firstSelectedItem.ResourceValue is Icon) { + FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); + ((Icon)firstSelectedItem.ResourceValue).Save(fstr); + fstr.Close(); + } else if (firstSelectedItem.ResourceValue is Image) { + Image img = (Image)firstSelectedItem.ResourceValue; + img.Save(sdialog.FileName); + } else { + FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); + BinaryWriter wr = new BinaryWriter(fstr); + wr.Write((byte[])firstSelectedItem.ResourceValue); + fstr.Close(); + } + } catch (Exception ex) { + SD.MessageService.ShowWarning("Can't save resource to " + sdialog.FileName + ": " + ex.Message); + } } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs index 6983c545c7..6563e7ffbc 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs @@ -60,6 +60,8 @@ namespace ResourceEditor.ViewModels readonly ObservableCollection metadataItems; readonly Dictionary itemViews; bool longUpdateRunning; + ResourceItem editedResourceItem; + string originalNameOfEditedItem; IResourceEditorView view; @@ -109,7 +111,9 @@ namespace ResourceEditor.ViewModels } set { if (view != null) { - view.SelectionChanged += View_SelectionChanged; + view.SelectionChanged -= View_SelectionChanged; + view.EditingFinished -= View_EditingFinished; + view.EditingCancelled -= View_EditingCancelled; ResourceItems.CollectionChanged -= ResourceItems_CollectionChanged; } @@ -129,6 +133,8 @@ namespace ResourceEditor.ViewModels return true; }; view.SelectionChanged += View_SelectionChanged; + view.EditingFinished += View_EditingFinished; + view.EditingCancelled += View_EditingCancelled; ResourceItems.CollectionChanged += ResourceItems_CollectionChanged; } } @@ -190,6 +196,43 @@ namespace ResourceEditor.ViewModels OnChangedDirtyState(true); } + public void StartEditing() + { + if (editedResourceItem != null) { + editedResourceItem.IsEditing = false; + editedResourceItem = null; + originalNameOfEditedItem = null; + } + + // Start editing currently selected item + var firstSelectedItem = SelectedItems.OfType().FirstOrDefault(); + if (firstSelectedItem != null) { + editedResourceItem = firstSelectedItem; + originalNameOfEditedItem = editedResourceItem.Name; + firstSelectedItem.IsEditing = true; + } + } + + void View_EditingFinished(object sender, EventArgs e) + { + if (editedResourceItem != null) { + editedResourceItem.IsEditing = false; + editedResourceItem = null; + originalNameOfEditedItem = null; + MakeDirty(); + } + } + + void View_EditingCancelled(object sender, EventArgs e) + { + if (editedResourceItem != null) { + editedResourceItem.IsEditing = false; + editedResourceItem.Name = originalNameOfEditedItem; + editedResourceItem = null; + originalNameOfEditedItem = null; + } + } + void StartUpdate() { // When loading many items at once, temporarily unbind view from model diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs index f24fa6de6a..c3b65a3922 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs @@ -46,6 +46,7 @@ namespace ResourceEditor.ViewModels string comment; ResourceItemEditorType resourceType; ResourceEditorViewModel resourceEditor; + bool isEditing; public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue) { @@ -112,6 +113,16 @@ namespace ResourceEditor.ViewModels } } + public bool IsEditing { + get { + return isEditing; + } + set { + isEditing = value; + OnPropertyChanged("IsEditing"); + } + } + ResourceItemEditorType GetResourceTypeFromValue(object val) { if (this.ResourceValue == null) { @@ -148,6 +159,7 @@ namespace ResourceEditor.ViewModels set { comment = value; OnPropertyChanged("Comment"); + resourceEditor.MakeDirty(); } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs index 4517b1ba38..b7a4d4e7b7 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/IResourceEditorView.cs @@ -39,6 +39,10 @@ namespace ResourceEditor.Views get; } + event EventHandler EditingStarted; + event EventHandler EditingFinished; + event EventHandler EditingCancelled; + void SetItemView(IResourceItemView view); object DataContext { @@ -46,8 +50,7 @@ namespace ResourceEditor.Views set; } - Predicate FilterPredicate - { + Predicate FilterPredicate { get; set; } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml index 4d77cbedb0..e79013d2d7 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ResourceEditorView.xaml @@ -56,7 +56,32 @@ - + + + + + + + + + + @@ -115,7 +140,9 @@ Grid.Row="1" ItemsSource="{Binding Source={StaticResource resourceItemListViewSource}}" ItemContainerStyle="{StaticResource listViewItemStyle}" - MouseRightButtonUp="ListView_MouseRightButtonUp"> + MouseRightButtonUp="ListView_MouseRightButtonUp" + KeyUp="ResourceItemsListView_KeyUp" + SelectionChanged="ListView_SelectionChanged"> ()) { -// SelectedItems.Remove(item); -// } -// foreach (var item in e.AddedItems.OfType()) { -// SelectedItems.Add(item); -// } if (SelectionChanged != null) { SelectionChanged(this, new EventArgs()); } @@ -124,5 +120,20 @@ namespace ResourceEditor.Views // Update CollectionViewSource to re-evaluate filter predicate itemCollectionViewSource.View.Refresh(); } + + void ResourceItemsListView_KeyUp(object sender, KeyEventArgs e) + { + if (e.Key == Key.Enter) { + if (EditingFinished != null) { + EditingFinished(this, new EventArgs()); + } + } else if (e.Key == Key.Escape) { + if (EditingCancelled != null) { + EditingCancelled(this, new EventArgs()); + } + } + + e.Handled = false; + } } } \ No newline at end of file From cd49d8c512b84a33f5f8734de1ae0dd522968f22 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 24 Aug 2014 19:24:34 +0200 Subject: [PATCH 084/146] reimplement "Insert 'TODO' comment in new event handler" option in Windows Forms Designer --- .../CSharpEventBindingService.cs | 4 ++- .../Src/Refactoring/CSharpCodeGenerator.cs | 26 ++++++++++++++++--- .../Project/Src/Refactoring/EditorScript.cs | 10 +++++++ .../Base/Project/Refactoring/CodeGenerator.cs | 9 ++++++- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpEventBindingService.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpEventBindingService.cs index 09fdcd0438..981092adf9 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpEventBindingService.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormsDesigner/CSharpEventBindingService.cs @@ -31,6 +31,7 @@ using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Project; +using ICSharpCode.SharpDevelop.Refactoring; using CSharpBinding.Refactoring; namespace CSharpBinding.FormsDesigner @@ -147,7 +148,8 @@ namespace CSharpBinding.FormsDesigner var primary = loader.GetPrimaryTypeDefinition(); var evtHandler = primary.GetMethods(m => m.Name == methodName, GetMemberOptions.IgnoreInheritedMembers).FirstOrDefault(); if (evtHandler == null) { - generator.InsertEventHandler(primary, methodName, evt, true); + var insertionType = GeneralOptionsPanel.InsertTodoComment ? InsertEventHandlerBodyKind.TodoComment : InsertEventHandlerBodyKind.Nothing; + generator.InsertEventHandler(primary, methodName, evt, true, insertionType); } else { CSharpBinding.Parser.CSharpFullParseInformation parseInfo; var node = evtHandler.GetDeclaration(out parseInfo) as MethodDeclaration; diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeGenerator.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeGenerator.cs index e49cb191c0..a7880dc1d6 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeGenerator.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpCodeGenerator.cs @@ -66,7 +66,7 @@ namespace CSharpBinding.Refactoring AddAttribute(target.Region, attribute, "return"); } - public override void InsertEventHandler(ITypeDefinition target, string name, IEvent eventDefinition, bool jumpTo) + public override void InsertEventHandler(ITypeDefinition target, string name, IEvent eventDefinition, bool jumpTo, InsertEventHandlerBodyKind bodyKind = InsertEventHandlerBodyKind.ThrowNotImplementedException) { IUnresolvedTypeDefinition match = null; @@ -103,12 +103,30 @@ namespace CSharpBinding.Refactoring decl.Parameters.AddRange(param); using (Script script = context.StartScript()) { - // FIXME : will not work properly if there are no members. + int eolLen = 0; if (last == match) { - script.InsertWithCursor("Insert event handler", Script.InsertPosition.End, decl).FireAndForget(); + eolLen = 2; + script.AddTo((TypeDeclaration)node, decl); } else { script.InsertAfter(node, decl); - script.Select(throwStmt); + } + switch (bodyKind) { + case InsertEventHandlerBodyKind.TodoComment: + Comment comment = new Comment(" TODO: Implement " + name); + script.Replace(throwStmt, comment); + script.Select(comment); + break; + case InsertEventHandlerBodyKind.Nothing: + var segment = script.GetSegment(throwStmt); + if (script is DocumentScript && eolLen > 0) { + eolLen = ((DocumentScript)script).CurrentDocument.GetLineByOffset(segment.Offset).DelimiterLength; + } + script.RemoveText(segment.Offset, segment.Length - eolLen); + script.Select(segment.Offset, segment.Offset); + break; + case InsertEventHandlerBodyKind.ThrowNotImplementedException: + script.Select(throwStmt); + break; } } } diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs index 02f9e05f70..30099aa233 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/EditorScript.cs @@ -81,6 +81,16 @@ namespace CSharpBinding.Refactoring editor.Select(startOffset, endOffset - startOffset); } + public override void Select(int startOffset, int endOffset) + { + editor.Select(Math.Min(startOffset, endOffset), Math.Abs(endOffset - startOffset)); + } + + public override void Select(TextLocation start, TextLocation end) + { + Select(editor.Document.GetOffset(start), editor.Document.GetOffset(end)); + } + public override Task Link(params AstNode[] nodes) { var segs = nodes.Select(node => GetSegment(node)).ToArray(); diff --git a/src/Main/Base/Project/Refactoring/CodeGenerator.cs b/src/Main/Base/Project/Refactoring/CodeGenerator.cs index 1f7a58891c..3ef90dcfbe 100644 --- a/src/Main/Base/Project/Refactoring/CodeGenerator.cs +++ b/src/Main/Base/Project/Refactoring/CodeGenerator.cs @@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring throw new NotSupportedException("Feature not supported!"); } - public virtual void InsertEventHandler(ITypeDefinition target, string name, IEvent eventDefinition, bool jumpTo) + public virtual void InsertEventHandler(ITypeDefinition target, string name, IEvent eventDefinition, bool jumpTo, InsertEventHandlerBodyKind bodyKind = InsertEventHandlerBodyKind.ThrowNotImplementedException) { throw new NotSupportedException("Feature not supported!"); } @@ -123,4 +123,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring throw new NotSupportedException("Feature not supported!"); } } + + public enum InsertEventHandlerBodyKind + { + Nothing, + TodoComment, + ThrowNotImplementedException + } } From 844a90bb3d271d40b6a572920309e133ee7521f3 Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Tue, 26 Aug 2014 02:37:57 +0200 Subject: [PATCH 085/146] Finished context menu commands of ResourceEditor. --- .../Project/ResourceEditor.csproj | 35 +----- .../Project/Src/Commands/AddNewFileCommand.cs | 90 +++++++------- .../Src/Commands/AddStringEntryCommand.cs | 38 +++--- .../Src/Commands/CopyResourceNameCommand.cs | 15 ++- .../Src/Commands/EditCommentCommand.cs | 20 ++-- .../Src/Commands/RenameEntryCommand.cs | 9 +- .../Src/Commands/ResourceItemCommand.cs | 107 +++++++++++++++++ .../Src/Commands/SaveEntryAsCommand.cs | 35 +++--- .../Src/ViewModels/ResourceEditorViewModel.cs | 61 ++++++---- .../Project/Src/ViewModels/ResourceItem.cs | 110 ++++++++--------- .../Project/Src/Views/ImageViewBase.xaml | 8 +- .../Project/Src/Views/InPlaceEditLabel.xaml | 14 +++ .../Src/Views/InPlaceEditLabel.xaml.cs | 112 ++++++++++++++++++ .../Project/Src/Views/ResourceEditorView.xaml | 44 +++---- .../Src/Views/ResourceEditorView.xaml.cs | 78 ++++++++++-- 15 files changed, 525 insertions(+), 251 deletions(-) create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml create mode 100644 src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/InPlaceEditLabel.xaml.cs diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj b/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj index 4f4746dc44..3c6e01d491 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/ResourceEditor.csproj @@ -63,37 +63,9 @@ + - - Component - - - UserControl - - - Component - - - Component - - - Component - - - Component - - - - UserControl - - - - Component - - - Component - @@ -108,6 +80,10 @@ ImageViewBase.xaml Code + + InPlaceEditLabel.xaml + Code + @@ -166,6 +142,7 @@ + diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs index 28b3a62ac5..3473396345 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddNewFileCommand.cs @@ -28,56 +28,50 @@ using ResourceEditor.ViewModels; namespace ResourceEditor.Commands { - class AddNewFileCommand : SimpleCommand + class AddNewFileCommand : ResourceItemCommand { - public override void Execute(object parameter) + public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems) { - ResourceEditorViewModel editor = ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor; - - // TODO Reactivate this // if (editor.ResourceList.WriteProtected) { // return; // } -// using (OpenFileDialog fdiag = new OpenFileDialog()) { -// fdiag.AddExtension = true; -// fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*"); -// fdiag.Multiselect = true; -// fdiag.CheckFileExists = true; -// -// if (fdiag.ShowDialog()) { -// foreach (string filename in fdiag.FileNames) { -// string oresname = Path.ChangeExtension(Path.GetFileName(filename), null); -// if (oresname == "") -// oresname = "new"; -// -// string resname = oresname; -// -// int i = 0; -// TestName: -// if (editor.ResourceList.Resources.ContainsKey(resname)) { -// if (i == 10) { -// continue; -// } -// i++; -// resname = oresname + "_" + i.ToString(); -// goto TestName; -// } -// -// object tmp = loadResource(filename); -// if (tmp == null) { -// continue; -// } -// editor.ResourceList.Resources.Add(resname, new ResourceItem(resname, tmp)); -// -// } -// editor.ResourceList.InitializeListView(); -// } -// } -// editor.ResourceList.OnChanged(); + var editor = ResourceEditor; + OpenFileDialog fdiag = new OpenFileDialog(); + fdiag.AddExtension = true; + fdiag.Filter = StringParser.Parse("${res:SharpDevelop.FileFilter.AllFiles}|*.*"); + fdiag.Multiselect = true; + fdiag.CheckFileExists = true; + + if ((bool)fdiag.ShowDialog()) { + foreach (string filename in fdiag.FileNames) { + string oresname = Path.ChangeExtension(Path.GetFileName(filename), null); + if (oresname == "") + oresname = "new"; + + string resname = oresname; + + int i = 0; + TestName: + if (editor.ContainsResourceName(resname)) { + if (i == 10) { + continue; + } + i++; + resname = oresname + "_" + i; + goto TestName; + } + + object tmp = LoadResource(filename); + if (tmp == null) { + continue; + } + editor.ResourceItems.Add(new ResourceItem(editor, resname, tmp)); + } + } } - object loadResource(string name) + object LoadResource(string name) { switch (Path.GetExtension(name).ToUpperInvariant()) { case ".CUR": @@ -93,13 +87,13 @@ namespace ResourceEditor.Commands return null; } default: - // try to read a bitmap + // Try to read a bitmap try { return new System.Drawing.Bitmap(name); } catch { } - // try to read a serialized object + // Try to read a serialized object try { Stream r = File.Open(name, FileMode.Open); try { @@ -113,17 +107,15 @@ namespace ResourceEditor.Commands } catch { } - // try to read a byte array :) + // Try to read a byte array try { FileStream s = new FileStream(name, FileMode.Open); BinaryReader r = new BinaryReader(s); - Byte[] d = new Byte[(int) s.Length]; - d = r.ReadBytes((int) s.Length); + Byte[] d = new Byte[(int)s.Length]; + d = r.ReadBytes((int)s.Length); s.Close(); return d; } catch (Exception) { - - string message = ResourceService.GetString("ResourceEditor.Messages.CantLoadResource"); MessageService.ShowWarning(message + " " + name + "."); } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs index 199ac36c9e..bde41d841a 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/AddStringEntryCommand.cs @@ -24,33 +24,29 @@ using ResourceEditor.ViewModels; namespace ResourceEditor.Commands { - class AddStringCommand : SimpleCommand + class AddStringCommand : ResourceItemCommand { - public override void Execute(object parameter) + public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems) { - ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - - // TODO Reactivate this // if(editor.ResourceList.WriteProtected) { // return; // } // -// int count = 1; -// string newNameBase = " new string entry "; -// string newName = newNameBase + count.ToString(); -// string type = "System.String"; -// -// while(editor.ResourceList.Resources.ContainsKey(newName)) { -// count++; -// newName = newNameBase + count.ToString(); -// } -// -// ResourceItem item = new ResourceItem(newName, ""); -// editor.ResourceList.Resources.Add(newName, item); -// ListViewItem lv = new ListViewItem(new string[] { newName, type, "" }, item.ImageIndex); -// editor.ResourceList.Items.Add(lv); -// editor.ResourceList.OnChanged(); -// lv.BeginEdit(); + var editor = ResourceEditor; + int count = 1; + string newNameBase = " new string entry "; + string newName = newNameBase + count; + + while (editor.ContainsResourceName(newName)) { + count++; + newName = newNameBase + count; + } + + ResourceItem item = new ResourceItem(editor, newName, ""); + editor.ResourceItems.Add(item); + editor.SelectedItems.Clear(); + editor.SelectedItems.Add(item); + editor.StartEditing(); } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs index 7073ea16bc..4adb6e4b4e 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/CopyResourceNameCommand.cs @@ -17,6 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.Linq; using System.Windows.Forms; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; @@ -25,16 +26,14 @@ using ResourceEditor.ViewModels; namespace ResourceEditor.Commands { - class CopyResourceNameCommand : SimpleCommand + class CopyResourceNameCommand : ResourceItemCommand { - public override void Execute(object parameter) + public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems) { - ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - - // TODO Reactivate this -// if(editor.ResourceList.SelectedItems.Count > 0) { -// Clipboard.SetText(editor.ResourceList.SelectedItems[0].Text); -// } + var firstSelectedItem = resourceItems.First(); + if (firstSelectedItem != null) { + Clipboard.SetText(firstSelectedItem.Name); + } } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs index 36c0254e3a..10b3d72c0b 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/EditCommentCommand.cs @@ -24,20 +24,16 @@ using ResourceEditor.ViewModels; namespace ResourceEditor.Commands { - class EditCommentCommand : SimpleCommand + class EditCommentCommand : ResourceItemCommand { - public override void Execute(object parameter) + public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems) { - ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - - if (editor.SelectedItems.Count != 0) { - var selectedItem = editor.SelectedItems.OfType().FirstOrDefault(); - string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}", - "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}", - selectedItem.Comment); - if (newValue != null && newValue != selectedItem.Comment) { - selectedItem.Comment = newValue; - } + var selectedItem = resourceItems.First(); + string newValue = SD.MessageService.ShowInputBox("${res:ResourceEditor.ResourceEdit.ContextMenu.EditComment}", + "${res:ResourceEditor.ResourceEdit.ContextMenu.EditCommentText}", + selectedItem.Comment); + if (newValue != null && newValue != selectedItem.Comment) { + selectedItem.Comment = newValue; } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs index 21f20b630a..f64c1bde83 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/RenameEntryCommand.cs @@ -23,12 +23,13 @@ using ResourceEditor.ViewModels; namespace ResourceEditor.Commands { - class RenameEntryCommand : SimpleCommand + class RenameEntryCommand : ResourceItemCommand { - public override void Execute(object parameter) + public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems) { - ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - editor.StartEditing(); + var editor = ResourceEditor; + if (editor != null) + editor.StartEditing(); } } } diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs new file mode 100644 index 0000000000..ba1a0aa692 --- /dev/null +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/ResourceItemCommand.cs @@ -0,0 +1,107 @@ +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.Collections.Generic; +using System.Linq; +using ICSharpCode.SharpDevelop; +using ResourceEditor.ViewModels; + +namespace ResourceEditor.Commands +{ + /// + /// Represents a -related command. + /// + public class ResourceItemCommand : SimpleCommand + { + /// + /// Defines whether this command supports multiselection of items. + /// If not, command will be disabled by default, when more than 1 item is selected. + /// + public virtual bool SupportsMultiSelections { + get { + return false; + } + } + + /// + /// Returns list of resource item types for which this command may be enabled or null to allow any type. + /// + public virtual IEnumerable AllowedTypes { + get { + return null; + } + } + + public override bool CanExecute(object parameter) + { + if (ResourceEditor == null) + return false; + + var selectedResourceItems = GetSelectedItems(); + if (!selectedResourceItems.Any()) + return false; + if (!SupportsMultiSelections && (selectedResourceItems.Count() > 1)) + return false; + + return CanExecuteWithResourceItems(selectedResourceItems); + } + + /// + /// Checks whether this command can be executed for the current set of selected resource items. + /// + /// List of selected resource items. Will always contain at least one element. + /// True, when command can be executed, false otherwise. + public virtual bool CanExecuteWithResourceItems(IEnumerable resourceItems) + { + return true; + } + + public override void Execute(object parameter) + { + var selectedResourceItems = GetSelectedItems(); + if (!selectedResourceItems.Any()) + return; + if (!SupportsMultiSelections && (selectedResourceItems.Count() > 1)) + return; + ExecuteWithResourceItems(selectedResourceItems); + } + + /// + /// Executes command for the given set of selected resource items. + /// + /// List of selected resource items. Will always contain at least one element. + public virtual void ExecuteWithResourceItems(IEnumerable resourceItems) + { + } + + public ResourceEditorViewModel ResourceEditor { + get { + return ((ResourceEditViewContent) SD.Workbench.ActiveViewContent).ResourceEditor; + } + } + + IEnumerable GetSelectedItems() + { + var editor = ResourceEditor; + if (editor != null) + return editor.SelectedItems.OfType() ?? new ResourceEditor.ViewModels.ResourceItem[0]; + return new ResourceEditor.ViewModels.ResourceItem[0]; + } + } +} diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs index f9f10807be..b41b673ddb 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Commands/SaveEntryAsCommand.cs @@ -20,6 +20,7 @@ using System; using System.Drawing; using System.IO; +using System.Linq; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; @@ -28,20 +29,22 @@ using ResourceEditor.ViewModels; namespace ResourceEditor.Commands { - class SaveEntryAsCommand : SimpleCommand + class SaveEntryAsCommand : ResourceItemCommand { - public override void Execute(object parameter) - { - ResourceEditorViewModel editor = ((ResourceEditViewContent)SD.Workbench.ActiveViewContent).ResourceEditor; - - if (editor.SelectedItems.Count != 1) { - return; - } - - ResourceItem firstSelectedItem = (editor.SelectedItems[0] as ResourceItem); - if (firstSelectedItem == null) { - return; + public override System.Collections.Generic.IEnumerable AllowedTypes { + get { + return new ResourceItemEditorType[] { + ResourceItemEditorType.Bitmap, + ResourceItemEditorType.Icon, + ResourceItemEditorType.Cursor, + ResourceItemEditorType.Binary + }; } + } + + public override void ExecuteWithResourceItems(System.Collections.Generic.IEnumerable resourceItems) + { + var firstSelectedItem = resourceItems.First(); var sdialog = new Microsoft.Win32.SaveFileDialog(); sdialog.AddExtension = true; @@ -64,22 +67,22 @@ namespace ResourceEditor.Commands } bool? dr = sdialog.ShowDialog(); - if (dr.HasValue && dr.Value) { + if (!dr.HasValue || !dr.Value) { return; } try { if (firstSelectedItem.ResourceValue is Icon) { FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); - ((Icon)firstSelectedItem.ResourceValue).Save(fstr); + ((Icon) firstSelectedItem.ResourceValue).Save(fstr); fstr.Close(); } else if (firstSelectedItem.ResourceValue is Image) { - Image img = (Image)firstSelectedItem.ResourceValue; + Image img = (Image) firstSelectedItem.ResourceValue; img.Save(sdialog.FileName); } else { FileStream fstr = new FileStream(sdialog.FileName, FileMode.Create); BinaryWriter wr = new BinaryWriter(fstr); - wr.Write((byte[])firstSelectedItem.ResourceValue); + wr.Write((byte[]) firstSelectedItem.ResourceValue); fstr.Close(); } } catch (Exception ex) { diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs index 6563e7ffbc..58869076fc 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceEditorViewModel.cs @@ -72,7 +72,7 @@ namespace ResourceEditor.ViewModels new FrameworkPropertyMetadata()); public string SearchTerm { - get { return (string)GetValue(SearchTermProperty); } + get { return (string) GetValue(SearchTermProperty); } set { SetValue(SearchTermProperty, value); } } @@ -100,6 +100,16 @@ namespace ResourceEditor.ViewModels } } + /// + /// Checks whether a resource name is existing in currently open file. + /// + /// Resource name to check. + /// True if name exists, false otherwise. + public bool ContainsResourceName(string name) + { + return resourceItemNames.Contains(name); + } + public void AddItemView(ResourceItemEditorType itemType, IResourceItemView view) { itemViews[itemType] = view; @@ -112,6 +122,7 @@ namespace ResourceEditor.ViewModels set { if (view != null) { view.SelectionChanged -= View_SelectionChanged; + view.EditingStarted -= View_EditingStarted; view.EditingFinished -= View_EditingFinished; view.EditingCancelled -= View_EditingCancelled; ResourceItems.CollectionChanged -= ResourceItems_CollectionChanged; @@ -133,6 +144,7 @@ namespace ResourceEditor.ViewModels return true; }; view.SelectionChanged += View_SelectionChanged; + view.EditingStarted += View_EditingStarted; view.EditingFinished += View_EditingFinished; view.EditingCancelled += View_EditingCancelled; ResourceItems.CollectionChanged += ResourceItems_CollectionChanged; @@ -198,11 +210,11 @@ namespace ResourceEditor.ViewModels public void StartEditing() { - if (editedResourceItem != null) { - editedResourceItem.IsEditing = false; - editedResourceItem = null; - originalNameOfEditedItem = null; - } +// if (editedResourceItem != null) { +// editedResourceItem.IsEditing = false; +// editedResourceItem = null; +// originalNameOfEditedItem = null; +// } // Start editing currently selected item var firstSelectedItem = SelectedItems.OfType().FirstOrDefault(); @@ -213,24 +225,29 @@ namespace ResourceEditor.ViewModels } } + void View_EditingStarted(object sender, EventArgs e) + { + StartEditing(); + } + void View_EditingFinished(object sender, EventArgs e) { - if (editedResourceItem != null) { - editedResourceItem.IsEditing = false; - editedResourceItem = null; - originalNameOfEditedItem = null; - MakeDirty(); - } +// if (editedResourceItem != null) { +// editedResourceItem.IsEditing = false; +// editedResourceItem = null; +// originalNameOfEditedItem = null; +// MakeDirty(); +// } } void View_EditingCancelled(object sender, EventArgs e) { - if (editedResourceItem != null) { - editedResourceItem.IsEditing = false; - editedResourceItem.Name = originalNameOfEditedItem; - editedResourceItem = null; - originalNameOfEditedItem = null; - } +// if (editedResourceItem != null) { +// editedResourceItem.IsEditing = false; +// editedResourceItem.Name = originalNameOfEditedItem; +// editedResourceItem = null; +// originalNameOfEditedItem = null; +// } } void StartUpdate() @@ -258,13 +275,13 @@ namespace ResourceEditor.ViewModels rx.UseResXDataNodes = true; IDictionaryEnumerator n = rx.GetEnumerator(); while (n.MoveNext()) { - ResXDataNode node = (ResXDataNode)n.Value; + ResXDataNode node = (ResXDataNode) n.Value; resourceItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver), node.Comment)); } n = rx.GetMetadataEnumerator(); while (n.MoveNext()) { - ResXDataNode node = (ResXDataNode)n.Value; + ResXDataNode node = (ResXDataNode) n.Value; metadataItems.Add(new ResourceItem(this, node.Name, node.GetValue(typeResolver))); } @@ -390,12 +407,12 @@ namespace ResourceEditor.ViewModels return; if (dob.GetDataPresent(typeof(Hashtable).FullName)) { - Hashtable tmphash = (Hashtable)dob.GetData(typeof(Hashtable)); + Hashtable tmphash = (Hashtable) dob.GetData(typeof(Hashtable)); foreach (DictionaryEntry entry in tmphash) { object resourceValue = GetClonedResource(entry.Value); ResourceItem item; - if (!resourceItemNames.Contains((string)entry.Key)) { + if (!resourceItemNames.Contains((string) entry.Key)) { item = new ResourceItem(this, entry.Key.ToString(), resourceValue); } else { int count = 1; diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs index c3b65a3922..a5e3ada11b 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/ViewModels/ResourceItem.cs @@ -20,6 +20,7 @@ using System; using System.ComponentModel; using System.Drawing; using System.Resources; +using System.Windows; using System.Windows.Forms; using ICSharpCode.SharpDevelop; @@ -39,66 +40,45 @@ namespace ResourceEditor.ViewModels Binary } - public class ResourceItem : INotifyPropertyChanged + public class ResourceItem : DependencyObject { - string name; - object resourceValue; - string comment; ResourceItemEditorType resourceType; ResourceEditorViewModel resourceEditor; - bool isEditing; + string nameBeforeEditing; public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue) { this.resourceEditor = resourceEditor; - this.name = name; - this.resourceValue = resourceValue; + this.Name = name; + this.ResourceValue = resourceValue; this.resourceType = GetResourceTypeFromValue(resourceValue); } public ResourceItem(ResourceEditorViewModel resourceEditor, string name, object resourceValue, string comment) { this.resourceEditor = resourceEditor; - this.name = name; - this.resourceValue = resourceValue; + this.Name = name; + this.ResourceValue = resourceValue; this.resourceType = GetResourceTypeFromValue(resourceValue); - this.comment = comment; + this.Comment = comment; } - #region INotifyPropertyChanged implementation - - public event PropertyChangedEventHandler PropertyChanged; - - void OnPropertyChanged(string propertyName) - { - if (PropertyChanged != null) { - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } - - #endregion + public static readonly DependencyProperty NameProperty = + DependencyProperty.Register("Name", typeof(string), typeof(ResourceItem), + new FrameworkPropertyMetadata()); public string Name { - get { - return name; - } - set { - name = value; - OnPropertyChanged("Name"); - } + get { return (string)GetValue(NameProperty); } + set { SetValue(NameProperty, value); } } + public static readonly DependencyProperty ResourceValueProperty = + DependencyProperty.Register("ResourceValue", typeof(object), typeof(ResourceItem), + new FrameworkPropertyMetadata()); + public object ResourceValue { - get { - return resourceValue; - } - set { - resourceValue = value; - OnPropertyChanged("ResourceValue"); - OnPropertyChanged("ResourceType"); - OnPropertyChanged("Content"); - resourceEditor.MakeDirty(); - } + get { return (object)GetValue(ResourceValueProperty); } + set { SetValue(ResourceValueProperty, value); } } public string DisplayedResourceType { @@ -113,13 +93,39 @@ namespace ResourceEditor.ViewModels } } + public static readonly DependencyProperty IsEditingProperty = + DependencyProperty.Register("IsEditing", typeof(bool), typeof(ResourceItem), + new FrameworkPropertyMetadata()); + public bool IsEditing { - get { - return isEditing; - } - set { - isEditing = value; - OnPropertyChanged("IsEditing"); + get { return (bool)GetValue(IsEditingProperty); } + set { SetValue(IsEditingProperty, value); } + } + + protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) + { + base.OnPropertyChanged(e); + + if (e.Property == IsEditingProperty) { + bool previouslyEditing = (bool)e.OldValue; + bool isEditing = (bool)e.NewValue; + if (!previouslyEditing && isEditing) { + // Save initial name to compare it later on cancellation + nameBeforeEditing = Name; + } else if (previouslyEditing && !isEditing) { + // Make dirty, if name has changed after finishing edit + if (nameBeforeEditing != Name) { + // Check if new name is valid + if (!String.IsNullOrEmpty(Name) && !resourceEditor.ContainsResourceName(Name)) { + resourceEditor.MakeDirty(); + } else { + // New name was not valid, revert it to the value before editing + Name = nameBeforeEditing; + } + } + } + } else { + resourceEditor.MakeDirty(); } } @@ -152,15 +158,13 @@ namespace ResourceEditor.ViewModels } } + public static readonly DependencyProperty CommentProperty = + DependencyProperty.Register("Comment", typeof(string), typeof(ResourceItem), + new FrameworkPropertyMetadata()); + public string Comment { - get { - return comment; - } - set { - comment = value; - OnPropertyChanged("Comment"); - resourceEditor.MakeDirty(); - } + get { return (string)GetValue(CommentProperty); } + set { SetValue(CommentProperty, value); } } public override string ToString() diff --git a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml index 8e7e41dd9d..782a0202e3 100644 --- a/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml +++ b/src/AddIns/DisplayBindings/ResourceEditor/Project/Src/Views/ImageViewBase.xaml @@ -8,6 +8,12 @@