/// <summary> /// Requests permission to close the client's Control.</summary> /// <param name="control">Client control to be closed</param> /// <returns>True if the control can close, or false to cancel</returns> bool IControlHostClient.Close(Control control) { bool closed = true; SceneDocument document = control.Tag as SceneDocument; if (document != null) { SceneEditingContext context = document.As <SceneEditingContext>(); if (context != null) { m_controlHostService.UnregisterControl(context.TreeEditor.TreeControl); } closed = m_documentService.Close(document); if (closed) { //m_currentEditContext = null; m_propertyEditor.PropertyGrid.Bind(null); m_contextRegistry.RemoveContext(document); } } return(closed); }
/// <summary> /// Does the command</summary> /// <param name="commandTag">Command to be done</param> void ICommandClient.DoCommand(object commandTag) { if (ECommand.eExportScene.Equals(commandTag)) { SceneDocument sceneDoc = m_documentRegistry.ActiveDocument as SceneDocument; _ExportScene(sceneDoc); } }
void _ExportScene(SceneDocument sceneDoc) { string sceneString = _ExportScene(sceneDoc.DomNode); string dstURI = sceneDoc.Uri.AbsolutePath; dstURI = dstURI.Replace(".src", ""); dstURI = dstURI.Replace(".source_scene", ".scene"); File.WriteAllText(dstURI, sceneString); }
/// <summary> /// Saves the document at the given URI</summary> /// <param name="document">Document to save</param> /// <param name="uri">New document URI</param> public void Save(IDocument document, Uri uri) { SceneDocument doc = document as SceneDocument; string filePath = uri.LocalPath; FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate; using (FileStream stream = new FileStream(filePath, fileMode)) { DomXmlWriter writer = new DomXmlWriter(m_schemaLoader.TypeCollection); writer.Write(doc.DomNode, stream, uri); } }
/// <summary> /// Activates the client control</summary> /// <param name="control">Client control to be activated</param> void IControlHostClient.Activate(Control control) { SceneDocument document = control.Tag as SceneDocument; if (document != null) { m_documentRegistry.ActiveDocument = document; SceneEditingContext context = document.As <SceneEditingContext>(); m_contextRegistry.ActiveContext = context; //context.TreeEditor.TreeControl.Focus(); } }
/// <summary> /// Opens or creates a document at the given URI</summary> /// <param name="uri">Document URI</param> /// <returns>Document, or null if the document couldn't be opened or created</returns> public IDocument Open(Uri uri) { DomNode node = null; string filePath = uri.LocalPath; string fileName = Path.GetFileName(filePath); 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(m_schemaLoader); node = reader.Read(stream, uri); } } else { // create new document by creating a Dom node of the root type defined by the schema node = SceneEditingContext._CreateSceneRoot("Scene"); } SceneDocument document = null; if (node != null) { // Initialize Dom extensions now that the data is complete; after this, all Dom node // adapters will have been bound to their underlying Dom node. node.InitializeExtensions(); SceneEditingContext context = node.As <SceneEditingContext>(); ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center); controlInfo.IsDocument = true; context.ControlInfo = controlInfo; document = node.As <SceneDocument>(); document.Uri = uri; context.PropertyEditor = m_propertyEditor; context.ContextRegistry = m_contextRegistry; context.Initialize(m_commandService); context.TreeEditor.TreeControl.Tag = document; context.Root = node; m_controlHostService.RegisterControl(context.TreeEditor.TreeControl, context.ControlInfo, this); } return(document); }
/// <summary> /// Checks whether the client can do the command, if it handles it</summary> /// <param name="commandTag">Command to be done</param> /// <returns>True iff client can do the command</returns> bool ICommandClient.CanDoCommand(object commandTag) { if (ECommand.eExportScene.Equals(commandTag)) { SceneDocument sceneDoc = m_documentRegistry.ActiveDocument as SceneDocument; return(sceneDoc != null); } else if (ECommand.eExportLevel.Equals(commandTag)) { bool result = false; foreach (IDocument doc in m_documentRegistry.Documents) { SceneDocument sceneDoc = doc as SceneDocument; if (sceneDoc != null) { result = true; break; } } return(result); } return(false); }