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);
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,
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);
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));
this->Close();
}
- void OnMRUFile(wxCommandEvent& event)
- {
- DoOpenMRUFile(event.GetId() - wxID_FILE1);
- }
-
void OnCloseWindow(wxCloseEvent& event)
{
if ( m_docManager && !m_docManager->Clear(!event.CanVeto()) )
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)
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))
// 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)