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
- XhtmlTextWriter.cs
- VScrollBar.cs
- DataColumnMapping.cs
- DefaultTypeArgumentAttribute.cs
- StringValidator.cs
- KeyGestureConverter.cs
- GeneralTransformGroup.cs
- SpellerInterop.cs
- LightweightCodeGenerator.cs
- TypeForwardedFromAttribute.cs
- AuthorizationRule.cs
- WindowsSidIdentity.cs
- CodeLabeledStatement.cs
- RetrieveVirtualItemEventArgs.cs
- PrimitiveDataContract.cs
- GeneralTransform3DGroup.cs
- TextDecorationLocationValidation.cs
- ReflectionServiceProvider.cs
- ReadOnlyHierarchicalDataSourceView.cs
- AdCreatedEventArgs.cs
- WmlLinkAdapter.cs
- PointAnimationUsingKeyFrames.cs
- ObjectIDGenerator.cs
- QilIterator.cs
- TransformerConfigurationWizardBase.cs
- SqlClientWrapperSmiStreamChars.cs
- ThreadPool.cs
- JsonQueryStringConverter.cs
- ScriptingScriptResourceHandlerSection.cs
- BindingWorker.cs
- EntityViewGenerator.cs
- Win32.cs
- Events.cs
- CodeExpressionStatement.cs
- DetailsViewDeletedEventArgs.cs
- DocumentPage.cs
- ConditionChanges.cs
- ParameterElement.cs
- LoadRetryConstantStrategy.cs
- ObjectStateFormatter.cs
- Frame.cs
- AttachedPropertyBrowsableAttribute.cs
- XPathScanner.cs
- RSACryptoServiceProvider.cs
- TextRangeEditTables.cs
- GraphicsPathIterator.cs
- Win32Exception.cs
- CachedFontFamily.cs
- ScriptRegistrationManager.cs
- LinqDataSourceHelper.cs
- WindowsFormsHostPropertyMap.cs
- ProfilePropertySettingsCollection.cs
- RijndaelManagedTransform.cs
- XmlNavigatorFilter.cs
- UriTemplateClientFormatter.cs
- WarningException.cs
- JsonGlobals.cs
- SerializationHelper.cs
- ReliabilityContractAttribute.cs
- FixedDocumentSequencePaginator.cs
- CheckBoxList.cs
- ProcessInfo.cs
- TrackingAnnotationCollection.cs
- MouseOverProperty.cs
- ProgressBar.cs
- RenderingBiasValidation.cs
- PngBitmapEncoder.cs
- InternalTransaction.cs
- ListControlConvertEventArgs.cs
- shaperfactoryquerycacheentry.cs
- FlowNode.cs
- ItemContainerGenerator.cs
- DesignerAttribute.cs
- WebBrowserSiteBase.cs
- NullableDecimalMinMaxAggregationOperator.cs
- WebPartDisplayModeCancelEventArgs.cs
- FixedTextView.cs
- GridViewRow.cs
- ControlHelper.cs
- OpCodes.cs
- CacheRequest.cs
- Splitter.cs
- HtmlTernaryTree.cs
- MultiView.cs
- Hashtable.cs
- ProgressBarBrushConverter.cs
- TargetControlTypeAttribute.cs
- DecoderExceptionFallback.cs
- LifetimeServices.cs
- StreamInfo.cs
- EventsTab.cs
- ExpressionVisitorHelpers.cs
- DataObject.cs
- TextClipboardData.cs
- ListenerSessionConnection.cs
- DictionaryManager.cs
- RuleSetCollection.cs
- WmfPlaceableFileHeader.cs
- SoapInteropTypes.cs
- Descriptor.cs