Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / Selection.cs / 1305376 / Selection.cs
namespace System.Activities.Presentation.View { using System.Runtime; using System.Diagnostics.CodeAnalysis; using System.Activities.Presentation; using System.Activities.Presentation.Model; using System.Activities.Presentation.Internal.Properties; using System; using System.Collections; using System.Collections.Generic; ////// The Selection class defines a selection of objects. Selections /// consist of zero or more objects. The first object in a selection /// is defined as the "primary" selection, which is used when /// one object in a group must be used as a key. /// [SuppressMessage(FxCop.Category.Naming, "CA1724:TypeNamesShouldNotMatchNamespaces", Justification = "Code imported from Cider; keeping changes to a minimum as it impacts xaml files as well")] public class Selection : ContextItem { private ICollection_selectedObjects; /// /// Creates an empty Selection object. /// public Selection() { _selectedObjects = new ModelItem[0]; } ////// Creates a collection object comprising the given /// selected objects. The first object in the enumeration /// is considered the "primary" selection. /// /// An enumeration of objects that should be selected. ///If selectedObjects is null. public Selection(IEnumerableselectedObjects) { if (selectedObjects == null) { throw FxTrace.Exception.ArgumentNull("selectedObjects"); } List selection = new List (); selection.AddRange(selectedObjects); _selectedObjects = selection; } /// /// Creates a collection object comprising the given /// selected objects. The first object in the enumeration /// is considered the "primary" selection. /// /// An enumeration of objects that should be selected. /// If provided, only those objects in selectedObjects that match the predicate will be added to the selection. ///If selectedObjects or match is null. public Selection(IEnumerableselectedObjects, Predicate match) { if (selectedObjects == null) throw FxTrace.Exception.ArgumentNull("selectedObjects"); if (match == null) throw FxTrace.Exception.ArgumentNull("match"); List selection = new List (); foreach (ModelItem o in selectedObjects) { if (match(o)) { selection.Add(o); } } _selectedObjects = selection; } /// /// Creates a collection object comprising the given /// selected objects. The first object in the enumeration /// is considered the "primary" selection. /// /// An enumeration of objects that should be selected. ///If selectedObjects is null. public Selection(IEnumerable selectedObjects) { if (selectedObjects == null) throw FxTrace.Exception.ArgumentNull("selectedObjects"); Listselection = new List (); foreach (object o in selectedObjects) { ModelItem item = o as ModelItem; if (item != null) { selection.Add(item); } } _selectedObjects = selection; } /// /// Creates a collection object comprising the given /// selected objects. The first object in the enumeration /// is considered the "primary" selection. /// /// An enumeration of objects that should be selected. /// If provided, only those objects in selectedObjects that match the predicate will be added to the selection. ///If selectedObjects is null. public Selection(IEnumerable selectedObjects, Predicatematch) { if (selectedObjects == null) throw FxTrace.Exception.ArgumentNull("selectedObjects"); if (match == null) throw FxTrace.Exception.ArgumentNull("match"); List selection = new List (); foreach (object o in selectedObjects) { ModelItem item = o as ModelItem; if (item != null && match(item)) { selection.Add(item); } } _selectedObjects = selection; } /// /// Creates a collection object comprising the given /// objects. The first object is considered the "primary" /// selection. /// /// A parameter array of objects that should be selected. ///If selectedObjects is null. public Selection(params ModelItem[] selectedObjects) : this((IEnumerable)selectedObjects) { } /// /// The primary selection. Some functions require a "key" /// element. For example, an "align lefts" command needs /// to know which element's "left" to align to. /// public ModelItem PrimarySelection { get { foreach (ModelItem obj in _selectedObjects) { return obj; } return null; } } ////// The enumeration of selected objects. /// public IEnumerableSelectedObjects { get { return _selectedObjects; } } /// /// The number of objects that are currently selected into /// this selection. /// public int SelectionCount { get { return _selectedObjects.Count; } } ////// Override of ContextItem's ItemType /// property. The ItemType of Selection is /// always "typeof(Selection)". /// public sealed override Type ItemType { get { return typeof(Selection); } } ////// Selection helper method. This takes the existing selection in the /// context and selects an item into it. If the item is already in the /// selection the selection is preserved and the item is promoted /// to the primary selection. /// /// The editing context to apply this selection change to. /// The item to select. ///A Selection object that contains the new selection. ///If context or itemToSelect is null. public static Selection Select(EditingContext context, ModelItem itemToSelect) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (itemToSelect == null) throw FxTrace.Exception.ArgumentNull("itemToSelect"); Selection existing = context.Items.GetValue(); // short cut if we're already in the right state. if (existing.PrimarySelection == itemToSelect) { return existing; } Selection selection = null; foreach (ModelItem obj in existing.SelectedObjects) { if (obj == itemToSelect) { List list = new List (existing.SelectedObjects); list.Remove(itemToSelect); list.Insert(0, itemToSelect); selection = new Selection(list); } } if (selection == null) { selection = new Selection(itemToSelect); } context.Items.SetValue(selection); return selection; } /// /// Selection helper method. This sets itemToSelect into the selection. /// Any existing items are deselected. /// /// The editing context to apply this selection change to. /// The item to select. ///A Selection object that contains the new selection. ///If context or itemToSelect is null. public static Selection SelectOnly(EditingContext context, ModelItem itemToSelect) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (itemToSelect == null) throw FxTrace.Exception.ArgumentNull("itemToSelect"); // Check to see if only this object is selected. If so, bail. Selection existing = context.Items.GetValue(); if (existing.PrimarySelection == itemToSelect) { IEnumerator en = existing.SelectedObjects.GetEnumerator(); en.MoveNext(); if (!en.MoveNext()) { return existing; } } Selection selection = new Selection(itemToSelect); context.Items.SetValue(selection); return selection; } /// /// Helper method that subscribes to selection change events. /// /// The editing context to listen to. /// The handler to be invoked when the selection changes. public static void Subscribe(EditingContext context, SubscribeContextCallbackhandler) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (handler == null) throw FxTrace.Exception.ArgumentNull("handler"); context.Items.Subscribe (handler); } /// /// Selection helper method. This takes the existing selection in the /// context and creates a new selection that contains the toggled /// state of the item. If the item is to be /// added to the selection, it is added as the primary selection. /// /// The editing context to apply this selection change to. /// The item to toggle selection for. ///A Selection object that contains the new selection. ///If context or itemToToggle is null. public static Selection Toggle(EditingContext context, ModelItem itemToToggle) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (itemToToggle == null) throw FxTrace.Exception.ArgumentNull("itemToToggle"); Selection existing = context.Items.GetValue(); // Is the item already in the selection? If so, remove it. // If not, add it to the beginning. List list = new List (existing.SelectedObjects); if (list.Contains(itemToToggle)) { list.Remove(itemToToggle); } else { list.Insert(0, itemToToggle); } Selection selection = new Selection(list); context.Items.SetValue(selection); return selection; } /// /// Selection helper method. This takes the existing selection in the /// context and creates a new selection that contains the original /// selection and the itemToAdd. If itemToAdd is already in the /// original selection it is promoted to the primary selection. /// /// The editing context to apply this selection change to. /// The item to add to the selection. ///A Selection object that contains the new selection. ///If context or itemToAdd is null. public static Selection Union(EditingContext context, ModelItem itemToAdd) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (itemToAdd == null) throw FxTrace.Exception.ArgumentNull("itemToAdd"); Selection existing = context.Items.GetValue(); // short cut if we're already in the right state. if (existing.PrimarySelection == itemToAdd) { return existing; } // Is the item already in the selection? If not, add it. List list = new List (existing.SelectedObjects); if (list.Contains(itemToAdd)) { list.Remove(itemToAdd); } list.Insert(0, itemToAdd); Selection selection = new Selection(list); context.Items.SetValue(selection); return selection; } /// /// Helper method that removes a previously added selection change event. /// /// The editing context to listen to. /// The handler to be invoked when the selection changes. public static void Unsubscribe(EditingContext context, SubscribeContextCallbackhandler) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (handler == null) throw FxTrace.Exception.ArgumentNull("handler"); context.Items.Unsubscribe (handler); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Activities.Presentation.View { using System.Runtime; using System.Diagnostics.CodeAnalysis; using System.Activities.Presentation; using System.Activities.Presentation.Model; using System.Activities.Presentation.Internal.Properties; using System; using System.Collections; using System.Collections.Generic; /// /// The Selection class defines a selection of objects. Selections /// consist of zero or more objects. The first object in a selection /// is defined as the "primary" selection, which is used when /// one object in a group must be used as a key. /// [SuppressMessage(FxCop.Category.Naming, "CA1724:TypeNamesShouldNotMatchNamespaces", Justification = "Code imported from Cider; keeping changes to a minimum as it impacts xaml files as well")] public class Selection : ContextItem { private ICollection_selectedObjects; /// /// Creates an empty Selection object. /// public Selection() { _selectedObjects = new ModelItem[0]; } ////// Creates a collection object comprising the given /// selected objects. The first object in the enumeration /// is considered the "primary" selection. /// /// An enumeration of objects that should be selected. ///If selectedObjects is null. public Selection(IEnumerableselectedObjects) { if (selectedObjects == null) { throw FxTrace.Exception.ArgumentNull("selectedObjects"); } List selection = new List (); selection.AddRange(selectedObjects); _selectedObjects = selection; } /// /// Creates a collection object comprising the given /// selected objects. The first object in the enumeration /// is considered the "primary" selection. /// /// An enumeration of objects that should be selected. /// If provided, only those objects in selectedObjects that match the predicate will be added to the selection. ///If selectedObjects or match is null. public Selection(IEnumerableselectedObjects, Predicate match) { if (selectedObjects == null) throw FxTrace.Exception.ArgumentNull("selectedObjects"); if (match == null) throw FxTrace.Exception.ArgumentNull("match"); List selection = new List (); foreach (ModelItem o in selectedObjects) { if (match(o)) { selection.Add(o); } } _selectedObjects = selection; } /// /// Creates a collection object comprising the given /// selected objects. The first object in the enumeration /// is considered the "primary" selection. /// /// An enumeration of objects that should be selected. ///If selectedObjects is null. public Selection(IEnumerable selectedObjects) { if (selectedObjects == null) throw FxTrace.Exception.ArgumentNull("selectedObjects"); Listselection = new List (); foreach (object o in selectedObjects) { ModelItem item = o as ModelItem; if (item != null) { selection.Add(item); } } _selectedObjects = selection; } /// /// Creates a collection object comprising the given /// selected objects. The first object in the enumeration /// is considered the "primary" selection. /// /// An enumeration of objects that should be selected. /// If provided, only those objects in selectedObjects that match the predicate will be added to the selection. ///If selectedObjects is null. public Selection(IEnumerable selectedObjects, Predicatematch) { if (selectedObjects == null) throw FxTrace.Exception.ArgumentNull("selectedObjects"); if (match == null) throw FxTrace.Exception.ArgumentNull("match"); List selection = new List (); foreach (object o in selectedObjects) { ModelItem item = o as ModelItem; if (item != null && match(item)) { selection.Add(item); } } _selectedObjects = selection; } /// /// Creates a collection object comprising the given /// objects. The first object is considered the "primary" /// selection. /// /// A parameter array of objects that should be selected. ///If selectedObjects is null. public Selection(params ModelItem[] selectedObjects) : this((IEnumerable)selectedObjects) { } /// /// The primary selection. Some functions require a "key" /// element. For example, an "align lefts" command needs /// to know which element's "left" to align to. /// public ModelItem PrimarySelection { get { foreach (ModelItem obj in _selectedObjects) { return obj; } return null; } } ////// The enumeration of selected objects. /// public IEnumerableSelectedObjects { get { return _selectedObjects; } } /// /// The number of objects that are currently selected into /// this selection. /// public int SelectionCount { get { return _selectedObjects.Count; } } ////// Override of ContextItem's ItemType /// property. The ItemType of Selection is /// always "typeof(Selection)". /// public sealed override Type ItemType { get { return typeof(Selection); } } ////// Selection helper method. This takes the existing selection in the /// context and selects an item into it. If the item is already in the /// selection the selection is preserved and the item is promoted /// to the primary selection. /// /// The editing context to apply this selection change to. /// The item to select. ///A Selection object that contains the new selection. ///If context or itemToSelect is null. public static Selection Select(EditingContext context, ModelItem itemToSelect) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (itemToSelect == null) throw FxTrace.Exception.ArgumentNull("itemToSelect"); Selection existing = context.Items.GetValue(); // short cut if we're already in the right state. if (existing.PrimarySelection == itemToSelect) { return existing; } Selection selection = null; foreach (ModelItem obj in existing.SelectedObjects) { if (obj == itemToSelect) { List list = new List (existing.SelectedObjects); list.Remove(itemToSelect); list.Insert(0, itemToSelect); selection = new Selection(list); } } if (selection == null) { selection = new Selection(itemToSelect); } context.Items.SetValue(selection); return selection; } /// /// Selection helper method. This sets itemToSelect into the selection. /// Any existing items are deselected. /// /// The editing context to apply this selection change to. /// The item to select. ///A Selection object that contains the new selection. ///If context or itemToSelect is null. public static Selection SelectOnly(EditingContext context, ModelItem itemToSelect) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (itemToSelect == null) throw FxTrace.Exception.ArgumentNull("itemToSelect"); // Check to see if only this object is selected. If so, bail. Selection existing = context.Items.GetValue(); if (existing.PrimarySelection == itemToSelect) { IEnumerator en = existing.SelectedObjects.GetEnumerator(); en.MoveNext(); if (!en.MoveNext()) { return existing; } } Selection selection = new Selection(itemToSelect); context.Items.SetValue(selection); return selection; } /// /// Helper method that subscribes to selection change events. /// /// The editing context to listen to. /// The handler to be invoked when the selection changes. public static void Subscribe(EditingContext context, SubscribeContextCallbackhandler) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (handler == null) throw FxTrace.Exception.ArgumentNull("handler"); context.Items.Subscribe (handler); } /// /// Selection helper method. This takes the existing selection in the /// context and creates a new selection that contains the toggled /// state of the item. If the item is to be /// added to the selection, it is added as the primary selection. /// /// The editing context to apply this selection change to. /// The item to toggle selection for. ///A Selection object that contains the new selection. ///If context or itemToToggle is null. public static Selection Toggle(EditingContext context, ModelItem itemToToggle) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (itemToToggle == null) throw FxTrace.Exception.ArgumentNull("itemToToggle"); Selection existing = context.Items.GetValue(); // Is the item already in the selection? If so, remove it. // If not, add it to the beginning. List list = new List (existing.SelectedObjects); if (list.Contains(itemToToggle)) { list.Remove(itemToToggle); } else { list.Insert(0, itemToToggle); } Selection selection = new Selection(list); context.Items.SetValue(selection); return selection; } /// /// Selection helper method. This takes the existing selection in the /// context and creates a new selection that contains the original /// selection and the itemToAdd. If itemToAdd is already in the /// original selection it is promoted to the primary selection. /// /// The editing context to apply this selection change to. /// The item to add to the selection. ///A Selection object that contains the new selection. ///If context or itemToAdd is null. public static Selection Union(EditingContext context, ModelItem itemToAdd) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (itemToAdd == null) throw FxTrace.Exception.ArgumentNull("itemToAdd"); Selection existing = context.Items.GetValue(); // short cut if we're already in the right state. if (existing.PrimarySelection == itemToAdd) { return existing; } // Is the item already in the selection? If not, add it. List list = new List (existing.SelectedObjects); if (list.Contains(itemToAdd)) { list.Remove(itemToAdd); } list.Insert(0, itemToAdd); Selection selection = new Selection(list); context.Items.SetValue(selection); return selection; } /// /// Helper method that removes a previously added selection change event. /// /// The editing context to listen to. /// The handler to be invoked when the selection changes. public static void Unsubscribe(EditingContext context, SubscribeContextCallbackhandler) { if (context == null) throw FxTrace.Exception.ArgumentNull("context"); if (handler == null) throw FxTrace.Exception.ArgumentNull("handler"); context.Items.Unsubscribe (handler); } } } // 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
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- PerformanceCountersBase.cs
- DbDataSourceEnumerator.cs
- UpdatePanelTriggerCollection.cs
- SignedXmlDebugLog.cs
- SoapSchemaExporter.cs
- Types.cs
- EntityDataSourceSelectingEventArgs.cs
- loginstatus.cs
- StreamUpdate.cs
- IxmlLineInfo.cs
- CodeGeneratorOptions.cs
- CompoundFileDeflateTransform.cs
- TableAutomationPeer.cs
- DrawingGroup.cs
- SourceSwitch.cs
- JoinSymbol.cs
- HostProtectionException.cs
- RequestedSignatureDialog.cs
- ClientSponsor.cs
- EncoderReplacementFallback.cs
- InsufficientExecutionStackException.cs
- Thread.cs
- PageMediaType.cs
- XmlSchemaDatatype.cs
- TdsParserSafeHandles.cs
- XmlDictionaryWriter.cs
- SchemaLookupTable.cs
- TransformerInfoCollection.cs
- ToolBar.cs
- InputProcessorProfiles.cs
- TableRowCollection.cs
- NegatedCellConstant.cs
- ConnectionPoint.cs
- WebBrowserSiteBase.cs
- DispatcherFrame.cs
- SqlHelper.cs
- RepeaterCommandEventArgs.cs
- assertwrapper.cs
- MDIClient.cs
- IxmlLineInfo.cs
- ValidationErrorCollection.cs
- BooleanAnimationBase.cs
- EditingMode.cs
- isolationinterop.cs
- FixedDSBuilder.cs
- DataBindingCollection.cs
- configsystem.cs
- MailAddress.cs
- securitycriticaldataformultiplegetandset.cs
- DataControlCommands.cs
- HebrewCalendar.cs
- DataGridColumn.cs
- ShaperBuffers.cs
- EntityDesignerUtils.cs
- ToolStripItemTextRenderEventArgs.cs
- DataList.cs
- XmlSiteMapProvider.cs
- Merger.cs
- ObjectListComponentEditor.cs
- DataGridViewColumnEventArgs.cs
- MSAAEventDispatcher.cs
- MatrixAnimationUsingPath.cs
- CheckableControlBaseAdapter.cs
- DigestComparer.cs
- ZoneMembershipCondition.cs
- XsltConvert.cs
- DbSetClause.cs
- DynamicILGenerator.cs
- SymbolTable.cs
- StdValidatorsAndConverters.cs
- StrongName.cs
- MatrixStack.cs
- ActiveXHost.cs
- CompositeControl.cs
- InProcStateClientManager.cs
- ColorPalette.cs
- TextTreeInsertUndoUnit.cs
- IIS7WorkerRequest.cs
- DragStartedEventArgs.cs
- AppDomainGrammarProxy.cs
- DataGridViewCellContextMenuStripNeededEventArgs.cs
- TextClipboardData.cs
- SvcMapFileSerializer.cs
- metadatamappinghashervisitor.cs
- FastEncoderWindow.cs
- Int32KeyFrameCollection.cs
- DescendantQuery.cs
- HttpStreamXmlDictionaryReader.cs
- CellRelation.cs
- DeploymentSection.cs
- MbpInfo.cs
- TablePattern.cs
- ImageUrlEditor.cs
- ImageField.cs
- FlowDocumentScrollViewer.cs
- TraceEventCache.cs
- SequenceNumber.cs
- OrderedDictionary.cs
- EntityStoreSchemaGenerator.cs