WM: expose file loading operator property init functions

This commit is contained in:
Campbell Barton 2014-04-03 11:04:02 +11:00
parent b2b4f2c033
commit 726628518d
3 changed files with 44 additions and 28 deletions

View File

@ -1151,3 +1151,39 @@ void wm_autosave_read(bContext *C, ReportList *reports)
WM_file_read(C, filename, reports);
}
/** \name Initialize WM_OT_open_xxx properties
*
* Check if load_ui was set by the caller.
* Fall back to user preference when file flags not specified.
*
* \{ */
void wm_open_init_load_ui(wmOperator *op, bool use_prefs)
{
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "load_ui");
if (!RNA_property_is_set(op->ptr, prop)) {
bool value = use_prefs ?
((U.flag & USER_FILENOUI) == 0) :
((G.fileflags & G_FILE_NO_UI) == 0);
RNA_property_boolean_set(op->ptr, prop, value);
}
}
void wm_open_init_use_scripts(wmOperator *op, bool use_prefs)
{
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
if (!RNA_property_is_set(op->ptr, prop)) {
/* use G_SCRIPT_AUTOEXEC rather than the userpref because this means if
* the flag has been disabled from the command line, then opening
* from the menu wont enable this setting. */
bool value = use_prefs ?
((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) :
((G.f & G_SCRIPT_AUTOEXEC) != 0);
RNA_property_boolean_set(op->ptr, prop, value);
}
}
/** \} */

View File

@ -2188,30 +2188,6 @@ struct FileRuntime {
bool is_untrusted;
};
static void open_set_load_ui(wmOperator *op, bool use_prefs)
{
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "load_ui");
if (!RNA_property_is_set(op->ptr, prop)) {
RNA_property_boolean_set(op->ptr, prop, use_prefs ?
(U.flag & USER_FILENOUI) == 0 :
(G.fileflags & G_FILE_NO_UI) == 0);
}
}
static void open_set_use_scripts(wmOperator *op, bool use_prefs)
{
PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
if (!RNA_property_is_set(op->ptr, prop)) {
/* use G_SCRIPT_AUTOEXEC rather than the userpref because this means if
* the flag has been disabled from the command line, then opening
* from the menu wont enable this setting. */
RNA_property_boolean_set(op->ptr, prop, use_prefs ?
(U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0 :
(G.f & G_SCRIPT_AUTOEXEC) != 0);
}
}
static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
const char *openname = G.main->name;
@ -2231,8 +2207,8 @@ static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *U
}
RNA_string_set(op->ptr, "filepath", openname);
open_set_load_ui(op, true);
open_set_use_scripts(op, true);
wm_open_init_load_ui(op, true);
wm_open_init_use_scripts(op, true);
op->customdata = NULL;
WM_event_add_fileselect(C, op);
@ -2248,8 +2224,8 @@ static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
RNA_string_get(op->ptr, "filepath", filepath);
/* re-use last loaded setting so we can reload a file without changing */
open_set_load_ui(op, false);
open_set_use_scripts(op, false);
wm_open_init_load_ui(op, false);
wm_open_init_use_scripts(op, false);
if (RNA_boolean_get(op->ptr, "load_ui"))
G.fileflags &= ~G_FILE_NO_UI;

View File

@ -76,6 +76,10 @@ void wm_autosave_delete(void);
void wm_autosave_read(bContext *C, struct ReportList *reports);
void wm_autosave_location(char *filepath);
/* init operator properties */
void wm_open_init_load_ui(wmOperator *op, bool use_prefs);
void wm_open_init_use_scripts(wmOperator *op, bool use_prefs);
/* hack to store circle select size - campbell, must replace with nice operator memory */
#define GESTURE_MEMORY