WM: app-template command line override
Without this, there was no simple way to have launchers for different app-templates. Also allows force-disabling the app-template stored in the preferences.
This commit is contained in:
		@@ -72,6 +72,9 @@ struct wmNDOFMotionData;
 | 
				
			|||||||
typedef struct wmJob wmJob;
 | 
					typedef struct wmJob wmJob;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* general API */
 | 
					/* general API */
 | 
				
			||||||
 | 
					void		WM_init_state_app_template_set(const char *app_template);
 | 
				
			||||||
 | 
					const char *WM_init_state_app_template_get(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void		WM_init_state_size_set		(int stax, int stay, int sizx, int sizy);
 | 
					void		WM_init_state_size_set		(int stax, int stay, int sizx, int sizy);
 | 
				
			||||||
void		WM_init_state_fullscreen_set(void);
 | 
					void		WM_init_state_fullscreen_set(void);
 | 
				
			||||||
void		WM_init_state_normal_set(void);
 | 
					void		WM_init_state_normal_set(void);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -638,6 +638,33 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct {
 | 
				
			||||||
 | 
						char app_template[64];
 | 
				
			||||||
 | 
						bool override;
 | 
				
			||||||
 | 
					} wm_init_state_app_template = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Used for setting app-template from the command line:
 | 
				
			||||||
 | 
					 * - non-empty string: overrides.
 | 
				
			||||||
 | 
					 * - empty string: override, using no app template.
 | 
				
			||||||
 | 
					 * - NULL: clears override.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void WM_init_state_app_template_set(const char *app_template)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (app_template) {
 | 
				
			||||||
 | 
							STRNCPY(wm_init_state_app_template.app_template, app_template);
 | 
				
			||||||
 | 
							wm_init_state_app_template.override = true;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else {
 | 
				
			||||||
 | 
							wm_init_state_app_template.app_template[0] = '\0';
 | 
				
			||||||
 | 
							wm_init_state_app_template.override = false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const char *WM_init_state_app_template_get(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return wm_init_state_app_template.override ? wm_init_state_app_template.app_template : NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Called on startup, (context entirely filled with NULLs)
 | 
					 * Called on startup, (context entirely filled with NULLs)
 | 
				
			||||||
@@ -1614,9 +1641,13 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		/* Always load preferences when switching templates. */
 | 
							/* Always load preferences when switching templates. */
 | 
				
			||||||
		use_userdef = true;
 | 
							use_userdef = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							/* Turn override off, since we're explicitly loading a different app-template. */
 | 
				
			||||||
 | 
							WM_init_state_app_template_set(NULL);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else {
 | 
						else {
 | 
				
			||||||
		app_template = NULL;
 | 
							/* Normally NULL, only set when overriding from the command-line. */
 | 
				
			||||||
 | 
							app_template = WM_init_state_app_template_get();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (wm_homefile_read(C, op->reports, use_factory_settings, use_empty_data, use_userdef, filepath, app_template)) {
 | 
						if (wm_homefile_read(C, op->reports, use_factory_settings, use_empty_data, use_userdef, filepath, app_template)) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -195,8 +195,7 @@ void WM_init(bContext *C, int argc, const char **argv)
 | 
				
			|||||||
	wm_init_reports(C);
 | 
						wm_init_reports(C);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* get the default database, plus a wm */
 | 
						/* get the default database, plus a wm */
 | 
				
			||||||
	wm_homefile_read(C, NULL, G.factory_startup, false, true, NULL, NULL);
 | 
						wm_homefile_read(C, NULL, G.factory_startup, false, true, NULL, WM_init_state_app_template_get());
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	BLT_lang_set(NULL);
 | 
						BLT_lang_set(NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -580,6 +580,7 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	printf("\n");
 | 
						printf("\n");
 | 
				
			||||||
	printf("Misc Options:\n");
 | 
						printf("Misc Options:\n");
 | 
				
			||||||
 | 
						BLI_argsPrintArgDoc(ba, "--app-template");
 | 
				
			||||||
	BLI_argsPrintArgDoc(ba, "--factory-startup");
 | 
						BLI_argsPrintArgDoc(ba, "--factory-startup");
 | 
				
			||||||
	printf("\n");
 | 
						printf("\n");
 | 
				
			||||||
	BLI_argsPrintArgDoc(ba, "--env-system-datafiles");
 | 
						BLI_argsPrintArgDoc(ba, "--env-system-datafiles");
 | 
				
			||||||
@@ -993,6 +994,22 @@ static int arg_handle_debug_fpe_set(int UNUSED(argc), const char **UNUSED(argv),
 | 
				
			|||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char arg_handle_app_template_doc[] =
 | 
				
			||||||
 | 
					"\n\tSet the application template, use 'default' for none."
 | 
				
			||||||
 | 
					;
 | 
				
			||||||
 | 
					static int arg_handle_app_template(int argc, const char **argv, void *UNUSED(data))
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (argc > 1) {
 | 
				
			||||||
 | 
							const char *app_template = STREQ(argv[1], "default") ? "" : argv[1];
 | 
				
			||||||
 | 
							WM_init_state_app_template_set(app_template);
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						else {
 | 
				
			||||||
 | 
							printf("\nError: App template must follow '--app-template'.\n");
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char arg_handle_factory_startup_set_doc[] =
 | 
					static const char arg_handle_factory_startup_set_doc[] =
 | 
				
			||||||
"\n\tSkip reading the " STRINGIFY(BLENDER_STARTUP_FILE) " in the users home directory."
 | 
					"\n\tSkip reading the " STRINGIFY(BLENDER_STARTUP_FILE) " in the users home directory."
 | 
				
			||||||
;
 | 
					;
 | 
				
			||||||
@@ -2043,6 +2060,7 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	BLI_argsAdd(ba, 1, NULL, "--verbose", CB(arg_handle_verbosity_set), NULL);
 | 
						BLI_argsAdd(ba, 1, NULL, "--verbose", CB(arg_handle_verbosity_set), NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						BLI_argsAdd(ba, 1, NULL, "--app-template", CB(arg_handle_app_template), NULL);
 | 
				
			||||||
	BLI_argsAdd(ba, 1, NULL, "--factory-startup", CB(arg_handle_factory_startup_set), NULL);
 | 
						BLI_argsAdd(ba, 1, NULL, "--factory-startup", CB(arg_handle_factory_startup_set), NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* TODO, add user env vars? */
 | 
						/* TODO, add user env vars? */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user