public void Save(Uri uri, SchemaLoader schemaLoader) { if (Dirty || m_uriChanged) { string filePath = uri.LocalPath; FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate; using (FileStream stream = new FileStream(filePath, fileMode)) { var writer = new CustomDomXmlWriter(Globals.ResourceRoot, schemaLoader.TypeCollection); writer.Write(DomNode, stream, uri); } m_uriChanged = false; } // save all the game-references foreach (var gameRef in GetChildList <GameReference>(Schema.gameType.gameReferenceChild)) { GameDocument subDoc = Adapters.As <GameDocument>(gameRef.Target); if (subDoc == null) { continue; } subDoc.Save(subDoc.Uri, schemaLoader); } Dirty = false; }
public virtual void Save(Uri uri, ISchemaLoader schemaLoader) { LevelEditorXLE.Patches.SelectNameForReferencedDocuments(this); if (Dirty || m_uriChanged) { SaveDomDocument(DomNode, uri, schemaLoader); m_uriChanged = false; } // save all the game-references foreach (var gameRef in GetChildList <GameReference>(Schema.gameType.gameReferenceChild)) { GameDocument subDoc = Adapters.As <GameDocument>(gameRef.Target); if (subDoc == null) { continue; } subDoc.Save(subDoc.Uri, schemaLoader); } LevelEditorXLE.Patches.SaveReferencedDocuments(this, schemaLoader); Dirty = false; }
public void Save(IDocument document, Uri uri) { GameDocument gameDocument = document as GameDocument; gameDocument.Save(uri, m_schemaLoader); // save external resources. foreach (var obj in Util.FindAll <IEditableResourceOwner>()) { if (obj.Dirty) { obj.Save(); } } m_projLister.Refresh(); }
void ICommandClient.DoCommand(object commandTag) { IGame game = TreeControlAdapter.LastHit.As <IGame>(); if (game == null) { GameReference gameRef = TreeControlAdapter.LastHit.As <GameReference>(); game = gameRef.Target; } IDocument gameDocument = game.As <IDocument>(); string filePath = null; switch ((Command)commandTag) { case Command.CreateNewSubGame: filePath = Util.GetFilePath(m_fileFilter, System.IO.Path.GetDirectoryName(gameDocument.Uri.LocalPath), true); if (!string.IsNullOrEmpty(filePath)) { try { if (!m_gameEditor.Info.IsCompatiblePath(filePath)) { throw new Exception("Incompatible file type " + filePath); } Uri ur = new Uri(filePath); if (m_gameDocumentRegistry.FindDocument(ur) != null) { throw new Exception(filePath + " is already open"); } GameDocument subGame = GameDocument.OpenOrCreate(ur, m_schemaLoader); subGame.Dirty = true; GameReference gameRef = GameReference.CreateNew(subGame); IHierarchical parent = game.As <IHierarchical>(); parent.AddChild(gameRef); // because we performing this operation outside of TransactionContext // we must set Document Dirty flag. gameDocument.Dirty = true; } catch (Exception ex) { MessageBox.Show(m_mainWindow.DialogOwner, ex.Message); } } break; case Command.AddSubGame: filePath = Util.GetFilePath(m_fileFilter, System.IO.Path.GetDirectoryName(gameDocument.Uri.LocalPath), false); if (!string.IsNullOrEmpty(filePath)) { try { if (!m_gameEditor.Info.IsCompatiblePath(filePath)) { throw new Exception("Incompatible file type " + filePath); } Uri ur = new Uri(filePath); if (m_gameDocumentRegistry.FindDocument(ur) != null) { throw new Exception(filePath + " is already open"); } GameReference gameRef = GameReference.CreateNew(ur); gameRef.Resolve(); IHierarchical parent = game.As <IHierarchical>(); parent.AddChild(gameRef); // because we performing this operation outside of TransactionContext // we must set Document Dirty flag. gameDocument.Dirty = true; } catch (Exception ex) { MessageBox.Show(m_mainWindow.DialogOwner, ex.Message); } } break; case Command.Exclude: { GameReference gameRef = TreeControlAdapter.LastHit.As <GameReference>(); gameDocument = gameRef.DomNode.Parent.Cast <IDocument>(); GameDocument subDoc = gameRef.Target.Cast <GameDocument>(); bool exclue = true; bool save = false; if (subDoc.Dirty) { string msg = "Save changes\r\n" + subDoc.Uri.LocalPath; DialogResult dlgResult = MessageBox.Show(m_mainWindow.DialogOwner, msg, m_mainWindow.Text , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); save = dlgResult == DialogResult.Yes; exclue = dlgResult != DialogResult.Cancel; } if (save) { subDoc.Save(subDoc.Uri, m_schemaLoader); } if (exclue) { gameRef.DomNode.RemoveFromParent(); // because we performing this operation outside of TransactionContext // we must set Document Dirty flag. gameDocument.Dirty = true; } } break; case Command.Resolve: { GameReference gameRef = TreeControlAdapter.LastHit.As <GameReference>(); gameRef.Resolve(); TreeControlAdapter.Refresh(gameRef); } break; case Command.Unresolve: { try { GameReference gameRef = TreeControlAdapter.LastHit.As <GameReference>(); GameDocument subDoc = gameRef.Target.Cast <GameDocument>(); bool unresolve = true; bool save = false; if (subDoc.Dirty) { string msg = "Save changes\r\n" + subDoc.Uri.LocalPath; DialogResult dlgResult = MessageBox.Show(m_mainWindow.DialogOwner, msg, m_mainWindow.Text , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); save = dlgResult == DialogResult.Yes; unresolve = dlgResult != DialogResult.Cancel; } //cando = gameRef != null && gameRef.Target != null; if (save) { subDoc.Save(subDoc.Uri, m_schemaLoader); } if (unresolve) { gameRef.Unresolve(); } TreeControlAdapter.Refresh(gameRef); } catch (Exception ex) { MessageBox.Show(m_mainWindow.DialogOwner, ex.Message); } } break; default: throw new ArgumentOutOfRangeException("commandTag"); } m_designView.InvalidateViews(); Refresh(); }