Add node to graph with Ctrl+V if valid node content is in the clipboard

Attempt to paste the clipboard's content in the graph when Ctrl+V is
pressed. If the clipboard contains a valid node description, add the
corresponding node to the graph.
Otherwise, do nothing.
This commit is contained in:
Candice Bentéjac 2022-08-18 16:51:05 +02:00
parent 751bad96c6
commit ddda62a652
5 changed files with 80 additions and 0 deletions

View file

@ -195,6 +195,26 @@ class DuplicateNodesCommand(GraphCommand):
self.graph.removeNode(duplicate)
class PasteNodeCommand(GraphCommand):
"""
Handle node pasting in a Graph.
"""
def __init__(self, graph, nodeType, parent=None, **kwargs):
super(PasteNodeCommand, self).__init__(graph, parent)
self.nodeType = nodeType
self.nodeName = None
self.kwargs = kwargs
def redoImpl(self):
node = self.graph.pasteNode(self.nodeType, **self.kwargs)
self.nodeName = node.name
self.setText("Paste Node {}".format(self.nodeName))
return node
def undoImpl(self):
self.graph.removeNode(self.nodeName)
class SetAttributeCommand(GraphCommand):
def __init__(self, graph, attribute, value, parent=None):
super(SetAttributeCommand, self).__init__(graph, parent)