Exemple #1
0
        private void UpdateControlInfo()
        {
            TimelineContext context = this.As <TimelineContext>();
            string          filePath;

            if (Uri.IsAbsoluteUri)
            {
                filePath = Uri.LocalPath;
            }
            else
            {
                filePath = Uri.OriginalString;
            }

            string fileName = Path.GetFileName(filePath);

            if (Dirty)
            {
                fileName += "*";
            }

            context.ControlInfo.Name        = fileName;
            context.ControlInfo.Description = filePath;
        }
Exemple #2
0
        private bool DoCommand(object commandTag, bool doing)
        {
            TimelineContext context = m_contextRegistry.GetActiveContext <TimelineContext>();

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

            document = context.As <TimelineDocument>();
            if (document == null)
            {
                return(false);
            }

            if (commandTag is Command)
            {
                if (Do_Media_Command(commandTag, doing) == true)
                {
                    return(true);
                }
                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);
        }
        /// <summary>
        /// Loads the document at the given URI. Creates a D2dTimelineRenderer and D2dTimelineControl
        /// (through TimelineDocument's Renderer property) to render and display timelines.
        /// If isMasterDocument is true and if the file doesn't exist, a new document is created.</summary>
        /// <param name="uri">URI of document to load</param>
        /// <param name="isMasterDocument">True iff is master document</param>
        /// <returns>TimelineDocument loaded</returns>
        private TimelineDocument LoadOrCreateDocument(Uri uri, bool isMasterDocument)
        {
            // Documents need to have a absolute Uri, so that the relative references to sub-documents
            //  are not ambiguous, and so that the FileWatcherService can be used.
            string filePath;

            if (uri.IsAbsoluteUri)
            {
                filePath = uri.LocalPath;
            }
            else if (!isMasterDocument)
            {
                filePath = PathUtil.GetAbsolutePath(uri.OriginalString,
                                                    Path.GetDirectoryName(s_repository.ActiveDocument.Uri.LocalPath));
                uri = new Uri(filePath, UriKind.Absolute);
            }
            else
            {
                filePath = PathUtil.GetAbsolutePath(uri.OriginalString, Directory.GetCurrentDirectory());
                uri      = new Uri(filePath, UriKind.Absolute);
            }

            // Check if the repository contains this Uri. Remember that document Uris have to be absolute.
            bool             isNewToThisEditor = true;
            DomNode          node     = null;
            TimelineDocument document = (TimelineDocument)s_repository.GetDocument(uri);

            if (document != null)
            {
                node = document.DomNode;
                isNewToThisEditor = false;
            }
            else if (File.Exists(filePath))
            {
                // read existing document using standard XML reader
                using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    DomXmlReader reader = new DomXmlReader(s_schemaLoader);
                    node = reader.Read(stream, uri);
                }
            }
            else if (isMasterDocument)
            {
                // create new document by creating a Dom node of the root type defined by the schema
                node = new DomNode(Schema.timelineType.Type, Schema.timelineRootElement);
            }

            if (node != null)
            {
                if (document == null)
                {
                    document = node.Cast <TimelineDocument>();

                    D2dTimelineRenderer renderer = CreateTimelineRenderer();
                    document.Renderer = renderer;
                    renderer.Init(document.TimelineControl.D2dGraphics);

                    string      fileName    = Path.GetFileName(filePath);
                    ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center);

                    //Set IsDocument to true to prevent exception in command service if two files with the
                    //  same name, but in different directories, are opened.
                    controlInfo.IsDocument = true;

                    TimelineContext timelineContext = document.Cast <TimelineContext>();
                    timelineContext.ControlInfo = controlInfo;

                    document.Uri = uri;

                    if (isMasterDocument)
                    {
                        s_repository.ActiveDocument = document;//adds 'document'
                    }
                    else
                    {
                        // For sub-documents, we want ActiveDocument to remain the main document so that
                        //  TimelineValidator can identify if a sub-document or master document is being
                        //  modified.
                        IDocument previous = s_repository.ActiveDocument;
                        s_repository.ActiveDocument = document; //adds 'document'
                        s_repository.ActiveDocument = previous; //restores master document
                    }
                }

                IHierarchicalTimeline hierarchical = document.Timeline as IHierarchicalTimeline;
                if (hierarchical != null)
                {
                    ResolveAll(hierarchical, new HashSet <IHierarchicalTimeline>());
                }

                // Listen to events if this is the first time we've seen this.
                if (isNewToThisEditor)
                {
                    // The master document/context needs to listen to events on any sub-document
                    //  so that transactions can be cancelled correctly.
                    if (isMasterDocument)
                    {
                        node.AttributeChanging += DomNode_AttributeChanging;
                    }
                    else
                    {
                        DomNode masterNode = s_repository.ActiveDocument.As <DomNode>();
                        node.SubscribeToEvents(masterNode);
                    }
                }

                // Initialize Dom extensions now that the data is complete
                node.InitializeExtensions();
            }

            return(document);
        }