/// <summary> /// Edits the value of the specified object. /// </summary> /// <param name="context">An <see cref="ITypeDescriptorContext"/> that can be used to gain /// additional context information.</param> /// <param name="provider">An <see cref="IServiceProvider"/> that this editor can use to obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var baseTypeAttribute = GetBaseTypeAttribute(context); var constraint = new TypeBuildNodeConstraint( baseTypeAttribute.BaseType, baseTypeAttribute.ConfigurationType, baseTypeAttribute.TypeSelectorIncludes); var model = new TypeBrowserViewModel(constraint, provider); var window = new TypeBrowser(model, (IAssemblyDiscoveryService)provider.GetService(typeof(IAssemblyDiscoveryService))); var service = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf)); if (service != null) { service.ShowDialog(window); } else { window.ShowDialog(); } if (window.DialogResult.HasValue && window.DialogResult.Value) { return(window.SelectedType != null ? window.SelectedType.AssemblyQualifiedName : null); } return(value); }
/// <summary> /// Edits the value of the specified object. /// </summary> /// <param name="context">An <see cref="ITypeDescriptorContext"/> that can be used to gain /// additional context information.</param> /// <param name="provider">An <see cref="IServiceProvider"/> that this editor can use to obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns>The new value of the object. If the value of the object has not changed, this should return the same object it was passed.</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var baseTypeAttribute = GetBaseTypeAttribute(context); var constraint = new TypeBuildNodeConstraint( baseTypeAttribute.BaseType, baseTypeAttribute.ConfigurationType, baseTypeAttribute.TypeSelectorIncludes); var model = new TypeBrowserViewModel(constraint, provider); var window = new TypeBrowser(model, (IAssemblyDiscoveryService)provider.GetService(typeof(IAssemblyDiscoveryService))); var service = (IUIServiceWpf)provider.GetService(typeof(IUIServiceWpf)); if (service != null) { service.ShowDialog(window); } else { window.ShowDialog(); } if (window.DialogResult.HasValue && window.DialogResult.Value) { return window.SelectedType != null ? window.SelectedType.AssemblyQualifiedName : null; } return value; }
/// <summary> /// Initializes a new instance of the <see cref="TypeBrowser"/> class with a view model and an /// assembly discovery service. /// </summary> /// <param name="viewModel">The <see cref="TypeBrowserViewModel"/>.</param> /// <param name="assemblyDiscoveryService">The assembly discovery service.</param> public TypeBrowser(TypeBrowserViewModel viewModel, IAssemblyDiscoveryService assemblyDiscoveryService) : this() { this.assemblyDiscoveryService = assemblyDiscoveryService; viewModel.UpdateAssemblyGroups(GetAssemblyGroups()); this.DataContext = viewModel; // Consider rearranging this this.AddFromFile.GetBindingExpression(Button.VisibilityProperty).UpdateTarget(); this.AddFromGac.GetBindingExpression(Button.VisibilityProperty).UpdateTarget(); }
public void SetUp() { var groups = new[] { new AssemblyGroup( "test", new [] { typeof(TestAssembly1.Namespace1.Class1).Assembly, typeof(TestAssembly2.Namespace1.Class1).Assembly }) }; this.model = new TypeBrowserViewModel(null); this.model.UpdateAssemblyGroups(groups); }
/// <summary> /// Retrieves and returns the selected type from the user. /// </summary> /// <param name="selectedType">The type to select in the type selection dialog.</param> /// <param name="baseType">The base type (class or interface) from which the constrained type should derive.</param> /// <param name="selectorIncludes">Indicates the types that can be browsed.</param> /// <param name="configurationType">The base type from which a type specified by the /// <see cref="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationElementTypeAttribute"/> /// bound to the constrained type should derive, or <see langword="null"/> if no such constraint is necessary. /// </param> /// <returns> /// The selected <see cref="Type"/> or <see langword="null"/> if not type is selected. /// </returns> protected virtual Type GetSelectedType(Type selectedType, Type baseType, TypeSelectorIncludes selectorIncludes, Type configurationType) { var viewModel = new TypeBrowserViewModel(new TypeBuildNodeConstraint(baseType, configurationType, selectorIncludes), this); var selector = new TypeBrowser(viewModel, this.discoveryService); Nullable<bool> result = false; if (this.UIService != null) { result = UIService.ShowDialog(selector); } else { result = selector.ShowDialog(); } if (result.HasValue && result.Value) { return selector.SelectedType; } return null; }
public void UpdatingTheTypeNameToASingleMatch_PerformsSearchAndSetsSelectionButDoesNotChangeTypeName() { var groups = new[] { new AssemblyGroup( "test", new[] { typeof(TestAssembly1.Namespace1.Class1).Assembly, typeof(TestAssembly2.Namespace1.Class1).Assembly})}; var model = new TypeBrowserViewModel(null); model.UpdateAssemblyGroups(groups); var modifiedProperties = new List<string>(); model.PropertyChanged += (s, a) => { modifiedProperties.Add(a.PropertyName); }; var frame = new DispatcherFrame(); model.AssemblyGroups[0].Assemblies[0].Namespaces[0].PropertyChanged += (s, a) => { frame.Continue = false; }; model.TypeName = "NamespaceClass"; Dispatcher.PushFrame(frame); Assert.IsNotNull(model.ConcreteType); Assert.AreEqual("NamespaceClass", model.TypeName); TreeAssert.IsMatch( new { DisplayName = "test", Assemblies = new object[] { new { DisplayName = "TestAssembly1", Visibility = Visibility.Collapsed, IsExpanded = false, Namespaces = new object [] { new { DisplayName = "TestAssembly1.Namespace1", Visibility = Visibility.Collapsed, IsExpanded = false, Types = new object[] { new { DisplayName = "Class1", FullName = "TestAssembly1.Namespace1.Class1", Visibility = Visibility.Collapsed, IsExpanded = false }, new { DisplayName = "Class2", FullName = "TestAssembly1.Namespace1.Class2", Visibility = Visibility.Collapsed, IsExpanded = false }, new { DisplayName = "InternalClass1", FullName = "TestAssembly1.Namespace1.InternalClass1", Visibility = Visibility.Collapsed, IsExpanded = false }, } }, new { DisplayName = "TestAssembly1.Namespace2", Visibility = Visibility.Collapsed, IsExpanded = false, Types = new object[] { new { DisplayName = "AnotherInternalClass", FullName = "TestAssembly1.Namespace2.AnotherInternalClass", Visibility = Visibility.Collapsed, IsExpanded = false } } } } }, new { DisplayName = "TestAssembly2", Visibility = Visibility.Visible, IsExpanded = true, Namespaces = new object [] { new { DisplayName = "TestAssembly2", Visibility = Visibility.Visible, IsExpanded = true, Types = new object[] { new { DisplayName = "Class1", FullName = "TestAssembly2.Class1", Visibility = Visibility.Collapsed, IsExpanded = false }, new { DisplayName = "NamespaceClass", FullName = "TestAssembly2.NamespaceClass", Visibility = Visibility.Visible, IsExpanded = false } } }, new { DisplayName = "TestAssembly2.Namespace1", Visibility = Visibility.Collapsed, IsExpanded = false, Types = new object[] { new { DisplayName = "Class1", FullName = "TestAssembly2.Namespace1.Class1", Visibility = Visibility.Collapsed, IsExpanded = false }, new { DisplayName = "Class12", FullName = "TestAssembly2.Namespace1.Class12", Visibility = Visibility.Collapsed, IsExpanded = false } } } } } } }, model.AssemblyGroups[0]); }
public void ViewModelIsInitialized() { var groups = new[] { new AssemblyGroup( "test", new[] { typeof(TestAssembly1.Namespace1.Class1).Assembly, typeof(TestAssembly2.Namespace1.Class1).Assembly})}; var model = new TypeBrowserViewModel(null); model.UpdateAssemblyGroups(groups); Assert.IsNull(model.TypeName); Assert.IsNull(model.ConcreteType); Assert.IsFalse(model.HasGenericParameters); Assert.AreEqual(0, model.GenericTypeParameters.Count); TreeAssert.IsMatch( new { DisplayName = "test", Assemblies = new object[] { new { DisplayName = "TestAssembly1", Visibility = Visibility.Visible, IsExpanded = false, Namespaces = new object [] { new { DisplayName = "TestAssembly1.Namespace1", Visibility = Visibility.Visible, IsExpanded = false, Types = new object[] { new { DisplayName = "Class1", FullName = "TestAssembly1.Namespace1.Class1", Visibility = Visibility.Visible, IsExpanded = false }, new { DisplayName = "Class2", FullName = "TestAssembly1.Namespace1.Class2", Visibility = Visibility.Visible, IsExpanded = false }, new { DisplayName = "InternalClass1", FullName = "TestAssembly1.Namespace1.InternalClass1", Visibility = Visibility.Visible, IsExpanded = false }, } }, new { DisplayName = "TestAssembly1.Namespace2", Visibility = Visibility.Visible, IsExpanded = false, Types = new object[] { new { DisplayName = "AnotherInternalClass", FullName = "TestAssembly1.Namespace2.AnotherInternalClass", Visibility = Visibility.Visible, IsExpanded = false } } } } }, new { DisplayName = "TestAssembly2", Visibility = Visibility.Visible, IsExpanded = false, Namespaces = new object [] { new { DisplayName = "TestAssembly2", Visibility = Visibility.Visible, IsExpanded = false, Types = new object[] { new { DisplayName = "Class1", FullName = "TestAssembly2.Class1", Visibility = Visibility.Visible, IsExpanded = false }, new { DisplayName = "NamespaceClass", FullName = "TestAssembly2.NamespaceClass", Visibility = Visibility.Visible, IsExpanded = false } } }, new { DisplayName = "TestAssembly2.Namespace1", Visibility = Visibility.Visible, IsExpanded = false, Types = new object[] { new { DisplayName = "Class1", FullName = "TestAssembly2.Namespace1.Class1", Visibility = Visibility.Visible, IsExpanded = false }, new { DisplayName = "Class12", FullName = "TestAssembly2.Namespace1.Class12", Visibility = Visibility.Visible, IsExpanded = false } } } } } } }, model.AssemblyGroups[0]); }
public void SelectingNonTypeNodeWhenTypeIsSelected_DoesChangeTextAndKeepsSelectedType() { var groups = new[] { new AssemblyGroup( "test", new[] { typeof(TestAssembly1.Namespace1.Class1).Assembly, typeof(TestAssembly2.Namespace1.Class1).Assembly})}; var model = new TypeBrowserViewModel(null); model.UpdateAssemblyGroups(groups); model.AssemblyGroups[0].Assemblies[0].Namespaces[0].Types[0].IsSelected = true; var modifiedProperties = new List<string>(); model.PropertyChanged += (s, a) => { modifiedProperties.Add(a.PropertyName); }; // simulate selection change model.AssemblyGroups[0].Assemblies[0].Namespaces[0].Types[0].IsSelected = false; model.AssemblyGroups[0].Assemblies[0].Namespaces[1].IsSelected = true; Assert.AreEqual(0, modifiedProperties.Count); Assert.IsNotNull(model.ConcreteType); Assert.IsFalse(model.HasGenericParameters); Assert.AreEqual("TestAssembly1.Namespace1.Class1", model.TypeName); }
public void SelectingNonGenericTypeNode_UpdatesTextToFullTypeName() { var groups = new[] { new AssemblyGroup( "test", new[] { typeof(TestAssembly1.Namespace1.Class1).Assembly, typeof(TestAssembly2.Namespace1.Class1).Assembly})}; var model = new TypeBrowserViewModel(null); model.UpdateAssemblyGroups(groups); var modifiedProperties = new List<string>(); model.PropertyChanged += (s, a) => { modifiedProperties.Add(a.PropertyName); }; model.AssemblyGroups[0].Assemblies[0].Namespaces[0].Types[0].IsSelected = true; CollectionAssert.AreEqual(new[] { "HasGenericParameters", "ConcreteType", "TypeName" }, modifiedProperties); Assert.IsNotNull(model.ConcreteType); Assert.IsFalse(model.HasGenericParameters); Assert.AreEqual("TestAssembly1.Namespace1.Class1", model.TypeName); }