private void OnSourceStateClicked(object sender, RoutedEventArgs e) { ModelItem sourceState = StateContainerEditor.GetParentStateModelItemForTransition(this.ModelItem); if (sourceState != null) { this.Designer.MakeRootDesigner(sourceState); } }
internal int DeleteConnectorModelItem(Connector connector, bool rerouting = false) { ModelItem connectorModelItem = StateContainerEditor.GetConnectorModelItem(connector); if (!rerouting) { if (connector is ConnectorWithStartDot) { connector.StartDot.MouseDown -= new MouseButtonEventHandler(OnConnectorStartDotMouseDown); connector.StartDot.MouseUp -= new MouseButtonEventHandler(OnConnectorStartDotMouseUp); } connector.GotKeyboardFocus -= new KeyboardFocusChangedEventHandler(OnConnectorGotKeyboardFocus); connector.RequestBringIntoView -= new RequestBringIntoViewEventHandler(OnConnectorRequestBringIntoView); connector.GotFocus -= new RoutedEventHandler(OnConnectorGotFocus); connector.MouseDoubleClick -= new MouseButtonEventHandler(OnConnectorMouseDoubleClick); connector.MouseDown -= new MouseButtonEventHandler(OnConnectorMouseDown); connector.KeyDown -= new KeyEventHandler(OnConnectorKeyDown); connector.ContextMenuOpening -= new ContextMenuEventHandler(OnConnectorContextMenuOpening); connector.Unloaded -= new RoutedEventHandler(OnConnectorUnloaded); } int removedIndex = InvalidIndex; if (connectorModelItem.ItemType == typeof(Transition)) { ModelItemCollection transitions = StateContainerEditor.GetParentStateModelItemForTransition(connectorModelItem).Properties[StateDesigner.TransitionsPropertyName].Collection; removedIndex = transitions.IndexOf(connectorModelItem); Fx.Assert(removedIndex >= 0, "can't find the connector ModelItem in collection"); transitions.Remove(connectorModelItem); } // Connector from initial node else if (connectorModelItem.ItemType == typeof(StateMachine)) { using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(SR.ClearInitialState)) { connectorModelItem.Properties[StateMachineDesigner.InitialStatePropertyName].SetValue(null); if (!rerouting) { this.ViewStateService.StoreViewStateWithUndo(connectorModelItem, ConnectorLocationViewStateKey, null); } es.Complete(); } } return(removedIndex); }
public TransitionDesigner() { InitializeComponent(); this.TransitionsSharingTrigger = new ObservableCollection <ExpandableItemWrapper>(); this.Loaded += (sender, e) => { if (!this.isPopulated) { this.isPopulated = true; this.TransitionsSharingTrigger.CollectionChanged += OnTransitionsCollectionChanged; this.ModelItem.PropertyChanged += OnModelItemPropertyChanged; this.parentStateModelItem = StateContainerEditor.GetParentStateModelItemForTransition(this.ModelItem); this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.CollectionChanged += OnTransitionsModelItemCollectionChanged; ExpandableItemWrapper selectedItem = this.UpdateTransitionsSharingTrigger(); if (null != selectedItem) { this.SelectedTransition = selectedItem; } } }; this.Unloaded += (sender, e) => { if (this.isPopulated) { this.isPopulated = false; this.TransitionsSharingTrigger.Clear(); this.TransitionsSharingTrigger.CollectionChanged -= OnTransitionsCollectionChanged; this.ModelItem.PropertyChanged -= OnModelItemPropertyChanged; this.parentStateModelItem.Properties[StateDesigner.TransitionsPropertyName].Collection.CollectionChanged -= OnTransitionsModelItemCollectionChanged; this.SelectedTransition = null; this.parentStateModelItem = null; } }; }
void DoDeleteItems(List <ModelItem> itemsToDelete, bool removeIncomingConnectors) { itemsToDelete.Remove(this.initialModelItem); if (itemsToDelete.Count == 1 && itemsToDelete.First().ItemType == typeof(Transition)) { this.DeleteConnectorModelItem(this.selectedConnector); return; } itemsToDelete.RemoveAll(item => item.ItemType == typeof(Transition)); HashSet <Connector> connectorsToDelete = new HashSet <Connector>(); List <ModelItem> allStateModelItemsToDelete = new List <ModelItem>(); IEnumerable <ModelItem> selectedStateModelItems = this.Context.Items.GetValue <Selection>().SelectedObjects .Where <ModelItem>((p) => { return(p.ItemType == typeof(State)); }); foreach (ModelItem stateModelItem in itemsToDelete) { allStateModelItemsToDelete.Add(stateModelItem); } foreach (ModelItem modelItem in allStateModelItemsToDelete) { // We only need to delete incoming connectors to the states to be deleted; outgoing connectors will be deleted // automatically when the containing state is deleted. List <Connector> incomingConnectors = StateContainerEditor.GetIncomingConnectors(GetStateView(modelItem)); foreach (Connector connector in incomingConnectors) { ModelItem transitionModelItem = StateContainerEditor.GetConnectorModelItem(connector); // If the transition is contained by the states to delete, we don't bother to delete it separately. if (!StateContainerEditor.IsTransitionModelItemContainedByStateModelItems(transitionModelItem, selectedStateModelItems)) { connectorsToDelete.Add(connector); } } } // If we don't need to remove incoming connectors, we still remove the transitions but then add them back later. // This is in order to create an undo unit that contains the change notifications needed to make undo/redo work correctly. foreach (Connector connector in connectorsToDelete) { ModelItem connectorModelItem = StateContainerEditor.GetConnectorModelItem(connector); if (removeIncomingConnectors || connectorModelItem.ItemType == typeof(Transition)) { this.DeleteConnectorModelItem(connector); } } if (!removeIncomingConnectors) { foreach (Connector connector in connectorsToDelete) { ModelItem connectorModelItem = StateContainerEditor.GetConnectorModelItem(connector); if (connectorModelItem.ItemType == typeof(Transition)) { StateContainerEditor.GetParentStateModelItemForTransition(connectorModelItem).Properties[StateDesigner.TransitionsPropertyName].Collection.Add(connectorModelItem); } } } if (null != itemsToDelete) { itemsToDelete.ForEach(p => this.DeleteState(p, removeIncomingConnectors)); } }