Add public wxDocManager::GetAnyUsableView().
This method tries to find the current view harder than GetCurrentView() and always returns a non-NULL view if there are any open documents at all. This is used by wxDocManager internally to find the view to apply the user commands to and will also be needed in the upcoming changes outside of wxDocManager, so just make this method public, as it seems that it could be useful in user code too, especially if we could use some better fallback than the first opened document (e.g. the last document the user interacted with would be better). This also clarifies the confusion between GetCurrentView() and GetActiveView(), see #13296. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73925 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
9fe942190d
commit
de28042337
@ -472,6 +472,12 @@ public:
|
||||
virtual void ActivateView(wxView *view, bool activate = true);
|
||||
virtual wxView *GetCurrentView() const { return m_currentView; }
|
||||
|
||||
// This method tries to find an active view harder than GetCurrentView():
|
||||
// if the latter is NULL, it also checks if we don't have just a single
|
||||
// view and returns it then.
|
||||
wxView *GetAnyUsableView() const;
|
||||
|
||||
|
||||
#ifndef __VISUALC6__
|
||||
wxDocVector GetDocumentsVector() const;
|
||||
wxDocTemplateVector GetTemplatesVector() const;
|
||||
@ -551,11 +557,6 @@ protected:
|
||||
// return the command processor for the current document, if any
|
||||
wxCommandProcessor *GetCurrentCommandProcessor() const;
|
||||
|
||||
// this method tries to find an active view harder than GetCurrentView():
|
||||
// if the latter is NULL, it also checks if we don't have just a single
|
||||
// view and returns it then
|
||||
wxView *GetActiveView() const;
|
||||
|
||||
int m_defaultDocumentNameCounter;
|
||||
int m_maxDocsOpen;
|
||||
wxList m_docs;
|
||||
|
@ -557,6 +557,18 @@ public:
|
||||
*/
|
||||
virtual wxDocTemplate* FindTemplateForPath(const wxString& path);
|
||||
|
||||
/**
|
||||
Returns the view to apply a user command to.
|
||||
|
||||
This method tries to find the view that the user wants to interact
|
||||
with. It returns the same view as GetCurrentDocument() if there is any
|
||||
currently active view but falls back to the first view of the first
|
||||
document if there is no active view.
|
||||
|
||||
@since 2.9.5
|
||||
*/
|
||||
wxView* GetAnyUsableView() const;
|
||||
|
||||
/**
|
||||
Returns the document associated with the currently active view (if
|
||||
any).
|
||||
@ -564,7 +576,11 @@ public:
|
||||
wxDocument* GetCurrentDocument() const;
|
||||
|
||||
/**
|
||||
Returns the currently active view
|
||||
Returns the currently active view.
|
||||
|
||||
This method can return @NULL if no view is currently active.
|
||||
|
||||
@see GetAnyUsableView()
|
||||
*/
|
||||
virtual wxView* GetCurrentView() const;
|
||||
|
||||
|
@ -1185,7 +1185,7 @@ void wxDocManager::OnMRUFileNotExist(unsigned n, const wxString& filename)
|
||||
|
||||
void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxView *view = GetActiveView();
|
||||
wxView *view = GetAnyUsableView();
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
@ -1219,7 +1219,7 @@ wxPreviewFrame* wxDocManager::CreatePreviewFrame(wxPrintPreviewBase* preview,
|
||||
void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxBusyCursor busy;
|
||||
wxView *view = GetActiveView();
|
||||
wxView *view = GetAnyUsableView();
|
||||
if (!view)
|
||||
return;
|
||||
|
||||
@ -1348,7 +1348,7 @@ void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event)
|
||||
cmdproc->SetMenuStrings();
|
||||
}
|
||||
|
||||
wxView *wxDocManager::GetActiveView() const
|
||||
wxView *wxDocManager::GetAnyUsableView() const
|
||||
{
|
||||
wxView *view = GetCurrentView();
|
||||
|
||||
@ -1374,7 +1374,7 @@ wxView *wxDocManager::GetActiveView() const
|
||||
|
||||
bool wxDocManager::TryBefore(wxEvent& event)
|
||||
{
|
||||
wxView * const view = GetActiveView();
|
||||
wxView * const view = GetAnyUsableView();
|
||||
return view && view->ProcessEventLocally(event);
|
||||
}
|
||||
|
||||
@ -1570,7 +1570,7 @@ bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc))
|
||||
|
||||
wxDocument *wxDocManager::GetCurrentDocument() const
|
||||
{
|
||||
wxView * const view = GetActiveView();
|
||||
wxView * const view = GetAnyUsableView();
|
||||
return view ? view->GetDocument() : NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user