Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / TypeBrowser.xaml.cs / 1477082 / TypeBrowser.xaml.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.IO; using System.Linq; using System.Reflection; using System.Windows; using System.Windows.Automation.Peers; using System.Windows.Controls; using System.Windows.Input; using System.Collections.Specialized; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text; using System.ComponentModel.Design; using System.Activities.Presentation.Hosting; using System.Windows.Threading; internal sealed partial class TypeBrowser : DialogWindow { static readonly DependencyProperty SelectedTypeProperty = DependencyProperty.Register("SelectedType", typeof(Type), typeof(TypeBrowser), new UIPropertyMetadata()); static readonly DependencyProperty HasGenericTypesProperty = DependencyProperty.Register("HasGenericTypes", typeof(bool), typeof(TypeBrowser)); static readonly DependencyProperty GenericTypeNameProperty = DependencyProperty.Register("GenericTypeName", typeof(String), typeof(TypeBrowser)); static readonly DependencyProperty GenericTypeMappingProperty = DependencyProperty.Register("GenericTypeMapping", typeof(ObservableCollection), typeof(TypeBrowser)); static readonly DependencyProperty ConcreteTypeProperty = DependencyProperty.Register("ConcreteType", typeof(Type), typeof(TypeBrowser)); static Size size = Size.Empty; SearchAction currentSearch = null; ObservableCollection localAssemblies; ObservableCollection referenceAssemblies; AssemblyContextControlItem assemblyContext; Func filter; public TypeBrowser(AssemblyContextControlItem assemblyContext, EditingContext context, Func filter) { this.assemblyContext = assemblyContext; this.Context = context; this.filter = filter; SetValue(GenericTypeMappingProperty, new ObservableCollection ()); GenericTypeMapping.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(GenericTypeMappingCollectionChanged); InitializeComponent(); this.typeEntryTextBox.Focus(); if (!size.IsEmpty) { this.Height = size.Height; this.Width = size.Width; } this.SizeChanged += new SizeChangedEventHandler(TypeBrowser_SizeChanged); this.HelpKeyword = HelpKeywords.TypeBrowser; } static void TypeBrowser_SizeChanged(object sender, SizeChangedEventArgs e) { TypeBrowser.size = e.NewSize; } Type SelectedType { get { return (Type)GetValue(SelectedTypeProperty); } set { SetValue(SelectedTypeProperty, value); } } bool HasGenericTypes { get { return (bool)GetValue(HasGenericTypesProperty); } set { SetValue(HasGenericTypesProperty, value); } } string GenericTypeName { get { return (string)GetValue(GenericTypeNameProperty); } set { SetValue(GenericTypeNameProperty, value); } } ObservableCollection GenericTypeMapping { get { return (ObservableCollection )GetValue(GenericTypeMappingProperty); } set { SetValue(GenericTypeMappingProperty, value); } } public Type ConcreteType { get { return (Type)GetValue(ConcreteTypeProperty); } private set { SetValue(ConcreteTypeProperty, value); } } public ObservableCollection LocalAssemblies { get { if (null == this.localAssemblies) { this.localAssemblies = new ObservableCollection (); if (null != this.assemblyContext) { if (null != this.assemblyContext.LocalAssemblyName) { IMultiTargetingSupportService multiTargetingSupportService = this.Context.Services.GetService (); Assembly local = AssemblyContextControlItem.GetAssembly(this.assemblyContext.LocalAssemblyName, multiTargetingSupportService); if (local != null) { this.localAssemblies.Add(new AssemblyNode(local, true, this.filter, this.Context)); } } } if (this.localAssemblies.Count == 0) { this.LocalAssembly.Visibility = Visibility.Collapsed; } else { this.LocalAssembly.Visibility = Visibility.Visible; } } return this.localAssemblies; } } public ObservableCollection ReferenceAssemblies { get { if (null == this.referenceAssemblies) { this.referenceAssemblies = new ObservableCollection (); if (null != this.assemblyContext) { IMultiTargetingSupportService multiTargetingSupportService = this.Context.Services.GetService (); IEnumerable assemblies = this.assemblyContext.GetEnvironmentAssemblies(multiTargetingSupportService); foreach (Assembly assembly in assemblies.OrderBy (p => p.FullName)) { this.referenceAssemblies.Add(new AssemblyNode(assembly, false, this.filter, this.Context)); } } } return this.referenceAssemblies; } } protected override void OnKeyDown(KeyEventArgs e) { if (e.Key == Key.Escape) { this.DialogResult = false; e.Handled = true; } else if (e.Key == Key.Enter && null != SelectedType) { OnDialogClose(); e.Handled = true; } else { base.OnKeyDown(e); } } protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer() { return new UIElementAutomationPeer(this); } private void GenericTypeMappingCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { this.HasGenericTypes = GenericTypeMapping.Count > 0 ? true : false; if (this.HasGenericTypes) { string strName = this.SelectedType.FullName; this.GenericTypeName = strName.Substring(0, strName.Length - 2) + " <"; } else { this.GenericTypeName = null; } } private Type ResolveType(out string errorTitle, out string errorMessage) { errorTitle = null; errorMessage = null; Type result = this.SelectedType; try { IMultiTargetingSupportService multiTargetingSupport = this.Context.Services.GetService (); if (multiTargetingSupport != null) { result = multiTargetingSupport.GetRuntimeType(result); } if (result == null) { errorTitle = SR.TypeBrowserErrorMessageTitle; errorMessage = SR.TypeBrowserError; return null; } if (result.IsGenericTypeDefinition) { bool isValid = true; //get number of generic parameters in edited type Type[] arguments = new Type[this.GenericTypeMapping.Count]; //for each argument, get resolved type for (int i = 0; i < this.GenericTypeMapping.Count && isValid; ++i) { arguments[i] = this.GenericTypeMapping[i].GetConcreteType(); if (multiTargetingSupport != null && arguments[i] != null) { arguments[i] = multiTargetingSupport.GetRuntimeType(arguments[i]); } isValid = isValid && (null != arguments[i]); } //if all parameters are resolved, create concrete type if (isValid) { result = result.MakeGenericType(arguments); } else { errorTitle = SR.TypeBrowserErrorMessageTitle; errorMessage = SR.TypeResolverError; result = null; } } } catch (ArgumentException err) { errorTitle = err.GetType().Name; errorMessage = err.Message; return null; } return result; } private void OnOkClick(object sender, RoutedEventArgs args) { OnDialogClose(); } private void OnCancelClick(object sender, RoutedEventArgs args) { this.DialogResult = false; } private void OnTypeDoubleClick(object sender, RoutedEventArgs args) { if (((System.Windows.Input.MouseButtonEventArgs)(args)).ChangedButton == MouseButton.Left) { TypeNode entry = ((TreeViewItem)sender).Header as TypeNode; if (null != entry && entry.Data is Type) { OnDialogClose(); args.Handled = true; } } } private void OnDialogClose() { string errorTitle = null; string errorMessage = null; Type type = ResolveType(out errorTitle, out errorMessage); if (null != type) { this.ConcreteType = type; this.DialogResult = true; } else { MessageBox.Show(errorMessage, errorTitle, MessageBoxButton.OK, MessageBoxImage.Error); } } private void OnTypeBrowserClickStart(object sender, RoutedEventArgs args) { TreeViewItem item = sender as TreeViewItem; NamespaceNode ns = null; if (null != item) { ns = item.Header as NamespaceNode; } if (null != ns && null == ns.Tag) { ns.Tag = string.Empty; Mouse.OverrideCursor = Cursors.Wait; } } private void OnTypeBrowserClickEnd(object sender, RoutedEventArgs args) { TreeViewItem item = sender as TreeViewItem; if (null != item && item.Header is AssemblyNode && null != Mouse.OverrideCursor) { Mouse.OverrideCursor = null; } } private void OnTypeSearchTextChanged(object sender, TextChangedEventArgs e) { string searchText = ((TextBox)sender).Text; SearchAction newSearch = new SearchAction(searchText, this.localAssemblies, this.referenceAssemblies); newSearch.Completed += delegate(object s, EventArgs args) { SearchAction senderAction = s as SearchAction; SearchAction currentAction = this.currentSearch; this.currentSearch = null; if (senderAction == currentAction) { TypeNode match = ((SearchActionEventArgs)args).Result as TypeNode; UpdateSelectedItem(match); if (match != null) { match.IsSelected = true; } } }; if (this.currentSearch != null) { this.currentSearch.Abort(); } ClearSelection(); this.currentSearch = newSearch; this.currentSearch.Run(); } private void ClearSelection() { TypeNode currentSelection = this.typesTreeView.SelectedItem as TypeNode; if (currentSelection != null) { currentSelection.IsSelected = false; } } private void OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TemplateControl.cs
- CellConstantDomain.cs
- XmlCountingReader.cs
- DefaultTextStore.cs
- BoundsDrawingContextWalker.cs
- ResourceContainerWrapper.cs
- UserControlCodeDomTreeGenerator.cs
- EntityCommand.cs
- ChtmlTextWriter.cs
- WorkflowInstanceQuery.cs
- TextSyndicationContent.cs
- AsyncCompletedEventArgs.cs
- WebBrowserEvent.cs
- Constraint.cs
- EventLogHandle.cs
- DynamicValueConverter.cs
- ProtocolsConfigurationEntry.cs
- WeakReference.cs
- SoapMessage.cs
- WindowCollection.cs
- Certificate.cs
- StorageInfo.cs
- ZipIOCentralDirectoryBlock.cs
- RowUpdatingEventArgs.cs
- BitmapEffectGroup.cs
- SslStreamSecurityBindingElement.cs
- HybridObjectCache.cs
- Stream.cs
- X509Certificate.cs
- Version.cs
- GeneralTransform3D.cs
- ImageConverter.cs
- QuaternionAnimationBase.cs
- PeerNameResolver.cs
- CodeNamespaceImport.cs
- RestHandler.cs
- CryptoConfig.cs
- ContractInstanceProvider.cs
- QuaternionAnimation.cs
- BrowserDefinition.cs
- Aggregates.cs
- dsa.cs
- IHttpResponseInternal.cs
- ButtonChrome.cs
- DataGridToolTip.cs
- StickyNote.cs
- ProgressChangedEventArgs.cs
- PlaceHolder.cs
- Validator.cs
- SelectionWordBreaker.cs
- Permission.cs
- CodeDOMProvider.cs
- IPPacketInformation.cs
- SerializationEventsCache.cs
- QualifierSet.cs
- CharAnimationBase.cs
- ModifierKeysValueSerializer.cs
- Subordinate.cs
- FontInfo.cs
- ReferencedAssembly.cs
- BoolExpression.cs
- CAGDesigner.cs
- CollectionViewGroupInternal.cs
- ChineseLunisolarCalendar.cs
- SoapExtensionReflector.cs
- UmAlQuraCalendar.cs
- InternalException.cs
- _ConnectStream.cs
- XsltLibrary.cs
- ToolStripSplitStackLayout.cs
- ArrangedElement.cs
- GridErrorDlg.cs
- SmtpAuthenticationManager.cs
- XmlSchemaSimpleContentExtension.cs
- EmptyEnumerator.cs
- handlecollector.cs
- Function.cs
- Model3D.cs
- Bits.cs
- AppDomainCompilerProxy.cs
- BrowserDefinition.cs
- HitTestResult.cs
- BasicCellRelation.cs
- ClientCredentialsElement.cs
- IsolatedStorageFile.cs
- SmtpTransport.cs
- NamedObject.cs
- ConnectionsZone.cs
- SiteMapNodeCollection.cs
- _Rfc2616CacheValidators.cs
- Soap12ProtocolReflector.cs
- BitmapEffectDrawingContent.cs
- ComPlusServiceLoader.cs
- SafeUserTokenHandle.cs
- DesignerValidatorAdapter.cs
- Errors.cs
- Visitors.cs
- UInt64Storage.cs
- SettingsSavedEventArgs.cs
- PropertyRecord.cs