Beispiel #1
0
        private bool DoCommand(object commandTag, bool doing)
        {
            TimelineContext context = m_contextRegistry.GetActiveContext <TimelineContext>();

            if (context == null)
            {
                return(false);
            }

            TimelineDocument document = context.As <TimelineDocument>();

            if (document == null)
            {
                return(false);
            }

            if (commandTag is Command)
            {
                if ((Command)commandTag == Command.ToggleSplitMode)
                {
                    if (doing && document.SplitManipulator != null)
                    {
                        document.SplitManipulator.Active = !document.SplitManipulator.Active;
                    }
                    return(true);
                }

                ITimelineObject target = m_contextRegistry.GetCommandTarget <ITimelineObject>();
                if (target == null)
                {
                    return(false);
                }

                IInterval activeInterval = target as IInterval;
                ITrack    activeTrack    =
                    (activeInterval != null) ? activeInterval.Track : target.As <ITrack>();
                IGroup activeGroup =
                    (activeTrack != null) ? activeTrack.Group : target.As <IGroup>();
                ITimeline activeTimeline =
                    (activeGroup != null) ? activeGroup.Timeline : target.As <ITimeline>();
                ITransactionContext transactionContext = context.TimelineControl.TransactionContext;

                switch ((Command)commandTag)
                {
                case Command.RemoveGroup:
                    if (activeGroup == null)
                    {
                        return(false);
                    }

                    if (doing)
                    {
                        transactionContext.DoTransaction(delegate
                        {
                            activeGroup.Timeline.Groups.Remove(activeGroup);
                        },
                                                         "Remove Group");
                    }
                    return(true);

                case Command.RemoveTrack:
                    if (activeTrack == null)
                    {
                        return(false);
                    }

                    if (doing)
                    {
                        transactionContext.DoTransaction(delegate
                        {
                            activeTrack.Group.Tracks.Remove(activeTrack);
                        },
                                                         "Remove Track");
                    }
                    return(true);

                case Command.RemoveEmptyGroupsAndTracks:
                    if (activeTimeline == null)
                    {
                        return(false);
                    }

                    if (doing)
                    {
                        transactionContext.DoTransaction(delegate
                        {
                            IList <IGroup> groups = activeTimeline.Groups;
                            for (int i = 0; i < groups.Count;)
                            {
                                IList <ITrack> tracks = groups[i].Tracks;
                                for (int j = 0; j < tracks.Count;)
                                {
                                    if (tracks[j].Intervals.Count == 0 && tracks[j].Keys.Count == 0)
                                    {
                                        tracks.RemoveAt(j);
                                    }
                                    else
                                    {
                                        j++;
                                    }
                                }

                                if (tracks.Count == 0)
                                {
                                    groups.RemoveAt(i);
                                }
                                else
                                {
                                    i++;
                                }
                            }
                        },
                                                         "Remove Empty Groups and Tracks");
                    }
                    return(true);
                }
            }
            else if (commandTag is StandardCommand)
            {
                switch ((StandardCommand)commandTag)
                {
                case StandardCommand.ViewZoomExtents:
                    if (doing)
                    {
                        document.TimelineControl.Frame();
                    }
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        private void Insert(ITimelineObject droppedItem, ITimelineObject dropTarget)
        {
            if (m_timelineDocument == null)
            {
                return;
            }

            // TimelineControl maintains target group and track
            ITimeline targetTimeline = m_timelineDocument.Timeline;
            IGroup    targetGroup    = m_timelineControl.TargetGroup != null ? (IGroup)m_timelineControl.TargetGroup.Last : null;
            ITrack    targetTrack    = m_timelineControl.TargetTrack != null ? (ITrack)m_timelineControl.TargetTrack.Last : null;

            // in case of drag and drop, use drop target instead
            if (dropTarget != null)
            {
                GetTrackAndGroup(dropTarget, out targetTrack, out targetGroup);
            }

            // Work up from insertion point to get target key/interval, track, group, timeline
            ITimelineReference reference = droppedItem.As <ITimelineReference>();

            if (reference != null)
            {
                ((Timeline)targetTimeline).AddReference(reference);
                return;
            }

            IGroup group = droppedItem.As <IGroup>();

            if (group != null)
            {
                // if this is a new group, add a default track
                if (group.Tracks.Count == 0)
                {
                    ITrack emptyTrack = group.CreateTrack();
                    if (emptyTrack != null)
                    {
                        group.Tracks.Add(emptyTrack);
                    }
                }

                targetTimeline.Groups.Add(group);
                return;
            }

            IMarker marker = droppedItem.As <IMarker>();

            if (marker != null)
            {
                targetTimeline.Markers.Add(marker);
                return;
            }

            // Must be track or interval; get the target group, or create one.
            ITrack track = droppedItem.As <ITrack>();
            IEvent ev    = droppedItem.As <IEvent>();

            if (track != null ||
                ev != null)
            {
                IList <IGroup> groups = targetTimeline.Groups;
                if (targetGroup == null)
                {
                    targetGroup = targetTimeline.CreateGroup();
                    groups.Add(targetGroup);
                }

                if (track != null)
                {
                    targetGroup.Tracks.Add(track);
                }
                else //if (ev != null)
                {
                    // interval or key; get the target track or create one
                    if (targetTrack == null)
                    {
                        targetTrack = targetGroup.CreateTrack();
                        targetGroup.Tracks.Add(targetTrack);
                    }

                    IInterval interval = droppedItem.As <IInterval>();
                    if (interval != null)
                    {
                        targetTrack.Intervals.Add(interval);
                    }
                    else
                    {
                        IKey key = droppedItem.As <IKey>();
                        if (key != null)
                        {
                            targetTrack.Keys.Add(key);
                        }
                    }
                }
            }
        }