Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / CollectionEditVerbManager.cs / 1 / CollectionEditVerbManager.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Windows.Forms.Design {
using System.Design;
using Accessibility;
using System.Runtime.Serialization.Formatters;
using System.Threading;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Diagnostics;
using System;
using System.Security;
using System.Security.Permissions;
using System.Collections;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Design;
using Microsoft.Win32;
///
/// Class for sharing code for launching the ToolStripItemsCollectionEditor from a verb.
/// This class implments the IWindowsFormsEditorService and ITypeDescriptorContext to
/// display the dialog.
///
///
internal class CollectionEditVerbManager : IWindowsFormsEditorService, ITypeDescriptorContext {
private ComponentDesigner _designer;
private IComponentChangeService _componentChangeSvc;
private PropertyDescriptor _targetProperty;
private DesignerVerb _editItemsVerb;
///
/// Create one of these things...
///
internal CollectionEditVerbManager(string text, ComponentDesigner designer, PropertyDescriptor prop, bool addToDesignerVerbs) {
Debug.Assert(designer != null, "Can't have a CollectionEditVerbManager without an associated designer");
this._designer = designer;
this._targetProperty = prop;
if (prop == null) {
prop = TypeDescriptor.GetDefaultProperty(designer.Component);
if (prop != null && typeof(ICollection).IsAssignableFrom(prop.PropertyType)) {
_targetProperty = prop;
}
}
Debug.Assert(_targetProperty != null, "Need PropertyDescriptor for ICollection property to associate collectoin edtior with.");
if (text == null) {
text = SR.GetString(SR.ToolStripItemCollectionEditorVerb);
}
_editItemsVerb = new DesignerVerb(text, new EventHandler(this.OnEditItems));
if (addToDesignerVerbs)
{
_designer.Verbs.Add(_editItemsVerb);
}
}
///
/// Our caching property for the IComponentChangeService
///
private IComponentChangeService ChangeService {
get {
if (_componentChangeSvc == null) {
_componentChangeSvc = (IComponentChangeService)((IServiceProvider)this).GetService(typeof(IComponentChangeService));
}
return _componentChangeSvc;
}
}
///
/// Self-explanitory interface impl.
///
IContainer ITypeDescriptorContext.Container
{
get
{
if (_designer.Component.Site != null) {
return _designer.Component.Site.Container;
}
return null;
}
}
public DesignerVerb EditItemsVerb
{
get
{
return _editItemsVerb;
}
}
///
/// Self-explanitory interface impl.
///
void ITypeDescriptorContext.OnComponentChanged()
{
ChangeService.OnComponentChanged(_designer.Component, _targetProperty, null, null);
}
///
/// Self-explanitory interface impl.
///
bool ITypeDescriptorContext.OnComponentChanging()
{
try {
ChangeService.OnComponentChanging(_designer.Component, _targetProperty);
}
catch(CheckoutException checkoutException) {
if (checkoutException == CheckoutException.Canceled) {
return false;
}
throw;
}
return true;
}
///
/// Self-explanitory interface impl.
///
object ITypeDescriptorContext.Instance
{
get
{
return _designer.Component;
}
}
///
/// Self-explanitory interface impl.
///
PropertyDescriptor ITypeDescriptorContext.PropertyDescriptor
{
get
{
return _targetProperty;
}
}
///
/// Self-explanitory interface impl.
///
object IServiceProvider.GetService(Type serviceType)
{
if (serviceType == typeof(ITypeDescriptorContext) ||
serviceType == typeof(IWindowsFormsEditorService)) {
return this;
}
if (_designer.Component.Site != null) {
return _designer.Component.Site.GetService(serviceType);
}
return null;
}
///
/// Self-explanitory interface impl.
///
void IWindowsFormsEditorService.CloseDropDown()
{
// we'll never be called to do this.
//
Debug.Fail("NOTIMPL");
return;
}
///
/// Self-explanitory interface impl.
///
void IWindowsFormsEditorService.DropDownControl(Control control)
{
// nope, sorry
//
Debug.Fail("NOTIMPL");
return;
}
///
/// Self-explanitory interface impl.
///
System.Windows.Forms.DialogResult IWindowsFormsEditorService.ShowDialog(Form dialog)
{
IUIService uiSvc = (IUIService)((IServiceProvider)this).GetService(typeof(IUIService));
if (uiSvc != null) {
return uiSvc.ShowDialog(dialog);
}
else {
return dialog.ShowDialog(_designer.Component as IWin32Window);
}
}
///
/// When the verb is invoked, use all the stuff above to show the dialog, etc.
///
private void OnEditItems(object sender, EventArgs e) {
// Hide the Chrome..
DesignerActionUIService actionUIService = (DesignerActionUIService)((IServiceProvider)this).GetService(typeof(DesignerActionUIService));
if (actionUIService != null)
{
actionUIService.HideUI(_designer.Component);
}
object propertyValue = _targetProperty.GetValue(_designer.Component);
if (propertyValue == null) {
return;
}
CollectionEditor itemsEditor = TypeDescriptor.GetEditor(propertyValue, typeof(UITypeEditor)) as CollectionEditor;
Debug.Assert(itemsEditor != null, "Didn't get a collection editor for type '" + _targetProperty.PropertyType.FullName + "'");
if (itemsEditor != null) {
itemsEditor.EditValue(this, this, propertyValue);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlObjectSerializerReadContextComplexJson.cs
- VerificationException.cs
- ViewKeyConstraint.cs
- AddInAdapter.cs
- ErrorHandler.cs
- ParseChildrenAsPropertiesAttribute.cs
- LicenseProviderAttribute.cs
- ScopeCompiler.cs
- EntityDesignerUtils.cs
- SecurityDocument.cs
- FileDialog_Vista.cs
- EditorReuseAttribute.cs
- FilteredAttributeCollection.cs
- EncodingDataItem.cs
- TransformerInfoCollection.cs
- Screen.cs
- WebEvents.cs
- JoinSymbol.cs
- BlockCollection.cs
- PolicyUnit.cs
- RoutingUtilities.cs
- SubMenuStyle.cs
- AvTraceDetails.cs
- WebServiceResponseDesigner.cs
- ConnectionsZone.cs
- MinimizableAttributeTypeConverter.cs
- FrameworkElement.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- Stack.cs
- BaseAddressPrefixFilterElement.cs
- InvalidPropValue.cs
- DataTableNewRowEvent.cs
- RedirectionProxy.cs
- ColorConvertedBitmapExtension.cs
- DrawingServices.cs
- DefaultParameterValueAttribute.cs
- HostProtectionException.cs
- ObjectCloneHelper.cs
- ReadOnlyHierarchicalDataSource.cs
- MetafileHeader.cs
- Pair.cs
- TransportConfigurationTypeElement.cs
- __Filters.cs
- SizeF.cs
- ItemDragEvent.cs
- COM2PropertyPageUITypeConverter.cs
- MethodExpression.cs
- CollectionViewGroupInternal.cs
- Vector3DKeyFrameCollection.cs
- XPathNavigatorReader.cs
- SQLByteStorage.cs
- MethodBody.cs
- ReflectTypeDescriptionProvider.cs
- DropSource.cs
- SQLCharsStorage.cs
- EntityDataSourceReferenceGroup.cs
- EntityContainer.cs
- SqlFileStream.cs
- Maps.cs
- TextServicesPropertyRanges.cs
- RIPEMD160.cs
- RtfToken.cs
- QueryResponse.cs
- DataControlFieldCollection.cs
- HttpListenerException.cs
- MessageHeaderException.cs
- SqlTypeSystemProvider.cs
- WebPartRestoreVerb.cs
- MarkerProperties.cs
- XXXOnTypeBuilderInstantiation.cs
- IisTraceListener.cs
- DataGridViewButtonColumn.cs
- Rect3D.cs
- MultiAsyncResult.cs
- MemoryMappedViewStream.cs
- FrameworkReadOnlyPropertyMetadata.cs
- DependencyPropertyValueSerializer.cs
- ResXFileRef.cs
- Binding.cs
- DesignRelation.cs
- DSASignatureDeformatter.cs
- ClientBuildManagerCallback.cs
- AbstractSvcMapFileLoader.cs
- RadioButtonFlatAdapter.cs
- AsymmetricKeyExchangeDeformatter.cs
- DeviceContext2.cs
- WebPartConnectionsConfigureVerb.cs
- RequestCacheManager.cs
- AssemblyResolver.cs
- ProvidePropertyAttribute.cs
- UDPClient.cs
- FieldCollectionEditor.cs
- SerializerDescriptor.cs
- PerspectiveCamera.cs
- UIInitializationException.cs
- XslAstAnalyzer.cs
- InvokeHandlers.cs
- CodeAttributeDeclarationCollection.cs
- WmlImageAdapter.cs
- ProjectionPlanCompiler.cs