Browse Source

Allow editing setting type.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2017 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
2225118f93
  1. 2
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs
  2. 17
      src/AddIns/DisplayBindings/SettingsEditor/Project/ISettingsEntryHost.cs
  3. 2
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj
  4. 125
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs
  5. 20
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs
  6. 75
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs
  7. 2
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx
  8. 2
      src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs
  9. 65
      src/AddIns/DisplayBindings/SettingsEditor/Project/SpecialTypes.cs
  10. 155
      src/AddIns/Misc/SubversionAddIn/Project/Src/Gui/HistoryViewDisplayBinding/DiffPanel.cs

2
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/AbstractDesignerGenerator.cs

@ -394,7 +394,7 @@ namespace ICSharpCode.FormsDesigner @@ -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)

17
src/AddIns/DisplayBindings/SettingsEditor/Project/ISettingsEntryHost.cs

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.SettingsEditor
{
public interface ISettingsEntryHost
{
string GetDisplayNameForType(Type type);
Type GetTypeByDisplayName(string displayName);
}
}

2
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEditor.csproj

@ -61,6 +61,8 @@ @@ -61,6 +61,8 @@
</EmbeddedResource>
<Compile Include="ProxyPropertyDescriptor.cs" />
<Compile Include="SettingsEntryPropertyGridWrapper.cs" />
<Compile Include="ISettingsEntryHost.cs" />
<Compile Include="SpecialTypes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">

125
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsEntry.cs

@ -12,6 +12,7 @@ using System.ComponentModel; @@ -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 @@ -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 @@ -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 @@ -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 @@ -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);
}
}

20
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.Designer.cs generated

@ -41,6 +41,7 @@ namespace ICSharpCode.SettingsEditor @@ -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 @@ -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 @@ -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 @@ -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 @@ -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;

75
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.cs

@ -14,14 +14,45 @@ using System.Windows.Forms; @@ -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<string> typeNames = new List<string>();
List<Type> types = new List<Type>();
IAmbience ambience;
public SettingsView()
{
//
@ -29,7 +60,19 @@ namespace ICSharpCode.SettingsEditor @@ -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<SettingsEntry> list)
@ -94,9 +137,37 @@ namespace ICSharpCode.SettingsEditor @@ -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;
}
}
}

2
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsView.resx

@ -117,7 +117,7 @@ @@ -117,7 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Scope.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="TypeColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="bindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

2
src/AddIns/DisplayBindings/SettingsEditor/Project/SettingsViewContent.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.SettingsEditor @@ -52,7 +52,7 @@ namespace ICSharpCode.SettingsEditor
List<SettingsEntry> entries = new List<SettingsEntry>();
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);

65
src/AddIns/DisplayBindings/SettingsEditor/Project/SpecialTypes.cs

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
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;
}
}
}

155
src/AddIns/Misc/SubversionAddIn/Project/Src/Gui/HistoryViewDisplayBinding/DiffPanel.cs

@ -0,0 +1,155 @@ @@ -0,0 +1,155 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
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<ListView>("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);
}
}
}
Loading…
Cancel
Save