Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/util/ed_util_ops.cc
| Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | WM_operator_properties_filesel(ot, | ||||
| FILE_TYPE_FOLDER | FILE_TYPE_IMAGE, | FILE_TYPE_FOLDER | FILE_TYPE_IMAGE, | ||||
| FILE_SPECIAL, | FILE_SPECIAL, | ||||
| FILE_OPENFILE, | FILE_OPENFILE, | ||||
| WM_FILESEL_FILEPATH, | WM_FILESEL_FILEPATH, | ||||
| FILE_DEFAULTDISPLAY, | FILE_DEFAULTDISPLAY, | ||||
| FILE_SORT_DEFAULT); | FILE_SORT_DEFAULT); | ||||
| } | } | ||||
| static bool lib_id_generate_preview_poll(bContext *C) | |||||
| { | |||||
| if (!lib_id_preview_editing_poll(C)) { | |||||
| return false; | |||||
| } | |||||
| const PointerRNA idptr = CTX_data_pointer_get(C, "id"); | |||||
| const ID *id = (ID *)idptr.data; | |||||
| if (GS(id->name) == ID_NT) { | |||||
| CTX_wm_operator_poll_msg_set(C, TIP_("Can't generate automatic preview for node group")); | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | |||||
| static int lib_id_generate_preview_exec(bContext *C, wmOperator *UNUSED(op)) | static int lib_id_generate_preview_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| PointerRNA idptr = CTX_data_pointer_get(C, "id"); | PointerRNA idptr = CTX_data_pointer_get(C, "id"); | ||||
| ID *id = (ID *)idptr.data; | ID *id = (ID *)idptr.data; | ||||
| ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); | ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); | ||||
| PreviewImage *preview = BKE_previewimg_id_get(id); | PreviewImage *preview = BKE_previewimg_id_get(id); | ||||
| Show All 11 Lines | |||||
| static void ED_OT_lib_id_generate_preview(wmOperatorType *ot) | static void ED_OT_lib_id_generate_preview(wmOperatorType *ot) | ||||
| { | { | ||||
| ot->name = "Generate Preview"; | ot->name = "Generate Preview"; | ||||
| ot->description = "Create an automatic preview for the selected data-block"; | ot->description = "Create an automatic preview for the selected data-block"; | ||||
| ot->idname = "ED_OT_lib_id_generate_preview"; | ot->idname = "ED_OT_lib_id_generate_preview"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->poll = lib_id_preview_editing_poll; | ot->poll = lib_id_generate_preview_poll; | ||||
| ot->exec = lib_id_generate_preview_exec; | ot->exec = lib_id_generate_preview_exec; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_INTERNAL | OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_INTERNAL | OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| static bool lib_id_generate_preview_from_object_poll(bContext *C) | |||||
| { | |||||
| if (!lib_id_preview_editing_poll(C)) { | |||||
| return false; | |||||
| } | |||||
| if (CTX_data_active_object(C) == nullptr) { | |||||
| return false; | |||||
| } | |||||
Severin: Bonus points if you add a disabled hint via `CTX_wm_operator_poll_msg_set()` ;) | |||||
| return true; | |||||
| } | |||||
| static int lib_id_generate_preview_from_object_exec(bContext *C, wmOperator *UNUSED(op)) | |||||
| { | |||||
| PointerRNA idptr = CTX_data_pointer_get(C, "id"); | |||||
| ID *id = (ID *)idptr.data; | |||||
| ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); | |||||
| Object *object_to_render = CTX_data_active_object(C); | |||||
| BKE_previewimg_id_free(id); | |||||
| PreviewImage *preview_image = BKE_previewimg_id_ensure(id); | |||||
| UI_icon_render_id_ex(C, nullptr, &object_to_render->id, ICON_SIZE_PREVIEW, true, preview_image); | |||||
Not Done Inline ActionsBKE_previewimg_id_ensure() returns the preview-image, no need to call the getter again. Severin: `BKE_previewimg_id_ensure()` returns the preview-image, no need to call the getter again. | |||||
| WM_event_add_notifier(C, NC_ASSET | NA_EDITED, nullptr); | |||||
| ED_assetlist_storage_tag_main_data_dirty(); | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static void ED_OT_lib_id_generate_preview_from_object(wmOperatorType *ot) | |||||
| { | |||||
| ot->name = "Generate Preview from Object"; | |||||
| ot->description = "Create a preview for this asset by rendering the active object"; | |||||
| ot->idname = "ED_OT_lib_id_generate_preview_from_object"; | |||||
| /* api callbacks */ | |||||
| ot->poll = lib_id_generate_preview_from_object_poll; | |||||
| ot->exec = lib_id_generate_preview_from_object_exec; | |||||
| /* flags */ | |||||
| ot->flag = OPTYPE_INTERNAL | OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| } | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Generic ID Operators | /** \name Generic ID Operators | ||||
| * \{ */ | * \{ */ | ||||
| static int lib_id_fake_user_toggle_exec(bContext *C, wmOperator *op) | static int lib_id_fake_user_toggle_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| void ED_operatortypes_edutils() | void ED_operatortypes_edutils() | ||||
| { | { | ||||
| WM_operatortype_append(ED_OT_lib_id_load_custom_preview); | WM_operatortype_append(ED_OT_lib_id_load_custom_preview); | ||||
| WM_operatortype_append(ED_OT_lib_id_generate_preview); | WM_operatortype_append(ED_OT_lib_id_generate_preview); | ||||
| WM_operatortype_append(ED_OT_lib_id_generate_preview_from_object); | |||||
| WM_operatortype_append(ED_OT_lib_id_fake_user_toggle); | WM_operatortype_append(ED_OT_lib_id_fake_user_toggle); | ||||
| WM_operatortype_append(ED_OT_lib_id_unlink); | WM_operatortype_append(ED_OT_lib_id_unlink); | ||||
| WM_operatortype_append(ED_OT_flush_edits); | WM_operatortype_append(ED_OT_flush_edits); | ||||
| WM_operatortype_append(ED_OT_undo); | WM_operatortype_append(ED_OT_undo); | ||||
| WM_operatortype_append(ED_OT_undo_push); | WM_operatortype_append(ED_OT_undo_push); | ||||
| WM_operatortype_append(ED_OT_redo); | WM_operatortype_append(ED_OT_redo); | ||||
| WM_operatortype_append(ED_OT_undo_redo); | WM_operatortype_append(ED_OT_undo_redo); | ||||
| WM_operatortype_append(ED_OT_undo_history); | WM_operatortype_append(ED_OT_undo_history); | ||||
| } | } | ||||
Bonus points if you add a disabled hint via CTX_wm_operator_poll_msg_set() ;)