diff --git a/eos/effectHandlerHelpers.py b/eos/effectHandlerHelpers.py index 446273a45..3cba3e40f 100644 --- a/eos/effectHandlerHelpers.py +++ b/eos/effectHandlerHelpers.py @@ -197,14 +197,20 @@ class HandledImplantBoosterList(HandledList): self.remove(thing) return + self.makeRoom(thing) + HandledList.append(self, thing) + + def makeRoom(self, thing): # if needed, remove booster that was occupying slot oldObj = next((m for m in self if m.slot == thing.slot), None) if oldObj: - pyfalog.info("Slot {0} occupied with {1}, replacing with {2}", thing.slot, oldObj.item.name, thing.item.name) + pyfalog.info("Slot {0} occupied with {1}, replacing with {2}", thing.slot, oldObj.item.name, + thing.item.name) + itemID = oldObj.itemID oldObj.itemID = 0 # hack to remove from DB. See GH issue #324 self.remove(oldObj) - - HandledList.append(self, thing) + return itemID + return None class HandledSsoCharacterList(list): diff --git a/gui/builtinAdditionPanes/boosterView.py b/gui/builtinAdditionPanes/boosterView.py index ef9c88f2d..48b3ed36d 100644 --- a/gui/builtinAdditionPanes/boosterView.py +++ b/gui/builtinAdditionPanes/boosterView.py @@ -148,7 +148,7 @@ class BoosterView(d.Display): def removeBooster(self, booster): fitID = self.mainFrame.getActiveFit() - self.mainFrame.command.Submit(cmd.GuiRemoveImplantCommand(fitID, self.origional.index(booster))) + self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(fitID, self.origional.index(booster))) def click(self, event): event.Skip() diff --git a/gui/fitCommands/calc/fitAddBooster.py b/gui/fitCommands/calc/fitAddBooster.py index 356a742da..61f4f5b49 100644 --- a/gui/fitCommands/calc/fitAddBooster.py +++ b/gui/fitCommands/calc/fitAddBooster.py @@ -19,7 +19,7 @@ class FitAddBoosterCommand(wx.Command): self.fitID = fitID self.itemID = itemID self.new_index = None - + self.old_item = None def Do(self): pyfalog.debug("Adding booster ({0}) to fit ID: {1}", self.itemID, self.fitID) @@ -31,11 +31,19 @@ class FitAddBoosterCommand(wx.Command): pyfalog.warning("Invalid item: {0}", self.itemID) return False + self.old_item = fit.boosters.makeRoom(booster) + fit.boosters.append(booster) self.new_index = fit.boosters.index(booster) return True def Undo(self): + if self.old_item: + # If we had an item in the slot previously, add it back. + cmd = FitAddBoosterCommand(self.fitID, self.old_item) + cmd.Do() + return True + from .fitRemoveBooster import FitRemoveBoosterCommand # Avoid circular import cmd = FitRemoveBoosterCommand(self.fitID, self.new_index) cmd.Do() diff --git a/gui/fitCommands/calc/fitAddImplant.py b/gui/fitCommands/calc/fitAddImplant.py index 91bc5be61..b65b53e69 100644 --- a/gui/fitCommands/calc/fitAddImplant.py +++ b/gui/fitCommands/calc/fitAddImplant.py @@ -18,6 +18,7 @@ class FitAddImplantCommand(wx.Command): wx.Command.__init__(self, True, "Cargo add") self.fitID = fitID self.itemID = itemID + self.old_item = None def Do(self): pyfalog.debug("Adding implant to fit ({0}) for item ID: {1}", self.fitID, self.itemID) @@ -30,11 +31,18 @@ class FitAddImplantCommand(wx.Command): pyfalog.warning("Invalid item: {0}", self.itemID) return False + self.old_item = fit.implants.makeRoom(implant) fit.implants.append(implant) self.new_index = fit.implants.index(implant) return True def Undo(self): + if self.old_item: + # If we had an item in the slot previously, add it back. + cmd = FitAddImplantCommand(self.fitID, self.old_item) + cmd.Do() + return True + from .fitRemoveImplant import FitRemoveImplantCommand # Avoid circular import cmd = FitRemoveImplantCommand(self.fitID, self.new_index) cmd.Do() diff --git a/gui/fitCommands/guiAddBooster.py b/gui/fitCommands/guiAddBooster.py index 392ce3034..3dc423cf6 100644 --- a/gui/fitCommands/guiAddBooster.py +++ b/gui/fitCommands/guiAddBooster.py @@ -17,6 +17,7 @@ class GuiAddBoosterCommand(wx.Command): def Do(self): if self.internal_history.Submit(self.cmd): + self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True return False @@ -24,6 +25,7 @@ class GuiAddBoosterCommand(wx.Command): def Undo(self): for x in self.internal_history.Commands: self.internal_history.Undo() + self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/guiRemoveBooster.py b/gui/fitCommands/guiRemoveBooster.py index 92578b0b8..2155ab120 100644 --- a/gui/fitCommands/guiRemoveBooster.py +++ b/gui/fitCommands/guiRemoveBooster.py @@ -17,6 +17,7 @@ class GuiRemoveBoosterCommand(wx.Command): def Do(self): if self.internal_history.Submit(self.cmd): + self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True return False @@ -24,6 +25,7 @@ class GuiRemoveBoosterCommand(wx.Command): def Undo(self): for x in self.internal_history.Commands: self.internal_history.Undo() + self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True