#if wxUSE_STD_IOSTREAM
#include "wx/ioswrap.h"
+ #include "wx/beforestd.h"
#if wxUSE_IOSTREAMH
#include <fstream.h>
#else
#include <fstream>
#endif
+ #include "wx/afterstd.h"
#else
#include "wx/wfstream.h"
#endif
// local functions
// ----------------------------------------------------------------------------
-static wxString FindExtension(const wxChar *path)
+static wxString FindExtension(const wxString& path)
{
wxString ext;
wxSplitPath(path, NULL, NULL, &ext);
Modify(false);
SetDocumentSaved(false);
- wxString name;
- GetDocumentManager()->MakeDefaultName(name);
+ const wxString name = GetDocumentManager()->MakeNewDocumentName();
SetTitle(name);
SetFilename(name, true);
#else
wxString filter = docTemplate->GetFileFilter() ;
#endif
- wxString tmp = wxFileSelector(_("Save as"),
- docTemplate->GetDirectory(),
+ wxString defaultDir = docTemplate->GetDirectory();
+ if (defaultDir.IsEmpty())
+ defaultDir = wxPathOnly(GetFilename());
+
+ wxString tmp = wxFileSelector(_("Save As"),
+ defaultDir,
wxFileNameFromPath(GetFilename()),
docTemplate->GetDefaultExtension(),
filter,
// Get title, or filename if no title, else unnamed
+#if WXWIN_COMPATIBILITY_2_8
bool wxDocument::GetPrintableName(wxString& buf) const
{
- if (!m_documentTitle.empty())
- {
- buf = m_documentTitle;
- return true;
- }
- else if (!m_documentFile.empty())
- {
- buf = wxFileNameFromPath(m_documentFile);
- return true;
- }
- else
- {
- buf = _("unnamed");
- return true;
- }
+ // this function can not only be overridden by the user code but also
+ // called by it so we need to ensure that we return the same thing as
+ // GetUserReadableName() but we can't call it because this would result in
+ // an infinite recursion, hence we use the helper DoGetUserReadableName()
+ buf = DoGetUserReadableName();
+
+ return true;
+}
+#endif // WXWIN_COMPATIBILITY_2_8
+
+wxString wxDocument::GetUserReadableName() const
+{
+#if WXWIN_COMPATIBILITY_2_8
+ // we need to call the old virtual function to ensure that the overridden
+ // version of it is still called
+ wxString name;
+ if ( GetPrintableName(name) )
+ return name;
+#endif // WXWIN_COMPATIBILITY_2_8
+
+ return DoGetUserReadableName();
+}
+
+wxString wxDocument::DoGetUserReadableName() const
+{
+ if ( !m_documentTitle.empty() )
+ return m_documentTitle;
+
+ if ( !m_documentFile.empty() )
+ return wxFileNameFromPath(m_documentFile);
+
+ return _("unnamed");
}
wxWindow *wxDocument::GetDocumentWindow() const
{
if (IsModified())
{
- wxString title;
- GetPrintableName(title);
+ wxString title = GetUserReadableName();
wxString msgTitle;
- if (!wxTheApp->GetAppName().empty())
- msgTitle = wxTheApp->GetAppName();
+ if (!wxTheApp->GetAppDisplayName().empty())
+ msgTitle = wxTheApp->GetAppDisplayName();
else
msgTitle = wxString(_("Warning"));
wxString prompt;
- prompt.Printf(_("Do you want to save changes to document %s?"),
- (const wxChar *)title);
+ prompt.Printf(_("Do you want to save changes to document %s?"), title);
int res = wxMessageBox(prompt, msgTitle,
wxYES_NO|wxCANCEL|wxICON_QUESTION,
GetDocumentWindow());
bool wxDocument::DoSaveDocument(const wxString& file)
{
wxString msgTitle;
- if (!wxTheApp->GetAppName().empty())
- msgTitle = wxTheApp->GetAppName();
+ if (!wxTheApp->GetAppDisplayName().empty())
+ msgTitle = wxTheApp->GetAppDisplayName();
else
msgTitle = wxString(_("File error"));
wxDocument *doc = GetDocument();
if (!doc) return;
- wxString name;
- doc->GetPrintableName(name);
- win->SetLabel(name);
+ win->SetLabel(doc->GetUserReadableName());
}
void wxView::SetDocument(wxDocument *doc)
return (wxDocument *) NULL;
}
-// Make a default document name
-bool wxDocManager::MakeDefaultName(wxString& name)
+// Make a default name for a new document
+#if WXWIN_COMPATIBILITY_2_8
+bool wxDocManager::MakeDefaultName(wxString& WXUNUSED(name))
+{
+ // we consider that this function can only be overridden by the user code,
+ // not called by it as it only makes sense to call it internally, so we
+ // don't bother to return anything from here
+ return false;
+}
+#endif // WXWIN_COMPATIBILITY_2_8
+
+wxString wxDocManager::MakeNewDocumentName()
{
- name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter);
- m_defaultDocumentNameCounter++;
+ wxString name;
- return true;
+#if WXWIN_COMPATIBILITY_2_8
+ if ( !MakeDefaultName(name) )
+#endif // WXWIN_COMPATIBILITY_2_8
+ {
+ name.Printf(_("unnamed%d"), m_defaultDocumentNameCounter);
+ m_defaultDocumentNameCounter++;
+ }
+
+ return name;
}
// Make a frame title (override this to do something different)
// If docName is empty, a document is not currently active.
wxString wxDocManager::MakeFrameTitle(wxDocument* doc)
{
- wxString appName = wxTheApp->GetAppName();
+ wxString appName = wxTheApp->GetAppDisplayName();
wxString title;
if (!doc)
title = appName;
else
{
- wxString docName;
- doc->GetPrintableName(docName);
+ wxString docName = doc->GetUserReadableName();
title = docName + wxString(_(" - ")) + appName;
}
return title;
wxWindow* parent = wxFindSuitableParent();
- wxString pathTmp = wxFileSelectorEx(_("Select a file"),
+ wxString pathTmp = wxFileSelectorEx(_("Open File"),
m_lastDirectory,
wxEmptyString,
&FilterIndex,
if (!wxFileExists(pathTmp))
{
wxString msgTitle;
- if (!wxTheApp->GetAppName().empty())
- msgTitle = wxTheApp->GetAppName();
+ if (!wxTheApp->GetAppDisplayName().empty())
+ msgTitle = wxTheApp->GetAppDisplayName();
else
msgTitle = wxString(_("File error"));
wxCHECK_RET( i < m_fileHistory.GetCount(),
wxT("invalid index in wxFileHistory::RemoveFileFromHistory") );
- // delete the element from the array
+ // delete the element from the array
m_fileHistory.RemoveAt(i);
wxList::compatibility_iterator node = m_fileMenus.GetFirst();
buf.Printf(wxT("file%d"), 1);
wxString historyFile;
- while ((m_fileHistory.GetCount() < m_fileMaxFiles) &&
+ while ((m_fileHistory.GetCount() < m_fileMaxFiles) &&
config.Read(buf, &historyFile) && !historyFile.empty())
{
m_fileHistory.Add(historyFile);
return false;
char buf[4096];
- do
+ for ( ;; )
{
stream.Read(buf, WXSIZEOF(buf));
const size_t nRead = stream.LastRead();
- if ( !nRead || !file.Write(buf, nRead) )
+ if ( !nRead )
+ {
+ if ( stream.Eof() )
+ break;
+
+ return false;
+ }
+
+ if ( !file.Write(buf, nRead) )
return false;
}
- while ( !stream.Eof() );
return true;
}