Change implant remove command to support batch removal

This commit is contained in:
DarkPhoenix
2019-04-25 14:56:09 +03:00
parent 07a9f77287
commit dc30b3ed1d
4 changed files with 16 additions and 10 deletions

View File

@@ -220,7 +220,7 @@ class ImplantDisplay(d.Display):
fit = sFit.getFit(fitID)
if fit.implantLocation == ImplantLocation.FIT and implant in self.original:
position = self.original.index(implant)
self.mainFrame.command.Submit(cmd.GuiRemoveImplantCommand(fitID=fitID, position=position))
self.mainFrame.command.Submit(cmd.GuiRemoveImplantsCommand(fitID=fitID, positions=[position]))
def click(self, event):
event.Skip()

View File

@@ -98,8 +98,8 @@ class RemoveItem(ContextMenuCombined):
fit = Fit.getInstance().getFit(fitID)
if mainItem in fit.implants:
position = fit.implants.index(mainItem)
self.mainFrame.command.Submit(cmd.GuiRemoveImplantCommand(
fitID=fitID, position=position))
self.mainFrame.command.Submit(cmd.GuiRemoveImplantsCommand(
fitID=fitID, positions=[position]))
def __handleBooster(self, mainItem, selection):
fitID = self.mainFrame.getActiveFit()

View File

@@ -14,7 +14,7 @@ from .gui.fitRename import GuiRenameFitCommand
from .gui.implant.add import GuiAddImplantCommand
from .gui.implant.changeLocation import GuiChangeImplantLocationCommand
from .gui.implant.changeMeta import GuiChangeImplantMetaCommand
from .gui.implant.remove import GuiRemoveImplantCommand
from .gui.implant.remove import GuiRemoveImplantsCommand
from .gui.implant.setAdd import GuiAddImplantSetCommand
from .gui.implant.toggleState import GuiToggleImplantStateCommand
from .gui.itemsRebase import GuiRebaseItemsCommand

View File

@@ -1,23 +1,28 @@
import wx
from service.fit import Fit
import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.helpers import InternalCommandHistory
from gui.fitCommands.calc.implant.remove import CalcRemoveImplantCommand
class GuiRemoveImplantCommand(wx.Command):
class GuiRemoveImplantsCommand(wx.Command):
def __init__(self, fitID, position):
wx.Command.__init__(self, True, 'Remove Implant')
def __init__(self, fitID, positions):
wx.Command.__init__(self, True, 'Remove Implants')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.positions = positions
def Do(self):
cmd = CalcRemoveImplantCommand(fitID=self.fitID, position=self.position)
success = self.internalHistory.submit(cmd)
results = []
for position in sorted(self.positions, reverse=True):
cmd = CalcRemoveImplantCommand(fitID=self.fitID, position=position, commit=False)
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
@@ -25,5 +30,6 @@ class GuiRemoveImplantCommand(wx.Command):
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
eos.db.commit()
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success