From: Thomas Debesse Date: Sat, 15 Jul 2017 14:46:09 +0000 (+0200) Subject: add command line support X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=37b140ce46c3afe6eeb7dc50e40632de59910fe2;p=xonotic%2Fnetradiant.git add command line support - enable generic Gtk options - allow to pass map filename as argument and open it --- diff --git a/radiant/main.cpp b/radiant/main.cpp index 196297ed..c0486710 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -558,8 +558,38 @@ int main( int argc, char* argv[] ){ } #endif + static GOptionEntry entries[] = { + { NULL } + }; + GError *error = NULL; + const char* mapname = NULL; + gtk_disable_setlocale(); - gtk_init( &argc, &argv ); + if ( !gtk_init_with_args( &argc, &argv, "", entries, NULL, &error) ) { + g_print( "%s\n", error->message ); + return -1; + } + + // Gtk already removed parsed `--options` + if (argc == 2) { + if ( strlen( argv[1] ) > 1 ) { + if ( g_str_has_suffix( argv[1], ".map" ) ) { + if ( g_path_is_absolute( argv[1] ) ) { + mapname = argv[1]; + } + else { + mapname = g_build_filename( g_get_current_dir(), argv[1], NULL ); + } + } + else { + g_print( "bad file name, will not load: %s\n", argv[1] ); + } + } + } + else if (argc > 2) { + g_print ( "%s\n", "too many arguments" ); + return -1; + } // redirect Gtk warnings to the console g_log_set_handler( "Gdk", (GLogLevelFlags)( G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | @@ -620,7 +650,10 @@ int main( int argc, char* argv[] ){ hide_splash(); - if ( g_bLoadLastMap && !g_strLastMap.empty() ) { + if ( mapname != NULL ) { + Map_LoadFile( mapname ); + } + else if ( g_bLoadLastMap && !g_strLastMap.empty() ) { Map_LoadFile( g_strLastMap.c_str() ); } else diff --git a/radiant/map.cpp b/radiant/map.cpp index 18d25c09..7e39d800 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -932,6 +932,8 @@ void Map_LoadFile( const char *filename ){ globalOutputStream() << "Loading map from " << filename << "\n"; ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Loading Map" ); + MRU_AddFile( filename ); + { ScopeTimer timer( "map load" ); @@ -1813,7 +1815,6 @@ void OpenMap(){ const char* filename = map_open( "Open Map" ); if ( filename != 0 ) { - MRU_AddFile( filename ); Map_RegionOff(); Map_Free(); Map_LoadFile( filename );