From 4a39fcdd8fc3436f20f43f7fda5ce9b56ed7e4be Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Fri, 21 Mar 2014 11:59:19 -0500 Subject: [PATCH] single_top.c logic, improved OpenProjectFiles() documentation. --- common/single_top.cpp | 87 ++++++++++++++++-------------------------- include/kiway_player.h | 11 +++++- 2 files changed, 41 insertions(+), 57 deletions(-) diff --git a/common/single_top.cpp b/common/single_top.cpp index 22da93aacd..ce9fe38202 100644 --- a/common/single_top.cpp +++ b/common/single_top.cpp @@ -353,76 +353,54 @@ bool PGM_SINGLE_TOP::OnPgmInit( wxApp* aWxApp ) if( argc > 1 ) { + /* + gerbview handles multiple project data files, i.e. gerber files on + cmd line. Others currently do not, they handle only one. For common + code simplicity we simply pass all the arguments in however, each + program module can do with them what they want, ignore, complain + whatever. We don't establish policy here, as this is a multi-purpose + launcher. + */ -#if defined(TOP_FRAME) && TOP_FRAME==GERBER_FRAME_TYPE - // gerbview handles multiple project data files, i.e. gerber files on cmd line. - - std::vector fileSet; - - // Load all files specified on the command line. + std::vector argSet; for( int i=1; iOpenProjectFiles( fileSet ) ) - { - // OpenProjectFiles() API asks that it report failure to the UI. - // Nothing further to say here. - - // Fail the process startup if the file could not be opened, - // although this is an optional choice, one that can be reversed - // also in the KIFACE specific OpenProjectFiles() return value. - return false; - } - -#else - - wxFileName fn( argv[1] ); - - if( !fn.IsOk() ) - { - return false; - } - #if defined(PGM_DATA_FILE_EXT) - // PGM_DATA_FILE_EXT is different for each compile, it may come from CMake - // on the compiler command line, or not. - if( !fn.GetExt() ) - fn.SetExt( wxT( PGM_DATA_FILE_EXT ) ); -#endif + // PGM_DATA_FILE_EXT is different for each compile, it may come + // from CMake on the compiler command line, often does not. + // This facillity is mostly useful only for those program modules + // supporting a single argv[1]. + if( !argv1.GetExt() ) + argv1.SetExt( wxT( PGM_DATA_FILE_EXT ) ); - if( !Pgm().LockFile( fn.GetFullPath() ) ) - { - wxLogSysError( _( "This file is already open." ) ); - return false; + argSet[0] = argv1.GetFullPath(); +#endif + if( !Pgm().LockFile( argSet[0] ) ) + { + wxLogSysError( _( "This file is already open." ) ); + return false; + } } - if( fn.GetPath().size() ) + // @todo: setting CWD is taboo in a multi-project environment, this + // will not be possible soon. + if( argv1.GetPath().size() ) // path only { - // wxSetWorkingDirectory does not like empty paths - wxSetWorkingDirectory( fn.GetPath() ); - - // @todo: setting CWD is taboo in a multi-project environment + // wxSetWorkingDirectory() does not like empty paths + wxSetWorkingDirectory( argv1.GetPath() ); } // Use the KIWAY_PLAYER::OpenProjectFiles() API function: - if( !frame->OpenProjectFiles( std::vector( 1, fn.GetFullPath() ) ) ) + if( !frame->OpenProjectFiles( argSet ) ) { // OpenProjectFiles() API asks that it report failure to the UI. // Nothing further to say here. @@ -432,7 +410,6 @@ bool PGM_SINGLE_TOP::OnPgmInit( wxApp* aWxApp ) // also in the KIFACE specific OpenProjectFiles() return value. return false; } -#endif } else { diff --git a/include/kiway_player.h b/include/kiway_player.h index 2ffab5acb6..b61b6f195c 100644 --- a/include/kiway_player.h +++ b/include/kiway_player.h @@ -129,8 +129,15 @@ public: * KIWAY_PLAYER is precluded. *

* Each derived class should handle this in a way specific to its needs. - * No prompting is done inside here for any file or project. There is no - * need to call this with aFileList which is empty. + * No prompting is done inside here for any file or project. There should be + * need to call this with aFileList which is empty. However, calling it with + * a single filename which does not exist should indicate to the implementor + * that a new session is being started and that the given name is the desired + * name for the data file at time of save. + *

+ * Therefore, one of the first things an implementation should do is test for + * existence of the first file in the list, and if it does not exist, treat + * it as a new session, possibly with a UI notification to that effect. *

* After loading the window should update its Title as part of this operation. * If the KIWAY_PLAYER needs to, it can load the *.pro file as part of this operation.