>From fd402a2613e5b5db4283e2b350adf8779fce2547 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 15 Feb 2015 19:18:47 +0100 Subject: [PATCH] Allow passing the names of the documents to open on command line. Handling all command line parameters as the names of the documents to open is a common convention for document-oriented applications, so make lmi conform to it, especially because it is quite convenient to be able to launch the program with e.g. a census directly instead of having to open it from the GUI. --- skeleton.cpp | 33 ++++++++++++++++++++++++++------- skeleton.hpp | 3 +++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/skeleton.cpp b/skeleton.cpp index 8d21ff0..99205c7 100644 --- a/skeleton.cpp +++ b/skeleton.cpp @@ -1317,14 +1317,16 @@ bool Skeleton::ProcessCommandLine(int argc, char* argv[]) } } - if((c = getopt_long.optind) < argc) + std::vector args; + for(c = getopt_long.optind; c < argc; ++c) { - warning() << "Unrecognized parameters:\n"; - while(c < argc) - { - warning() << " '" << argv[c++] << "'\n"; - } - warning() << std::flush; + args.push_back(argv[c]); + } + if (!args.empty()) + { + // We can't open the files yet, do it after the main window is + // initialized. + CallAfter(&Skeleton::OpenCommandLineFiles, args); } if(show_help) @@ -1338,6 +1340,23 @@ bool Skeleton::ProcessCommandLine(int argc, char* argv[]) return true; } +void Skeleton::OpenCommandLineFiles(std::vector const& files) +{ + LMI_ASSERT(doc_manager_); + + typedef std::vector::const_iterator vsci; + for(vsci ci = files.begin(); ci != files.end(); ++ci) + { + if(!doc_manager_->CreateDocument(*ci, wxDOC_SILENT)) + { + wxLogError + ("Failed to open document \"%s\" specified on command line." + ,*ci + ); + } + } +} + void Skeleton::UpdateViews() { wxBusyCursor wait; diff --git a/skeleton.hpp b/skeleton.hpp index 9e1c22a..32b5ae5 100644 --- a/skeleton.hpp +++ b/skeleton.hpp @@ -41,6 +41,8 @@ #include #include +#include + class DocManagerEx; class ViewEx; @@ -129,6 +131,7 @@ class Skeleton virtual void OnUnhandledException (); bool ProcessCommandLine(int argc, char* argv[]); + void OpenCommandLineFiles(std::vector const& files); void UpdateViews(); wxConfigBase* config_; -- 2.1.0