Fix #112618: many Outliner operators crash running without a region
This could happen when e.g. overriding context with just the area. Now add poll functions that check for an active region when running operators that require a region. The fix is similar to72688791dcAlternatively, we could have a fix similar toa8892c7264(getting the correct region from the area), this would require less setup by scripters, however for some operators the usage of the region is a little further down the line, so implementation would be a bit more involved. Also: for some of the operators, this would have to be done in both `invoke` and `exec` (so would be more duplicate code changes). Pull Request: https://projects.blender.org/blender/blender/pulls/119696
This commit is contained in:
committed by
Thomas Dinges
parent
50aa9357ef
commit
7b53ab3a5f
@@ -508,6 +508,7 @@ bool ED_operator_region_gizmo_active(bContext *C);
|
|||||||
*/
|
*/
|
||||||
bool ED_operator_animview_active(bContext *C);
|
bool ED_operator_animview_active(bContext *C);
|
||||||
bool ED_operator_outliner_active(bContext *C);
|
bool ED_operator_outliner_active(bContext *C);
|
||||||
|
bool ED_operator_region_outliner_active(bContext *C);
|
||||||
bool ED_operator_outliner_active_no_editobject(bContext *C);
|
bool ED_operator_outliner_active_no_editobject(bContext *C);
|
||||||
/**
|
/**
|
||||||
* \note Will return true for file spaces in either file or asset browsing mode! See
|
* \note Will return true for file spaces in either file or asset browsing mode! See
|
||||||
|
|||||||
@@ -283,6 +283,20 @@ bool ED_operator_outliner_active(bContext *C)
|
|||||||
return ed_spacetype_test(C, SPACE_OUTLINER);
|
return ed_spacetype_test(C, SPACE_OUTLINER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ED_operator_region_outliner_active(bContext *C)
|
||||||
|
{
|
||||||
|
if (!ED_operator_outliner_active(C)) {
|
||||||
|
CTX_wm_operator_poll_msg_set(C, "Expected an active Outliner");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const ARegion *region = CTX_wm_region(C);
|
||||||
|
if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
|
||||||
|
CTX_wm_operator_poll_msg_set(C, "Expected an Outliner region");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ED_operator_outliner_active_no_editobject(bContext *C)
|
bool ED_operator_outliner_active_no_editobject(bContext *C)
|
||||||
{
|
{
|
||||||
if (ed_spacetype_test(C, SPACE_OUTLINER)) {
|
if (ed_spacetype_test(C, SPACE_OUTLINER)) {
|
||||||
|
|||||||
@@ -184,6 +184,17 @@ static bool collection_edit_in_active_scene_poll(bContext *C)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool collection_new_poll(bContext *C)
|
||||||
|
{
|
||||||
|
if (!ED_operator_region_outliner_active(C)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!collection_edit_in_active_scene_poll(C)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
@@ -269,7 +280,7 @@ void OUTLINER_OT_collection_new(wmOperatorType *ot)
|
|||||||
|
|
||||||
/* api callbacks */
|
/* api callbacks */
|
||||||
ot->exec = collection_new_exec;
|
ot->exec = collection_new_exec;
|
||||||
ot->poll = collection_edit_in_active_scene_poll;
|
ot->poll = collection_new_poll;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ void OUTLINER_OT_parent_drop(wmOperatorType *ot)
|
|||||||
/* api callbacks */
|
/* api callbacks */
|
||||||
ot->invoke = parent_drop_invoke;
|
ot->invoke = parent_drop_invoke;
|
||||||
|
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
||||||
@@ -609,7 +609,7 @@ void OUTLINER_OT_scene_drop(wmOperatorType *ot)
|
|||||||
/* api callbacks */
|
/* api callbacks */
|
||||||
ot->invoke = scene_drop_invoke;
|
ot->invoke = scene_drop_invoke;
|
||||||
|
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
||||||
@@ -662,7 +662,7 @@ void OUTLINER_OT_material_drop(wmOperatorType *ot)
|
|||||||
/* api callbacks */
|
/* api callbacks */
|
||||||
ot->invoke = material_drop_invoke;
|
ot->invoke = material_drop_invoke;
|
||||||
|
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ void OUTLINER_OT_item_openclose(wmOperatorType *ot)
|
|||||||
ot->invoke = outliner_item_openclose_invoke;
|
ot->invoke = outliner_item_openclose_invoke;
|
||||||
ot->modal = outliner_item_openclose_modal;
|
ot->modal = outliner_item_openclose_modal;
|
||||||
|
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
RNA_def_boolean(ot->srna, "all", false, "All", "Close or open all items");
|
RNA_def_boolean(ot->srna, "all", false, "All", "Close or open all items");
|
||||||
}
|
}
|
||||||
@@ -438,7 +438,7 @@ void OUTLINER_OT_item_rename(wmOperatorType *ot)
|
|||||||
|
|
||||||
ot->invoke = outliner_item_rename_invoke;
|
ot->invoke = outliner_item_rename_invoke;
|
||||||
|
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* Flags. */
|
/* Flags. */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||||
@@ -590,7 +590,7 @@ void OUTLINER_OT_id_delete(wmOperatorType *ot)
|
|||||||
ot->description = "Delete the ID under cursor";
|
ot->description = "Delete the ID under cursor";
|
||||||
|
|
||||||
ot->invoke = outliner_id_delete_invoke;
|
ot->invoke = outliner_id_delete_invoke;
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* Flags. */
|
/* Flags. */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||||
@@ -729,7 +729,7 @@ void OUTLINER_OT_id_remap(wmOperatorType *ot)
|
|||||||
/* callbacks */
|
/* callbacks */
|
||||||
ot->invoke = outliner_id_remap_invoke;
|
ot->invoke = outliner_id_remap_invoke;
|
||||||
ot->exec = outliner_id_remap_exec;
|
ot->exec = outliner_id_remap_exec;
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* Flags. */
|
/* Flags. */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||||
@@ -990,7 +990,7 @@ void OUTLINER_OT_lib_relocate(wmOperatorType *ot)
|
|||||||
ot->description = "Relocate the library under cursor";
|
ot->description = "Relocate the library under cursor";
|
||||||
|
|
||||||
ot->invoke = outliner_lib_relocate_invoke;
|
ot->invoke = outliner_lib_relocate_invoke;
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* Flags. */
|
/* Flags. */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||||
@@ -1047,7 +1047,7 @@ void OUTLINER_OT_lib_reload(wmOperatorType *ot)
|
|||||||
ot->description = "Reload the library under cursor";
|
ot->description = "Reload the library under cursor";
|
||||||
|
|
||||||
ot->invoke = outliner_lib_reload_invoke;
|
ot->invoke = outliner_lib_reload_invoke;
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* Flags. */
|
/* Flags. */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||||
@@ -1177,7 +1177,7 @@ void OUTLINER_OT_expanded_toggle(wmOperatorType *ot)
|
|||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
ot->exec = outliner_toggle_expanded_exec;
|
ot->exec = outliner_toggle_expanded_exec;
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* no undo or registry, UI option */
|
/* no undo or registry, UI option */
|
||||||
}
|
}
|
||||||
@@ -1379,7 +1379,7 @@ void OUTLINER_OT_show_active(wmOperatorType *ot)
|
|||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
ot->exec = outliner_show_active_exec;
|
ot->exec = outliner_show_active_exec;
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
@@ -1418,7 +1418,7 @@ void OUTLINER_OT_scroll_page(wmOperatorType *ot)
|
|||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
ot->exec = outliner_scroll_page_exec;
|
ot->exec = outliner_scroll_page_exec;
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
prop = RNA_def_boolean(ot->srna, "up", false, "Up", "Scroll up one page");
|
prop = RNA_def_boolean(ot->srna, "up", false, "Up", "Scroll up one page");
|
||||||
@@ -1490,7 +1490,7 @@ void OUTLINER_OT_show_one_level(wmOperatorType *ot)
|
|||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
ot->exec = outliner_one_level_exec;
|
ot->exec = outliner_one_level_exec;
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* no undo or registry, UI option */
|
/* no undo or registry, UI option */
|
||||||
|
|
||||||
@@ -1583,7 +1583,8 @@ void OUTLINER_OT_show_hierarchy(wmOperatorType *ot)
|
|||||||
|
|
||||||
/* callbacks */
|
/* callbacks */
|
||||||
ot->exec = outliner_show_hierarchy_exec;
|
ot->exec = outliner_show_hierarchy_exec;
|
||||||
ot->poll = ED_operator_outliner_active; /* TODO: shouldn't be allowed in RNA views... */
|
/* TODO: shouldn't be allowed in RNA views... */
|
||||||
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* no undo or registry, UI option */
|
/* no undo or registry, UI option */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1900,7 +1900,7 @@ void OUTLINER_OT_item_activate(wmOperatorType *ot)
|
|||||||
|
|
||||||
ot->invoke = outliner_item_activate_invoke;
|
ot->invoke = outliner_item_activate_invoke;
|
||||||
|
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||||
|
|
||||||
@@ -2008,7 +2008,7 @@ void OUTLINER_OT_select_box(wmOperatorType *ot)
|
|||||||
ot->modal = WM_gesture_box_modal;
|
ot->modal = WM_gesture_box_modal;
|
||||||
ot->cancel = WM_gesture_box_cancel;
|
ot->cancel = WM_gesture_box_cancel;
|
||||||
|
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
|
|
||||||
/* flags */
|
/* flags */
|
||||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||||
|
|||||||
@@ -3806,7 +3806,7 @@ void OUTLINER_OT_operation(wmOperatorType *ot)
|
|||||||
|
|
||||||
ot->invoke = outliner_operation_invoke;
|
ot->invoke = outliner_operation_invoke;
|
||||||
|
|
||||||
ot->poll = ED_operator_outliner_active;
|
ot->poll = ED_operator_region_outliner_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|||||||
Reference in New Issue
Block a user