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)
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
// manager: gives document a chance to initialise and (usually) create a
// view

View File

@@ -740,8 +740,7 @@ public:
/**
Called when the filename has changed. The default implementation
constructs a suitable title and sets the title of the view frame (if
any).
constructs a suitable title and sets the title of the view frame (if any).
*/
virtual void OnChangeFilename();
@@ -1296,11 +1295,19 @@ public:
/**
Sets the filename for this document. Usually called by the framework.
If @a notifyViews is @true, wxView::OnChangeFilename() is called for
all views.
Calls OnChangeFilename() which in turn calls wxView::OnChangeFilename() for
all views if @a notifyViews is @true,
*/
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
associated frame (if any), and is usually constructed by the framework

View File

@@ -310,7 +310,7 @@ bool wxDocument::SaveAs()
if (defaultDir.IsEmpty())
defaultDir = wxPathOnly(GetFilename());
wxString tmp = wxFileSelector(_("Save As"),
wxString fileName = wxFileSelector(_("Save As"),
defaultDir,
wxFileNameFromPath(GetFilename()),
docTemplate->GetDefaultExtension(),
@@ -318,12 +318,11 @@ bool wxDocument::SaveAs()
wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
GetDocumentWindow());
if (tmp.empty())
if (fileName.empty())
return false;
wxString fileName(tmp);
wxString path, name, ext;
wxFileName::SplitPath(fileName, & path, & name, & ext);
wxString ext;
wxFileName::SplitPath(fileName, NULL, NULL, &ext);
if (ext.empty())
{
@@ -331,22 +330,13 @@ bool wxDocument::SaveAs()
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.
if (!OnSaveDocument(m_documentFile))
if (!OnSaveDocument(fileName))
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
// via the FileHistory, so we do not add it.
if (docTemplate->FileMatchesTemplate(fileName))
@@ -485,8 +475,8 @@ bool wxDocument::OnSaveModified()
GetUserReadableName()
),
wxTheApp->GetAppDisplayName(),
wxYES_NO | wxCANCEL | wxICON_QUESTION,
GetDocumentWindow()
wxYES_NO | wxCANCEL | wxICON_QUESTION | wxCENTRE,
wxFindSuitableParent()
) )
{
case wxNO:
@@ -566,6 +556,11 @@ void wxDocument::NotifyClosing()
void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
{
m_documentFile = filename;
OnChangeFilename(notifyViews);
}
void wxDocument::OnChangeFilename(bool notifyViews)
{
if ( notifyViews )
{
// Notify the views that the filename has changed
@@ -1509,7 +1504,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
else
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);
path = wxEmptyString;
@@ -1531,7 +1526,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates,
// can only happen if the application changes the allowed templates in runtime.
(void)wxMessageBox(_("Sorry, the format for this file is unknown."),
_("Open File"),
wxOK | wxICON_EXCLAMATION, wxFindSuitableParent());
wxOK | wxICON_EXCLAMATION | wxCENTRE, wxFindSuitableParent());
}
}
else