/// <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); }
//public _TimelineControl(ITimelineDocument timelineDocument) : base(timelineDocument) //{ //} //public _TimelineControl(ITimelineDocument timelineDocument, D2dTimelineRenderer timelineRenderer) : base(timelineDocument, timelineRenderer) //{ //} //public _TimelineControl(ITimelineDocument timelineDocument, D2dTimelineRenderer timelineRenderer, Sce.Atf.Controls.Timelines.TimelineConstraints timelineConstraints) : base(timelineDocument, timelineRenderer, timelineConstraints) //{ //} public _TimelineControl(ITimelineDocument timelineDocument, D2dTimelineRenderer timelineRenderer, Sce.Atf.Controls.Timelines.TimelineConstraints timelineConstraints, bool createDefaultManipulators) : base(timelineDocument, timelineRenderer, timelineConstraints, createDefaultManipulators) { }