Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1858 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
16 changed files with 627 additions and 53 deletions
@ -0,0 +1,56 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Drawing.Design; |
||||||
|
using System.Windows.Forms; |
||||||
|
using System.Windows.Forms.Design; |
||||||
|
|
||||||
|
namespace ICSharpCode.WixBinding |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Property grid editor for Guids
|
||||||
|
/// </summary>
|
||||||
|
public class GuidEditor : UITypeEditor |
||||||
|
{ |
||||||
|
public GuidEditor() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the drop down style.
|
||||||
|
/// </summary>
|
||||||
|
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) |
||||||
|
{ |
||||||
|
return UITypeEditorEditStyle.DropDown; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the Guid editor control in the drop down so the user
|
||||||
|
/// can change the Guid.
|
||||||
|
/// </summary>
|
||||||
|
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) |
||||||
|
{ |
||||||
|
IWindowsFormsEditorService editorService = null; |
||||||
|
|
||||||
|
if (provider != null) { |
||||||
|
editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); |
||||||
|
} |
||||||
|
|
||||||
|
if (editorService != null) { |
||||||
|
using (GuidEditorListBox listBox = new GuidEditorListBox(editorService)) { |
||||||
|
listBox.Guid = (string)value; |
||||||
|
editorService.DropDownControl(listBox); |
||||||
|
value = listBox.Guid; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return value; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,73 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using ICSharpCode.Core; |
||||||
|
using System; |
||||||
|
using System.Drawing; |
||||||
|
using System.Windows.Forms; |
||||||
|
using System.Windows.Forms.Design; |
||||||
|
|
||||||
|
namespace ICSharpCode.WixBinding |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// A list box which has one entry called "New Guid".
|
||||||
|
/// </summary>
|
||||||
|
public class GuidEditorListBox : ListBox |
||||||
|
{ |
||||||
|
string guid = String.Empty; |
||||||
|
IWindowsFormsEditorService editorService; |
||||||
|
|
||||||
|
public GuidEditorListBox(IWindowsFormsEditorService editorService) |
||||||
|
{ |
||||||
|
this.editorService = editorService; |
||||||
|
Items.Add("New Guid"); |
||||||
|
Size = new Size(Width, ItemHeight); |
||||||
|
BorderStyle = BorderStyle.None; |
||||||
|
} |
||||||
|
|
||||||
|
public string Guid { |
||||||
|
get { |
||||||
|
return guid; |
||||||
|
} |
||||||
|
set { |
||||||
|
guid = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override bool ShowFocusCues { |
||||||
|
get { |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnMouseClick(MouseEventArgs e) |
||||||
|
{ |
||||||
|
base.OnMouseClick(e); |
||||||
|
int index = IndexFromPoint(e.Location); |
||||||
|
if (index != -1) { |
||||||
|
CreateNewGuid(); |
||||||
|
editorService.CloseDropDown(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e) |
||||||
|
{ |
||||||
|
base.OnPreviewKeyDown(e); |
||||||
|
if (e.KeyData == Keys.Return) { |
||||||
|
if (SelectedIndex != -1) { |
||||||
|
CreateNewGuid(); |
||||||
|
} |
||||||
|
editorService.CloseDropDown(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void CreateNewGuid() |
||||||
|
{ |
||||||
|
guid = System.Guid.NewGuid().ToString().ToUpperInvariant(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,83 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using ICSharpCode.WixBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Drawing.Design; |
||||||
|
using System.Windows.Forms.Design; |
||||||
|
|
||||||
|
namespace WixBinding.Tests.PropertyGrid |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class GuidPropertyDescriptorTestFixture |
||||||
|
{ |
||||||
|
WixXmlAttributePropertyDescriptor propertyDescriptor; |
||||||
|
EditorAttribute editorAttribute; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.ComponentGuid); |
||||||
|
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute); |
||||||
|
editorAttribute = GetEditorAttribute(propertyDescriptor.Attributes); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void EditorAttributeAdded() |
||||||
|
{ |
||||||
|
Assert.IsNotNull(editorAttribute); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void EditorAttributeBaseTypeName() |
||||||
|
{ |
||||||
|
Assert.AreEqual(typeof(UITypeEditor).AssemblyQualifiedName, editorAttribute.EditorBaseTypeName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void EditorAttributeTypeName() |
||||||
|
{ |
||||||
|
Assert.AreEqual(typeof(GuidEditor).AssemblyQualifiedName, editorAttribute.EditorTypeName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AutogenUuid() |
||||||
|
{ |
||||||
|
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.AutogenUuid); |
||||||
|
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute); |
||||||
|
EditorAttribute editorAttribute = GetEditorAttribute(propertyDescriptor.Attributes); |
||||||
|
|
||||||
|
Assert.IsNotNull(editorAttribute); |
||||||
|
Assert.AreEqual(typeof(GuidEditor).AssemblyQualifiedName, editorAttribute.EditorTypeName); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Uuid() |
||||||
|
{ |
||||||
|
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.Uuid); |
||||||
|
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute); |
||||||
|
EditorAttribute editorAttribute = GetEditorAttribute(propertyDescriptor.Attributes); |
||||||
|
|
||||||
|
Assert.IsNotNull(editorAttribute); |
||||||
|
Assert.AreEqual(typeof(GuidEditor).AssemblyQualifiedName, editorAttribute.EditorTypeName); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
static EditorAttribute GetEditorAttribute(AttributeCollection attributes) |
||||||
|
{ |
||||||
|
foreach (Attribute attribute in attributes) { |
||||||
|
EditorAttribute editorAttribute = attribute as EditorAttribute; |
||||||
|
if (editorAttribute != null) { |
||||||
|
return editorAttribute; |
||||||
|
} |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,115 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using ICSharpCode.WixBinding; |
||||||
|
using NUnit.Framework; |
||||||
|
using System; |
||||||
|
using System.Drawing.Design; |
||||||
|
using System.Windows.Forms; |
||||||
|
using System.Windows.Forms.Design; |
||||||
|
using WixBinding.Tests.Utils; |
||||||
|
|
||||||
|
namespace WixBinding.Tests.PropertyGrid |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class GuidTypeEditorTestFixture |
||||||
|
{ |
||||||
|
GuidEditor editor; |
||||||
|
object newValue; |
||||||
|
string expectedNewGuid; |
||||||
|
MockServiceProvider mockServiceProvider; |
||||||
|
MockWindowsFormsEditorService mockWindowsFormsEditorService; |
||||||
|
Type expectedGuidControlType; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
editor = new GuidEditor(); |
||||||
|
|
||||||
|
// Edit the guid value.
|
||||||
|
mockServiceProvider = new MockServiceProvider(); |
||||||
|
mockWindowsFormsEditorService = new MockWindowsFormsEditorService(); |
||||||
|
mockServiceProvider.SetServiceToReturn(mockWindowsFormsEditorService); |
||||||
|
expectedNewGuid = Guid.NewGuid().ToString().ToUpperInvariant(); |
||||||
|
mockWindowsFormsEditorService.SetNewValue(expectedNewGuid); |
||||||
|
|
||||||
|
Guid guid = Guid.NewGuid(); |
||||||
|
|
||||||
|
newValue = editor.EditValue(mockServiceProvider, guid.ToString().ToUpperInvariant()); |
||||||
|
|
||||||
|
expectedGuidControlType = mockWindowsFormsEditorService.GetDropDownControlTypeUsed(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void DropDownEditStyle() |
||||||
|
{ |
||||||
|
Assert.AreEqual(UITypeEditorEditStyle.DropDown, editor.GetEditStyle()); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsDropDownResizable() |
||||||
|
{ |
||||||
|
Assert.IsFalse(editor.IsDropDownResizable); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NewGuidReturned() |
||||||
|
{ |
||||||
|
Assert.IsInstanceOfType(typeof(String), newValue); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NewGuidValue() |
||||||
|
{ |
||||||
|
Assert.AreEqual(newValue, expectedNewGuid); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void WindowsFormsEditorServiceRequested() |
||||||
|
{ |
||||||
|
Assert.AreEqual(typeof(IWindowsFormsEditorService), |
||||||
|
mockServiceProvider.GetServiceRequested(0)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void SameValueReturnedIfNoServiceProviderSet() |
||||||
|
{ |
||||||
|
string oldValue = "Test"; |
||||||
|
string newValue = (string)editor.EditValue(null, null, oldValue); |
||||||
|
Assert.IsTrue(Object.ReferenceEquals(oldValue, newValue)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void SameValueReturnedIfWindowsFormsServiceReturned() |
||||||
|
{ |
||||||
|
mockServiceProvider.SetServiceToReturn(null); |
||||||
|
|
||||||
|
string oldValue = "Test"; |
||||||
|
string newValue = (string)editor.EditValue(null, mockServiceProvider, oldValue); |
||||||
|
Assert.IsTrue(Object.ReferenceEquals(oldValue, newValue)); |
||||||
|
Assert.AreEqual(typeof(IWindowsFormsEditorService), |
||||||
|
mockServiceProvider.GetServiceRequested(1)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void SameGuidValueReturnedIfNotEdited() |
||||||
|
{ |
||||||
|
mockWindowsFormsEditorService = new MockWindowsFormsEditorService(); |
||||||
|
mockServiceProvider.SetServiceToReturn(mockWindowsFormsEditorService); |
||||||
|
|
||||||
|
string oldValue = Guid.NewGuid().ToString().ToUpperInvariant(); |
||||||
|
string newValue = (string)editor.EditValue(null, mockServiceProvider, oldValue); |
||||||
|
Assert.AreEqual(oldValue, newValue); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void GuidEditorControlUsedAsDropDownControl() |
||||||
|
{ |
||||||
|
Assert.AreEqual("GuidEditorListBox", expectedGuidControlType.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,51 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
namespace WixBinding.Tests.Utils |
||||||
|
{ |
||||||
|
public class MockServiceProvider : IServiceProvider |
||||||
|
{ |
||||||
|
List<object> services = new List<object>(); |
||||||
|
List<Type> servicesRequested = new List<Type>(); |
||||||
|
|
||||||
|
public MockServiceProvider() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public object GetService(Type serviceType) |
||||||
|
{ |
||||||
|
if (services.Count > 0) { |
||||||
|
object service = services[0]; |
||||||
|
services.RemoveAt(0); |
||||||
|
servicesRequested.Add(serviceType); |
||||||
|
return service; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public void SetServiceToReturn(object service) |
||||||
|
{ |
||||||
|
services.Add(service); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the service requested via the GetService method.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index">The first service requested will
|
||||||
|
/// be at index 0.</param>
|
||||||
|
public Type GetServiceRequested(int index) |
||||||
|
{ |
||||||
|
if (index < servicesRequested.Count) { |
||||||
|
return servicesRequested[index]; |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,57 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using ICSharpCode.WixBinding; |
||||||
|
using System; |
||||||
|
using System.Windows.Forms; |
||||||
|
using System.Windows.Forms.Design; |
||||||
|
|
||||||
|
namespace WixBinding.Tests.Utils |
||||||
|
{ |
||||||
|
public class MockWindowsFormsEditorService : IWindowsFormsEditorService |
||||||
|
{ |
||||||
|
Type controlType; |
||||||
|
string newValue; |
||||||
|
bool newValueSet; |
||||||
|
|
||||||
|
public MockWindowsFormsEditorService() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public void CloseDropDown() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public void DropDownControl(Control control) |
||||||
|
{ |
||||||
|
controlType = control.GetType(); |
||||||
|
|
||||||
|
if (newValueSet) { |
||||||
|
GuidEditorListBox listBox = control as GuidEditorListBox; |
||||||
|
if (listBox != null) { |
||||||
|
listBox.Guid = newValue; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public DialogResult ShowDialog(Form dialog) |
||||||
|
{ |
||||||
|
return DialogResult.None; |
||||||
|
} |
||||||
|
|
||||||
|
public Type GetDropDownControlTypeUsed() |
||||||
|
{ |
||||||
|
return controlType; |
||||||
|
} |
||||||
|
|
||||||
|
public void SetNewValue(string value) |
||||||
|
{ |
||||||
|
newValue = value; |
||||||
|
newValueSet = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue