Show how to handle files on command line in docview sample.
This is not totally obvious, so show how to do it, including the Mac-specific MacNewFile() overriding part. Closes #16816. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78498 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
0e6af4ac39
commit
ad527c5468
@ -101,6 +101,7 @@ All (GUI):
|
||||
- Fix creating/removing mode buttons in wxPG manager (Artur Wieczorek).
|
||||
- Harmonize wxMenuEvent handling between all major ports.
|
||||
- Fix wxPGChoices copy ctor (Snoits).
|
||||
- Show how to handle files on command line in docview sample (Neil Mayhew).
|
||||
|
||||
wxGTK:
|
||||
|
||||
|
@ -108,6 +108,10 @@ void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
|
||||
"run in SDI mode: multiple documents, multiple windows");
|
||||
parser.AddSwitch("", CmdLineOption::SINGLE,
|
||||
"run in single document mode");
|
||||
|
||||
parser.AddParam("document-file",
|
||||
wxCMD_LINE_VAL_STRING,
|
||||
wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL);
|
||||
}
|
||||
|
||||
bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser)
|
||||
@ -140,9 +144,19 @@ bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser)
|
||||
return false;
|
||||
}
|
||||
|
||||
// save any files given on the command line: we'll open them in OnInit()
|
||||
// later, after creating the frame
|
||||
for ( size_t i = 0; i != parser.GetParamCount(); ++i )
|
||||
m_filesFromCmdLine.push_back(parser.GetParam(i));
|
||||
|
||||
return wxApp::OnCmdLineParsed(parser);
|
||||
}
|
||||
|
||||
void MyApp::MacNewFile()
|
||||
{
|
||||
wxDocManager::GetDocumentManager()->CreateNewDocument();
|
||||
}
|
||||
|
||||
bool MyApp::OnInit()
|
||||
{
|
||||
if ( !wxApp::OnInit() )
|
||||
@ -229,7 +243,6 @@ bool MyApp::OnInit()
|
||||
{
|
||||
m_canvas = new MyCanvas(NULL, frame);
|
||||
m_menuEdit = CreateDrawingEditMenu();
|
||||
docManager->CreateNewDocument();
|
||||
}
|
||||
|
||||
CreateMenuBarForFrame(frame, menuFile, m_menuEdit);
|
||||
@ -238,6 +251,16 @@ bool MyApp::OnInit()
|
||||
frame->Centre();
|
||||
frame->Show();
|
||||
|
||||
if ( m_filesFromCmdLine.empty() )
|
||||
{
|
||||
docManager->CreateNewDocument();
|
||||
}
|
||||
else // we have files to open on command line
|
||||
{
|
||||
for ( size_t i = 0; i != m_filesFromCmdLine.size(); ++i )
|
||||
docManager->CreateDocument(m_filesFromCmdLine[i], wxDOC_SILENT);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define _WX_SAMPLES_DOCVIEW_DOCVIEW_H_
|
||||
|
||||
#include "wx/docview.h"
|
||||
#include "wx/vector.h"
|
||||
|
||||
class MyCanvas;
|
||||
|
||||
@ -39,6 +40,8 @@ public:
|
||||
virtual void OnInitCmdLine(wxCmdLineParser& parser) wxOVERRIDE;
|
||||
virtual bool OnCmdLineParsed(wxCmdLineParser& parser) wxOVERRIDE;
|
||||
|
||||
virtual void MacNewFile() wxOVERRIDE;
|
||||
|
||||
// our specific methods
|
||||
Mode GetMode() const { return m_mode; }
|
||||
wxFrame *CreateChildFrame(wxView *view, bool isCanvas);
|
||||
@ -68,6 +71,8 @@ private:
|
||||
// application object itself
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
|
||||
// contains the file names given on the command line, possibly empty
|
||||
wxVector<wxString> m_filesFromCmdLine;
|
||||
|
||||
// the currently used mode
|
||||
Mode m_mode;
|
||||
|
Loading…
Reference in New Issue
Block a user