fixes for auto script execution, changing the user preference also updates the global...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 27 Feb 2010 12:34:49 +0000 (12:34 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 27 Feb 2010 12:34:49 +0000 (12:34 +0000)
source/blender/blenkernel/intern/blender.c
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_operators.c

index b96493704b57fe10e7ec382c1688078bdf59fb89..171b48af974ae99c57aa2b81f4513cb00f8d72fb 100644 (file)
@@ -291,8 +291,6 @@ static void setup_app_data(bContext *C, BlendFileData *bfd, char *filename)
        if (G.f & G_SWAP_EXCHANGE) bfd->globalf |= G_SWAP_EXCHANGE;
        else bfd->globalf &= ~G_SWAP_EXCHANGE;
 
-       if ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE)) bfd->globalf &= ~G_SCRIPT_AUTOEXEC;
-
        G.f= bfd->globalf;
 
        if (!G.background) {
index a2602bc3cb71c47d46f98be167a197611fbc2b77..6f6ee5216ae35bcc889974a8be6db7bacff545ab 100644 (file)
@@ -47,6 +47,7 @@
 #include "BKE_depsgraph.h"
 #include "DNA_object_types.h"
 #include "GPU_draw.h"
+#include "BKE_global.h"
 
 #include "MEM_guardedalloc.h"
 
@@ -55,6 +56,13 @@ static void rna_userdef_update(Main *bmain, Scene *scene, PointerRNA *ptr)
        WM_main_add_notifier(NC_WINDOW, NULL);
 }
 
+static void rna_userdef_script_autoexec_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+       UserDef *userdef = (UserDef*)ptr->data;
+       if (userdef->flag & USER_SCRIPT_AUTOEXEC_DISABLE)       G.f &= ~G_SCRIPT_AUTOEXEC;
+       else                                                                                            G.f |=  G_SCRIPT_AUTOEXEC;
+}
+
 static void rna_userdef_mipmap_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
@@ -2346,8 +2354,9 @@ static void rna_def_userdef_system(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Enable All Codecs", "Enables automatic saving of preview images in the .blend file (Windows only)");
 
        prop= RNA_def_property(srna, "auto_execute_scripts", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", USER_SCRIPT_AUTOEXEC_DISABLE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", USER_SCRIPT_AUTOEXEC_DISABLE);
        RNA_def_property_ui_text(prop, "Auto Run Python Scripts", "Allow any .blend file to run scripts automatically (unsafe with blend files from an untrusted source)");
+       RNA_def_property_update(prop, 0, "rna_userdef_script_autoexec_update");
 
        prop= RNA_def_property(srna, "prefetch_frames", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "prefetchframes");
index 16776517e40344129c855d6aa8d42ee82b71dff0..2ab6f78daa5c0d94a205d255f89d5524bb7fdc57 100644 (file)
@@ -241,6 +241,10 @@ static void wm_init_userdef(bContext *C)
        UI_init_userdef();
        MEM_CacheLimiter_set_maximum(U.memcachelimit * 1024 * 1024);
        sound_init(CTX_data_main(C));
+
+       /* set the python auto-execute setting from user prefs */
+       if (U.flag & USER_SCRIPT_AUTOEXEC_DISABLE)      G.f &= ~G_SCRIPT_AUTOEXEC;
+       else                                                                            G.f |=  G_SCRIPT_AUTOEXEC;
 }
 
 void WM_read_file(bContext *C, char *name, ReportList *reports)
index 0938c583d2e2ed2e28bd524c437aa2c7f279784e..29359b1ddb93afe5241ca750cd8727efc29f6b37 100644 (file)
@@ -1329,7 +1329,7 @@ static void open_set_load_ui(wmOperator *op)
 static void open_set_use_scripts(wmOperator *op)
 {
        if(!RNA_property_is_set(op->ptr, "use_scripts"))
-               RNA_boolean_set(op->ptr, "use_scripts", (U.flag & USER_SCRIPT_AUTOEXEC_DISABLE));
+               RNA_boolean_set(op->ptr, "use_scripts", !(U.flag & USER_SCRIPT_AUTOEXEC_DISABLE));
 }
 
 static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, wmEvent *event)