Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / DeleteHelper.cs / 1305376 / DeleteHelper.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation { using System.Activities.Presentation.Model; using System.Activities.Presentation.View; using System.Collections.Generic; using System.Linq; static class DeleteHelper { public static bool CanDelete(EditingContext context) { if (context == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("context")); } bool canExecute = false; Selection selection = context.Items.GetValue(); if (null != selection && selection.SelectionCount > 0) { DesignerView designerView = context.Services.GetService (); canExecute = selection.SelectedObjects.All( p => (null != p.View && p.View is WorkflowViewElement && !p.View.Equals(designerView.RootDesigner))); } return canExecute; } public static void Delete(EditingContext context) { if (context == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("context")); } Selection selection = context.Items.GetValue (); if (null != selection) { bool selectRoot = false; DesignerView designerView = context.Services.GetService (); var toDelete = selection.SelectedObjects.Where(p => null != p.View && p.View is WorkflowViewElement && !p.View.Equals(designerView.RootDesigner)); if (toDelete.Count() > 0) { using (EditingScope es = (EditingScope)toDelete.FirstOrDefault().BeginEdit(SR.DeleteOperationEditingScopeDescription)) { Dictionary > containerToModelItemsDict = new Dictionary >(); List modelItemsPerContainer; foreach (var item in toDelete) { ICompositeView container = (ICompositeView)DragDropHelper.GetCompositeView((WorkflowViewElement)item.View); if (null != item.Parent && typeof(ActivityAction).IsAssignableFrom(item.Parent.ItemType)) { item.Parent.Properties["Handler"].ClearValue(); selectRoot = true; } else if (null != container) { if (!containerToModelItemsDict.TryGetValue(container, out modelItemsPerContainer)) { modelItemsPerContainer = new List (); containerToModelItemsDict.Add(container, modelItemsPerContainer); } modelItemsPerContainer.Add(item); } } foreach (ICompositeView container in containerToModelItemsDict.Keys) { container.OnItemsDelete(containerToModelItemsDict[container]); selectRoot = true; } if (selectRoot) { DesignerView view = context.Services.GetService (); if (null != view) { WorkflowViewElement rootView = view.RootDesigner as WorkflowViewElement; if (rootView != null) { Selection.SelectOnly(context, rootView.ModelItem); } } } es.Complete(); } } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation { using System.Activities.Presentation.Model; using System.Activities.Presentation.View; using System.Collections.Generic; using System.Linq; static class DeleteHelper { public static bool CanDelete(EditingContext context) { if (context == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("context")); } bool canExecute = false; Selection selection = context.Items.GetValue (); if (null != selection && selection.SelectionCount > 0) { DesignerView designerView = context.Services.GetService (); canExecute = selection.SelectedObjects.All( p => (null != p.View && p.View is WorkflowViewElement && !p.View.Equals(designerView.RootDesigner))); } return canExecute; } public static void Delete(EditingContext context) { if (context == null) { throw FxTrace.Exception.AsError(new ArgumentNullException("context")); } Selection selection = context.Items.GetValue (); if (null != selection) { bool selectRoot = false; DesignerView designerView = context.Services.GetService (); var toDelete = selection.SelectedObjects.Where(p => null != p.View && p.View is WorkflowViewElement && !p.View.Equals(designerView.RootDesigner)); if (toDelete.Count() > 0) { using (EditingScope es = (EditingScope)toDelete.FirstOrDefault().BeginEdit(SR.DeleteOperationEditingScopeDescription)) { Dictionary > containerToModelItemsDict = new Dictionary >(); List modelItemsPerContainer; foreach (var item in toDelete) { ICompositeView container = (ICompositeView)DragDropHelper.GetCompositeView((WorkflowViewElement)item.View); if (null != item.Parent && typeof(ActivityAction).IsAssignableFrom(item.Parent.ItemType)) { item.Parent.Properties["Handler"].ClearValue(); selectRoot = true; } else if (null != container) { if (!containerToModelItemsDict.TryGetValue(container, out modelItemsPerContainer)) { modelItemsPerContainer = new List (); containerToModelItemsDict.Add(container, modelItemsPerContainer); } modelItemsPerContainer.Add(item); } } foreach (ICompositeView container in containerToModelItemsDict.Keys) { container.OnItemsDelete(containerToModelItemsDict[container]); selectRoot = true; } if (selectRoot) { DesignerView view = context.Services.GetService (); if (null != view) { WorkflowViewElement rootView = view.RootDesigner as WorkflowViewElement; if (rootView != null) { Selection.SelectOnly(context, rootView.ModelItem); } } } es.Complete(); } } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EntityDataSourceConfigureObjectContext.cs
- ConstructorNeedsTagAttribute.cs
- _NestedSingleAsyncResult.cs
- ValidationVisibilityAttribute.cs
- ReadWriteSpinLock.cs
- TagMapCollection.cs
- StylusPointPropertyId.cs
- HttpEncoderUtility.cs
- PersonalizableAttribute.cs
- CompoundFileStreamReference.cs
- IssuedTokenParametersElement.cs
- Duration.cs
- ClickablePoint.cs
- PrefixHandle.cs
- BindUriHelper.cs
- DataGridViewCellStyle.cs
- OutputCacheSection.cs
- RectangleConverter.cs
- configsystem.cs
- NullableBoolConverter.cs
- ContextMenuAutomationPeer.cs
- StructuredProperty.cs
- XmlSubtreeReader.cs
- CryptoSession.cs
- TdsParserSessionPool.cs
- ProxyWebPart.cs
- StyleSheetRefUrlEditor.cs
- ServiceObjectContainer.cs
- DeflateEmulationStream.cs
- NullableIntAverageAggregationOperator.cs
- PrintPreviewControl.cs
- WebBrowserContainer.cs
- CollectionBuilder.cs
- CollectionContainer.cs
- XmlQueryStaticData.cs
- StylusPointPropertyUnit.cs
- PrimarySelectionGlyph.cs
- JsonReaderDelegator.cs
- DataControlFieldHeaderCell.cs
- recordstatefactory.cs
- SmiGettersStream.cs
- IntSecurity.cs
- ListDictionaryInternal.cs
- ScriptManagerProxy.cs
- UserCancellationException.cs
- ResolveMatchesMessage11.cs
- TextViewDesigner.cs
- SerializerDescriptor.cs
- ThemeInfoAttribute.cs
- Tile.cs
- TransformerConfigurationWizardBase.cs
- DesignerToolStripControlHost.cs
- AttributeAction.cs
- Base64Encoder.cs
- CharacterMetrics.cs
- AsymmetricSecurityBindingElement.cs
- TdsParserHelperClasses.cs
- PictureBoxDesigner.cs
- shaperfactory.cs
- CommandHelper.cs
- SessionPageStatePersister.cs
- DataColumnChangeEvent.cs
- EntitySetBaseCollection.cs
- Focus.cs
- DocumentPageView.cs
- IndividualDeviceConfig.cs
- TokenBasedSet.cs
- XmlDictionaryReaderQuotas.cs
- CodeAccessSecurityEngine.cs
- EmbeddedMailObject.cs
- WeakReferenceEnumerator.cs
- EntityDataSourceDataSelection.cs
- EventProvider.cs
- TTSVoice.cs
- FixedSOMElement.cs
- SystemIPInterfaceProperties.cs
- ValidationEventArgs.cs
- SafeRightsManagementPubHandle.cs
- WebServiceHostFactory.cs
- TemplateBuilder.cs
- StringStorage.cs
- InkCanvasSelection.cs
- Rect.cs
- GreenMethods.cs
- DataServices.cs
- TextParaClient.cs
- UnsafeNativeMethods.cs
- DbConvert.cs
- BitmapEffectvisualstate.cs
- FolderBrowserDialog.cs
- BCryptNative.cs
- BuildProviderAppliesToAttribute.cs
- XmlSerializerAssemblyAttribute.cs
- HtmlAnchor.cs
- Buffer.cs
- WindowsScroll.cs
- TextElementEnumerator.cs
- propertytag.cs
- XmlDataImplementation.cs
- WebRequestModuleElementCollection.cs