Implemented delayed closing of an existing document
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20408 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -373,6 +373,9 @@ public:
|
|||||||
// closes all currently open documents
|
// closes all currently open documents
|
||||||
bool CloseDocuments(bool force = TRUE);
|
bool CloseDocuments(bool force = TRUE);
|
||||||
|
|
||||||
|
// closes the specified document
|
||||||
|
bool CloseDocument(wxDocument* doc, bool force = FALSE);
|
||||||
|
|
||||||
// Clear remaining documents and templates
|
// Clear remaining documents and templates
|
||||||
bool Clear(bool force = TRUE);
|
bool Clear(bool force = TRUE);
|
||||||
|
|
||||||
|
@@ -774,6 +774,24 @@ wxDocManager::~wxDocManager()
|
|||||||
sm_docManager = (wxDocManager*) NULL;
|
sm_docManager = (wxDocManager*) NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// closes the specified document
|
||||||
|
bool wxDocManager::CloseDocument(wxDocument* doc, bool force)
|
||||||
|
{
|
||||||
|
if (doc->Close() || force)
|
||||||
|
{
|
||||||
|
// Implicitly deletes the document when
|
||||||
|
// the last view is deleted
|
||||||
|
doc->DeleteAllViews();
|
||||||
|
|
||||||
|
// Check we're really deleted
|
||||||
|
if (m_docs.Member(doc))
|
||||||
|
delete doc;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
bool wxDocManager::CloseDocuments(bool force)
|
bool wxDocManager::CloseDocuments(bool force)
|
||||||
{
|
{
|
||||||
wxNode *node = m_docs.GetFirst();
|
wxNode *node = m_docs.GetFirst();
|
||||||
@@ -781,18 +799,10 @@ bool wxDocManager::CloseDocuments(bool force)
|
|||||||
{
|
{
|
||||||
wxDocument *doc = (wxDocument *)node->GetData();
|
wxDocument *doc = (wxDocument *)node->GetData();
|
||||||
wxNode *next = node->GetNext();
|
wxNode *next = node->GetNext();
|
||||||
|
|
||||||
if (!doc->Close() && !force)
|
if (!CloseDocument(doc, force))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// Implicitly deletes the document when the last
|
|
||||||
// view is removed (deleted)
|
|
||||||
doc->DeleteAllViews();
|
|
||||||
|
|
||||||
// Check document is deleted
|
|
||||||
if (m_docs.Member(doc))
|
|
||||||
delete doc;
|
|
||||||
|
|
||||||
// This assumes that documents are not connected in
|
// This assumes that documents are not connected in
|
||||||
// any way, i.e. deleting one document does NOT
|
// any way, i.e. deleting one document does NOT
|
||||||
// delete another.
|
// delete another.
|
||||||
@@ -1070,27 +1080,15 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
|
|||||||
delete[] templates;
|
delete[] templates;
|
||||||
return (wxDocument *) NULL;
|
return (wxDocument *) NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxDocument* docToClose = NULL;
|
||||||
|
|
||||||
// If we've reached the max number of docs, close the
|
// If we've reached the max number of docs, close the
|
||||||
// first one.
|
// first one.
|
||||||
if ( (int)GetDocuments().GetCount() >= m_maxDocsOpen )
|
if ( (int)GetDocuments().GetCount() >= m_maxDocsOpen )
|
||||||
{
|
{
|
||||||
wxDocument *doc = (wxDocument *)GetDocuments().GetFirst()->GetData();
|
wxDocument *doc = (wxDocument *)GetDocuments().GetFirst()->GetData();
|
||||||
if (doc->Close())
|
docToClose = doc;
|
||||||
{
|
|
||||||
// Implicitly deletes the document when
|
|
||||||
// the last view is deleted
|
|
||||||
doc->DeleteAllViews();
|
|
||||||
|
|
||||||
// Check we're really deleted
|
|
||||||
if (m_docs.Member(doc))
|
|
||||||
delete doc;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete[] templates;
|
|
||||||
return (wxDocument *) NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New document: user chooses a template, unless there's only one.
|
// New document: user chooses a template, unless there's only one.
|
||||||
@@ -1098,9 +1096,18 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
|
|||||||
{
|
{
|
||||||
if (n == 1)
|
if (n == 1)
|
||||||
{
|
{
|
||||||
|
if (docToClose)
|
||||||
|
{
|
||||||
|
if (!CloseDocument(docToClose, FALSE))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wxDocTemplate *temp = templates[0];
|
wxDocTemplate *temp = templates[0];
|
||||||
delete[] templates;
|
delete[] templates;
|
||||||
wxDocument *newDoc = temp->CreateDocument(path, flags);
|
wxDocument *newDoc = temp->CreateDocument(path, flags);
|
||||||
|
|
||||||
if (newDoc)
|
if (newDoc)
|
||||||
{
|
{
|
||||||
newDoc->SetDocumentName(temp->GetDocumentName());
|
newDoc->SetDocumentName(temp->GetDocumentName());
|
||||||
@@ -1114,7 +1121,16 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
|
|||||||
delete[] templates;
|
delete[] templates;
|
||||||
if (temp)
|
if (temp)
|
||||||
{
|
{
|
||||||
|
if (docToClose)
|
||||||
|
{
|
||||||
|
if (!CloseDocument(docToClose, FALSE))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wxDocument *newDoc = temp->CreateDocument(path, flags);
|
wxDocument *newDoc = temp->CreateDocument(path, flags);
|
||||||
|
|
||||||
if (newDoc)
|
if (newDoc)
|
||||||
{
|
{
|
||||||
newDoc->SetDocumentName(temp->GetDocumentName());
|
newDoc->SetDocumentName(temp->GetDocumentName());
|
||||||
@@ -1143,6 +1159,14 @@ wxDocument *wxDocManager::CreateDocument(const wxString& path, long flags)
|
|||||||
|
|
||||||
if (temp)
|
if (temp)
|
||||||
{
|
{
|
||||||
|
if (docToClose)
|
||||||
|
{
|
||||||
|
if (!CloseDocument(docToClose, FALSE))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wxDocument *newDoc = temp->CreateDocument(path2, flags);
|
wxDocument *newDoc = temp->CreateDocument(path2, flags);
|
||||||
if (newDoc)
|
if (newDoc)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user