Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-12-16 13:44:22 +0300
committerJulian Eisel <julian@blender.org>2020-12-16 14:10:58 +0300
commit58d818f8bebf8c08b528d1637c93f15d2559cca1 (patch)
tree2b7f0b7ce67238620b1118562d0360feb20ef535
parentc7a500e3a0fa0721eb1771a422b6b17255692843 (diff)
Assets: Add operator & button to regenerate the automatic preview
This makes it possible to trigger a refresh of the data-block preview, available next to the preview in the Asset Browser sidebar. The previews get easily outdated and automatically refreshing it all the time is not an option because it would be a consistently running, quite expensive process. So a button to cause a refresh should be reasonable. This button can also be used to switch back from a custom preview to a generated one. Although that may not be clear, and we should probably think of a way to explain that better. Addresses T82719.
-rw-r--r--release/scripts/startup/bl_ui/space_filebrowser.py2
-rw-r--r--source/blender/editors/include/ED_util.h1
-rw-r--r--source/blender/editors/screen/screen_ops.c1
-rw-r--r--source/blender/editors/util/ed_util.c37
4 files changed, 39 insertions, 2 deletions
diff --git a/release/scripts/startup/bl_ui/space_filebrowser.py b/release/scripts/startup/bl_ui/space_filebrowser.py
index 98368f304d9..58a4269ab96 100644
--- a/release/scripts/startup/bl_ui/space_filebrowser.py
+++ b/release/scripts/startup/bl_ui/space_filebrowser.py
@@ -609,6 +609,8 @@ class ASSETBROWSER_PT_metadata_preview(asset_utils.AssetMetaDataPanel, Panel):
if bpy.ops.ed.lib_id_load_custom_preview.poll():
col = row.column(align=True)
col.operator("ed.lib_id_load_custom_preview", icon='FILEBROWSER', text="")
+ col.separator()
+ col.operator("ed.lib_id_generate_preview", icon='FILE_REFRESH', text="")
class ASSETBROWSER_PT_metadata_details(asset_utils.AssetMetaDataPanel, Panel):
diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h
index d74a80045f1..ca6b4bdc618 100644
--- a/source/blender/editors/include/ED_util.h
+++ b/source/blender/editors/include/ED_util.h
@@ -54,6 +54,7 @@ void ED_spacedata_id_remap(struct ScrArea *area,
void ED_OT_flush_edits(struct wmOperatorType *ot);
void ED_OT_lib_id_load_custom_preview(struct wmOperatorType *ot);
+void ED_OT_lib_id_generate_preview(struct wmOperatorType *ot);
/* ************** XXX OLD CRUFT WARNING ************* */
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index a0c5762c73c..51687d5de1d 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -5511,6 +5511,7 @@ void ED_operatortypes_screen(void)
WM_operatortype_append(ED_OT_flush_edits);
WM_operatortype_append(ED_OT_lib_id_load_custom_preview);
+ WM_operatortype_append(ED_OT_lib_id_generate_preview);
}
/** \} */
diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c
index 4740e4d8d33..d78758dcc1c 100644
--- a/source/blender/editors/util/ed_util.c
+++ b/source/blender/editors/util/ed_util.c
@@ -67,6 +67,7 @@
#include "ED_object.h"
#include "ED_outliner.h"
#include "ED_paint.h"
+#include "ED_render.h"
#include "ED_space_api.h"
#include "ED_util.h"
@@ -505,7 +506,7 @@ void ED_OT_flush_edits(wmOperatorType *ot)
ot->flag = OPTYPE_INTERNAL;
}
-static bool lib_id_load_custom_preview_poll(bContext *C)
+static bool lib_id_preview_editing_poll(bContext *C)
{
const PointerRNA idptr = CTX_data_pointer_get(C, "id");
BLI_assert(!idptr.data || RNA_struct_is_ID(idptr.type));
@@ -558,7 +559,7 @@ void ED_OT_lib_id_load_custom_preview(wmOperatorType *ot)
ot->idname = "ED_OT_lib_id_load_custom_preview";
/* api callbacks */
- ot->poll = lib_id_load_custom_preview_poll;
+ ot->poll = lib_id_preview_editing_poll;
ot->exec = lib_id_load_custom_preview_exec;
ot->invoke = WM_operator_filesel;
@@ -573,3 +574,35 @@ void ED_OT_lib_id_load_custom_preview(wmOperatorType *ot)
FILE_DEFAULTDISPLAY,
FILE_SORT_DEFAULT);
}
+
+static int lib_id_generate_preview_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ PointerRNA idptr = CTX_data_pointer_get(C, "id");
+ ID *id = idptr.data;
+
+ ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
+
+ PreviewImage *preview = BKE_previewimg_id_get(id);
+ if (preview) {
+ BKE_previewimg_clear(preview);
+ }
+ UI_icon_render_id(C, NULL, id, true, true);
+
+ WM_event_add_notifier(C, NC_ASSET, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+void ED_OT_lib_id_generate_preview(wmOperatorType *ot)
+{
+ ot->name = "Generate Preview";
+ ot->description = "Create an automatic preview for the selected data-block";
+ ot->idname = "ED_OT_lib_id_generate_preview";
+
+ /* api callbacks */
+ ot->poll = lib_id_preview_editing_poll;
+ ot->exec = lib_id_generate_preview_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_INTERNAL;
+}