Fix processing of events for MRU entries #10 and more in docview.
We only handled events for wxID_FILE1..wxID_FILE9 range but there can be more than 9 entries in the MRU list. Handle events for as many of them as there are correctly. This required adding a fallback handler for all menu events and checking if the id of the menu item is in the MRU range inside it. Also move this to wxDocManager itself from wxDocParentFrameAnyBase as it's common for all kinds of frames anyhow. Closes #12141. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64569 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
67eca664b5
commit
c70da1a243
@ -371,6 +371,7 @@ public:
|
||||
void OnFileRevert(wxCommandEvent& event);
|
||||
void OnFileSave(wxCommandEvent& event);
|
||||
void OnFileSaveAs(wxCommandEvent& event);
|
||||
void OnMRUFile(wxCommandEvent& event);
|
||||
#if wxUSE_PRINTING_ARCHITECTURE
|
||||
void OnPrint(wxCommandEvent& event);
|
||||
void OnPreview(wxCommandEvent& event);
|
||||
@ -484,6 +485,8 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
// Open the MRU file with the given index in our associated file history.
|
||||
void DoOpenMRUFile(unsigned n);
|
||||
#if wxUSE_PRINTING_ARCHITECTURE
|
||||
virtual wxPreviewFrame* CreatePreviewFrame(wxPrintPreviewBase* preview,
|
||||
wxWindow *parent,
|
||||
@ -783,12 +786,6 @@ public:
|
||||
wxDocManager *GetDocumentManager() const { return m_docManager; }
|
||||
|
||||
protected:
|
||||
// Open the MRU file with the given index in our associated file history.
|
||||
//
|
||||
// This is called from the derived class event handler for the MRU menu
|
||||
// items.
|
||||
void DoOpenMRUFile(unsigned n);
|
||||
|
||||
wxDocManager *m_docManager;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAnyBase);
|
||||
@ -830,8 +827,6 @@ public:
|
||||
|
||||
this->Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
|
||||
wxCommandEventHandler(wxDocParentFrameAny::OnExit));
|
||||
this->Connect(wxID_FILE1, wxID_FILE9, wxEVT_COMMAND_MENU_SELECTED,
|
||||
wxCommandEventHandler(wxDocParentFrameAny::OnMRUFile));
|
||||
this->Connect(wxEVT_CLOSE_WINDOW,
|
||||
wxCloseEventHandler(wxDocParentFrameAny::OnCloseWindow));
|
||||
|
||||
@ -854,11 +849,6 @@ private:
|
||||
this->Close();
|
||||
}
|
||||
|
||||
void OnMRUFile(wxCommandEvent& event)
|
||||
{
|
||||
DoOpenMRUFile(event.GetId() - wxID_FILE1);
|
||||
}
|
||||
|
||||
void OnCloseWindow(wxCloseEvent& event)
|
||||
{
|
||||
if ( m_docManager && !m_docManager->Clear(!event.CanVeto()) )
|
||||
|
@ -884,6 +884,11 @@ BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler)
|
||||
EVT_MENU(wxID_UNDO, wxDocManager::OnUndo)
|
||||
EVT_MENU(wxID_REDO, wxDocManager::OnRedo)
|
||||
|
||||
// We don't know in advance how many items can there be in the MRU files
|
||||
// list so set up OnMRUFile() as a handler for all menu events and do the
|
||||
// check for the id of the menu item clicked inside it.
|
||||
EVT_MENU(wxID_ANY, wxDocManager::OnMRUFile)
|
||||
|
||||
EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen)
|
||||
EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateDisableIfNoDoc)
|
||||
EVT_UPDATE_UI(wxID_CLOSE_ALL, wxDocManager::OnUpdateDisableIfNoDoc)
|
||||
@ -1083,6 +1088,53 @@ void wxDocManager::OnFileSaveAs(wxCommandEvent& WXUNUSED(event))
|
||||
doc->SaveAs();
|
||||
}
|
||||
|
||||
void wxDocManager::OnMRUFile(wxCommandEvent& event)
|
||||
{
|
||||
// Check if the id is in the range assigned to MRU list entries.
|
||||
const int id = event.GetId();
|
||||
if ( id >= wxID_FILE1 &&
|
||||
id < wxID_FILE1 + m_fileHistory->GetBaseId() )
|
||||
{
|
||||
DoOpenMRUFile(id - wxID_FILE1);
|
||||
}
|
||||
else
|
||||
{
|
||||
event.Skip();
|
||||
}
|
||||
}
|
||||
|
||||
void wxDocManager::DoOpenMRUFile(unsigned n)
|
||||
{
|
||||
wxString filename(GetHistoryFile(n));
|
||||
if ( filename.empty() )
|
||||
return;
|
||||
|
||||
wxString errMsg; // must contain exactly one "%s" if non-empty
|
||||
if ( wxFile::Exists(filename) )
|
||||
{
|
||||
// try to open it
|
||||
if ( CreateDocument(filename, wxDOC_SILENT) )
|
||||
return;
|
||||
|
||||
errMsg = _("The file '%s' couldn't be opened.");
|
||||
}
|
||||
else // file doesn't exist
|
||||
{
|
||||
errMsg = _("The file '%s' doesn't exist and couldn't be opened.");
|
||||
}
|
||||
|
||||
|
||||
wxASSERT_MSG( !errMsg.empty(), "should have an error message" );
|
||||
|
||||
// remove the file which we can't open from the MRU list
|
||||
RemoveFileFromHistory(n);
|
||||
|
||||
// and tell the user about it
|
||||
wxLogError(errMsg + '\n' +
|
||||
_("It has been removed from the most recently used files list."),
|
||||
filename);
|
||||
}
|
||||
|
||||
#if wxUSE_PRINTING_ARCHITECTURE
|
||||
|
||||
void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event))
|
||||
@ -1914,38 +1966,6 @@ bool wxDocChildFrameAnyBase::CloseView(wxCloseEvent& event)
|
||||
// wxDocParentFrameAnyBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxDocParentFrameAnyBase::DoOpenMRUFile(unsigned n)
|
||||
{
|
||||
wxString filename(m_docManager->GetHistoryFile(n));
|
||||
if ( filename.empty() )
|
||||
return;
|
||||
|
||||
wxString errMsg; // must contain exactly one "%s" if non-empty
|
||||
if ( wxFile::Exists(filename) )
|
||||
{
|
||||
// try to open it
|
||||
if ( m_docManager->CreateDocument(filename, wxDOC_SILENT) )
|
||||
return;
|
||||
|
||||
errMsg = _("The file '%s' couldn't be opened.");
|
||||
}
|
||||
else // file doesn't exist
|
||||
{
|
||||
errMsg = _("The file '%s' doesn't exist and couldn't be opened.");
|
||||
}
|
||||
|
||||
|
||||
wxASSERT_MSG( !errMsg.empty(), "should have an error message" );
|
||||
|
||||
// remove the file which we can't open from the MRU list
|
||||
m_docManager->RemoveFileFromHistory(n);
|
||||
|
||||
// and tell the user about it
|
||||
wxLogError(errMsg + '\n' +
|
||||
_("It has been removed from the most recently used files list."),
|
||||
filename);
|
||||
}
|
||||
|
||||
#if wxUSE_PRINTING_ARCHITECTURE
|
||||
|
||||
wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title)
|
||||
|
Loading…
Reference in New Issue
Block a user