Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1860 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
23 changed files with 734 additions and 58 deletions
@ -0,0 +1,81 @@
@@ -0,0 +1,81 @@
|
||||
// <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 |
||||
{ |
||||
public class DropDownEditor : UITypeEditor |
||||
{ |
||||
/// <summary>
|
||||
/// Returns the drop down style.
|
||||
/// </summary>
|
||||
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) |
||||
{ |
||||
return UITypeEditorEditStyle.DropDown; |
||||
} |
||||
|
||||
public override bool IsDropDownResizable { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the drop down editor control in the drop down so the user
|
||||
/// can change the value.
|
||||
/// </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 (Control control = CreateDropDownControl(context, editorService)) { |
||||
SetValue(control, value); |
||||
editorService.DropDownControl(control); |
||||
value = GetValue(control); |
||||
} |
||||
} |
||||
|
||||
return value; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates the drop down control.
|
||||
/// </summary>
|
||||
protected virtual Control CreateDropDownControl(ITypeDescriptorContext context, IWindowsFormsEditorService editorService) |
||||
{ |
||||
return new DropDownEditorListBox(context, editorService); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the current value in the drop down control.
|
||||
/// </summary>
|
||||
protected virtual void SetValue(Control control, object value) |
||||
{ |
||||
DropDownEditorListBox listBox = (DropDownEditorListBox)control; |
||||
listBox.Value = (string)value; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the current value from the drop down control.
|
||||
/// </summary>
|
||||
protected virtual object GetValue(Control control) |
||||
{ |
||||
DropDownEditorListBox listBox = (DropDownEditorListBox)control; |
||||
return listBox.Value; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// <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.ComponentModel; |
||||
using System.Drawing; |
||||
using System.Windows.Forms; |
||||
using System.Windows.Forms.Design; |
||||
|
||||
namespace ICSharpCode.WixBinding |
||||
{ |
||||
public class DropDownEditorListBox : ListBox |
||||
{ |
||||
IWindowsFormsEditorService editorService; |
||||
string dropDownValue = String.Empty; |
||||
WixXmlAttributePropertyDescriptor propertyDescriptor; |
||||
|
||||
public DropDownEditorListBox(ITypeDescriptorContext context, IWindowsFormsEditorService editorService) |
||||
{ |
||||
this.editorService = editorService; |
||||
BorderStyle = BorderStyle.None; |
||||
if (context != null) { |
||||
propertyDescriptor = context.PropertyDescriptor as WixXmlAttributePropertyDescriptor; |
||||
} |
||||
AddDropDownItems(); |
||||
} |
||||
|
||||
public string Value { |
||||
get { |
||||
return dropDownValue; |
||||
} |
||||
set { |
||||
dropDownValue = value; |
||||
SelectListItem(dropDownValue); |
||||
} |
||||
} |
||||
|
||||
protected override void OnMouseClick(MouseEventArgs e) |
||||
{ |
||||
base.OnMouseClick(e); |
||||
int index = IndexFromPoint(e.Location); |
||||
if (index != -1) { |
||||
dropDownValue = (string)SelectedItem; |
||||
editorService.CloseDropDown(); |
||||
} |
||||
} |
||||
|
||||
protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e) |
||||
{ |
||||
base.OnPreviewKeyDown(e); |
||||
if (e.KeyData == Keys.Return) { |
||||
if (SelectedIndex != -1) { |
||||
dropDownValue = (string)SelectedItem; |
||||
} |
||||
editorService.CloseDropDown(); |
||||
} |
||||
} |
||||
|
||||
void AddDropDownItems() |
||||
{ |
||||
if (propertyDescriptor != null && propertyDescriptor.WixXmlAttribute.HasValues) { |
||||
foreach (string item in propertyDescriptor.WixXmlAttribute.Values) { |
||||
Items.Add(item); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void SelectListItem(string item) |
||||
{ |
||||
int index = Items.IndexOf(item); |
||||
SelectedIndex = index; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -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 System; |
||||
using System.ComponentModel; |
||||
using System.Windows.Forms.Design; |
||||
|
||||
namespace ICSharpCode.WixBinding |
||||
{ |
||||
/// <summary>
|
||||
/// Used to editor relative filenames in the property grid.
|
||||
/// </summary>
|
||||
public class RelativeFileNameEditor : FileNameEditor |
||||
{ |
||||
public RelativeFileNameEditor() |
||||
{ |
||||
} |
||||
|
||||
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) |
||||
{ |
||||
WixDocument document = GetWixDocument(context); |
||||
|
||||
// Convert relative path to full path for editing.
|
||||
string relativePath = (string)value; |
||||
string fullPath = document.GetFullPath(relativePath); |
||||
string newFullPath = (string)base.EditValue(context, provider, fullPath); |
||||
|
||||
// Convert full path back to relative path.
|
||||
return document.GetRelativePath(newFullPath); |
||||
} |
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Wix document associated with the property
|
||||
/// descriptor.
|
||||
/// </summary>
|
||||
WixDocument GetWixDocument(ITypeDescriptorContext context) |
||||
{ |
||||
WixDocument document = null; |
||||
if (context != null) { |
||||
WixXmlAttributePropertyDescriptor propertyDescriptor = context.PropertyDescriptor as WixXmlAttributePropertyDescriptor; |
||||
if (propertyDescriptor != null) { |
||||
document = propertyDescriptor.WixXmlAttribute.Document; |
||||
} |
||||
} |
||||
|
||||
if (document != null) { |
||||
return document; |
||||
} |
||||
return new WixDocument(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,76 @@
@@ -0,0 +1,76 @@
|
||||
// <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; |
||||
|
||||
namespace WixBinding.Tests.PackageFiles |
||||
{ |
||||
[TestFixture] |
||||
public class GetRelativeFileNameTestFixture |
||||
{ |
||||
WixDocument doc; |
||||
string fullPathBeforeWixDocumentLoaded; |
||||
string relativePathBeforeWixDocumentLoaded; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
doc = new WixDocument(); |
||||
string relativeFileNamePath = @"..\..\bin\Test.exe"; |
||||
fullPathBeforeWixDocumentLoaded = doc.GetFullPath(relativeFileNamePath); |
||||
string fullFileName = @"C:\Projects\MySetup\Test\Test.exe"; |
||||
relativePathBeforeWixDocumentLoaded = doc.GetRelativePath(fullFileName); |
||||
|
||||
doc.LoadXml("<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'></Wix>"); |
||||
doc.FileName = @"C:\Projects\Test\Setup.wxs"; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The WixPackageFilesEditor does not change the path if no document
|
||||
/// is loaded since there is no WixDocument to work out the full path.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void FullPathBeforeWixDocumentLoaded() |
||||
{ |
||||
Assert.AreEqual(@"..\..\bin\Test.exe", fullPathBeforeWixDocumentLoaded); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Again the path should be the same as that passed in since
|
||||
/// no WixDocument is available to work out the relative path.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void RelativePathBeforeWixDocumentLoaded() |
||||
{ |
||||
Assert.AreEqual(@"C:\Projects\MySetup\Test\Test.exe", relativePathBeforeWixDocumentLoaded); |
||||
} |
||||
|
||||
[Test] |
||||
public void FullPath() |
||||
{ |
||||
string relativePath = @"..\Source\bin\Test.exe"; |
||||
Assert.AreEqual(@"C:\Projects\Source\bin\Test.exe", doc.GetFullPath(relativePath)); |
||||
} |
||||
|
||||
[Test] |
||||
public void RelativePath() |
||||
{ |
||||
string fullPath = @"C:\Projects\MyTest\bin\Test.exe"; |
||||
Assert.AreEqual(@"..\MyTest\bin\Test.exe", doc.GetRelativePath(fullPath)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NullWixDocumentFileName() |
||||
{ |
||||
doc.FileName = null; |
||||
string relativeFileNamePath = @"..\..\bin\Test.exe"; |
||||
Assert.AreEqual(relativeFileNamePath, doc.GetFullPath(relativeFileNamePath)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
// <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; |
||||
using WixBinding.Tests.Utils; |
||||
|
||||
namespace WixBinding.Tests.PropertyGrid |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the DropDownEditor is specified as the editor for a
|
||||
/// WixAttributePropertyDescriptor that has possible attribute values.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class DropDownPropertyDescriptorTestFixture |
||||
{ |
||||
WixXmlAttributePropertyDescriptor propertyDescriptor; |
||||
EditorAttribute editorAttribute; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.Text, new string[] {"a", "b"}, null); |
||||
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute); |
||||
editorAttribute = WixBindingTestsHelper.GetEditorAttribute(propertyDescriptor.Attributes); |
||||
} |
||||
|
||||
[Test] |
||||
public void EditorAttributeAdded() |
||||
{ |
||||
Assert.IsNotNull(editorAttribute); |
||||
} |
||||
|
||||
[Test] |
||||
public void EditorAttributeTypeName() |
||||
{ |
||||
Assert.AreEqual(typeof(DropDownEditor).AssemblyQualifiedName, editorAttribute.EditorTypeName); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,107 @@
@@ -0,0 +1,107 @@
|
||||
// <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 DropDownTypeEditorTestFixture |
||||
{ |
||||
DropDownEditor editor; |
||||
object newValue; |
||||
string expectedNewValue; |
||||
MockServiceProvider mockServiceProvider; |
||||
MockWindowsFormsEditorService mockWindowsFormsEditorService; |
||||
Type expectedControlType; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
editor = new DropDownEditor(); |
||||
|
||||
// Edit the value.
|
||||
mockServiceProvider = new MockServiceProvider(); |
||||
mockWindowsFormsEditorService = new MockWindowsFormsEditorService(); |
||||
mockServiceProvider.SetServiceToReturn(mockWindowsFormsEditorService); |
||||
expectedNewValue = "NewValue"; |
||||
mockWindowsFormsEditorService.SetNewValue(expectedNewValue); |
||||
|
||||
newValue = editor.EditValue(mockServiceProvider, "Test"); |
||||
|
||||
expectedControlType = mockWindowsFormsEditorService.GetDropDownControlTypeUsed(); |
||||
} |
||||
|
||||
[Test] |
||||
public void DropDownEditStyle() |
||||
{ |
||||
Assert.AreEqual(UITypeEditorEditStyle.DropDown, editor.GetEditStyle()); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsDropDownResizable() |
||||
{ |
||||
Assert.IsFalse(editor.IsDropDownResizable); |
||||
} |
||||
|
||||
[Test] |
||||
public void NewValue() |
||||
{ |
||||
Assert.AreEqual(newValue, expectedNewValue); |
||||
} |
||||
|
||||
[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 SameValueReturnedIfNotEdited() |
||||
{ |
||||
mockWindowsFormsEditorService = new MockWindowsFormsEditorService(); |
||||
mockServiceProvider.SetServiceToReturn(mockWindowsFormsEditorService); |
||||
|
||||
string oldValue = "test"; |
||||
string newValue = (string)editor.EditValue(null, mockServiceProvider, oldValue); |
||||
Assert.AreEqual(oldValue, newValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void DropDownEditorControlUsedAsDropDownControl() |
||||
{ |
||||
Assert.AreEqual("DropDownEditorListBox", expectedControlType.Name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -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 ICSharpCode.WixBinding; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.ComponentModel; |
||||
using System.Drawing.Design; |
||||
using System.Windows.Forms.Design; |
||||
using WixBinding.Tests.Utils; |
||||
|
||||
namespace WixBinding.Tests.PropertyGrid |
||||
{ |
||||
[TestFixture] |
||||
public class FileNamePropertyDescriptorTestFixture |
||||
{ |
||||
WixXmlAttributePropertyDescriptor propertyDescriptor; |
||||
EditorAttribute editorAttribute; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.FileName); |
||||
propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute); |
||||
editorAttribute = WixBindingTestsHelper.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(RelativeFileNameEditor).AssemblyQualifiedName, editorAttribute.EditorTypeName); |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue