예제 #1
0
        public void CreateNewEventTrigger()
        {
            if (this.CurrentContainer == null)
            {
                return;
            }
            SceneViewModel    activeSceneViewModel = this.ActiveSceneViewModel;
            SceneDocument     document             = activeSceneViewModel.Document;
            ITriggerContainer currentContainer     = this.CurrentContainer;

            using (SceneEditTransaction editTransaction = document.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
            {
                IProjectContext projectContext = document.ProjectContext;
                IType           type           = projectContext.GetType(currentContainer.TargetElementType);
                if (type != null)
                {
                    TriggerSourceInformation triggerSource = (TriggerSourceInformation)TriggersHelper.GetDefaultEvent((ITypeResolver)projectContext, type);
                    if (triggerSource != (TriggerSourceInformation)null)
                    {
                        TriggerBaseNode trigger = TriggersHelper.CreateTrigger(triggerSource, activeSceneViewModel);
                        if (trigger != null)
                        {
                            int index = currentContainer.VisualTriggers.Count;
                            if (this.selectedItem != null)
                            {
                                index = this.selectedItem != this.noneTrigger ? currentContainer.VisualTriggers.IndexOf(this.selectedItem.SceneNode) + 1 : 0;
                            }
                            currentContainer.VisualTriggers.Insert(index, trigger);
                            this.TriggerToBeSelected = trigger;
                        }
                    }
                }
                editTransaction.Commit();
            }
        }
예제 #2
0
        public static void CreateDefaultTrigger(StoryboardTimelineSceneNode storyboard)
        {
            ITriggerContainer triggerContainer = (ITriggerContainer)storyboard.StoryboardContainer ?? storyboard.ViewModel.RootNode as ITriggerContainer;

            if (triggerContainer == null || !triggerContainer.CanEditTriggers)
            {
                return;
            }
            SceneViewModel  viewModel      = storyboard.ViewModel;
            IProjectContext projectContext = viewModel.ProjectContext;
            IType           type           = projectContext.GetType(triggerContainer.TargetElementType);

            if (type == null)
            {
                return;
            }
            TriggerSourceInformation triggerSource = (TriggerSourceInformation)TriggersHelper.GetDefaultEvent((ITypeResolver)projectContext, type);

            if (!(triggerSource != (TriggerSourceInformation)null))
            {
                return;
            }
            TriggerBaseNode orCreateTrigger = TriggersHelper.FindOrCreateTrigger(triggerSource, triggerContainer, viewModel);

            if (orCreateTrigger == null)
            {
                return;
            }
            TimelineActionNode timelineActionNode = (TimelineActionNode)BeginActionNode.Factory.Instantiate(viewModel);

            timelineActionNode.TargetTimeline = storyboard;
            TriggersHelper.DefaultAddAction(orCreateTrigger, (TriggerActionNode)timelineActionNode);
        }
예제 #3
0
        public static TriggerBaseNode FindOrCreateTrigger(TriggerSourceInformation triggerSource, ITriggerContainer triggerContainer, SceneViewModel viewModel)
        {
            RoutedEventInformation eventInformation    = triggerSource as RoutedEventInformation;
            PropertyInformation    propertyInformation = triggerSource as PropertyInformation;

            foreach (TriggerBaseNode triggerBaseNode in (IEnumerable <TriggerBaseNode>)triggerContainer.VisualTriggers)
            {
                EventTriggerNode eventTriggerNode = triggerBaseNode as EventTriggerNode;
                TriggerNode      triggerNode      = triggerBaseNode as TriggerNode;
                if (eventTriggerNode != null && (TriggerSourceInformation)eventInformation != (TriggerSourceInformation)null && eventTriggerNode.RoutedEvent == eventInformation.RoutedEvent)
                {
                    return((TriggerBaseNode)eventTriggerNode);
                }
                if (triggerNode != null && (TriggerSourceInformation)propertyInformation != (TriggerSourceInformation)null && ((ITriggerConditionNode)triggerNode).PropertyKey == propertyInformation.DependencyProperty)
                {
                    return((TriggerBaseNode)triggerNode);
                }
            }
            TriggerBaseNode trigger = TriggersHelper.CreateTrigger(triggerSource, viewModel);

            if (trigger != null)
            {
                triggerContainer.VisualTriggers.Add(trigger);
            }
            return(trigger);
        }
예제 #4
0
        public static TriggerNode ConvertToTrigger(MultiTriggerNode multiTrigger)
        {
            TriggerNode triggerNode = TriggerNode.Factory.Instantiate(multiTrigger.ViewModel);

            if (multiTrigger.Conditions.Count > 0)
            {
                ConditionNode conditionNode = multiTrigger.Conditions[0];
                ((ITriggerConditionNode)triggerNode).Value       = conditionNode.Value;
                ((ITriggerConditionNode)triggerNode).PropertyKey = conditionNode.PropertyKey;
                if (conditionNode.SourceName != null)
                {
                    ((ITriggerConditionNode)triggerNode).SourceName = conditionNode.SourceName;
                }
            }
            List <SceneNode> list1 = new List <SceneNode>((IEnumerable <SceneNode>)multiTrigger.Setters);

            while (multiTrigger.Setters.Count > 0)
            {
                multiTrigger.Setters.RemoveAt(0);
            }
            List <TriggerActionNode> list2 = new List <TriggerActionNode>((IEnumerable <TriggerActionNode>)multiTrigger.EnterActions);

            while (multiTrigger.EnterActions.Count > 0)
            {
                multiTrigger.EnterActions.RemoveAt(0);
            }
            List <TriggerActionNode> list3 = new List <TriggerActionNode>((IEnumerable <TriggerActionNode>)multiTrigger.ExitActions);

            while (multiTrigger.ExitActions.Count > 0)
            {
                multiTrigger.ExitActions.RemoveAt(0);
            }
            TriggersHelper.ReplaceSceneNode((SceneNode)multiTrigger, (SceneNode)triggerNode);
            foreach (SceneNode sceneNode in list1)
            {
                triggerNode.Setters.Add(sceneNode);
            }
            foreach (TriggerActionNode triggerActionNode in list2)
            {
                triggerNode.EnterActions.Add(triggerActionNode);
            }
            foreach (TriggerActionNode triggerActionNode in list3)
            {
                triggerNode.ExitActions.Add(triggerActionNode);
            }
            SceneViewModel viewModel = multiTrigger.ViewModel;

            if (viewModel.ActiveVisualTrigger == multiTrigger)
            {
                viewModel.SetActiveTrigger((TriggerBaseNode)triggerNode);
            }
            return(triggerNode);
        }
예제 #5
0
        private void EnsureProperActions(TriggerBaseNode trigger, StoryboardTimelineSceneNode storyboard)
        {
            if (!TriggersHelper.NeedsBeginAction(storyboard))
            {
                return;
            }
            TimelineActionNode timelineActionNode = (TimelineActionNode)BeginActionNode.Factory.Instantiate(storyboard.ViewModel);

            timelineActionNode.TargetTimeline = storyboard;
            TriggersHelper.DefaultAddAction(trigger, (TriggerActionNode)timelineActionNode);
            storyboard.UpdateActionNames();
        }
예제 #6
0
        private void CreateExitAction()
        {
            TriggerActionNode defaultAction = TriggersHelper.CreateDefaultAction(this.SceneNode.ViewModel, TriggersHelper.GetDefaultStoryboardName(this.SceneNode));

            if (defaultAction == null)
            {
                return;
            }
            using (SceneEditTransaction editTransaction = this.SceneNode.ViewModel.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
            {
                this.SceneNode.ExitActions.Add(defaultAction);
                editTransaction.Commit();
            }
        }
예제 #7
0
        public static ConditionNode CreateDefaultCondition(Type targetType, SceneViewModel viewModel, IDocumentContext documentContext)
        {
            PropertyInformation.GetPropertiesForType(targetType, documentContext.TypeResolver).GetEnumerator();
            PropertyInformation defaultProperty = TriggersHelper.GetDefaultProperty(targetType, documentContext);

            if (!((TriggerSourceInformation)defaultProperty != (TriggerSourceInformation)null))
            {
                return((ConditionNode)null);
            }
            ConditionNode conditionNode = ConditionNode.Factory.Instantiate(viewModel);

            conditionNode.PropertyKey = defaultProperty.DependencyProperty;
            conditionNode.Value       = defaultProperty.DependencyProperty.DefaultMetadata.DefaultValue;
            return(conditionNode);
        }
예제 #8
0
        private void OperationsView_CurrentChanged(object sender, EventArgs e)
        {
            TimelineOperation timelineOperation = (TimelineOperation)this.operationsView.CurrentItem;

            if (timelineOperation == this.TimelineAction.TimelineOperation)
            {
                return;
            }
            using (SceneEditTransaction editTransaction = this.SceneNode.ViewModel.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
            {
                TimelineActionNode actionForOperation = TimelineActionNode.CreateActionForOperation(timelineOperation, this.SceneNode.ViewModel);
                actionForOperation.TargetTimeline = this.TimelineAction.TargetTimeline;
                TriggersHelper.ReplaceSceneNode((SceneNode)this.TimelineAction, (SceneNode)actionForOperation);
                actionForOperation.TargetTimeline.UpdateActionNames();
                this.EnsureProperActions(actionForOperation.FindSceneNodeTypeAncestor <TriggerBaseNode>(), actionForOperation.TargetTimeline);
                editTransaction.Commit();
            }
        }
예제 #9
0
        public void Delete()
        {
            ConditionNode conditionNode = this.Condition as ConditionNode;

            if (conditionNode == null)
            {
                return;
            }
            using (SceneEditTransaction editTransaction = conditionNode.ViewModel.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
            {
                MultiTriggerNode nodeTypeAncestor = conditionNode.FindSceneNodeTypeAncestor <MultiTriggerNode>();
                conditionNode.Remove();
                if (nodeTypeAncestor != null && nodeTypeAncestor.Conditions.Count == 1)
                {
                    TriggersHelper.ConvertToTrigger(nodeTypeAncestor);
                }
                editTransaction.Commit();
            }
        }
예제 #10
0
 protected virtual void Delete()
 {
     if (!this.SceneNode.IsAttached)
     {
         return;
     }
     if (!TriggersHelper.CanDeleteTrigger(this.SceneNode))
     {
         this.SceneNode.ViewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.TriggerDeleteBeginAction);
     }
     else
     {
         using (SceneEditTransaction editTransaction = this.SceneNode.ViewModel.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
         {
             this.SceneNode.Remove();
             editTransaction.Commit();
         }
     }
 }
예제 #11
0
 protected override void Delete()
 {
     if (!this.SceneNode.IsAttached)
     {
         return;
     }
     if (!TriggersHelper.CanDeleteAction(this.TimelineAction))
     {
         this.SceneNode.ViewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.TriggerDeleteBeginAction);
     }
     else
     {
         using (SceneEditTransaction editTransaction = this.SceneNode.ViewModel.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
         {
             StoryboardTimelineSceneNode targetTimeline = this.TimelineAction.TargetTimeline;
             this.SceneNode.Remove();
             targetTimeline.UpdateActionNames();
             editTransaction.Commit();
         }
     }
 }
예제 #12
0
        public void CreateNewPropertyTrigger()
        {
            if (this.CurrentContainer == null)
            {
                return;
            }
            ITriggerContainer        currentContainer         = this.CurrentContainer;
            SceneViewModel           activeSceneViewModel     = this.ActiveSceneViewModel;
            SceneDocument            document                 = activeSceneViewModel.Document;
            StyleNode                styleNode                = currentContainer as StyleNode;
            FrameworkTemplateElement frameworkTemplateElement = currentContainer as FrameworkTemplateElement;

            using (SceneEditTransaction editTransaction = document.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
            {
                TriggerSourceInformation triggerSource = (TriggerSourceInformation)null;
                if (styleNode != null || frameworkTemplateElement != null)
                {
                    triggerSource = (TriggerSourceInformation)TriggersHelper.GetDefaultProperty(currentContainer.TargetElementType, document.DocumentContext);
                }
                if (triggerSource != (TriggerSourceInformation)null)
                {
                    TriggerBaseNode trigger = TriggersHelper.CreateTrigger(triggerSource, activeSceneViewModel);
                    if (trigger != null)
                    {
                        int index = currentContainer.VisualTriggers.Count;
                        if (this.selectedItem != null)
                        {
                            index = this.selectedItem != this.noneTrigger ? currentContainer.VisualTriggers.IndexOf(this.selectedItem.SceneNode) + 1 : 0;
                        }
                        currentContainer.VisualTriggers.Insert(index, trigger);
                        activeSceneViewModel.SetActiveTrigger(trigger);
                    }
                }
                editTransaction.Commit();
            }
        }
예제 #13
0
        private void AddCondition()
        {
            ConditionNode defaultCondition = TriggersHelper.CreateDefaultCondition(this.baseTriggerNode.TriggerContainer.TargetElementType, this.baseTriggerNode.ViewModel, this.baseTriggerNode.DocumentContext);

            if (defaultCondition == null)
            {
                return;
            }
            using (SceneEditTransaction editTransaction = this.baseTriggerNode.ViewModel.CreateEditTransaction(StringTable.TriggerChangeUndoUnit))
            {
                MultiTriggerNode multiTriggerNode1 = this.baseTriggerNode as MultiTriggerNode;
                if (multiTriggerNode1 != null)
                {
                    multiTriggerNode1.Conditions.Add(defaultCondition);
                }
                else
                {
                    MultiTriggerNode multiTriggerNode2 = TriggersHelper.ConvertToMultiTrigger((Microsoft.Expression.DesignSurface.ViewModel.TriggerNode) this.baseTriggerNode);
                    multiTriggerNode2.Conditions.Add(defaultCondition);
                    this.triggerManager.TriggerToBeSelected = (TriggerBaseNode)multiTriggerNode2;
                }
                editTransaction.Commit();
            }
        }