diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs index ee9228c6ba..0e405e32a5 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs @@ -394,7 +394,7 @@ namespace ICSharpCode.FormsDesigner viewContent.Document.Insert(offset, CreateEventHandler(edesc, eventMethodName, body, tabs)); position = line + GetCursorLineAfterEventHandlerCreation(); - return false; + return true; } protected virtual int GetEventHandlerInsertionLine(IClass c) diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/ISettingsEntryHost.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/ISettingsEntryHost.cs new file mode 100644 index 0000000000..d8e8418e37 --- /dev/null +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/ISettingsEntryHost.cs @@ -0,0 +1,17 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.SettingsEditor +{ + public interface ISettingsEntryHost + { + string GetDisplayNameForType(Type type); + Type GetTypeByDisplayName(string displayName); + } +} diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj index a1e24e920b..c0c184f7a2 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj @@ -61,6 +61,8 @@ + + diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs index 4585c65e12..c51eb1bc64 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs @@ -12,6 +12,7 @@ using System.ComponentModel; using System.Xml; using System.Configuration; using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop; namespace ICSharpCode.SettingsEditor { @@ -35,13 +36,28 @@ namespace ICSharpCode.SettingsEditor SettingScope scope = SettingScope.User; Type type; object value; + ISettingsEntryHost host; + [Obsolete("This constructor is required by the DataGridView, but not used because we " + + "use the BindingSourceAddingNew event. Use the overload specifying a host " + + "argument instead!")] public SettingsEntry() { + throw new NotSupportedException(); } - public SettingsEntry(XmlElement element) + public SettingsEntry(ISettingsEntryHost host) { + if (host == null) + throw new ArgumentNullException("host"); + this.host = host; + } + + public SettingsEntry(ISettingsEntryHost host, XmlElement element) + : this(host) + { + if (element == null) + throw new ArgumentNullException("element"); description = element.GetAttribute("Description"); if (!bool.TryParse(element.GetAttribute("GenerateDefaultValueInCode"), out generateDefaultValueInCode)) generateDefaultValueInCode = GenerateDefaultValueInCodeDefault; @@ -100,13 +116,7 @@ namespace ICSharpCode.SettingsEditor writer.WriteStartElement("Value"); writer.WriteAttributeString("Profile", "(Default)"); - if (type != null && type != typeof(string)) { - SettingsPropertyValue v = GetSettingConverter(type, name); - v.PropertyValue = value; - writer.WriteValue(v.SerializedValue); - } else { - writer.WriteValue((value ?? "").ToString()); - } + writer.WriteValue(SerializedValue); writer.WriteEndElement(); writer.WriteEndElement(); // Setting @@ -114,6 +124,11 @@ namespace ICSharpCode.SettingsEditor Type GetType(string typeName) { + foreach (SpecialTypeDescriptor d in SpecialTypeDescriptor.Descriptors) { + if (string.Equals(typeName, d.name, StringComparison.OrdinalIgnoreCase)) + return d.type; + } + return typeof(object).Assembly.GetType(typeName, false) ?? typeof(Uri).Assembly.GetType(typeName, false) ?? typeof(System.Data.DataRow).Assembly.GetType(typeName, false); @@ -175,34 +190,98 @@ namespace ICSharpCode.SettingsEditor } } - [Browsable(false)] - public string SerializedSettingType { - get { - if (type != null) - return type.FullName; - else - return "(null)"; - } - } - public object Value { - get { return value; } + get { return this.value; } set { - if (type == null || type.IsInstanceOfType(value)) { + if (type == null || value == null || type.IsInstanceOfType(value)) { this.value = value; + cachedSerializedValue = null; OnPropertyChanged(new PropertyChangedEventArgs("Value")); + OnPropertyChanged(new PropertyChangedEventArgs("SerializedValue")); } else { throw new ArgumentException("Invalid type for property value."); } } } - [Browsable(false)] + string cachedSerializedValue; + + public string SerializedValue { + get { + if (cachedSerializedValue != null) + return cachedSerializedValue; + if (type != null && type != typeof(string)) { + foreach (SpecialTypeDescriptor d in SpecialTypeDescriptor.Descriptors) { + if (type == d.type) { + return cachedSerializedValue = d.GetString(value); + } + } + + SettingsPropertyValue v = GetSettingConverter(type, name); + v.PropertyValue = value; + cachedSerializedValue = (v.SerializedValue ?? "").ToString(); + } else if (value != null) { + cachedSerializedValue = value.ToString(); + } else { + cachedSerializedValue = ""; + } + return cachedSerializedValue; + } + set { + if (type != null && type != typeof(string)) { + foreach (SpecialTypeDescriptor d in SpecialTypeDescriptor.Descriptors) { + if (type == d.type) { + this.Value = d.GetValue(value); + return; + } + } + + SettingsPropertyValue v = GetSettingConverter(type, name); + v.SerializedValue = value; + this.Value = v.PropertyValue; + } else { + this.Value = value; + } + } + } + public Type Type { get { return type; } set { - type = value; - OnPropertyChanged(new PropertyChangedEventArgs("Type")); + if (type != value) { + string oldValue = this.SerializedValue; + this.cachedSerializedValue = null; + this.value = null; + + type = value; + OnPropertyChanged(new PropertyChangedEventArgs("Type")); + OnPropertyChanged(new PropertyChangedEventArgs("WrappedSettingType")); + + this.SerializedValue = oldValue; + } + } + } + + [Browsable(false)] + public string SerializedSettingType { + get { + foreach (SpecialTypeDescriptor d in SpecialTypeDescriptor.Descriptors) { + if (type == d.type) + return d.name; + } + if (type != null) + return type.FullName; + else + return "(null)"; + } + } + + public string WrappedSettingType { + get { + return host.GetDisplayNameForType(type); + } + set { + this.Type = host.GetTypeByDisplayName(value); } } diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs index 87e90c40fd..67a7a49d89 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs @@ -41,6 +41,7 @@ namespace ICSharpCode.SettingsEditor this.bindingSource = new System.Windows.Forms.BindingSource(this.components); this.label1 = new System.Windows.Forms.Label(); this.NameColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.TypeColumn = new System.Windows.Forms.DataGridViewComboBoxColumn(); this.ScopeColumn = new System.Windows.Forms.DataGridViewComboBoxColumn(); this.ValueColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit(); @@ -56,6 +57,7 @@ namespace ICSharpCode.SettingsEditor this.grid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.grid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.NameColumn, + this.TypeColumn, this.ScopeColumn, this.ValueColumn}); this.grid.DataSource = this.bindingSource; @@ -64,6 +66,7 @@ namespace ICSharpCode.SettingsEditor this.grid.Name = "grid"; this.grid.Size = new System.Drawing.Size(480, 321); this.grid.TabIndex = 0; + this.grid.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.GridDataError); this.grid.SelectionChanged += new System.EventHandler(this.GridSelectionChanged); // // bindingSource @@ -84,19 +87,31 @@ namespace ICSharpCode.SettingsEditor // this.NameColumn.DataPropertyName = "Name"; this.NameColumn.HeaderText = "Name"; + this.NameColumn.MinimumWidth = 50; this.NameColumn.Name = "NameColumn"; // - // Scope + // TypeColumn + // + this.TypeColumn.DataPropertyName = "WrappedSettingType"; + this.TypeColumn.DropDownWidth = 255; + this.TypeColumn.HeaderText = "Type"; + this.TypeColumn.MinimumWidth = 50; + this.TypeColumn.Name = "TypeColumn"; + // + // ScopeColumn // this.ScopeColumn.DataPropertyName = "Scope"; + this.ScopeColumn.DropDownWidth = 80; this.ScopeColumn.HeaderText = "Scope"; + this.ScopeColumn.MinimumWidth = 30; this.ScopeColumn.Name = "ScopeColumn"; // // ValueColumn // this.ValueColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ValueColumn.DataPropertyName = "Value"; + this.ValueColumn.DataPropertyName = "SerializedValue"; this.ValueColumn.HeaderText = "Value"; + this.ValueColumn.MinimumWidth = 50; this.ValueColumn.Name = "ValueColumn"; // // SettingsView @@ -112,6 +127,7 @@ namespace ICSharpCode.SettingsEditor this.ResumeLayout(false); this.PerformLayout(); } + private System.Windows.Forms.DataGridViewComboBoxColumn TypeColumn; private System.Windows.Forms.DataGridViewComboBoxColumn ScopeColumn; private System.Windows.Forms.DataGridViewTextBoxColumn ValueColumn; private System.Windows.Forms.DataGridViewTextBoxColumn NameColumn; diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs index 6121c109a3..f88aaa91de 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs @@ -14,14 +14,45 @@ using System.Windows.Forms; using System.Collections.Generic; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Dom; +using ICSharpCode.SharpDevelop; namespace ICSharpCode.SettingsEditor { - public partial class SettingsView : UserControl + public partial class SettingsView : UserControl, ISettingsEntryHost { public event EventHandler SelectionChanged; public event EventHandler SettingsChanged; + static readonly Type[] defaultAvailableTypes = new Type[] { + typeof(bool), + typeof(byte), + typeof(char), + typeof(decimal), + typeof(double), + typeof(float), + typeof(int), + typeof(long), + typeof(sbyte), + typeof(short), + typeof(string), + typeof(System.Collections.Specialized.StringCollection), + typeof(System.DateTime), + typeof(System.Drawing.Color), + typeof(System.Drawing.Font), + typeof(System.Drawing.Point), + typeof(System.Drawing.Size), + typeof(System.Guid), + typeof(System.TimeSpan), + typeof(uint), + typeof(ulong), + typeof(ushort) + }; + + List typeNames = new List(); + List types = new List(); + IAmbience ambience; + public SettingsView() { // @@ -29,7 +60,19 @@ namespace ICSharpCode.SettingsEditor // InitializeComponent(); + + ambience = AmbienceService.CurrentAmbience; + foreach (Type type in defaultAvailableTypes) { + types.Add(type); + typeNames.Add(ambience.GetIntrinsicTypeName(type.FullName)); + } + foreach (SpecialTypeDescriptor d in SpecialTypeDescriptor.Descriptors) { + types.Add(d.type); + typeNames.Add(d.name); + } + ScopeColumn.DataSource = Enum.GetValues(typeof(SettingScope)); + TypeColumn.DataSource = typeNames; } public void ShowEntries(IList list) @@ -94,9 +137,37 @@ namespace ICSharpCode.SettingsEditor void BindingSourceAddingNew(object sender, AddingNewEventArgs e) { - SettingsEntry entry = new SettingsEntry(); + SettingsEntry entry = new SettingsEntry(this); entry.Type = typeof(string); e.NewObject = entry; } + + void GridDataError(object sender, DataGridViewDataErrorEventArgs e) + { + LoggingService.Debug("Row " + e.RowIndex + ", column " + e.ColumnIndex + ", error " + e.Exception.ToString()); + if (e.Exception != null) { + MessageBox.Show("Error in data entry: " + e.Exception.Message); + } else { + MessageBox.Show("Error in data entry"); + } + } + + string ISettingsEntryHost.GetDisplayNameForType(Type type) + { + foreach (SpecialTypeDescriptor d in SpecialTypeDescriptor.Descriptors) { + if (type == d.type) + return d.name; + } + return ambience.GetIntrinsicTypeName(type.FullName); + } + + Type ISettingsEntryHost.GetTypeByDisplayName(string displayName) + { + for (int i = 0; i < typeNames.Count; i++) { + if (typeNames[i] == displayName) + return types[i]; + } + return null; + } } } diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx index 5962756a76..22812d6b53 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx @@ -117,7 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + True diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs index 9c60d6d720..c0f6a83bf4 100644 --- a/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.SettingsEditor List entries = new List(); foreach (XmlNode node in settings.ChildNodes) { if (node is XmlElement) { - entries.Add(new SettingsEntry(node as XmlElement)); + entries.Add(new SettingsEntry(view, node as XmlElement)); } } view.ShowEntries(entries); diff --git a/src/AddIns/DisplayBindings/SettingsEditor/Project/SpecialTypes.cs b/src/AddIns/DisplayBindings/SettingsEditor/Project/SpecialTypes.cs new file mode 100644 index 0000000000..83c03d7a21 --- /dev/null +++ b/src/AddIns/DisplayBindings/SettingsEditor/Project/SpecialTypes.cs @@ -0,0 +1,65 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.Reflection; + +namespace ICSharpCode.SettingsEditor +{ + sealed class SpecialTypeDescriptor + { + internal string name; + internal Type type; + + internal SpecialTypeDescriptor(string name, Type type) + { + this.name = name; + this.type = type; + } + + public string GetString(object value) + { + if (value == null) + return ""; + else + return type.InvokeMember("name", + BindingFlags.GetField | BindingFlags.Instance | BindingFlags.Public, + null, value, null) as string ?? ""; + } + + public object GetValue(string text) + { + return Activator.CreateInstance(type, text); + } + + internal static readonly SpecialTypeDescriptor[] Descriptors = { + new SpecialTypeDescriptor("(Web Service URL)", typeof(WebServiceUrlDummyType)), + new SpecialTypeDescriptor("(Connection string)", typeof(ConnectionStringDummyType)), + }; + } + + sealed class WebServiceUrlDummyType + { + public string name; + + public WebServiceUrlDummyType(string name) + { + this.name = name; + } + } + + sealed class ConnectionStringDummyType + { + public string name; + + public ConnectionStringDummyType(string name) + { + this.name = name; + } + } +} diff --git a/src/AddIns/Misc/SubversionAddIn/Project/Src/Gui/HistoryViewDisplayBinding/DiffPanel.cs b/src/AddIns/Misc/SubversionAddIn/Project/Src/Gui/HistoryViewDisplayBinding/DiffPanel.cs new file mode 100644 index 0000000000..9335f142f3 --- /dev/null +++ b/src/AddIns/Misc/SubversionAddIn/Project/Src/Gui/HistoryViewDisplayBinding/DiffPanel.cs @@ -0,0 +1,155 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.ComponentModel; +using System.Drawing; +using System.Windows.Forms; +using ICSharpCode.TextEditor; +using ICSharpCode.TextEditor.Document; +using ICSharpCode.TextEditor.Gui; +using ICSharpCode.SharpDevelop.Gui; +using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; +using NSvn.Core; +using NSvn.Common; +using System.IO; +using System.Text; + +namespace ICSharpCode.Svn +{ + public partial class DiffPanel + { + IViewContent viewContent; + TextEditorControl textEditor; + + public DiffPanel(IViewContent viewContent) + { + this.viewContent = viewContent; + + // + // The InitializeComponent() call is required for Windows Forms designer support. + // + InitializeComponent(); + + textEditor = new TextEditorControl(); + textEditor.Dock = DockStyle.Fill; + diffViewPanel.Controls.Add(textEditor); + + textEditor.TextEditorProperties = new SharpDevelopTextEditorProperties(); + textEditor.Document.ReadOnly = true; + textEditor.Enabled = false; + + textEditor.Document.HighlightingStrategy = HighlightingManager.Manager.FindHighlighter("Patch"); + + ListViewItem newItem; + newItem = new ListViewItem(new string[] { "Base", "", "", "" }); + newItem.Tag = Revision.Base; + leftListView.Items.Add(newItem); + newItem.Selected = true; + newItem = new ListViewItem(new string[] { "Work", "", "", "" }); + newItem.Tag = Revision.Working; + rightListView.Items.Add(newItem); + } + + void LeftListViewSelectedIndexChanged(object sender, EventArgs e) + { + ShowDiff(); + } + + void RightListViewSelectedIndexChanged(object sender, EventArgs e) + { + ShowDiff(); + } + + /* + protected override void OnLoad(EventArgs e) + { + // fix sizing problems + Get("toRevision").Width -= 13; + ControlDictionary["fromRevisionPanel"].Width = ControlDictionary["topPanel"].Width / 2 - 2; + } + */ + + string output = null; + string fileName = null; + Revision fromRevision; + Revision toRevision; + + void DoDiffOperation() + { + output = null; + MemoryStream outStream = new MemoryStream(); + MemoryStream errStream = new MemoryStream(); + SvnClient.Instance.Client.Diff(new string [] {} , + fileName, + fromRevision, + fileName, + toRevision, + Recurse.None, + false, + true, + outStream, + errStream); + output = Encoding.Default.GetString(outStream.ToArray()); + WorkbenchSingleton.SafeThreadCall(SetOutput); + } + + void SetOutput() + { + textEditor.Enabled = true; + diffLabel.Text = "Diff from revision " + fromRevision + " to " + toRevision + ":"; + textEditor.Text = output; + } + + void Disable() + { + textEditor.Enabled = false; + diffLabel.Text = "Diff:"; + textEditor.Text = ""; + } + + void ShowDiff() + { + Disable(); + + if (leftListView.SelectedItems.Count == 0 || rightListView.SelectedItems.Count == 0 ) { + return; + } + + fromRevision = leftListView.SelectedItems[0].Tag as Revision; + toRevision = rightListView.SelectedItems[0].Tag as Revision; + fileName = Path.GetFullPath(viewContent.FileName); + + if (fromRevision.ToString() == toRevision.ToString()) { + output = ""; + } else { + SvnClient.Instance.OperationStart("Diff", DoDiffOperation); + } + } + + public void AddLogMessage(LogMessage logMessage) + { + ListViewItem newItem = new ListViewItem(new string[] { + logMessage.Revision.ToString(), + logMessage.Author, + logMessage.Date.ToString(), + logMessage.Message + }); + newItem.Tag = Revision.FromNumber(logMessage.Revision); + leftListView.Items.Add(newItem); + + ListViewItem newItem2 = new ListViewItem(new string[] { + logMessage.Revision.ToString(), + logMessage.Author, + logMessage.Date.ToString(), + logMessage.Message + }); + newItem2.Tag = Revision.FromNumber(logMessage.Revision); + rightListView.Items.Add(newItem2); + } + } +}