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:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user