Esempio n. 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();
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public static TriggerBaseNode CreateTrigger(TriggerSourceInformation triggerSource, SceneViewModel viewModel)
        {
            RoutedEventInformation eventInformation    = triggerSource as RoutedEventInformation;
            PropertyInformation    propertyInformation = triggerSource as PropertyInformation;

            if ((TriggerSourceInformation)eventInformation != (TriggerSourceInformation)null)
            {
                EventTriggerNode eventTriggerNode = EventTriggerNode.Factory.Instantiate(viewModel);
                eventTriggerNode.RoutedEvent = eventInformation.RoutedEvent;
                return((TriggerBaseNode)eventTriggerNode);
            }
            if (!((TriggerSourceInformation)propertyInformation != (TriggerSourceInformation)null))
            {
                return((TriggerBaseNode)null);
            }
            TriggerNode        triggerNode        = (TriggerNode)null;
            DependencyProperty dependencyProperty = propertyInformation.DependencyProperty;

            if (dependencyProperty != null)
            {
                triggerNode = TriggerNode.Factory.Instantiate(viewModel);
                ITriggerConditionNode triggerConditionNode = (ITriggerConditionNode)triggerNode;
                triggerConditionNode.PropertyKey = dependencyProperty;
                triggerConditionNode.Value       = dependencyProperty.DefaultMetadata.DefaultValue;
            }
            return((TriggerBaseNode)triggerNode);
        }
Esempio n. 5
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();
            }
        }