msgTitle = wxString(_("File error"));
#if wxUSE_STD_IOSTREAM
- wxSTD ofstream store(file.mb_str());
+ wxSTD ofstream store(file.mb_str(), wxSTD ios::binary);
if (store.fail() || store.bad())
#else
wxFileOutputStream store(file);
bool wxDocument::DoOpenDocument(const wxString& file)
{
- wxString msgTitle;
- if (!wxTheApp->GetAppName().empty())
- msgTitle = wxTheApp->GetAppName();
- else
- msgTitle = wxString(_("File error"));
-
#if wxUSE_STD_IOSTREAM
- wxSTD ifstream store(file.mb_str());
- if (store.fail() || store.bad())
+ wxSTD ifstream store(file.mb_str(), wxSTD ios::binary);
+ if (!store.fail() && !store.bad())
#else
wxFileInputStream store(file);
- if (store.GetLastError() != wxSTREAM_NO_ERROR)
+ if (store.GetLastError() == wxSTREAM_NO_ERROR)
#endif
{
- (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION,
- GetDocumentWindow());
- return false;
- }
#if wxUSE_STD_IOSTREAM
- LoadObject(store);
- if ( !store && !store.eof() )
+ LoadObject(store);
+ if ( !!store || store.eof() )
#else
- int res = LoadObject(store).GetLastError();
- if ((res != wxSTREAM_NO_ERROR) &&
- (res != wxSTREAM_EOF))
+ int res = LoadObject(store).GetLastError();
+ if ( res == wxSTREAM_NO_ERROR || res == wxSTREAM_EOF )
#endif
- {
- (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION,
- GetDocumentWindow());
- return false;
+ return true;
}
- return true;
+ wxLogError(_("Sorry, could not open this file."));
+ return false;
}
{
newDoc->SetDocumentName(temp->GetDocumentName());
newDoc->SetDocumentTemplate(temp);
- newDoc->OnNewDocument();
+ if (!newDoc->OnNewDocument() )
+ {
+ // Document is implicitly deleted by DeleteAllViews
+ newDoc->DeleteAllViews();
+ return NULL;
+ }
}
return newDoc;
}
{
newDoc->SetDocumentName(temp->GetDocumentName());
newDoc->SetDocumentTemplate(temp);
- newDoc->OnNewDocument();
+ if (!newDoc->OnNewDocument() )
+ {
+ // Document is implicitly deleted by DeleteAllViews
+ newDoc->DeleteAllViews();
+ return NULL;
+ }
}
return newDoc;
}
}
}
+ //see if this file is already open
+ for (size_t i = 0; i < GetDocuments().GetCount(); ++i)
+ {
+ wxDocument* currentDoc = (wxDocument*)(GetDocuments().Item(i)->GetData());
+#ifdef __WXMSW__
+ //file paths are case-insensitive on Windows
+ if (path2.CmpNoCase(currentDoc->GetFilename()) == 0)
+#else
+ if (path2.Cmp(currentDoc->GetFilename()) == 0)
+#endif
+ {
+ //file already open. Just activate it and return
+ if (currentDoc->GetFirstView())
+ {
+ ActivateView(currentDoc->GetFirstView(), true);
+ if (currentDoc->GetDocumentWindow())
+ currentDoc->GetDocumentWindow()->SetFocus();
+ return currentDoc;
+ }
+ }
+ }
+
wxDocument *newDoc = temp->CreateDocument(path2, flags);
if (newDoc)
{
pathInMenu = m_fileHistory[i];
}
+ // we need to quote '&' characters which are used for mnemonics
+ pathInMenu.Replace(_T("&"), _T("&&"));
wxString buf;
buf.Printf(s_MRUEntryFormat, i + 1, pathInMenu.c_str());
wxList::compatibility_iterator node = m_fileMenus.GetFirst();