Example #1
0
//
/// Returns a pointer to the TDocument object if the specified document
/// is currently opened and manager by the DocManager. Returns 0 otherwise.
//
TDocument*
TDocManager::FindDocument(LPCTSTR path)
{
  TDocument* doc = 0;
  while ((doc = DocList.Next(doc)) != 0)
    if (path) {
      if (doc->GetDocPath() && _tcscmp(doc->GetDocPath(), path) == 0)
        break;
    }
    else {
      if (doc->GetDocPath() == 0)
        break;
    }
  return doc;
}
Example #2
0
//
/// Displays FileSave dialog prompting the user to select a file name for savinng the document.
/// Filters out read-only files.
//
bool
TDocManager::SelectSave(TDocument& doc)
{
  TDocTemplate* tpl = doc.GetTemplate();

  if (!tpl || !tpl->GetFileFilter())
    return false;

  tchar filepath[_MAX_PATH];
  if (doc.GetDocPath())
    ::_tcscpy(filepath, doc.GetDocPath());
  else
    filepath[0] = 0;    // no initial file path

  int index = SelectDocPath(&tpl, 1, filepath, COUNTOF(filepath), 0, true, &doc);
  return index ? doc.SetDocPath(filepath) : false;
}
Example #3
0
void
TDocManager::FileRevert()
{
  TDocument* doc = GetCurrentDoc();
  if (doc && doc->GetDocPath()) {
    if (!doc->IsDirty()) {
      PostDocError(*doc, IDS_NOTCHANGED);
      return;
    }
    doc->Revert();
  }
}
Example #4
0
void
TDocManager::FileSave()
{
  TDocument* doc = GetCurrentDoc();
  if (doc) {
    if (!doc->GetDocPath()) {
      CmFileSaveAs();
      return;
    }
    if (!(Mode & dmSaveEnable) && !doc->IsDirty()) {
      PostDocError(*doc, IDS_NOTCHANGED);
      return;
    }
    doc->Commit();  // No force of write here since is just to same file
  }
}
Example #5
0
//
/// Method invoked when specified document is about to be closed.
/// Updates the document with any changes and prompts the user for confirmation of
/// updates.
/// Returns 'true' if DocManager should proceed with the closing
/// stages of the document, or 'false' otherwise.
//
bool
TDocManager::FlushDoc(TDocument& doc)
{
  while (doc.IsDirty()) {
    int saveOrNot = doc.IsEmbedded() ?
                      IDYES :
                      PostDocError(doc, IDS_DOCCHANGED, MB_YESNOCANCEL);

    switch (saveOrNot) {
      case IDYES:
        // Prompt the user for filename in save-as situation
        //
        if (!doc.IsEmbedded() && doc.GetDocPath() == 0) {

        // !BB
        // !BB It does not make sense to invoke SelectAnySave
        // !BB with false here... This would allow the user
        // !BB to switch to any available template when saving the
        // !BB document. In other words, a user would be allowed to
        // !BB save a .TXT file as a .PTS file although they are
        // !BB not related whatsoever...
        // !BB
        // !BB I'm switching this to use true - let me know if you
        // !BB know of a reason for the prior behaviour.
        // !BB

#if defined(OLD_DOCVIEW)
          TDocTemplate* tpl = SelectAnySave(doc, false);
#else
          TDocTemplate* tpl = SelectAnySave(doc, true);
#endif
          if (!tpl)
            continue;

          // !BB
          // !BB The following is suspicious: Is there a reason
          // !BB to allow the user to switch the template in the first
          // !BB place?? OK, if everyone agrees that same TDocument-derived
          // !BB type implies compatible document, that would be OK.
          // !BB However, that's not what we've encouraged. Our own
          // !BB examples use the same TFileDocument for incompatible
          // !BB document types. Hence, if an app. has a
          // !BB TBitmapView/TFileDocument and a TTextView/TFileDocument pair,
          // !BB the following would allow the user to save a text file as a .BMP
          // !BB Ack!!
          // !BB If the following is really the intent, then DV users must be
          // !BB conscious that they will more often than not be using TFileDocument-
          // !BB derived documents as a method to specify compatible and incompatible
          // !BB document types.
          //
          if (tpl != doc.Template)
            doc.SetTemplate(tpl);
        }
        if (doc.Commit())
          return true;
        continue;

      case IDNO:
        if (doc.Revert(true))
          return true;
        return false;

      case IDCANCEL:
        return false;
    }
  }
  return true;
}
Example #6
0
//
/// Command enabler for CmFileRevert.
//
void
TDocManager::CeFileRevert(TCommandEnabler& ce)
{
  TDocument* doc = GetCurrentDoc();
  ce.Enable(doc && doc->IsDirty() && doc->GetDocPath());
}