Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_files.c
| Show First 20 Lines • Show All 1,999 Lines • ▼ Show 20 Lines | if (autoexec_init) { | ||||
| WM_file_autoexec_init(filepath); | WM_file_autoexec_init(filepath); | ||||
| } | } | ||||
| success = WM_file_read(C, filepath, reports); | success = WM_file_read(C, filepath, reports); | ||||
| return success; | return success; | ||||
| } | } | ||||
| /* currently fits in a pointer */ | /* Generic operator state utilities | ||||
| struct FileRuntime { | *********************************************/ | ||||
| bool is_untrusted; | |||||
| static void create_operator_state(wmOperatorType *ot, int first_state) | |||||
| { | |||||
| PropertyRNA *prop = RNA_def_int( | |||||
| ot->srna, "state", first_state, INT32_MIN, INT32_MAX, "State", "", INT32_MIN, INT32_MAX); | |||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |||||
| RNA_def_property_flag(prop, PROP_HIDDEN); | |||||
| } | |||||
| static int get_operator_state(wmOperator *op) | |||||
| { | |||||
| return RNA_int_get(op->ptr, "state"); | |||||
| } | |||||
| static void set_next_operator_state(wmOperator *op, int state) | |||||
| { | |||||
| RNA_int_set(op->ptr, "state", state); | |||||
| } | |||||
| typedef struct OperatorDispatchTarget { | |||||
| int state; | |||||
| int (*run)(bContext *C, wmOperator *op); | |||||
| } OperatorDispatchTarget; | |||||
| static int operator_state_dispatch(bContext *C, wmOperator *op, OperatorDispatchTarget *targets) | |||||
| { | |||||
| int state = get_operator_state(op); | |||||
| for (int i = 0; targets[i].run; i++) { | |||||
| OperatorDispatchTarget target = targets[i]; | |||||
| if (target.state == state) { | |||||
| return target.run(C, op); | |||||
| } | |||||
| } | |||||
| BLI_assert(false); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| /* Open Mainfile operator | |||||
| ********************************************/ | |||||
| enum { | |||||
| OPEN_MAINFILE_STATE_DISCARD_CHANGES, | |||||
| OPEN_MAINFILE_STATE_SELECT_FILE_PATH, | |||||
| OPEN_MAINFILE_STATE_OPEN, | |||||
| }; | }; | ||||
| static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int wm_open_mainfile_dispatch(bContext *C, wmOperator *op); | ||||
| static int wm_open_mainfile__discard_changes(bContext *C, wmOperator *op) | |||||
| { | |||||
| if (RNA_boolean_get(op->ptr, "display_file_selector")) { | |||||
| set_next_operator_state(op, OPEN_MAINFILE_STATE_SELECT_FILE_PATH); | |||||
| } | |||||
| else { | |||||
| set_next_operator_state(op, OPEN_MAINFILE_STATE_OPEN); | |||||
| } | |||||
| wmWindowManager *wm = CTX_wm_manager(C); | |||||
brecht: Should also have PROP_HIDDEN. | |||||
| if (U.uiflag & USER_SAVE_PROMPT && !wm->file_saved) { | |||||
| return WM_operator_confirm_message_ex(C, | |||||
| op, | |||||
| "Warning", | |||||
| ICON_INFO, | |||||
| "Changes in current file will be lost. Continue?", | |||||
| WM_OP_INVOKE_DEFAULT); | |||||
| } | |||||
| else { | |||||
| return wm_open_mainfile_dispatch(C, op); | |||||
| } | |||||
| } | |||||
| static int wm_open_mainfile__select_file_path(bContext *C, wmOperator *op) | |||||
| { | { | ||||
| set_next_operator_state(op, OPEN_MAINFILE_STATE_OPEN); | |||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| const char *openname = BKE_main_blendfile_path(bmain); | const char *openname = BKE_main_blendfile_path(bmain); | ||||
| if (CTX_wm_window(C) == NULL) { | if (CTX_wm_window(C) == NULL) { | ||||
| /* in rare cases this could happen, when trying to invoke in background | /* in rare cases this could happen, when trying to invoke in background | ||||
| * mode on load for example. Don't use poll for this because exec() | * mode on load for example. Don't use poll for this because exec() | ||||
| * can still run without a window */ | * can still run without a window */ | ||||
| BKE_report(op->reports, RPT_ERROR, "Context window not set"); | BKE_report(op->reports, RPT_ERROR, "Context window not set"); | ||||
| Show All 11 Lines | static int wm_open_mainfile__select_file_path(bContext *C, wmOperator *op) | ||||
| wm_open_init_use_scripts(op, true); | wm_open_init_use_scripts(op, true); | ||||
| op->customdata = NULL; | op->customdata = NULL; | ||||
| WM_event_add_fileselect(C, op); | WM_event_add_fileselect(C, op); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| static int wm_open_mainfile_exec(bContext *C, wmOperator *op) | static int wm_open_mainfile__open(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| char filepath[FILE_MAX]; | char filepath[FILE_MAX]; | ||||
| bool success; | bool success; | ||||
| RNA_string_get(op->ptr, "filepath", filepath); | RNA_string_get(op->ptr, "filepath", filepath); | ||||
| /* re-use last loaded setting so we can reload a file without changing */ | /* re-use last loaded setting so we can reload a file without changing */ | ||||
| wm_open_init_load_ui(op, false); | wm_open_init_load_ui(op, false); | ||||
| Show All 21 Lines | static int wm_open_mainfile__open(bContext *C, wmOperator *op) | ||||
| if (success) { | if (success) { | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| else { | else { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| static OperatorDispatchTarget wm_open_mainfile_dispatch_targets[] = { | |||||
| {OPEN_MAINFILE_STATE_DISCARD_CHANGES, wm_open_mainfile__discard_changes}, | |||||
| {OPEN_MAINFILE_STATE_SELECT_FILE_PATH, wm_open_mainfile__select_file_path}, | |||||
| {OPEN_MAINFILE_STATE_OPEN, wm_open_mainfile__open}, | |||||
| {0, NULL}, | |||||
| }; | |||||
| static int wm_open_mainfile_dispatch(bContext *C, wmOperator *op) | |||||
| { | |||||
| return operator_state_dispatch(C, op, wm_open_mainfile_dispatch_targets); | |||||
| } | |||||
| static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | |||||
| { | |||||
| return wm_open_mainfile_dispatch(C, op); | |||||
| } | |||||
| static int wm_open_mainfile_exec(bContext *C, wmOperator *op) | |||||
| { | |||||
| return wm_open_mainfile__open(C, op); | |||||
| } | |||||
| /* currently fits in a pointer */ | |||||
| struct FileRuntime { | |||||
| bool is_untrusted; | |||||
| }; | |||||
| static bool wm_open_mainfile_check(bContext *UNUSED(C), wmOperator *op) | static bool wm_open_mainfile_check(bContext *UNUSED(C), wmOperator *op) | ||||
| { | { | ||||
| struct FileRuntime *file_info = (struct FileRuntime *)&op->customdata; | struct FileRuntime *file_info = (struct FileRuntime *)&op->customdata; | ||||
| PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts"); | PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts"); | ||||
| bool is_untrusted = false; | bool is_untrusted = false; | ||||
| char path[FILE_MAX]; | char path[FILE_MAX]; | ||||
| char *lslash; | char *lslash; | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | void WM_OT_open_mainfile(wmOperatorType *ot) | ||||
| RNA_def_boolean( | RNA_def_boolean( | ||||
| ot->srna, "load_ui", true, "Load UI", "Load user interface setup in the .blend file"); | ot->srna, "load_ui", true, "Load UI", "Load user interface setup in the .blend file"); | ||||
| RNA_def_boolean(ot->srna, | RNA_def_boolean(ot->srna, | ||||
| "use_scripts", | "use_scripts", | ||||
| true, | true, | ||||
| "Trusted Source", | "Trusted Source", | ||||
| "Allow .blend file to execute scripts automatically, default available from " | "Allow .blend file to execute scripts automatically, default available from " | ||||
| "system preferences"); | "system preferences"); | ||||
| PropertyRNA *prop = RNA_def_boolean( | |||||
| ot->srna, "display_file_selector", true, "Display File Selector", ""); | |||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | |||||
Not Done Inline ActionsThe default for this should be true. brecht: The default for this should be `true`. | |||||
| create_operator_state(ot, OPEN_MAINFILE_STATE_DISCARD_CHANGES); | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /** \name Reload (revert) main .blend file. | /** \name Reload (revert) main .blend file. | ||||
| * | * | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 536 Lines • Show Last 20 Lines | |||||
Should also have PROP_HIDDEN.