diff --git a/gui/builtinAdditionPanes/boosterView.py b/gui/builtinAdditionPanes/boosterView.py index 3758017e6..cc1f59215 100644 --- a/gui/builtinAdditionPanes/boosterView.py +++ b/gui/builtinAdditionPanes/boosterView.py @@ -85,7 +85,7 @@ class BoosterView(d.Display): def kbEvent(self, event): keycode = event.GetKeyCode() - if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE: + if keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE): row = self.GetFirstSelected() if row != -1: self.removeBooster(self.boosters[self.GetItemData(row)]) diff --git a/gui/builtinAdditionPanes/cargoView.py b/gui/builtinAdditionPanes/cargoView.py index c5eb20af8..f2a3c9903 100644 --- a/gui/builtinAdditionPanes/cargoView.py +++ b/gui/builtinAdditionPanes/cargoView.py @@ -80,7 +80,7 @@ class CargoView(d.Display): elif data[0] == "market": fit = self.mainFrame.getActiveFit() if fit: - self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fit, int(data[1]))) + self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fit, int(data[1]), 1)) def startDrag(self, event): row = event.GetIndex() @@ -97,13 +97,12 @@ class CargoView(d.Display): def kbEvent(self, event): keycode = event.GetKeyCode() - if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE: - fitID = self.mainFrame.getActiveFit() - sFit = Fit.getInstance() + if keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE): row = self.GetFirstSelected() if row != -1: - sFit.removeCargo(fitID, self.GetItemData(row)) - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) + fitID = self.mainFrame.getActiveFit() + cargo = self.cargo[self.GetItemData(row)] + self.mainFrame.command.Submit(cmd.GuiRemoveCargoCommand(fitID=fitID, itemID=cargo.itemID)) event.Skip() def swapModule(self, x, y, modIdx): diff --git a/gui/builtinAdditionPanes/implantView.py b/gui/builtinAdditionPanes/implantView.py index 1e80d3db2..cd3952fc1 100644 --- a/gui/builtinAdditionPanes/implantView.py +++ b/gui/builtinAdditionPanes/implantView.py @@ -136,7 +136,7 @@ class ImplantDisplay(d.Display): def kbEvent(self, event): keycode = event.GetKeyCode() - if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE: + if keycode in (wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE): row = self.GetFirstSelected() if row != -1: self.removeImplant(self.implants[self.GetItemData(row)]) diff --git a/gui/builtinContextMenus/amount.py b/gui/builtinContextMenus/amount.py index f6f92bebe..f06849dc6 100644 --- a/gui/builtinContextMenus/amount.py +++ b/gui/builtinContextMenus/amount.py @@ -50,7 +50,7 @@ class ChangeAmount(ContextMenu): cleanInput = int(float(re.sub(r'[^0-9.]', '', dlg.input.GetLineText(0).strip()))) if isinstance(thing, es_Cargo): - self.mainFrame.command.Submit(cmd.GuiChangeCargoQty(fitID, thing.itemID, cleanInput)) + self.mainFrame.command.Submit(cmd.GuiChangeCargoAmount(fitID, thing.itemID, cleanInput)) elif isinstance(thing, Drone): if srcContext == "projectedDrone": self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneQty(fitID, thing.itemID, cleanInput)) diff --git a/gui/builtinContextMenus/cargo.py b/gui/builtinContextMenus/cargo.py index 3bcadfa31..d7586b842 100644 --- a/gui/builtinContextMenus/cargo.py +++ b/gui/builtinContextMenus/cargo.py @@ -35,7 +35,7 @@ class Cargo(ContextMenu): typeID = int(selection[0].ID) - self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fitID, typeID)) + self.mainFrame.command.Submit(cmd.GuiAddCargoCommand(fitID, typeID, 1)) self.mainFrame.additionsPane.select("Cargo") diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index a8ee6a34b..75852f557 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -2,7 +2,9 @@ from .booster.add import GuiAddBoosterCommand from .booster.remove import GuiRemoveBoosterCommand from .booster.sideEffectToggleState import GuiToggleBoosterSideEffectStateCommand from .booster.toggleState import GuiToggleBoosterStateCommand -from .guiAddCargo import GuiAddCargoCommand +from .cargo.add import GuiAddCargoCommand +from .cargo.changeAmount import GuiChangeCargoAmount +from .cargo.remove import GuiRemoveCargoCommand from .guiAddCharge import GuiModuleAddChargeCommand from .guiAddCommand import GuiAddCommandCommand from .guiAddDrone import GuiAddDroneCommand @@ -10,7 +12,6 @@ from .guiAddFighter import GuiAddFighterCommand from .guiAddModule import GuiModuleAddCommand from .guiAddProjected import GuiAddProjectedCommand from .guiCargoToModule import GuiCargoToModuleCommand -from .guiChangeCargoQty import GuiChangeCargoQty from .guiChangeDroneQty import GuiChangeDroneQty from .guiChangeFighterQty import GuiChangeFighterQty from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty @@ -24,7 +25,6 @@ from .guiModuleToCargo import GuiModuleToCargoCommand from .guiMutaConvert import GuiMutaConvertCommand from .guiMutaRevert import GuiMutaRevertCommand from .guiRebaseItems import GuiRebaseItemsCommand -from .guiRemoveCargo import GuiRemoveCargoCommand from .guiRemoveCommand import GuiRemoveCommandCommand from .guiRemoveDrone import GuiRemoveDroneCommand from .guiRemoveFighter import GuiRemoveFighterCommand diff --git a/gui/fitCommands/cargo/__init__.py b/gui/fitCommands/cargo/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/gui/fitCommands/guiAddCargo.py b/gui/fitCommands/cargo/add.py similarity index 54% rename from gui/fitCommands/guiAddCargo.py rename to gui/fitCommands/cargo/add.py index 52400dd71..093e60d72 100644 --- a/gui/fitCommands/guiAddCargo.py +++ b/gui/fitCommands/cargo/add.py @@ -1,29 +1,27 @@ import wx -from service.fit import Fit import gui.mainFrame from gui import globalEvents as GE -from gui.fitCommands.helpers import CargoInfo -from .calcCommands.cargo.add import CalcAddCargoCommand +from gui.fitCommands.calcCommands.cargo.add import CalcAddCargoCommand +from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory class GuiAddCargoCommand(wx.Command): - def __init__(self, fitID, itemID, amount=1): - wx.Command.__init__(self, True, "Cargo Add") - self.internalHistory = wx.CommandProcessor() + def __init__(self, fitID, itemID, amount): + wx.Command.__init__(self, True, 'Add Cargo') + self.internalHistory = InternalCommandHistory() self.fitID = fitID self.itemID = itemID self.amount = amount def Do(self): - if self.internalHistory.Submit(CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=self.amount))): + if self.internalHistory.submit(CalcAddCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=self.amount))): wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return True return False def Undo(self): - for _ in self.internalHistory.Commands: - self.internalHistory.Undo() + success = self.internalHistory.undoAll() wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True + return success diff --git a/gui/fitCommands/cargo/changeAmount.py b/gui/fitCommands/cargo/changeAmount.py new file mode 100644 index 000000000..93653492c --- /dev/null +++ b/gui/fitCommands/cargo/changeAmount.py @@ -0,0 +1,35 @@ +import math + +import wx + +import gui.mainFrame +from gui import globalEvents as GE +from gui.fitCommands.calcCommands.cargo.changeAmount import CalcChangeCargoAmountCommand +from gui.fitCommands.calcCommands.cargo.remove import CalcRemoveCargoCommand +from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory + + +class GuiChangeCargoAmount(wx.Command): + + def __init__(self, fitID, itemID, amount): + wx.Command.__init__(self, True, 'Change Cargo Amount') + self.internalHistory = InternalCommandHistory() + self.fitID = fitID + self.itemID = itemID + self.amount = amount + + def Do(self): + if self.amount > 0: + if self.internalHistory.submit(CalcChangeCargoAmountCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=self.amount))): + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return True + else: + if self.internalHistory.submit(CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf))): + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return True + return False + + def Undo(self): + success = self.internalHistory.undoAll() + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + return success diff --git a/gui/fitCommands/guiRemoveCargo.py b/gui/fitCommands/cargo/remove.py similarity index 57% rename from gui/fitCommands/guiRemoveCargo.py rename to gui/fitCommands/cargo/remove.py index f5c401b3c..cfd4d3ca3 100644 --- a/gui/fitCommands/guiRemoveCargo.py +++ b/gui/fitCommands/cargo/remove.py @@ -1,29 +1,28 @@ import math import wx -from service.fit import Fit import gui.mainFrame from gui import globalEvents as GE -from gui.fitCommands.helpers import CargoInfo -from .calcCommands.cargo.remove import CalcRemoveCargoCommand +from gui.fitCommands.calcCommands.cargo.remove import CalcRemoveCargoCommand +from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory class GuiRemoveCargoCommand(wx.Command): + def __init__(self, fitID, itemID): - wx.Command.__init__(self, True, "Cargo Remove") - self.internalHistory = wx.CommandProcessor() + wx.Command.__init__(self, True, 'Remove Cargo') + self.internalHistory = InternalCommandHistory() self.fitID = fitID self.itemID = itemID def Do(self): - if self.internalHistory.Submit(CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf))): + if self.internalHistory.submit(CalcRemoveCargoCommand(fitID=self.fitID, cargoInfo=CargoInfo(itemID=self.itemID, amount=math.inf))): wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) return True return False def Undo(self): - for _ in self.internalHistory.GetCommands(): - self.internalHistory.Undo() + success = self.internalHistory.undoAll() wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True + return success diff --git a/gui/fitCommands/guiChangeCargoQty.py b/gui/fitCommands/guiChangeCargoQty.py deleted file mode 100644 index 4be9db1ac..000000000 --- a/gui/fitCommands/guiChangeCargoQty.py +++ /dev/null @@ -1,33 +0,0 @@ -import wx -import gui.mainFrame -from gui import globalEvents as GE -from .calcCommands.cargo.changeAmount import CalcChangeCargoAmountCommand -from service.fit import Fit -from gui.fitCommands.helpers import CargoInfo -from logbook import Logger -pyfalog = Logger(__name__) - - -class GuiChangeCargoQty(wx.Command): - - def __init__(self, fitID, itemID, amount): - wx.Command.__init__(self, True, "") - self.fitID = fitID - self.itemID = itemID - self.amount = amount - self.internalHistory = wx.CommandProcessor() - - def Do(self): - cmd = CalcChangeCargoAmountCommand(self.fitID, CargoInfo(itemID=self.itemID, amount=self.amount)) - if self.internalHistory.Submit(cmd): - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True - return False - - def Undo(self): - for _ in self.internalHistory.Commands: - self.internalHistory.Undo() - Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) - return True diff --git a/service/fitDeprecated.py b/service/fitDeprecated.py index a103fad77..3bea7a12e 100644 --- a/service/fitDeprecated.py +++ b/service/fitDeprecated.py @@ -607,18 +607,6 @@ class FitDeprecated(object): return True - @deprecated - def removeCargo(self, fitID, position): - pyfalog.debug("Removing cargo from position ({0}) fit ID: {1}", position, fitID) - if fitID is None: - return False - - fit = eos.db.getFit(fitID) - charge = fit.cargo[position] - fit.cargo.remove(charge) - self.recalc(fit) - return True - @deprecated def addFighter(self, fitID, itemID, recalc=True): pyfalog.debug("Adding fighters ({0}) to fit ID: {1}", itemID, fitID)