Fix undo for fill with module (which was caused by module add command not being undone properly in case of failure)
This commit is contained in:
@@ -1026,6 +1026,16 @@ class Fit:
|
||||
if mod.isEmpty:
|
||||
del self.modules[i]
|
||||
|
||||
def clearTail(self):
|
||||
tailPositions = {}
|
||||
for mod in reversed(self.modules):
|
||||
if not mod.isEmpty:
|
||||
break
|
||||
tailPositions[self.modules.index(mod)] = mod.slot
|
||||
for pos in reversed(tailPositions):
|
||||
self.modules.remove(self.modules[pos])
|
||||
return tailPositions
|
||||
|
||||
@property
|
||||
def modCount(self):
|
||||
x = 0
|
||||
|
||||
@@ -67,7 +67,7 @@ class CalcAddLocalModuleCommand(wx.Command):
|
||||
if self.savedPosition is None:
|
||||
return False
|
||||
from .localRemove import CalcRemoveLocalModulesCommand
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.savedPosition], recalc=False)
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.savedPosition], recalc=False, clearTail=True)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
|
||||
@@ -3,7 +3,7 @@ from logbook import Logger
|
||||
|
||||
import eos.db
|
||||
from eos.const import FittingSlot
|
||||
from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates
|
||||
from gui.fitCommands.helpers import ModuleInfo, restoreCheckedStates, restoreRemovedDummies
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
@@ -12,14 +12,16 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class CalcRemoveLocalModulesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, positions, recalc=True):
|
||||
def __init__(self, fitID, positions, recalc=True, clearTail=False):
|
||||
wx.Command.__init__(self, True, 'Remove Module')
|
||||
self.fitID = fitID
|
||||
self.positions = positions
|
||||
self.recalc = recalc
|
||||
self.clearTail = clearTail
|
||||
self.savedSubInfos = None
|
||||
self.savedModInfos = None
|
||||
self.savedStateCheckChanges = None
|
||||
self.savedTail = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing removal of local modules from positions {} on fit {}'.format(self.positions, self.fitID))
|
||||
@@ -40,6 +42,9 @@ class CalcRemoveLocalModulesCommand(wx.Command):
|
||||
if len(self.savedSubInfos) == 0 and len(self.savedModInfos) == 0:
|
||||
return False
|
||||
|
||||
if self.clearTail:
|
||||
self.savedTail = fit.clearTail()
|
||||
|
||||
if self.recalc:
|
||||
# Need to flush because checkStates sometimes relies on module->fit
|
||||
# relationship via .owner attribute, which is handled by SQLAlchemy
|
||||
@@ -76,6 +81,7 @@ class CalcRemoveLocalModulesCommand(wx.Command):
|
||||
if not any(results):
|
||||
return False
|
||||
restoreCheckedStates(fit, self.savedStateCheckChanges)
|
||||
restoreRemovedDummies(fit, self.savedTail)
|
||||
return True
|
||||
|
||||
@property
|
||||
|
||||
@@ -353,6 +353,8 @@ def restoreCheckedStates(fit, stateInfo, ignoreModPoss=()):
|
||||
|
||||
|
||||
def restoreRemovedDummies(fit, dummyInfo):
|
||||
if dummyInfo is None:
|
||||
return
|
||||
# Need this to properly undo the case when removal of subsystems removes dummy slots
|
||||
for position in sorted(dummyInfo):
|
||||
slot = dummyInfo[position]
|
||||
|
||||
Reference in New Issue
Block a user