Skip to content

Commit d9bdadb

Browse files
committed
Add functionality to add a node to an existing group.
1 parent 4b99a02 commit d9bdadb

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

Sources/NodeEngine/NE_NodeGroupList.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ void NodeGroupList::DeleteGroup (const NodeGroupConstPtr& group)
5555

5656
void NodeGroupList::AddNodeToGroup (const NodeGroupPtr& group, const NodeId& nodeId)
5757
{
58+
NodeGroupConstPtr existingGroup = GetNodeGroup (nodeId);
59+
if (existingGroup != nullptr && group == existingGroup) {
60+
return;
61+
}
5862
RemoveNodeFromGroup (nodeId);
5963
groupToNodes[group].Insert (nodeId);
6064
nodeToGroup.insert ({ nodeId, group });

Sources/NodeUIEngine/NUIE_NodeMenuCommands.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,35 @@ class RemoveNodesFromGroupMenuCommand : public SingleMenuCommand
689689
NE::NodeCollection relevantNodes;
690690
};
691691

692+
class AddNodesToGroupMenuCommand : public SingleMenuCommand
693+
{
694+
public:
695+
AddNodesToGroupMenuCommand (NodeUIManager& uiManager, const UINodeGroupPtr& uiNodeGroup, const NE::NodeCollection& relevantNodes) :
696+
SingleMenuCommand (std::wstring (L"Add To Group \"") + uiNodeGroup->GetName () + std::wstring (L"\""), false),
697+
uiManager (uiManager),
698+
uiNodeGroup (uiNodeGroup),
699+
relevantNodes (relevantNodes)
700+
{
701+
702+
}
703+
704+
virtual ~AddNodesToGroupMenuCommand ()
705+
{
706+
707+
}
708+
709+
virtual void Do () override
710+
{
711+
AddNodesToGroupCommand command (uiNodeGroup, relevantNodes);
712+
uiManager.ExecuteCommand (command);
713+
}
714+
715+
private:
716+
NodeUIManager& uiManager;
717+
UINodeGroupPtr uiNodeGroup;
718+
NE::NodeCollection relevantNodes;
719+
};
720+
692721
NE::NodeCollection GetNodesForCommand (const NodeUIManager& uiManager, const UINodePtr& uiNode)
693722
{
694723
const NE::NodeCollection& selectedNodes = uiManager.GetSelectedNodes ();
@@ -720,10 +749,17 @@ MenuCommandStructure CreateNodeCommandStructure (NodeUIManager& uiManager, NodeU
720749

721750
GroupMenuCommandPtr groupingCommandGroup (new GroupMenuCommand (L"Grouping"));
722751
groupingCommandGroup->AddChildCommand (MenuCommandPtr (new CreateGroupMenuCommand (uiManager, relevantNodes)));
752+
723753
UINodeGroupConstPtr nodeGroup = uiManager.GetUINodeGroup (uiNode->GetId ());
724754
if (nodeGroup != nullptr) {
725755
groupingCommandGroup->AddChildCommand (MenuCommandPtr (new RemoveNodesFromGroupMenuCommand (uiManager, relevantNodes)));
726756
}
757+
758+
uiManager.EnumerateUINodeGroups ([&] (const UINodeGroupPtr& group) {
759+
groupingCommandGroup->AddChildCommand (MenuCommandPtr (new AddNodesToGroupMenuCommand (uiManager, group, relevantNodes)));
760+
return true;
761+
});
762+
727763
commandStructureBuilder.RegisterCommand (groupingCommandGroup);
728764

729765
return commandStructureBuilder.GetCommandStructure ();

Sources/NodeUIEngine/NUIE_NodeUIManagerCommands.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ void DeleteGroupCommand::Do (NodeUIManager& uiManager)
202202
uiManager.DeleteUINodeGroup (uiGroup);
203203
}
204204

205+
AddNodesToGroupCommand::AddNodesToGroupCommand (const UINodeGroupPtr& uiGroup, const NE::NodeCollection& nodes) :
206+
UndoableCommand (),
207+
uiGroup (uiGroup),
208+
nodes (nodes)
209+
{
210+
211+
}
212+
213+
void AddNodesToGroupCommand::Do (NodeUIManager& uiManager)
214+
{
215+
uiManager.AddNodesToUIGroup (uiGroup, nodes);
216+
}
217+
205218
RemoveNodesFromGroupCommand::RemoveNodesFromGroupCommand (const NE::NodeCollection& nodes) :
206219
UndoableCommand (),
207220
nodes (nodes)

Sources/NodeUIEngine/NUIE_NodeUIManagerCommands.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ class DeleteGroupCommand : public UndoableCommand
151151
const UINodeGroupPtr& uiGroup;
152152
};
153153

154+
class AddNodesToGroupCommand : public UndoableCommand
155+
{
156+
public:
157+
AddNodesToGroupCommand (const UINodeGroupPtr& uiGroup, const NE::NodeCollection& nodes);
158+
159+
virtual void Do (NodeUIManager& uiManager) override;
160+
161+
private:
162+
const UINodeGroupPtr& uiGroup;
163+
const NE::NodeCollection& nodes;
164+
};
165+
154166
class RemoveNodesFromGroupCommand : public UndoableCommand
155167
{
156168
public:

0 commit comments

Comments
 (0)