Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_files.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| "Remap relative paths when saving to a different directory"); | "Remap relative paths when saving to a different directory"); | ||||
| prop = RNA_def_boolean(ot->srna, "exit", false, "Exit", "Exit Blender after saving"); | prop = RNA_def_boolean(ot->srna, "exit", false, "Exit", "Exit Blender after saving"); | ||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Save Main .blend File Incremental Operator | |||||
| * | |||||
| * \{ */ | |||||
| static int wm_save_mainfile_incremental_exec(bContext *C, wmOperator *op) | |||||
| { | |||||
| Main *bmain = CTX_data_main(C); | |||||
| const char *blendfile_path = BKE_main_blendfile_path(bmain); | |||||
| if (blendfile_path[0] == '\0') { | |||||
| BKE_report(op->reports, RPT_ERROR, "Unsaved file cannot be incremented"); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| char head[FILE_MAXFILE], tail[FILE_MAXFILE], path[FILE_MAXFILE]; | |||||
| ushort digits; | |||||
| int num = BLI_path_sequence_decode(blendfile_path, head, tail, &digits); | |||||
| int tries = 0; | |||||
| do { | |||||
| num++; | |||||
| tries++; | |||||
| BLI_path_sequence_encode(path, head, tail, digits, num); | |||||
| } while (BLI_exists(path) && tries < 1000); | |||||
| if (tries == 1000) { | |||||
| BKE_report(op->reports, RPT_ERROR, "Unable to find an available incremented file name"); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| if (!wm_file_write(C, path, G.fileflags, BLO_WRITE_PATH_REMAP_RELATIVE, false, op->reports)) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| WM_event_add_notifier(C, NC_WM | ND_FILESAVE, NULL); | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static bool wm_save_mainfile_incremental_poll(bContext *C) | |||||
| { | |||||
| Main *bmain = CTX_data_main(C); | |||||
| const char *blendfile_path = BKE_main_blendfile_path(bmain); | |||||
| return (blendfile_path[0] != '\0'); | |||||
| } | |||||
| void WM_OT_save_mainfile_incremental(wmOperatorType *ot) | |||||
| { | |||||
| ot->name = "Save Incremental"; | |||||
| ot->idname = "WM_OT_save_mainfile_incremental"; | |||||
| ot->description = "Save the current Blender file with incremented name"; | |||||
| ot->exec = wm_save_mainfile_incremental_exec; | |||||
| ot->poll = wm_save_mainfile_incremental_poll; | |||||
| } | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Auto Script Execution Warning Dialog | /** \name Auto Script Execution Warning Dialog | ||||
| * \{ */ | * \{ */ | ||||
| static void wm_block_autorun_warning_ignore(bContext *C, void *arg_block, void *UNUSED(arg)) | static void wm_block_autorun_warning_ignore(bContext *C, void *arg_block, void *UNUSED(arg)) | ||||
| { | { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| UI_popup_block_close(C, win, arg_block); | UI_popup_block_close(C, win, arg_block); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||