// view and returns it then
wxView *GetActiveView() const;
+ // activate the first view of the given document if any
+ void ActivateDocument(wxDocument *doc);
+
int m_defaultDocumentNameCounter;
int m_maxDocsOpen;
} // anonymous namespace
+void wxDocManager::ActivateDocument(wxDocument *doc)
+{
+ wxView * const view = doc->GetFirstView();
+ if ( !view )
+ return;
+
+ view->Activate(true);
+ if ( wxWindow *win = view->GetFrame() )
+ win->SetFocus();
+}
+
wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags)
{
// this ought to be const but SelectDocumentType/Path() are not
if ( fn == doc->GetFilename() )
{
// file already open, just activate it and return
- if ( doc->GetFirstView() )
- {
- ActivateView(doc->GetFirstView());
- if ( doc->GetDocumentWindow() )
- doc->GetDocumentWindow()->SetFocus();
- return doc;
- }
+ ActivateDocument(doc);
}
}
}
if ( !(flags & wxDOC_NEW) && temp->FileMatchesTemplate(path) )
AddFileToHistory(path);
+ // at least under Mac (where views are top level windows) it seems to be
+ // necessary to manually activate the new document to bring it to the
+ // forefront -- and it shouldn't hurt doing this under the other platforms
+ ActivateDocument(docNew);
+
return docNew;
}