>From 3c8376c82074514e186d42d81be062efa2489fe6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Mar 2015 00:36:39 +0100 Subject: [PATCH] Add --file command line option to the GUI program too. The CLI program allows to open input files from the command line using the --file option, add a similar option to the GUI program as it is convenient there as well. This could also be used in the future to associate lmi with the extensions of the different files used for it (such as .ill, .cns, and so on). --- skeleton.cpp | 36 ++++++++++++++++++++++++++++++++++++ skeleton.hpp | 3 +++ 2 files changed, 39 insertions(+) diff --git a/skeleton.cpp b/skeleton.cpp index b082a99..da06ebe 100644 --- a/skeleton.cpp +++ b/skeleton.cpp @@ -1183,6 +1183,7 @@ bool Skeleton::ProcessCommandLine(int argc, char* argv[]) {"mellon" ,NO_ARG ,0 ,002 ,0 ,"pedo mellon a minno"}, {"mello" ,NO_ARG ,0 ,003 ,0 ,"fraud"}, {"pyx" ,REQD_ARG ,0 ,'x' ,0 ,"for docimasy"}, + {"file" ,REQD_ARG ,0 ,'f' ,0 ,"input file to run"}, {"data_path" ,REQD_ARG ,0 ,'d' ,0 ,"path to data files"}, {"print_db" ,NO_ARG ,0 ,'p' ,0 ,"print product databases"}, {"prospicience" ,REQD_ARG ,0 ,004 ,0 ,"validation date"}, @@ -1201,6 +1202,8 @@ bool Skeleton::ProcessCommandLine(int argc, char* argv[]) ,true ); + std::vector input_files; + int c; while(EOF != (c = getopt_long())) { @@ -1248,6 +1251,13 @@ bool Skeleton::ProcessCommandLine(int argc, char* argv[]) } break; + case 'f': + { + LMI_ASSERT(NULL != getopt_long.optarg); + input_files.push_back(getopt_long.optarg); + } + break; + case 'h': { show_help = true; @@ -1304,6 +1314,13 @@ bool Skeleton::ProcessCommandLine(int argc, char* argv[]) warning() << std::flush; } + if (!input_files.empty()) + { + // We can't open the files yet, do it after the main window is + // initialized. + CallAfter(&Skeleton::OpenCommandLineFiles, input_files); + } + if(show_help) { std::ostringstream oss; @@ -1315,6 +1332,25 @@ 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)) + { + warning() + << "Document '" + << *ci + << "' specified on the command line couldn't be opened." + << LMI_FLUSH + ; + } + } +} + 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