Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/io/io_cache.c
| Show All 32 Lines | |||||
| #include "BKE_cachefile.h" | #include "BKE_cachefile.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "DEG_depsgraph.h" | |||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "io_cache.h" | #include "io_cache.h" | ||||
| static void cachefile_init(bContext *C, wmOperator *op) | static void cachefile_init(bContext *C, wmOperator *op) | ||||
| Show All 39 Lines | static int cachefile_open_exec(bContext *C, wmOperator *op) | ||||
| char filename[FILE_MAX]; | char filename[FILE_MAX]; | ||||
| RNA_string_get(op->ptr, "filepath", filename); | RNA_string_get(op->ptr, "filepath", filename); | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, BLI_path_basename(filename), 0); | CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, BLI_path_basename(filename), 0); | ||||
| BLI_strncpy(cache_file->filepath, filename, FILE_MAX); | BLI_strncpy(cache_file->filepath, filename, FILE_MAX); | ||||
| BKE_cachefile_reload(bmain, cache_file); | DEG_id_tag_update(&cache_file->id, ID_RECALC_COPY_ON_WRITE); | ||||
| /* Will be set when running invoke, not exec directly. */ | /* Will be set when running invoke, not exec directly. */ | ||||
| if (op->customdata != NULL) { | if (op->customdata != NULL) { | ||||
| /* hook into UI */ | /* hook into UI */ | ||||
| PropertyPointerRNA *pprop = op->customdata; | PropertyPointerRNA *pprop = op->customdata; | ||||
| if (pprop->prop) { | if (pprop->prop) { | ||||
| /* When creating new ID blocks, use is already 1, but RNA | /* When creating new ID blocks, use is already 1, but RNA | ||||
| * pointer see also increases user, so this compensates it. */ | * pointer see also increases user, so this compensates it. */ | ||||
| Show All 27 Lines | WM_operator_properties_filesel(ot, | ||||
| FILE_SAVE, | FILE_SAVE, | ||||
| WM_FILESEL_FILEPATH, | WM_FILESEL_FILEPATH, | ||||
| FILE_DEFAULTDISPLAY, | FILE_DEFAULTDISPLAY, | ||||
| FILE_SORT_ALPHA); | FILE_SORT_ALPHA); | ||||
| } | } | ||||
| /* ***************************** Reload Operator **************************** */ | /* ***************************** Reload Operator **************************** */ | ||||
| static int cachefile_reload_exec(bContext *C, wmOperator *op) | static int cachefile_reload_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| CacheFile *cache_file = CTX_data_edit_cachefile(C); | CacheFile *cache_file = CTX_data_edit_cachefile(C); | ||||
| if (!cache_file) { | if (!cache_file) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| Main *bmain = CTX_data_main(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| BKE_cachefile_reload(depsgraph, cache_file); | |||||
| BLI_freelistN(&cache_file->object_paths); | |||||
| BKE_cachefile_reload(bmain, cache_file); | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| UNUSED_VARS(op); | |||||
| } | } | ||||
| void CACHEFILE_OT_reload(wmOperatorType *ot) | void CACHEFILE_OT_reload(wmOperatorType *ot) | ||||
| { | { | ||||
| ot->name = "Refresh Archive"; | ot->name = "Refresh Archive"; | ||||
| ot->description = "Update objects paths list with new data from the archive"; | ot->description = "Update objects paths list with new data from the archive"; | ||||
| ot->idname = "CACHEFILE_OT_reload"; | ot->idname = "CACHEFILE_OT_reload"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->exec = cachefile_reload_exec; | ot->exec = cachefile_reload_exec; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||