Fix for #36739: Delete new nodes added via the Add menu or toolbar if the subsequent transform operator is cancelled. This prevents ugly situations where nodes stick "under" the toolbar after clicking a

wrong button.

Works by adding a flag to transform operators "remove_on_cancel". This is currently only used for node transforms, the idea is that if set, the operator will remove the transformed elements when it is
cancelled. It's not possible to do that in the original NODE_OT_add_node operator, because transform is modal and there is no way of reacting to a cancel outside of the transform itself (previous attempt
used a macro operator, but that also doesn't work because subsequent operators don't get executed if the previous transform cancels).
This commit is contained in:
Lukas Toenne
2013-09-17 13:07:48 +00:00
parent 40b5b66527
commit 29b546fe7f
6 changed files with 33 additions and 3 deletions

View File

@@ -123,7 +123,8 @@ class NodeAddOperator():
result = self.execute(context)
if self.use_transform and ('FINISHED' in result):
bpy.ops.transform.translate('INVOKE_DEFAULT')
# removes the node again if transform is cancelled
bpy.ops.transform.translate('INVOKE_DEFAULT', remove_on_cancel = True)
return result

View File

@@ -1854,7 +1854,7 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
options |= CTX_TEXTURE;
}
}
t->options = options;
t->mode = mode;

View File

@@ -341,7 +341,9 @@ typedef struct TransInfo {
float auto_values[4];
float axis[3];
float axis_orig[3]; /* TransCon can change 'axis', store the original value here */
short remove_on_cancel; /* remove elements if operator is cancelled */
void *view;
struct bContext *context; /* Only valid (non null) during an operator called function. */
struct ScrArea *sa;

View File

@@ -5323,6 +5323,25 @@ static void special_aftertrans_update__mask(bContext *C, TransInfo *t)
}
}
static void special_aftertrans_update__node(bContext *UNUSED(C), TransInfo *t)
{
int canceled = (t->state == TRANS_CANCEL);
if (canceled && t->remove_on_cancel) {
/* remove selected nodes on cancel */
SpaceNode *snode = (SpaceNode *)t->sa->spacedata.first;
bNodeTree *ntree = snode->edittree;
if (ntree) {
bNode *node, *node_next;
for (node = ntree->nodes.first; node; node = node_next) {
node_next = node->next;
if (node->flag & NODE_SELECT)
nodeFreeNode(ntree, node);
}
}
}
}
static void special_aftertrans_update__mesh(bContext *UNUSED(C), TransInfo *t)
{
/* so automerge supports mirror */
@@ -5434,6 +5453,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
}
else if (t->spacetype == SPACE_NODE) {
SpaceNode *snode = (SpaceNode *)t->sa->spacedata.first;
special_aftertrans_update__node(C, t);
if (canceled == 0) {
ED_node_post_apply_transform(C, snode->edittree);

View File

@@ -1105,6 +1105,12 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *even
t->options |= CTX_EDGE;
}
t->remove_on_cancel = false;
if ((prop = RNA_struct_find_property(op->ptr, "remove_on_cancel")) && RNA_property_is_set(op->ptr, prop)) {
if (RNA_property_boolean_get(op->ptr, prop)) {
t->remove_on_cancel = true;
}
}
/* Assign the space type, some exceptions for running in different mode */
if (sa == NULL) {

View File

@@ -537,6 +537,7 @@ void Transform_Properties(struct wmOperatorType *ot, int flags)
if (flags & P_OPTIONS) {
RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
RNA_def_boolean(ot->srna, "remove_on_cancel", 0, "Remove on Cancel", "Remove elements on cancel");
}
if (flags & P_CORRECT_UV) {