From e97c79abff60d752574fbb1b8caae5b9a35b3fc1 Mon Sep 17 00:00:00 2001
From: Josh Morman <jmorman@perspectalabs.com>
Date: Thu, 18 Jul 2019 19:09:28 -0400
Subject: grc: restore copy/paste behavior

Restores the gnuradio 3.7 copy/paste behavior where the variable name is
changed to x_# of the copied block if the name is in conflict.  The
issue in 3.8 was that blocks always got copied as variable_# even when
there was no conflict in naming

Fixes #2614
---
 grc/gui/canvas/flowgraph.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

(limited to 'grc/gui/canvas/flowgraph.py')

diff --git a/grc/gui/canvas/flowgraph.py b/grc/gui/canvas/flowgraph.py
index a9010026c3..248ea3ba22 100644
--- a/grc/gui/canvas/flowgraph.py
+++ b/grc/gui/canvas/flowgraph.py
@@ -280,6 +280,13 @@ class FlowGraph(CoreFlowgraph, Drawable):
             block_key = block_n.get('id')
             if block_key == 'options':
                 continue
+
+            block_name = block_n.get('name')
+            # Verify whether a block with this name exists before adding it
+            if block_name in (blk.name for blk in self.blocks):
+                block_name = self._get_unique_id(block_name)
+                block_n['name'] = block_name
+
             block = self.new_block(block_key)
             if not block:
                 continue  # unknown block was pasted (e.g. dummy block)
@@ -290,8 +297,7 @@ class FlowGraph(CoreFlowgraph, Drawable):
             # move block to offset coordinate
             block.move((x_off, y_off))
 
-            if block.params['id'].value in (blk.name for blk in self.blocks):
-                block.params['id'].value = self._get_unique_id(block_key)
+            #TODO: prevent block from being pasted directly on top of another block
 
         # update before creating connections
         self.update()
-- 
cgit v1.2.3