Browse Source
Moved common code from all CodeDOM designer loaders to new base class AbstractCodeDomDesignerLoader. Fixed field change detection for types with type arguments. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3273 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
13 changed files with 584 additions and 209 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Christian Hornung" email="chhornung@googlemail.com"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.CodeDom.Compiler; |
||||
using System.Collections; |
||||
using System.ComponentModel.Design; |
||||
using System.ComponentModel.Design.Serialization; |
||||
|
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.FormsDesigner |
||||
{ |
||||
/// <summary>
|
||||
/// An abstract base class for CodeDOM designer loaders.
|
||||
/// </summary>
|
||||
public abstract class AbstractCodeDomDesignerLoader : CodeDomDesignerLoader |
||||
{ |
||||
bool loading = true; |
||||
IDesignerLoaderHost designerLoaderHost = null; |
||||
ITypeResolutionService typeResolutionService = null; |
||||
readonly IDesignerGenerator generator; |
||||
|
||||
public override bool Loading { |
||||
get { return base.Loading || loading; } |
||||
} |
||||
|
||||
protected override ITypeResolutionService TypeResolutionService { |
||||
get { return this.typeResolutionService; } |
||||
} |
||||
|
||||
protected IDesignerLoaderHost DesignerLoaderHost { |
||||
get { return this.designerLoaderHost; } |
||||
} |
||||
|
||||
protected override CodeDomProvider CodeDomProvider { |
||||
get { return this.generator.CodeDomProvider; } |
||||
} |
||||
|
||||
protected IDesignerGenerator Generator { |
||||
get { return this.generator; } |
||||
} |
||||
|
||||
protected AbstractCodeDomDesignerLoader(IDesignerGenerator generator) |
||||
{ |
||||
if (generator == null) { |
||||
throw new ArgumentNullException("generator", "Generator cannot be null"); |
||||
} |
||||
this.generator = generator; |
||||
} |
||||
|
||||
public override void BeginLoad(IDesignerLoaderHost host) |
||||
{ |
||||
this.loading = true; |
||||
this.typeResolutionService = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)); |
||||
this.designerLoaderHost = host; |
||||
base.BeginLoad(host); |
||||
} |
||||
|
||||
protected override void Initialize() |
||||
{ |
||||
CodeDomLocalizationModel model = FormsDesigner.Gui.OptionPanels.LocalizationModelOptionsPanel.DefaultLocalizationModel; |
||||
|
||||
if (FormsDesigner.Gui.OptionPanels.LocalizationModelOptionsPanel.KeepLocalizationModel) { |
||||
// Try to find out the current localization model of the designed form
|
||||
CodeDomLocalizationModel existingModel = this.GetCurrentLocalizationModelFromDesignedFile(); |
||||
if (existingModel != CodeDomLocalizationModel.None) { |
||||
LoggingService.Debug("Determined existing localization model, using that: " + existingModel.ToString()); |
||||
model = existingModel; |
||||
} else { |
||||
LoggingService.Debug("Could not determine existing localization model, using default: " + model.ToString()); |
||||
} |
||||
} else { |
||||
LoggingService.Debug("Using default localization model: " + model.ToString()); |
||||
} |
||||
|
||||
CodeDomLocalizationProvider localizationProvider = new CodeDomLocalizationProvider(designerLoaderHost, model); |
||||
IDesignerSerializationManager manager = (IDesignerSerializationManager)designerLoaderHost.GetService(typeof(IDesignerSerializationManager)); |
||||
manager.AddSerializationProvider(localizationProvider); |
||||
base.Initialize(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// When overridden in derived classes, this method should return the current
|
||||
/// localization model of the designed file or None, if it cannot be determined.
|
||||
/// </summary>
|
||||
/// <returns>The default implementation always returns None.</returns>
|
||||
protected virtual CodeDomLocalizationModel GetCurrentLocalizationModelFromDesignedFile() |
||||
{ |
||||
return CodeDomLocalizationModel.None; |
||||
} |
||||
|
||||
protected override void OnEndLoad(bool successful, ICollection errors) |
||||
{ |
||||
this.loading = false; |
||||
//when control's Dispose() has a exception and on loading also raised exception
|
||||
//then this is only place where this error can be logged, because after errors is
|
||||
//catched internally in .net
|
||||
try { |
||||
base.OnEndLoad(successful, errors); |
||||
} catch(ExceptionCollection e) { |
||||
LoggingService.Error("DesignerLoader.OnEndLoad error" + e.Message); |
||||
foreach(Exception ine in e.Exceptions) { |
||||
LoggingService.Error("DesignerLoader.OnEndLoad error" + ine.Message); |
||||
} |
||||
throw; |
||||
} catch(Exception e) { |
||||
LoggingService.Error("DesignerLoader.OnEndLoad error" + e.Message); |
||||
throw; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,167 @@
@@ -0,0 +1,167 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Christian Hornung" email="chhornung@googlemail.com"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Windows.Forms; |
||||
using System.ComponentModel.Design.Serialization; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.FormsDesigner.Gui.OptionPanels |
||||
{ |
||||
/// <summary>
|
||||
/// Options panel for localization model options.
|
||||
/// </summary>
|
||||
public class LocalizationModelOptionsPanel : AbstractOptionPanel |
||||
{ |
||||
public LocalizationModelOptionsPanel() |
||||
{ |
||||
} |
||||
|
||||
#region Windows Forms Designer code
|
||||
|
||||
void InitializeComponent() |
||||
{ |
||||
System.Windows.Forms.GroupBox modelGroupBox; |
||||
this.assignmentRadioButton = new System.Windows.Forms.RadioButton(); |
||||
this.reflectionRadioButton = new System.Windows.Forms.RadioButton(); |
||||
this.keepModelCheckBox = new System.Windows.Forms.CheckBox(); |
||||
modelGroupBox = new System.Windows.Forms.GroupBox(); |
||||
modelGroupBox.SuspendLayout(); |
||||
this.SuspendLayout(); |
||||
//
|
||||
// modelGroupBox
|
||||
//
|
||||
modelGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
modelGroupBox.Controls.Add(this.assignmentRadioButton); |
||||
modelGroupBox.Controls.Add(this.reflectionRadioButton); |
||||
modelGroupBox.Location = new System.Drawing.Point(3, 3); |
||||
modelGroupBox.Name = "modelGroupBox"; |
||||
modelGroupBox.Size = new System.Drawing.Size(385, 166); |
||||
modelGroupBox.TabIndex = 0; |
||||
modelGroupBox.TabStop = false; |
||||
modelGroupBox.Text = "${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.OptionPanels.LocalizationModelOpt" + |
||||
"ionsPanel.DefaultLocalizationModel}"; |
||||
//
|
||||
// assignmentRadioButton
|
||||
//
|
||||
this.assignmentRadioButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
this.assignmentRadioButton.CheckAlign = System.Drawing.ContentAlignment.TopLeft; |
||||
this.assignmentRadioButton.Location = new System.Drawing.Point(6, 91); |
||||
this.assignmentRadioButton.Name = "assignmentRadioButton"; |
||||
this.assignmentRadioButton.Size = new System.Drawing.Size(373, 69); |
||||
this.assignmentRadioButton.TabIndex = 1; |
||||
this.assignmentRadioButton.TabStop = true; |
||||
this.assignmentRadioButton.Text = "${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.OptionPanels.LocalizationModelOpt" + |
||||
"ionsPanel.AssignmentRadioButton}"; |
||||
this.assignmentRadioButton.TextAlign = System.Drawing.ContentAlignment.TopLeft; |
||||
this.assignmentRadioButton.UseVisualStyleBackColor = true; |
||||
//
|
||||
// reflectionRadioButton
|
||||
//
|
||||
this.reflectionRadioButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
this.reflectionRadioButton.CheckAlign = System.Drawing.ContentAlignment.TopLeft; |
||||
this.reflectionRadioButton.Location = new System.Drawing.Point(6, 19); |
||||
this.reflectionRadioButton.Name = "reflectionRadioButton"; |
||||
this.reflectionRadioButton.Size = new System.Drawing.Size(373, 66); |
||||
this.reflectionRadioButton.TabIndex = 0; |
||||
this.reflectionRadioButton.TabStop = true; |
||||
this.reflectionRadioButton.Text = "${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.OptionPanels.LocalizationModelOpt" + |
||||
"ionsPanel.ReflectionRadioButton}"; |
||||
this.reflectionRadioButton.TextAlign = System.Drawing.ContentAlignment.TopLeft; |
||||
this.reflectionRadioButton.UseVisualStyleBackColor = true; |
||||
//
|
||||
// keepModelCheckBox
|
||||
//
|
||||
this.keepModelCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) |
||||
| System.Windows.Forms.AnchorStyles.Right))); |
||||
this.keepModelCheckBox.CheckAlign = System.Drawing.ContentAlignment.TopLeft; |
||||
this.keepModelCheckBox.Location = new System.Drawing.Point(9, 175); |
||||
this.keepModelCheckBox.Name = "keepModelCheckBox"; |
||||
this.keepModelCheckBox.Size = new System.Drawing.Size(373, 95); |
||||
this.keepModelCheckBox.TabIndex = 1; |
||||
this.keepModelCheckBox.Text = "${res:ICSharpCode.SharpDevelop.FormDesigner.Gui.OptionPanels.LocalizationModelOpt" + |
||||
"ionsPanel.KeepModelCheckBox}"; |
||||
this.keepModelCheckBox.TextAlign = System.Drawing.ContentAlignment.TopLeft; |
||||
this.keepModelCheckBox.UseVisualStyleBackColor = true; |
||||
//
|
||||
// LocalizationModelOptionsPanel
|
||||
//
|
||||
this.Controls.Add(this.keepModelCheckBox); |
||||
this.Controls.Add(modelGroupBox); |
||||
this.Name = "LocalizationModelOptionsPanel"; |
||||
this.Size = new System.Drawing.Size(391, 300); |
||||
modelGroupBox.ResumeLayout(false); |
||||
this.ResumeLayout(false); |
||||
} |
||||
private System.Windows.Forms.CheckBox keepModelCheckBox; |
||||
private System.Windows.Forms.RadioButton reflectionRadioButton; |
||||
private System.Windows.Forms.RadioButton assignmentRadioButton; |
||||
|
||||
#endregion
|
||||
|
||||
public override void LoadPanelContents() |
||||
{ |
||||
base.LoadPanelContents(); |
||||
if (this.Controls.Count == 0) { |
||||
this.InitializeComponent(); |
||||
Translate(this); |
||||
} |
||||
|
||||
this.reflectionRadioButton.Checked = (DefaultLocalizationModel == CodeDomLocalizationModel.PropertyReflection); |
||||
this.assignmentRadioButton.Checked = !this.reflectionRadioButton.Checked; |
||||
this.keepModelCheckBox.Checked = KeepLocalizationModel; |
||||
} |
||||
|
||||
static void Translate(Control container) { |
||||
container.Text = StringParser.Parse(container.Text); |
||||
foreach (Control c in container.Controls) { |
||||
Translate(c); |
||||
} |
||||
} |
||||
|
||||
public override bool StorePanelContents() |
||||
{ |
||||
if (this.reflectionRadioButton.Checked) { |
||||
DefaultLocalizationModel = CodeDomLocalizationModel.PropertyReflection; |
||||
} else if (this.assignmentRadioButton.Checked) { |
||||
DefaultLocalizationModel = CodeDomLocalizationModel.PropertyAssignment; |
||||
} else { |
||||
MessageService.ShowError("One localization model must be selected!"); |
||||
return false; |
||||
} |
||||
|
||||
KeepLocalizationModel = this.keepModelCheckBox.Checked; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
|
||||
public const string DefaultLocalizationModelPropertyName = "FormsDesigner.DesignerOptions.DefaultLocalizationModel"; |
||||
public const string KeepLocalizationModelPropertyName = "FormsDesigner.DesignerOptions.KeepLocalizationModel"; |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default localization model to be used by the Windows Forms designer.
|
||||
/// </summary>
|
||||
public static CodeDomLocalizationModel DefaultLocalizationModel { |
||||
get { return PropertyService.Get<CodeDomLocalizationModel>(DefaultLocalizationModelPropertyName, CodeDomLocalizationModel.PropertyReflection); } |
||||
set { PropertyService.Set(DefaultLocalizationModelPropertyName, value); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the Windows Forms designer should keep the localization model of existing files.
|
||||
/// </summary>
|
||||
public static bool KeepLocalizationModel { |
||||
get { return PropertyService.Get<bool>(KeepLocalizationModelPropertyName, false); } |
||||
set { PropertyService.Set(KeepLocalizationModelPropertyName, value); } |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,123 @@
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<root> |
||||
<!-- |
||||
Microsoft ResX Schema |
||||
|
||||
Version 2.0 |
||||
|
||||
The primary goals of this format is to allow a simple XML format |
||||
that is mostly human readable. The generation and parsing of the |
||||
various data types are done through the TypeConverter classes |
||||
associated with the data types. |
||||
|
||||
Example: |
||||
|
||||
... ado.net/XML headers & schema ... |
||||
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||
<resheader name="version">2.0</resheader> |
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||
</data> |
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||
<comment>This is a comment</comment> |
||||
</data> |
||||
|
||||
There are any number of "resheader" rows that contain simple |
||||
name/value pairs. |
||||
|
||||
Each data row contains a name, and value. The row also contains a |
||||
type or mimetype. Type corresponds to a .NET class that support |
||||
text/value conversion through the TypeConverter architecture. |
||||
Classes that don't support this are serialized and stored with the |
||||
mimetype set. |
||||
|
||||
The mimetype is used for serialized objects, and tells the |
||||
ResXResourceReader how to depersist the object. This is currently not |
||||
extensible. For a given mimetype the value must be set accordingly: |
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||
that the ResXResourceWriter will generate, however the reader can |
||||
read any of the formats listed below. |
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64 |
||||
value : The object must be serialized with |
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||
: and then encoded with base64 encoding. |
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||
value : The object must be serialized into a byte array |
||||
: using a System.ComponentModel.TypeConverter |
||||
: and then encoded with base64 encoding. |
||||
--> |
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> |
||||
<xsd:element name="root" msdata:IsDataSet="true"> |
||||
<xsd:complexType> |
||||
<xsd:choice maxOccurs="unbounded"> |
||||
<xsd:element name="metadata"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" use="required" type="xsd:string" /> |
||||
<xsd:attribute name="type" type="xsd:string" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="assembly"> |
||||
<xsd:complexType> |
||||
<xsd:attribute name="alias" type="xsd:string" /> |
||||
<xsd:attribute name="name" type="xsd:string" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="data"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> |
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||
<xsd:attribute ref="xml:space" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
<xsd:element name="resheader"> |
||||
<xsd:complexType> |
||||
<xsd:sequence> |
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
</xsd:sequence> |
||||
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:choice> |
||||
</xsd:complexType> |
||||
</xsd:element> |
||||
</xsd:schema> |
||||
<resheader name="resmimetype"> |
||||
<value>text/microsoft-resx</value> |
||||
</resheader> |
||||
<resheader name="version"> |
||||
<value>2.0</value> |
||||
</resheader> |
||||
<resheader name="reader"> |
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<resheader name="writer"> |
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
</resheader> |
||||
<metadata name="modelGroupBox.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> |
||||
<value>False</value> |
||||
</metadata> |
||||
</root> |
Binary file not shown.
Loading…
Reference in new issue