Browse Source

Fix unlink block by reusing existing code

master
Nils 4 years ago
parent
commit
1f14140260
  1. 18
      engine/api.py
  2. 5
      engine/block.py
  3. 1
      engine/track.py
  4. 2
      template/engine/history.py

18
engine/api.py

@ -897,11 +897,23 @@ def unlinkCurrentBlock():
def unlinkBlock(blockId): def unlinkBlock(blockId):
track, block = session.data.blockById(blockId) track, block = session.data.blockById(blockId)
newData = block.getUnlinkedData() #if len(block.linkedContentBlocks) == 1: return #This will not work because block is still the old one. unlink replaces with a standalone copy but we keep the original for undo.
assert newData
_setBlockData(block, newData) #handles undo and callbacks
with session.history.sequence("unlink block"):
duplicateBlock(blockId)
deleteBlock(blockId) #original one
callbacks._historyChanged()
#Does not work properly:
#newData = block.getUnlinkedData()
#assert newData
#_setBlockData(block, newData) #handles undo and callbacks
#deprecated
def _setBlockData(block, newData): def _setBlockData(block, newData):
"""DEPRECATED. This did not work. The linked blocks were not reduced.
At point of the bug reports, instead of fixing this, we used
duplicate block and delete which already provides all functionality"""
session.history.register(lambda bl=block, old=block.data: _setBlockData(bl, old), descriptionString = "set block data") session.history.register(lambda bl=block, old=block.data: _setBlockData(bl, old), descriptionString = "set block data")
block.data = newData block.data = newData
#no callbacks needed. #no callbacks needed.

5
engine/block.py

@ -167,7 +167,10 @@ class Block(object):
return new return new
def getUnlinkedData(self): def getUnlinkedData(self):
"""Set and handled for undo/redo by the api""" """
Returns a new list with copies of items.
Set and handled for undo/redo by the api.
"""
newData = [] newData = []
newParentBlocks = WeakSet() newParentBlocks = WeakSet()
newParentBlocks.add(self) newParentBlocks.add(self)

1
engine/track.py

@ -436,6 +436,7 @@ class Track(object):
return new return new
def appendExistingBlock(self, block): def appendExistingBlock(self, block):
assert type(block) is Block, block
block.parentTrack = self block.parentTrack = self
self.blocks.append(block) self.blocks.append(block)

2
template/engine/history.py

@ -69,7 +69,7 @@ class History(object):
def sequence(self, descriptionString): def sequence(self, descriptionString):
"""Convenience function. All registrations from now on will be undone at once. """Convenience function. All registrations from now on will be undone at once.
call stopSequence when done. call stopSequence when done.
This is not meant for high level scripts and not for user-interaction. This is meant for high level scripts and not for user-interaction.
This context can also be used to force a custom name for the undo description, even if it is This context can also be used to force a custom name for the undo description, even if it is
only one step. only one step.

Loading…
Cancel
Save