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
path: root/source
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-12-23 16:25:58 +0300
committerJulian Eisel <julian@blender.org>2020-12-23 16:34:24 +0300
commit27fcaa61733827dbb81b69fdeec0db2f656c6f03 (patch)
tree26e279f330c22e7362bf6b685a2af7cc1c809aea /source
parent78d2ce19c4fbb5678995efae74a6128a3dcc4e73 (diff)
Cleanup: Move functions to new ED (editor) operators file & general cleanup
With the new `ed_util_ops.c` introduced in 2250b5cefee7, existing code can be cleaned up to use it. * Move new ID preview operators to `ed_util_ops.c` * Move ED operator registration to `ed_util_ops.c` * Use doxygen sections in `ed_util_ops.c` * Rename ID related ED operators to use `ED_OT_lib_id_` prefix. * Remove unused `#include`s
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/include/ED_util.h3
-rw-r--r--source/blender/editors/interface/interface_templates.c4
-rw-r--r--source/blender/editors/screen/screen_ops.c10
-rw-r--r--source/blender/editors/util/ed_util.c117
-rw-r--r--source/blender/editors/util/ed_util_ops.c156
5 files changed, 148 insertions, 142 deletions
diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h
index 1e87a940a7d..54e2b3ba501 100644
--- a/source/blender/editors/include/ED_util.h
+++ b/source/blender/editors/include/ED_util.h
@@ -52,9 +52,6 @@ void ED_spacedata_id_remap(struct ScrArea *area,
struct ID *old_id,
struct ID *new_id);
-void ED_OT_lib_id_load_custom_preview(struct wmOperatorType *ot);
-void ED_OT_lib_id_generate_preview(struct wmOperatorType *ot);
-
void ED_operatortypes_edutils(void);
/* ************** XXX OLD CRUFT WARNING ************* */
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index f134038918d..8349577ff04 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1392,7 +1392,7 @@ static void template_id_name_button(
UI_but_extra_operator_icon_add(but, template_ui->unlink_op, WM_OP_INVOKE_DEFAULT, ICON_X);
}
else if (!never_unlink) {
- UI_but_extra_operator_icon_add(but, "ED_OT_lib_unlink", WM_OP_INVOKE_DEFAULT, ICON_X);
+ UI_but_extra_operator_icon_add(but, "ED_OT_lib_id_unlink", WM_OP_INVOKE_DEFAULT, ICON_X);
}
}
@@ -1401,7 +1401,7 @@ static void template_id_name_button(
if (add_extra_fake_user_icon && id->lib == NULL &&
!(ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_TXT, ID_OB, ID_WS))) {
UI_but_extra_operator_icon_add(but,
- "ED_OT_lib_fake_user_toggle",
+ "ED_OT_lib_id_fake_user_toggle",
WM_OP_INVOKE_DEFAULT,
ID_FAKE_USERS(id) ? ICON_FAKE_USER_ON : ICON_FAKE_USER_OFF);
}
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 87255bf8b5c..ca0b9aa93b7 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -5506,16 +5506,6 @@ void ED_operatortypes_screen(void)
/* new/delete */
WM_operatortype_append(SCREEN_OT_new);
WM_operatortype_append(SCREEN_OT_delete);
-
- /* tools shared by more space types */
- WM_operatortype_append(ED_OT_undo);
- WM_operatortype_append(ED_OT_undo_push);
- WM_operatortype_append(ED_OT_redo);
- WM_operatortype_append(ED_OT_undo_redo);
- WM_operatortype_append(ED_OT_undo_history);
-
- 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 5d2584c566d..4b1335cf047 100644
--- a/source/blender/editors/util/ed_util.c
+++ b/source/blender/editors/util/ed_util.c
@@ -29,50 +29,34 @@
#include "DNA_armature_types.h"
#include "DNA_mesh_types.h"
-#include "DNA_object_types.h"
-#include "DNA_packedFile_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_space_types.h"
-#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
-#include "BLI_utildefines.h"
#include "BLT_translation.h"
-#include "BKE_context.h"
#include "BKE_global.h"
-#include "BKE_icons.h"
-#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_multires.h"
#include "BKE_object.h"
#include "BKE_packedFile.h"
#include "BKE_paint.h"
-#include "BKE_report.h"
#include "BKE_screen.h"
#include "BKE_undo_system.h"
-#include "BKE_workspace.h"
#include "DEG_depsgraph.h"
#include "ED_armature.h"
#include "ED_image.h"
#include "ED_mesh.h"
-#include "ED_node.h"
#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"
#include "GPU_immediate.h"
-#include "GPU_state.h"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -484,104 +468,3 @@ void ED_spacedata_id_remap(struct ScrArea *area, struct SpaceLink *sl, ID *old_i
st->id_remap(area, sl, old_id, new_id);
}
}
-
-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));
-
- const ID *id = idptr.data;
- if (!id) {
- return false;
- }
- if (ID_IS_LINKED(id)) {
- CTX_wm_operator_poll_msg_set(C, TIP_("Can't edit external library data"));
- return false;
- }
- if (ID_IS_OVERRIDE_LIBRARY(id)) {
- CTX_wm_operator_poll_msg_set(C, TIP_("Can't edit previews of overridden library data"));
- return false;
- }
- if (!BKE_previewimg_id_get_p(id)) {
- CTX_wm_operator_poll_msg_set(C, TIP_("Data-block does not support previews"));
- return false;
- }
-
- return true;
-}
-
-static int lib_id_load_custom_preview_exec(bContext *C, wmOperator *op)
-{
- char path[FILE_MAX];
-
- RNA_string_get(op->ptr, "filepath", path);
-
- if (!BLI_is_file(path)) {
- BKE_reportf(op->reports, RPT_ERROR, "File not found '%s'", path);
- return OPERATOR_CANCELLED;
- }
-
- PointerRNA idptr = CTX_data_pointer_get(C, "id");
- ID *id = idptr.data;
-
- BKE_previewimg_id_custom_set(id, path);
-
- WM_event_add_notifier(C, NC_ASSET, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-void ED_OT_lib_id_load_custom_preview(wmOperatorType *ot)
-{
- ot->name = "Load Custom Preview";
- ot->description = "Choose an image to help identify the data-block visually";
- ot->idname = "ED_OT_lib_id_load_custom_preview";
-
- /* api callbacks */
- ot->poll = lib_id_preview_editing_poll;
- ot->exec = lib_id_load_custom_preview_exec;
- ot->invoke = WM_operator_filesel;
-
- /* flags */
- ot->flag = OPTYPE_INTERNAL;
-
- WM_operator_properties_filesel(ot,
- FILE_TYPE_FOLDER | FILE_TYPE_IMAGE,
- FILE_SPECIAL,
- FILE_OPENFILE,
- WM_FILESEL_FILEPATH,
- 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;
-}
diff --git a/source/blender/editors/util/ed_util_ops.c b/source/blender/editors/util/ed_util_ops.c
index d8d1a64c1ee..88df20c5966 100644
--- a/source/blender/editors/util/ed_util_ops.c
+++ b/source/blender/editors/util/ed_util_ops.c
@@ -22,15 +22,22 @@
#include <string.h>
+#include "BLI_fileops.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
+#include "BKE_icons.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_report.h"
+#include "BLT_translation.h"
+
+#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h"
+#include "ED_render.h"
+#include "ED_undo.h"
#include "ED_util.h"
#include "RNA_access.h"
@@ -40,7 +47,118 @@
#include "WM_api.h"
#include "WM_types.h"
-static int lib_fake_user_toggle_exec(bContext *C, wmOperator *op)
+/* -------------------------------------------------------------------- */
+/** \name ID Previews
+ * \{ */
+
+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));
+
+ const ID *id = idptr.data;
+ if (!id) {
+ return false;
+ }
+ if (ID_IS_LINKED(id)) {
+ CTX_wm_operator_poll_msg_set(C, TIP_("Can't edit external library data"));
+ return false;
+ }
+ if (ID_IS_OVERRIDE_LIBRARY(id)) {
+ CTX_wm_operator_poll_msg_set(C, TIP_("Can't edit previews of overridden library data"));
+ return false;
+ }
+ if (!BKE_previewimg_id_get_p(id)) {
+ CTX_wm_operator_poll_msg_set(C, TIP_("Data-block does not support previews"));
+ return false;
+ }
+
+ return true;
+}
+
+static int lib_id_load_custom_preview_exec(bContext *C, wmOperator *op)
+{
+ char path[FILE_MAX];
+
+ RNA_string_get(op->ptr, "filepath", path);
+
+ if (!BLI_is_file(path)) {
+ BKE_reportf(op->reports, RPT_ERROR, "File not found '%s'", path);
+ return OPERATOR_CANCELLED;
+ }
+
+ PointerRNA idptr = CTX_data_pointer_get(C, "id");
+ ID *id = idptr.data;
+
+ BKE_previewimg_id_custom_set(id, path);
+
+ WM_event_add_notifier(C, NC_ASSET, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+static void ED_OT_lib_id_load_custom_preview(wmOperatorType *ot)
+{
+ ot->name = "Load Custom Preview";
+ ot->description = "Choose an image to help identify the data-block visually";
+ ot->idname = "ED_OT_lib_id_load_custom_preview";
+
+ /* api callbacks */
+ ot->poll = lib_id_preview_editing_poll;
+ ot->exec = lib_id_load_custom_preview_exec;
+ ot->invoke = WM_operator_filesel;
+
+ /* flags */
+ ot->flag = OPTYPE_INTERNAL;
+
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_FOLDER | FILE_TYPE_IMAGE,
+ FILE_SPECIAL,
+ FILE_OPENFILE,
+ WM_FILESEL_FILEPATH,
+ 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;
+}
+
+static 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;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Generic ID Operators
+ * \{ */
+
+static int lib_id_fake_user_toggle_exec(bContext *C, wmOperator *op)
{
PropertyPointerRNA pprop;
PointerRNA idptr = PointerRNA_NULL;
@@ -74,21 +192,21 @@ static int lib_fake_user_toggle_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
-static void ED_OT_lib_fake_user_toggle(wmOperatorType *ot)
+static void ED_OT_lib_id_fake_user_toggle(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Toggle Fake User";
ot->description = "Save this data-block even if it has no users";
- ot->idname = "ED_OT_lib_fake_user_toggle";
+ ot->idname = "ED_OT_lib_id_fake_user_toggle";
/* api callbacks */
- ot->exec = lib_fake_user_toggle_exec;
+ ot->exec = lib_id_fake_user_toggle_exec;
/* flags */
ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
}
-static int lib_unlink_exec(bContext *C, wmOperator *op)
+static int lib_id_unlink_exec(bContext *C, wmOperator *op)
{
PropertyPointerRNA pprop;
PointerRNA idptr;
@@ -112,20 +230,26 @@ static int lib_unlink_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
-static void ED_OT_lib_unlink(wmOperatorType *ot)
+static void ED_OT_lib_id_unlink(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Unlink Data-Block";
ot->description = "Remove a usage of a data-block, clearing the assignment";
- ot->idname = "ED_OT_lib_unlink";
+ ot->idname = "ED_OT_lib_id_unlink";
/* api callbacks */
- ot->exec = lib_unlink_exec;
+ ot->exec = lib_id_unlink_exec;
/* flags */
ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name General editor utils.
+ * \{ */
+
static int ed_flush_edits_exec(bContext *C, wmOperator *UNUSED(op))
{
Main *bmain = CTX_data_main(C);
@@ -147,9 +271,21 @@ static void ED_OT_flush_edits(wmOperatorType *ot)
ot->flag = OPTYPE_INTERNAL;
}
+/** \} */
+
void ED_operatortypes_edutils(void)
{
- WM_operatortype_append(ED_OT_lib_fake_user_toggle);
- WM_operatortype_append(ED_OT_lib_unlink);
+ 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_fake_user_toggle);
+ WM_operatortype_append(ED_OT_lib_id_unlink);
+
WM_operatortype_append(ED_OT_flush_edits);
+
+ WM_operatortype_append(ED_OT_undo);
+ WM_operatortype_append(ED_OT_undo_push);
+ WM_operatortype_append(ED_OT_redo);
+ WM_operatortype_append(ED_OT_undo_redo);
+ WM_operatortype_append(ED_OT_undo_history);
}