From 4445b55559353981e1cf1fa98178f218b243ecc5 Mon Sep 17 00:00:00 2001 From: Olivier Keshavjee Date: Fri, 10 Nov 2017 17:33:48 +0100 Subject: [PATCH] Allows pasted items to keep ID if not already in model. --- manuskript/models/outlineModel.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/manuskript/models/outlineModel.py b/manuskript/models/outlineModel.py index 2748ba2..140def2 100644 --- a/manuskript/models/outlineModel.py +++ b/manuskript/models/outlineModel.py @@ -398,11 +398,23 @@ class outlineModel(QAbstractItemModel): if not items: return False - r = self.insertItems(items, beginRow, parent) - + # In case of copy actions, items might be duplicates, so we need new IDs. + # But they might not be, if we cut, then paste. Paste is a Copy Action. + # The first paste would not need new IDs. But subsequent ones will. if action == Qt.CopyAction: + IDs = self.rootItem.listAllIDs() + for item in items: - item.getUniqueID(recursive=True) + if item.ID() in IDs: + # Recursively remove ID. So will get a new one when inserted. + def stripID(item): + item.setData(Outline.ID.value, None) + for c in item.children(): + stripID(c) + + stripID(item) + + r = self.insertItems(items, beginRow, parent) return r @@ -928,7 +940,7 @@ class outlineItem(): # Inserting item using the model to signal views self._model.insertItem(item, self.row()+1, self.parent().index()) - def mergeWith(self, items, sep="\n---\n"): + def mergeWith(self, items, sep="\n\n"): """ Merges item with several other items. Merge is basic, it merges only the text.