Refactor: De-duplicate mask operator poll functions

The poll function with same semantic was defined in both screen and
mask space modules. The only reason for this seems to be that the
image editor needed a mask poll function which was private to the
mask module.

Make the mask editing poll functions public, avoiding code duplication.

Also, added a brief explanation about what the poll functions are
checking for.

No user-level changes are expected to happen.
This commit is contained in:
Sergey Sharybin 2022-06-17 09:58:23 +02:00
parent f8cec1ff30
commit e658c8851a
8 changed files with 21 additions and 37 deletions

View File

@ -22,6 +22,19 @@ struct wmKeyConfig;
/* mask_edit.c */
/* Returns true when the following conditions are met:
* - Current space supports mask editing.
* - The space is configured to interact with mask.
*
* It is not required to have mask opened for editing. */
bool ED_maskedit_poll(struct bContext *C);
/* Returns true when the following conditions are met:
* - Current space supports mask editing.
* - The space is configured to interact with mask.
* - The space has mask open for editing. */
bool ED_maskedit_mask_poll(struct bContext *C);
void ED_mask_deselect_all(const struct bContext *C);
void ED_operatortypes_mask(void);

View File

@ -595,7 +595,6 @@ bool ED_operator_object_active_local_editable_posemode_exclusive(struct bContext
bool ED_operator_posemode_context(struct bContext *C);
bool ED_operator_posemode(struct bContext *C);
bool ED_operator_posemode_local(struct bContext *C);
bool ED_operator_mask(struct bContext *C);
bool ED_operator_camera_poll(struct bContext *C);
/* screen_user_menu.c */

View File

@ -583,7 +583,7 @@ void MASK_OT_add_vertex(wmOperatorType *ot)
/* api callbacks */
ot->exec = add_vertex_exec;
ot->invoke = add_vertex_invoke;
ot->poll = ED_operator_mask;
ot->poll = ED_maskedit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -862,7 +862,7 @@ void MASK_OT_primitive_circle_add(wmOperatorType *ot)
/* api callbacks */
ot->exec = primitive_circle_add_exec;
ot->invoke = primitive_add_invoke;
ot->poll = ED_operator_mask;
ot->poll = ED_maskedit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -897,7 +897,7 @@ void MASK_OT_primitive_square_add(wmOperatorType *ot)
/* api callbacks */
ot->exec = primitive_square_add_exec;
ot->invoke = primitive_add_invoke;
ot->poll = ED_operator_mask;
ot->poll = ED_maskedit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

View File

@ -86,9 +86,6 @@ void ED_mask_select_flush_all(struct Mask *mask);
/* mask_editor.c */
bool ED_maskedit_poll(struct bContext *C);
bool ED_maskedit_mask_poll(struct bContext *C);
/* Generalized solution for preserving editor viewport when making changes while lock-to-selection
* is enabled.
* Any mask operator can use this API, without worrying that some editors do not have an idea of

View File

@ -113,7 +113,7 @@ void MASK_OT_new(wmOperatorType *ot)
/* api callbacks */
ot->exec = mask_new_exec;
ot->poll = ED_operator_mask;
ot->poll = ED_maskedit_poll;
/* properties */
RNA_def_string(ot->srna, "name", NULL, MAX_ID_NAME - 2, "Name", "Name of new mask");
@ -907,7 +907,7 @@ void MASK_OT_slide_point(wmOperatorType *ot)
/* api callbacks */
ot->invoke = slide_point_invoke;
ot->modal = slide_point_modal;
ot->poll = ED_operator_mask;
ot->poll = ED_maskedit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@ -1297,7 +1297,7 @@ void MASK_OT_slide_spline_curvature(wmOperatorType *ot)
/* api callbacks */
ot->invoke = slide_spline_curvature_invoke;
ot->modal = slide_spline_curvature_modal;
ot->poll = ED_operator_mask;
ot->poll = ED_maskedit_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;

View File

@ -21,6 +21,7 @@
#include "WM_types.h"
#include "ED_clip.h" /* frame remapping functions */
#include "ED_mask.h"
#include "ED_screen.h"
#include "mask_intern.h" /* own include */

View File

@ -659,32 +659,6 @@ bool ED_operator_editmball(bContext *C)
return false;
}
bool ED_operator_mask(bContext *C)
{
ScrArea *area = CTX_wm_area(C);
if (area && area->spacedata.first) {
switch (area->spacetype) {
case SPACE_CLIP: {
SpaceClip *space_clip = area->spacedata.first;
return ED_space_clip_check_show_maskedit(space_clip);
}
case SPACE_SEQ: {
SpaceSeq *sseq = area->spacedata.first;
Scene *scene = CTX_data_scene(C);
return ED_space_sequencer_check_show_maskedit(sseq, scene);
}
case SPACE_IMAGE: {
SpaceImage *sima = area->spacedata.first;
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
return ED_space_image_check_show_maskedit(sima, obedit);
}
}
}
return false;
}
bool ED_operator_camera_poll(bContext *C)
{
struct Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;

View File

@ -964,7 +964,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
static bool image_view_selected_poll(bContext *C)
{
return (space_image_main_region_poll(C) && (ED_operator_uvedit(C) || ED_operator_mask(C)));
return (space_image_main_region_poll(C) && (ED_operator_uvedit(C) || ED_maskedit_poll(C)));
}
void IMAGE_OT_view_selected(wmOperatorType *ot)