Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_outliner/outliner_edit.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| RNA_int_set(op->ptr, "num_deleted", num_tagged[INDEX_ID_NULL]); | RNA_int_set(op->ptr, "num_deleted", num_tagged[INDEX_ID_NULL]); | ||||
| if (num_tagged[INDEX_ID_NULL] == 0) { | if (num_tagged[INDEX_ID_NULL] == 0) { | ||||
| BKE_report(op->reports, RPT_INFO, "No orphaned data-blocks to purge"); | BKE_report(op->reports, RPT_INFO, "No orphaned data-blocks to purge"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| DynStr *dyn_str = BLI_dynstr_new(); | return WM_operator_confirm(C, op, NULL); | ||||
| BLI_dynstr_appendf(dyn_str, "Purging %d unused data-blocks (", num_tagged[INDEX_ID_NULL]); | |||||
| bool is_first = true; | |||||
| for (int i = 0; i < INDEX_ID_MAX - 2; i++) { | |||||
| if (num_tagged[i] != 0) { | |||||
| if (!is_first) { | |||||
| BLI_dynstr_append(dyn_str, ", "); | |||||
| } | |||||
| else { | |||||
| is_first = false; | |||||
| } | |||||
| BLI_dynstr_appendf(dyn_str, | |||||
| "%d %s", | |||||
| num_tagged[i], | |||||
| TIP_(BKE_idtype_idcode_to_name_plural(BKE_idtype_idcode_from_index(i)))); | |||||
| } | |||||
| } | |||||
| BLI_dynstr_append(dyn_str, TIP_("). Click here to proceed...")); | |||||
| char *message = BLI_dynstr_get_cstring(dyn_str); | |||||
| int ret = WM_operator_confirm_message(C, op, message); | |||||
| MEM_freeN(message); | |||||
| BLI_dynstr_free(dyn_str); | |||||
| return ret; | |||||
| } | } | ||||
| static int outliner_orphans_purge_exec(bContext *C, wmOperator *op) | static int outliner_orphans_purge_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| ScrArea *area = CTX_wm_area(C); | ScrArea *area = CTX_wm_area(C); | ||||
| SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); | SpaceOutliner *space_outliner = CTX_wm_space_outliner(C); | ||||
| int num_tagged[INDEX_ID_MAX] = {0}; | int num_tagged[INDEX_ID_MAX] = {0}; | ||||
| Show All 29 Lines | |||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| WM_event_add_notifier(C, NC_ID | NA_REMOVED, nullptr); | WM_event_add_notifier(C, NC_ID | NA_REMOVED, nullptr); | ||||
| /* Force full redraw of the UI. */ | /* Force full redraw of the UI. */ | ||||
| WM_main_add_notifier(NC_WINDOW, nullptr); | WM_main_add_notifier(NC_WINDOW, nullptr); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void orphans_purge_warning(bContext *C, wmOperator *op, wmWarningDetails *warning) | |||||
| { | |||||
| Main *bmain = CTX_data_main(C); | |||||
| int num_tagged[INDEX_ID_MAX] = {0}; | |||||
| const bool do_local_ids = RNA_boolean_get(op->ptr, "do_local_ids"); | |||||
| const bool do_linked_ids = RNA_boolean_get(op->ptr, "do_linked_ids"); | |||||
| const bool do_recursive_cleanup = RNA_boolean_get(op->ptr, "do_recursive"); | |||||
| /* Tag all IDs to delete. */ | |||||
| BKE_lib_query_unused_ids_tag( | |||||
| bmain, LIB_TAG_DOIT, do_local_ids, do_linked_ids, do_recursive_cleanup, num_tagged); | |||||
| DynStr *dyn_str = BLI_dynstr_new(); | |||||
| bool is_first = true; | |||||
| for (int i = 0; i < INDEX_ID_MAX - 2; i++) { | |||||
| if (num_tagged[i] != 0) { | |||||
| if (!is_first) { | |||||
| BLI_dynstr_append(dyn_str, ", "); | |||||
| } | |||||
| else { | |||||
| is_first = false; | |||||
| } | |||||
| BLI_dynstr_appendf(dyn_str, | |||||
| "%d %s", | |||||
| num_tagged[i], | |||||
| TIP_(BKE_idtype_idcode_to_name_plural(BKE_idtype_idcode_from_index(i)))); | |||||
| } | |||||
| } | |||||
| STRNCPY(warning->title, IFACE_("Remove Unused Data")); | |||||
| STRNCPY(warning->message, BLI_dynstr_get_cstring(dyn_str)); | |||||
| STRNCPY(warning->confirm_button, TIP_("Purge")); | |||||
| BLI_dynstr_free(dyn_str); | |||||
| } | |||||
| void OUTLINER_OT_orphans_purge(wmOperatorType *ot) | void OUTLINER_OT_orphans_purge(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->idname = "OUTLINER_OT_orphans_purge"; | ot->idname = "OUTLINER_OT_orphans_purge"; | ||||
| ot->name = "Purge All"; | ot->name = "Purge All"; | ||||
| ot->description = "Clear all orphaned data-blocks without any users from the file"; | ot->description = "Clear all orphaned data-blocks without any users from the file"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->invoke = outliner_orphans_purge_invoke; | ot->invoke = outliner_orphans_purge_invoke; | ||||
| ot->exec = outliner_orphans_purge_exec; | ot->exec = outliner_orphans_purge_exec; | ||||
| ot->poll = ed_operator_outliner_id_orphans_active; | ot->poll = ed_operator_outliner_id_orphans_active; | ||||
| ot->warning = orphans_purge_warning; | |||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| PropertyRNA *prop = RNA_def_int(ot->srna, "num_deleted", 0, 0, INT_MAX, "", "", 0, INT_MAX); | PropertyRNA *prop = RNA_def_int(ot->srna, "num_deleted", 0, 0, INT_MAX, "", "", 0, INT_MAX); | ||||
| RNA_def_property_flag(prop, (PropertyFlag)(PROP_SKIP_SAVE | PROP_HIDDEN)); | RNA_def_property_flag(prop, (PropertyFlag)(PROP_SKIP_SAVE | PROP_HIDDEN)); | ||||
| Show All 22 Lines | |||||