// /// Checks to see if all child documents can be closed before closing the current /// document. If any child returns false, CanClose returns false and aborts the /// process. If all children return true, calls TDocManager::FlushDoc. If FlushDoc /// finds that the document has been changed but not saved, it displays a message /// asking the user to either save the document, discard any changes, or cancel the /// operation. If the document has not been changed and all children's CanClose /// functions return true, this CanClose function returns true. // bool TDocument::CanClose() { TDocument* pdoc = 0; while ((pdoc = ChildDoc.Next(pdoc)) != 0) if (!pdoc->CanClose()) return false; return DocManager->FlushDoc(*this); // do the UI in the doc manager }
// /// Checks to see if all child documents can be closed before closing the current /// document. If any child returns false, returns false and aborts the process. If /// all children return true, EvCanClose calls TDocManager::FlushDoc for each /// document. If FlushDoc finds that the document is dirty, it displays a message /// asking the user to save the document, discard any changes, or cancel the /// operation. If the document is not dirty and CanClose returns true, EvCanClose /// returns true. // bool TDocManager::EvCanClose() { TDocument* doc = 0; while ((doc = DocList.Next(doc)) != 0) { if (!doc->CanClose()) // normally calls back to FlushDoc() return false; } return true; }
// /// If the document can be closed it is closed. // void TDocManager::FileClose() { TDocument* doc = GetCurrentDoc(); if (doc && doc->CanClose()) { // normally calls back to FlushDoc() if (!doc->Close()) PostDocError(*doc, IDS_UNABLECLOSE); else delete doc; } WARNX(OwlDocView, !doc, 0, _T("FileClose invoked with no current doc")); }
void TDocument::Streamer::Write(opstream& os) const { TDocument* o = GetObject(); while (!o->CanClose()) // can't permit cancel here ; os << o->OpenMode; _USES_CONVERSION; os.fwriteString(_W2A(o->DocPath)); os.fwriteString(_W2A(o->Title)); os << o->Template; // templates already streamed, must be so if static os << o->ParentDoc; os << o->ViewList; // each view streams out the next os << TView::NextViewId; // insure that this static var gets set on reload }
// /// Overrideable method invoked just before the DocumentManager creates a new /// document. The default behaviour is to close and delete the current /// document if we're in SDI mode. // bool TDocManager::CreatingDoc(TDocTemplate* /*tpl*/) { if (Mode & dmSDI) { TDocument* doc = DocList.Next(0); if (doc) { if (!doc->CanClose()) return false; if (!doc->Close()) { PostDocError(*doc, IDS_UNABLECLOSE); return false; } delete doc; } } return true; }