Cleanup: Move select all nodes code to operator
This more specific high level functionality isn't needed elsewhere. Move it to the operator and clean it up a bit.
This commit is contained in:
parent
2d38768f89
commit
1d24586a90
|
@ -1473,43 +1473,6 @@ void NODE_OT_duplicate(wmOperatorType *ot)
|
|||
ot->srna, "keep_inputs", false, "Keep Inputs", "Keep the input links to duplicated nodes");
|
||||
}
|
||||
|
||||
static bool node_select_check(const ListBase *lb)
|
||||
{
|
||||
LISTBASE_FOREACH (const bNode *, node, lb) {
|
||||
if (node->flag & NODE_SELECT) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void node_select_all(ListBase *lb, int action)
|
||||
{
|
||||
if (action == SEL_TOGGLE) {
|
||||
if (node_select_check(lb)) {
|
||||
action = SEL_DESELECT;
|
||||
}
|
||||
else {
|
||||
action = SEL_SELECT;
|
||||
}
|
||||
}
|
||||
|
||||
LISTBASE_FOREACH (bNode *, node, lb) {
|
||||
switch (action) {
|
||||
case SEL_SELECT:
|
||||
nodeSetSelected(node, true);
|
||||
break;
|
||||
case SEL_DESELECT:
|
||||
nodeSetSelected(node, false);
|
||||
break;
|
||||
case SEL_INVERT:
|
||||
nodeSetSelected(node, !(node->flag & SELECT));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX: some code needing updating to operators. */
|
||||
|
||||
/* goes over all scenes, reads render layers */
|
||||
|
|
|
@ -288,8 +288,6 @@ float2 node_link_calculate_multi_input_position(const float2 &socket_position,
|
|||
int index,
|
||||
int total_inputs);
|
||||
|
||||
void node_select_all(ListBase *lb, int action);
|
||||
|
||||
float node_socket_calculate_height(const bNodeSocket &socket);
|
||||
|
||||
void snode_set_context(const bContext &C);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "BKE_context.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_node.h"
|
||||
#include "BKE_node_runtime.hh"
|
||||
#include "BKE_workspace.h"
|
||||
|
||||
#include "ED_node.h" /* own include */
|
||||
|
@ -1034,13 +1035,48 @@ void NODE_OT_select_lasso(wmOperatorType *ot)
|
|||
/** \name (De)select All Operator
|
||||
* \{ */
|
||||
|
||||
static bool any_node_selected(const bNodeTree &node_tree)
|
||||
{
|
||||
for (const bNode *node : node_tree.all_nodes()) {
|
||||
if (node->flag & NODE_SELECT) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int node_select_all_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
SpaceNode &snode = *CTX_wm_space_node(C);
|
||||
ListBase *node_lb = &snode.edittree->nodes;
|
||||
int action = RNA_enum_get(op->ptr, "action");
|
||||
bNodeTree &node_tree = *snode.edittree;
|
||||
|
||||
node_select_all(node_lb, action);
|
||||
node_tree.ensure_topology_cache();
|
||||
|
||||
int action = RNA_enum_get(op->ptr, "action");
|
||||
if (action == SEL_TOGGLE) {
|
||||
if (any_node_selected(node_tree)) {
|
||||
action = SEL_DESELECT;
|
||||
}
|
||||
else {
|
||||
action = SEL_SELECT;
|
||||
}
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case SEL_SELECT:
|
||||
for (bNode *node : node_tree.all_nodes()) {
|
||||
nodeSetSelected(node, true);
|
||||
}
|
||||
break;
|
||||
case SEL_DESELECT:
|
||||
node_deselect_all(snode);
|
||||
break;
|
||||
case SEL_INVERT:
|
||||
for (bNode *node : node_tree.all_nodes()) {
|
||||
nodeSetSelected(node, !(node->flag & SELECT));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
node_sort(*snode.edittree);
|
||||
|
||||
|
|
Loading…
Reference in New Issue