Add wxDocManager::FindDocumentByPath() helper.
Simply refactor the code which already existed inside wxDocManager in a new public method. Closes #15126. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73730 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -625,6 +625,7 @@ All (GUI):
|
|||||||
- Make wxGenericDataViewCtrl::SetFont() really work (Laurent Poujoulat).
|
- Make wxGenericDataViewCtrl::SetFont() really work (Laurent Poujoulat).
|
||||||
- Remove wxLogWindow::OnFrameCreate(), it was never called anyhow.
|
- Remove wxLogWindow::OnFrameCreate(), it was never called anyhow.
|
||||||
- Added wxDocument::Activate() (troelsk).
|
- Added wxDocument::Activate() (troelsk).
|
||||||
|
- Added wxDocManager::FindDocumentByPath() (troelsk).
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -446,6 +446,9 @@ public:
|
|||||||
// Find template from document class info, may return NULL.
|
// Find template from document class info, may return NULL.
|
||||||
wxDocTemplate* FindTemplate(const wxClassInfo* documentClassInfo);
|
wxDocTemplate* FindTemplate(const wxClassInfo* documentClassInfo);
|
||||||
|
|
||||||
|
// Find document from file name, may return NULL.
|
||||||
|
wxDocument* FindDocumentByPath(const wxString& path) const;
|
||||||
|
|
||||||
wxDocument *GetCurrentDocument() const;
|
wxDocument *GetCurrentDocument() const;
|
||||||
|
|
||||||
void SetMaxDocsOpen(int n) { m_maxDocsOpen = n; }
|
void SetMaxDocsOpen(int n) { m_maxDocsOpen = n; }
|
||||||
|
@@ -414,6 +414,19 @@ public:
|
|||||||
*/
|
*/
|
||||||
wxDocTemplate* FindTemplate(const wxClassInfo* classinfo);
|
wxDocTemplate* FindTemplate(const wxClassInfo* classinfo);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Search for the document corresponding to the given file.
|
||||||
|
|
||||||
|
@param path
|
||||||
|
Document file path.
|
||||||
|
@return
|
||||||
|
Pointer to a wxDocument, or @NULL if none found.
|
||||||
|
|
||||||
|
@since 2.9.5
|
||||||
|
*/
|
||||||
|
wxDocument* FindDocumentByPath(const wxString& path) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Closes the specified document.
|
Closes the specified document.
|
||||||
|
|
||||||
|
@@ -1418,6 +1418,19 @@ void wxDocument::Activate()
|
|||||||
win->Raise();
|
win->Raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxDocument* wxDocManager::FindDocumentByPath(const wxString& path) const
|
||||||
|
{
|
||||||
|
const wxFileName fileName(path);
|
||||||
|
for ( wxList::const_iterator i = m_docs.begin(); i != m_docs.end(); ++i )
|
||||||
|
{
|
||||||
|
wxDocument * const doc = wxStaticCast(*i, wxDocument);
|
||||||
|
|
||||||
|
if ( fileName == wxFileName(doc->GetFilename()) )
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags)
|
wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags)
|
||||||
{
|
{
|
||||||
// this ought to be const but SelectDocumentType/Path() are not
|
// this ought to be const but SelectDocumentType/Path() are not
|
||||||
@@ -1464,20 +1477,14 @@ wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags)
|
|||||||
// check whether the document with this path is already opened
|
// check whether the document with this path is already opened
|
||||||
if ( !path.empty() )
|
if ( !path.empty() )
|
||||||
{
|
{
|
||||||
const wxFileName fn(path);
|
wxDocument * const doc = FindDocumentByPath(path);
|
||||||
for ( wxList::const_iterator i = m_docs.begin(); i != m_docs.end(); ++i )
|
if (doc)
|
||||||
{
|
|
||||||
wxDocument * const doc = (wxDocument*)*i;
|
|
||||||
|
|
||||||
if ( fn == doc->GetFilename() )
|
|
||||||
{
|
{
|
||||||
// file already open, just activate it and return
|
// file already open, just activate it and return
|
||||||
doc->Activate();
|
doc->Activate();
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// no, we need to create a new document
|
// no, we need to create a new document
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user