forked from bartvdbraak/blender
Fix #35640, part 2. Check id.lib in poll functions for operators which do critical modification of node trees (create nodes, link, etc.). Transform operators and hide/show type operators are still
allowed, this does not modify actual behavior of the nodes and can be useful for inspecting linked nodes.
This commit is contained in:
parent
4c2a51e1f9
commit
f681ce08c4
@ -100,7 +100,7 @@ class NodeAddOperator():
|
||||
def poll(cls, context):
|
||||
space = context.space_data
|
||||
# needs active node editor and a tree to add nodes to
|
||||
return (space.type == 'NODE_EDITOR' and space.edit_tree)
|
||||
return (space.type == 'NODE_EDITOR' and space.edit_tree and not space.edit_tree.library)
|
||||
|
||||
# Default execute simply adds a node
|
||||
def execute(self, context):
|
||||
@ -231,7 +231,7 @@ class NODE_OT_collapse_hide_unused_toggle(Operator):
|
||||
def poll(cls, context):
|
||||
space = context.space_data
|
||||
# needs active node editor and a tree
|
||||
return (space.type == 'NODE_EDITOR' and space.edit_tree)
|
||||
return (space.type == 'NODE_EDITOR' and space.edit_tree and not space.edit_tree.library)
|
||||
|
||||
def execute(self, context):
|
||||
space = context.space_data
|
||||
|
@ -142,6 +142,7 @@ int ED_operator_file_active(struct bContext *C);
|
||||
int ED_operator_action_active(struct bContext *C);
|
||||
int ED_operator_buttons_active(struct bContext *C);
|
||||
int ED_operator_node_active(struct bContext *C);
|
||||
int ED_operator_node_editable(struct bContext *C);
|
||||
int ED_operator_graphedit_active(struct bContext *C);
|
||||
int ED_operator_sequencer_active(struct bContext *C);
|
||||
int ED_operator_image_active(struct bContext *C);
|
||||
|
@ -260,6 +260,16 @@ int ED_operator_node_active(bContext *C)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ED_operator_node_editable(bContext *C)
|
||||
{
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
|
||||
if (snode && snode->edittree && snode->edittree->id.lib == NULL)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* XXX rename */
|
||||
int ED_operator_graphedit_active(bContext *C)
|
||||
{
|
||||
|
@ -308,7 +308,7 @@ void NODE_OT_add_reroute(wmOperatorType *ot)
|
||||
ot->exec = add_reroute_exec;
|
||||
ot->cancel = WM_gesture_lines_cancel;
|
||||
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -416,7 +416,7 @@ void NODE_OT_add_file(wmOperatorType *ot)
|
||||
/* callbacks */
|
||||
ot->exec = node_add_file_exec;
|
||||
ot->invoke = node_add_file_invoke;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
@ -318,6 +318,17 @@ int composite_node_active(bContext *C)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* operator poll callback */
|
||||
int composite_node_editable(bContext *C)
|
||||
{
|
||||
if (ED_operator_node_editable(C)) {
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
if (ED_node_is_compositor(snode))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int has_nodetree(bNodeTree *ntree, bNodeTree *lookup)
|
||||
{
|
||||
bNode *node;
|
||||
@ -1239,7 +1250,7 @@ void NODE_OT_duplicate(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_duplicate_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1611,7 +1622,7 @@ void NODE_OT_mute_toggle(wmOperatorType *ot)
|
||||
|
||||
/* callbacks */
|
||||
ot->exec = node_mute_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1653,7 +1664,7 @@ void NODE_OT_delete(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_delete_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1696,7 +1707,7 @@ void NODE_OT_delete_reconnect(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_delete_reconnect_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1743,7 +1754,7 @@ void NODE_OT_output_file_add_socket(wmOperatorType *ot)
|
||||
|
||||
/* callbacks */
|
||||
ot->exec = node_output_file_add_socket_exec;
|
||||
ot->poll = composite_node_active;
|
||||
ot->poll = composite_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1789,7 +1800,7 @@ void NODE_OT_output_file_remove_active_socket(wmOperatorType *ot)
|
||||
|
||||
/* callbacks */
|
||||
ot->exec = node_output_file_remove_active_socket_exec;
|
||||
ot->poll = composite_node_active;
|
||||
ot->poll = composite_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1859,7 +1870,7 @@ void NODE_OT_output_file_move_active_socket(wmOperatorType *ot)
|
||||
|
||||
/* callbacks */
|
||||
ot->exec = node_output_file_move_active_socket_exec;
|
||||
ot->poll = composite_node_active;
|
||||
ot->poll = composite_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1907,7 +1918,7 @@ void NODE_OT_node_copy_color(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_copy_color_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -2100,7 +2111,7 @@ void NODE_OT_clipboard_paste(wmOperatorType *ot)
|
||||
/* api callbacks */
|
||||
ot->exec = node_clipboard_paste_exec;
|
||||
ot->invoke = node_clipboard_paste_invoke;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -2172,7 +2183,7 @@ void NODE_OT_tree_socket_add(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = ntree_socket_add_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -2218,7 +2229,7 @@ void NODE_OT_tree_socket_remove(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = ntree_socket_remove_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -2286,7 +2297,7 @@ void NODE_OT_tree_socket_move(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = ntree_socket_move_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -2304,6 +2315,9 @@ static int node_shader_script_update_poll(bContext *C)
|
||||
bNode *node;
|
||||
Text *text;
|
||||
|
||||
if (!ED_operator_node_editable(C))
|
||||
return 0;
|
||||
|
||||
/* test if we have a render engine that supports shaders scripts */
|
||||
if (!(type && type->update_script_node))
|
||||
return 0;
|
||||
@ -2311,7 +2325,7 @@ static int node_shader_script_update_poll(bContext *C)
|
||||
/* see if we have a shader script node in context */
|
||||
node = CTX_data_pointer_get_type(C, "node", &RNA_ShaderNodeScript).data;
|
||||
|
||||
if (!node && snode && snode->edittree)
|
||||
if (!node)
|
||||
node = nodeGetActive(snode->edittree);
|
||||
|
||||
if (node && node->type == SH_NODE_SCRIPT) {
|
||||
|
@ -71,7 +71,7 @@
|
||||
|
||||
static int node_group_operator_poll(bContext *C)
|
||||
{
|
||||
if (ED_operator_node_active(C)) {
|
||||
if (ED_operator_node_editable(C)) {
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
|
||||
/* Group operators only defined for standard node tree types.
|
||||
|
@ -176,6 +176,7 @@ void snode_set_context(const struct bContext *C);
|
||||
|
||||
void snode_update(struct SpaceNode *snode, struct bNode *node);
|
||||
int composite_node_active(struct bContext *C);
|
||||
int composite_node_editable(struct bContext *C);
|
||||
|
||||
int node_has_hidden_sockets(bNode *node);
|
||||
void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set);
|
||||
|
@ -386,7 +386,7 @@ void NODE_OT_link_viewer(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_active_link_viewer;
|
||||
ot->poll = composite_node_active;
|
||||
ot->poll = composite_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -690,7 +690,7 @@ void NODE_OT_link(wmOperatorType *ot)
|
||||
ot->invoke = node_link_invoke;
|
||||
ot->modal = node_link_modal;
|
||||
// ot->exec = node_link_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
ot->cancel = node_link_cancel;
|
||||
|
||||
/* flags */
|
||||
@ -731,7 +731,7 @@ void NODE_OT_link_make(wmOperatorType *ot)
|
||||
|
||||
/* callbacks */
|
||||
ot->exec = node_make_link_exec;
|
||||
ot->poll = ED_operator_node_active; // XXX we need a special poll which checks that there are selected input/output sockets
|
||||
ot->poll = ED_operator_node_editable; // XXX we need a special poll which checks that there are selected input/output sockets
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -826,7 +826,7 @@ void NODE_OT_links_cut(wmOperatorType *ot)
|
||||
ot->exec = cut_links_exec;
|
||||
ot->cancel = WM_gesture_lines_cancel;
|
||||
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -868,7 +868,7 @@ void NODE_OT_links_detach(wmOperatorType *ot)
|
||||
ot->description = "Remove all links to selected nodes, and try to connect neighbor nodes together";
|
||||
|
||||
ot->exec = detach_links_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -937,7 +937,7 @@ void NODE_OT_parent_set(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_parent_set_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -971,7 +971,7 @@ void NODE_OT_parent_clear(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_parent_clear_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1057,7 +1057,7 @@ void NODE_OT_join(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_join_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1137,7 +1137,7 @@ void NODE_OT_attach(wmOperatorType *ot)
|
||||
/* api callbacks */
|
||||
ot->exec = node_attach_exec;
|
||||
ot->invoke = node_attach_invoke;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
@ -1206,7 +1206,7 @@ void NODE_OT_detach(wmOperatorType *ot)
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = node_detach_exec;
|
||||
ot->poll = ED_operator_node_active;
|
||||
ot->poll = ED_operator_node_editable;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
@ -1050,6 +1050,15 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac
|
||||
WM_keymap_add_item(keymap, "NODE_OT_translate_attach", GKEY, KM_PRESS, 0, 0);
|
||||
WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_A, KM_ANY, 0, 0);
|
||||
WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_S, KM_ANY, 0, 0);
|
||||
/* NB: small trick: macro operator poll may fail due to library data edit,
|
||||
* in that case the secondary regular operators are called with same keymap.
|
||||
*/
|
||||
kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
|
||||
RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
|
||||
kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_A, KM_ANY, 0, 0);
|
||||
RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
|
||||
kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
|
||||
RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
|
||||
|
||||
WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user