minor cleanup; add wxDocument::OnChangeFilename for coherence with wxView::OnChangefilename; avoid some (small) code duplication; closes #10080

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57950 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2009-01-09 16:13:49 +00:00
parent 828c8f98d5
commit 00e3ea1c6f
3 changed files with 32 additions and 26 deletions

View File

@@ -107,6 +107,10 @@ public:
// modified to false) // modified to false)
virtual bool OnSaveModified(); virtual bool OnSaveModified();
// if you override, remember to call the default
// implementation (wxDocument::OnChangeFilename)
virtual void OnChangeFilename(bool notifyViews);
// Called by framework if created automatically by the default document // Called by framework if created automatically by the default document
// manager: gives document a chance to initialise and (usually) create a // manager: gives document a chance to initialise and (usually) create a
// view // view

View File

@@ -740,8 +740,7 @@ public:
/** /**
Called when the filename has changed. The default implementation Called when the filename has changed. The default implementation
constructs a suitable title and sets the title of the view frame (if constructs a suitable title and sets the title of the view frame (if any).
any).
*/ */
virtual void OnChangeFilename(); virtual void OnChangeFilename();
@@ -1296,11 +1295,19 @@ public:
/** /**
Sets the filename for this document. Usually called by the framework. Sets the filename for this document. Usually called by the framework.
If @a notifyViews is @true, wxView::OnChangeFilename() is called for Calls OnChangeFilename() which in turn calls wxView::OnChangeFilename() for
all views. all views if @a notifyViews is @true,
*/ */
void SetFilename(const wxString& filename, bool notifyViews = false); void SetFilename(const wxString& filename, bool notifyViews = false);
/**
If @a notifyViews is @true, wxView::OnChangeFilename() is called for
all views.
@since 2.9.0
*/
virtual void OnChangeFilename(bool notifyViews);
/** /**
Sets the title for this document. The document title is used for an Sets the title for this document. The document title is used for an
associated frame (if any), and is usually constructed by the framework associated frame (if any), and is usually constructed by the framework

View File

@@ -310,7 +310,7 @@ bool wxDocument::SaveAs()
if (defaultDir.IsEmpty()) if (defaultDir.IsEmpty())
defaultDir = wxPathOnly(GetFilename()); defaultDir = wxPathOnly(GetFilename());
wxString tmp = wxFileSelector(_("Save As"), wxString fileName = wxFileSelector(_("Save As"),
defaultDir, defaultDir,
wxFileNameFromPath(GetFilename()), wxFileNameFromPath(GetFilename()),
docTemplate->GetDefaultExtension(), docTemplate->GetDefaultExtension(),
@@ -318,12 +318,11 @@ bool wxDocument::SaveAs()
wxFD_SAVE | wxFD_OVERWRITE_PROMPT, wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
GetDocumentWindow()); GetDocumentWindow());
if (tmp.empty()) if (fileName.empty())
return false; return false;
wxString fileName(tmp); wxString ext;
wxString path, name, ext; wxFileName::SplitPath(fileName, NULL, NULL, &ext);
wxFileName::SplitPath(fileName, & path, & name, & ext);
if (ext.empty()) if (ext.empty())
{ {
@@ -331,22 +330,13 @@ bool wxDocument::SaveAs()
fileName += docTemplate->GetDefaultExtension(); fileName += docTemplate->GetDefaultExtension();
} }
SetFilename(fileName);
SetTitle(wxFileNameFromPath(fileName));
// Notify the views that the filename has changed
wxList::compatibility_iterator node = m_documentViews.GetFirst();
while (node)
{
wxView *view = (wxView *)node->GetData();
view->OnChangeFilename();
node = node->GetNext();
}
// Files that were not saved correctly are not added to the FileHistory. // Files that were not saved correctly are not added to the FileHistory.
if (!OnSaveDocument(m_documentFile)) if (!OnSaveDocument(fileName))
return false; return false;
SetTitle(wxFileNameFromPath(fileName));
SetFilename(fileName, true); // will call OnChangeFileName automatically
// A file that doesn't use the default extension of its document template cannot be opened // A file that doesn't use the default extension of its document template cannot be opened
// via the FileHistory, so we do not add it. // via the FileHistory, so we do not add it.
if (docTemplate->FileMatchesTemplate(fileName)) if (docTemplate->FileMatchesTemplate(fileName))
@@ -485,8 +475,8 @@ bool wxDocument::OnSaveModified()
GetUserReadableName() GetUserReadableName()
), ),
wxTheApp->GetAppDisplayName(), wxTheApp->GetAppDisplayName(),
wxYES_NO | wxCANCEL | wxICON_QUESTION, wxYES_NO | wxCANCEL | wxICON_QUESTION | wxCENTRE,
GetDocumentWindow() wxFindSuitableParent()
) ) ) )
{ {
case wxNO: case wxNO:
@@ -566,6 +556,11 @@ void wxDocument::NotifyClosing()
void wxDocument::SetFilename(const wxString& filename, bool notifyViews) void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
{ {
m_documentFile = filename; m_documentFile = filename;
OnChangeFilename(notifyViews);
}
void wxDocument::OnChangeFilename(bool notifyViews)
{
if ( notifyViews ) if ( notifyViews )
{ {
// Notify the views that the filename has changed // Notify the views that the filename has changed
@@ -1509,7 +1504,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
else else
msgTitle = wxString(_("File error")); msgTitle = wxString(_("File error"));
(void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION, (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION | wxCENTRE,
parent); parent);
path = wxEmptyString; path = wxEmptyString;
@@ -1531,7 +1526,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
// can only happen if the application changes the allowed templates in runtime. // can only happen if the application changes the allowed templates in runtime.
(void)wxMessageBox(_("Sorry, the format for this file is unknown."), (void)wxMessageBox(_("Sorry, the format for this file is unknown."),
_("Open File"), _("Open File"),
wxOK | wxICON_EXCLAMATION, wxFindSuitableParent()); wxOK | wxICON_EXCLAMATION | wxCENTRE, wxFindSuitableParent());
} }
} }
else else