Change booster removal commands to support multi-selection
This commit is contained in:
@@ -48,6 +48,7 @@ class BoosterViewDrop(wx.DropTarget):
|
|||||||
|
|
||||||
|
|
||||||
class BoosterView(d.Display):
|
class BoosterView(d.Display):
|
||||||
|
|
||||||
DEFAULT_COLS = [
|
DEFAULT_COLS = [
|
||||||
"State",
|
"State",
|
||||||
"attr:boosterness",
|
"attr:boosterness",
|
||||||
@@ -162,8 +163,8 @@ class BoosterView(d.Display):
|
|||||||
fitID = self.mainFrame.getActiveFit()
|
fitID = self.mainFrame.getActiveFit()
|
||||||
if booster in self.original:
|
if booster in self.original:
|
||||||
position = self.original.index(booster)
|
position = self.original.index(booster)
|
||||||
self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(
|
self.mainFrame.command.Submit(cmd.GuiRemoveBoostersCommand(
|
||||||
fitID=fitID, position=position))
|
fitID=fitID, positions=[position]))
|
||||||
|
|
||||||
def click(self, event):
|
def click(self, event):
|
||||||
event.Skip()
|
event.Skip()
|
||||||
|
|||||||
@@ -226,35 +226,33 @@ class ImplantDisplay(d.Display):
|
|||||||
def click(self, event):
|
def click(self, event):
|
||||||
fitID = self.mainFrame.getActiveFit()
|
fitID = self.mainFrame.getActiveFit()
|
||||||
fit = Fit.getInstance().getFit(fitID)
|
fit = Fit.getInstance().getFit(fitID)
|
||||||
if fit.implantLocation != ImplantLocation.FIT:
|
if fit.implantLocation == ImplantLocation.FIT:
|
||||||
event.Skip()
|
mainRow, _ = self.HitTest(event.Position)
|
||||||
return
|
if mainRow != -1:
|
||||||
mainRow, _ = self.HitTest(event.Position)
|
col = self.getColumn(event.Position)
|
||||||
if mainRow != -1:
|
if col == self.getColIndex(State):
|
||||||
col = self.getColumn(event.Position)
|
fitID = self.mainFrame.getActiveFit()
|
||||||
if col == self.getColIndex(State):
|
try:
|
||||||
fitID = self.mainFrame.getActiveFit()
|
mainImplant = self.implants[mainRow]
|
||||||
try:
|
except IndexError:
|
||||||
mainImplant = self.implants[mainRow]
|
return
|
||||||
except IndexError:
|
if mainImplant in self.original:
|
||||||
return
|
mainPosition = self.original.index(mainImplant)
|
||||||
if mainImplant in self.original:
|
positions = []
|
||||||
mainPosition = self.original.index(mainImplant)
|
for row in self.getSelectedRows():
|
||||||
positions = []
|
try:
|
||||||
for row in self.getSelectedRows():
|
implant = self.implants[row]
|
||||||
try:
|
except IndexError:
|
||||||
implant = self.implants[row]
|
continue
|
||||||
except IndexError:
|
if implant in self.original:
|
||||||
continue
|
positions.append(self.original.index(implant))
|
||||||
if implant in self.original:
|
if mainPosition not in positions:
|
||||||
positions.append(self.original.index(implant))
|
positions = [mainPosition]
|
||||||
if mainPosition not in positions:
|
self.mainFrame.command.Submit(cmd.GuiToggleImplantStatesCommand(
|
||||||
positions = [mainPosition]
|
fitID=fitID,
|
||||||
self.mainFrame.command.Submit(cmd.GuiToggleImplantStatesCommand(
|
mainPosition=mainPosition,
|
||||||
fitID=fitID,
|
positions=positions))
|
||||||
mainPosition=mainPosition,
|
return
|
||||||
positions=positions))
|
|
||||||
return
|
|
||||||
event.Skip()
|
event.Skip()
|
||||||
|
|
||||||
def spawnMenu(self, event):
|
def spawnMenu(self, event):
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class RemoveItem(ContextMenuCombined):
|
|||||||
fit = Fit.getInstance().getFit(fitID)
|
fit = Fit.getInstance().getFit(fitID)
|
||||||
if mainItem in fit.boosters:
|
if mainItem in fit.boosters:
|
||||||
position = fit.boosters.index(mainItem)
|
position = fit.boosters.index(mainItem)
|
||||||
self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(
|
self.mainFrame.command.Submit(cmd.GuiRemoveBoostersCommand(
|
||||||
fitID=fitID, position=position))
|
fitID=fitID, position=position))
|
||||||
|
|
||||||
def __handleCargo(self, mainItem, selection):
|
def __handleCargo(self, mainItem, selection):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from .gui.booster.add import GuiAddBoosterCommand
|
from .gui.booster.add import GuiAddBoosterCommand
|
||||||
from .gui.booster.changeMeta import GuiChangeBoosterMetaCommand
|
from .gui.booster.changeMeta import GuiChangeBoosterMetaCommand
|
||||||
from .gui.booster.remove import GuiRemoveBoosterCommand
|
from .gui.booster.remove import GuiRemoveBoostersCommand
|
||||||
from .gui.booster.sideEffectToggleState import GuiToggleBoosterSideEffectStateCommand
|
from .gui.booster.sideEffectToggleState import GuiToggleBoosterSideEffectStateCommand
|
||||||
from .gui.booster.toggleState import GuiToggleBoosterStateCommand
|
from .gui.booster.toggleState import GuiToggleBoosterStateCommand
|
||||||
from .gui.cargo.add import GuiAddCargoCommand
|
from .gui.cargo.add import GuiAddCargoCommand
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ pyfalog = Logger(__name__)
|
|||||||
|
|
||||||
class CalcAddBoosterCommand(wx.Command):
|
class CalcAddBoosterCommand(wx.Command):
|
||||||
|
|
||||||
def __init__(self, fitID, boosterInfo, position=None):
|
def __init__(self, fitID, boosterInfo, position=None, commit=True):
|
||||||
wx.Command.__init__(self, True, 'Add Booster')
|
wx.Command.__init__(self, True, 'Add Booster')
|
||||||
self.fitID = fitID
|
self.fitID = fitID
|
||||||
self.newBoosterInfo = boosterInfo
|
self.newBoosterInfo = boosterInfo
|
||||||
self.newPosition = position
|
self.newPosition = position
|
||||||
|
self.commit = commit
|
||||||
self.oldBoosterInfo = None
|
self.oldBoosterInfo = None
|
||||||
self.oldPosition = None
|
self.oldPosition = None
|
||||||
|
|
||||||
@@ -38,7 +39,11 @@ class CalcAddBoosterCommand(wx.Command):
|
|||||||
fit.boosters.insert(self.newPosition, newBooster)
|
fit.boosters.insert(self.newPosition, newBooster)
|
||||||
except HandledListActionError:
|
except HandledListActionError:
|
||||||
pyfalog.warning('Failed to insert to list')
|
pyfalog.warning('Failed to insert to list')
|
||||||
cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=self.oldBoosterInfo, position=self.oldPosition)
|
cmd = CalcAddBoosterCommand(
|
||||||
|
fitID=self.fitID,
|
||||||
|
boosterInfo=self.oldBoosterInfo,
|
||||||
|
position=self.oldPosition,
|
||||||
|
commit=self.commit)
|
||||||
cmd.Do()
|
cmd.Do()
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@@ -46,19 +51,24 @@ class CalcAddBoosterCommand(wx.Command):
|
|||||||
fit.boosters.append(newBooster)
|
fit.boosters.append(newBooster)
|
||||||
except HandledListActionError:
|
except HandledListActionError:
|
||||||
pyfalog.warning('Failed to append to list')
|
pyfalog.warning('Failed to append to list')
|
||||||
cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=self.oldBoosterInfo, position=self.oldPosition)
|
cmd = CalcAddBoosterCommand(
|
||||||
|
fitID=self.fitID,
|
||||||
|
boosterInfo=self.oldBoosterInfo,
|
||||||
|
position=self.oldPosition,
|
||||||
|
commit=self.commit)
|
||||||
cmd.Do()
|
cmd.Do()
|
||||||
return False
|
return False
|
||||||
self.newPosition = fit.boosters.index(newBooster)
|
self.newPosition = fit.boosters.index(newBooster)
|
||||||
|
|
||||||
eos.db.commit()
|
if self.commit:
|
||||||
|
eos.db.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def Undo(self):
|
def Undo(self):
|
||||||
pyfalog.debug('Undo addition of booster {} to fit {}'.format(self.newBoosterInfo, self.fitID))
|
pyfalog.debug('Undo addition of booster {} to fit {}'.format(self.newBoosterInfo, self.fitID))
|
||||||
if self.oldBoosterInfo is not None and self.oldPosition is not None:
|
if self.oldBoosterInfo is not None and self.oldPosition is not None:
|
||||||
cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=self.oldBoosterInfo, position=self.oldPosition)
|
cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=self.oldBoosterInfo, position=self.oldPosition, commit=self.commit)
|
||||||
return cmd.Do()
|
return cmd.Do()
|
||||||
from .remove import CalcRemoveBoosterCommand
|
from .remove import CalcRemoveBoosterCommand
|
||||||
cmd = CalcRemoveBoosterCommand(fitID=self.fitID, position=self.newPosition)
|
cmd = CalcRemoveBoosterCommand(fitID=self.fitID, position=self.newPosition, commit=self.commit)
|
||||||
return cmd.Do()
|
return cmd.Do()
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ pyfalog = Logger(__name__)
|
|||||||
|
|
||||||
class CalcRemoveBoosterCommand(wx.Command):
|
class CalcRemoveBoosterCommand(wx.Command):
|
||||||
|
|
||||||
def __init__(self, fitID, position):
|
def __init__(self, fitID, position, commit=True):
|
||||||
wx.Command.__init__(self, True, 'Remove Booster')
|
wx.Command.__init__(self, True, 'Remove Booster')
|
||||||
self.fitID = fitID
|
self.fitID = fitID
|
||||||
self.position = position
|
self.position = position
|
||||||
|
self.commit = commit
|
||||||
self.savedBoosterInfo = None
|
self.savedBoosterInfo = None
|
||||||
|
|
||||||
def Do(self):
|
def Do(self):
|
||||||
@@ -23,11 +24,16 @@ class CalcRemoveBoosterCommand(wx.Command):
|
|||||||
booster = fit.boosters[self.position]
|
booster = fit.boosters[self.position]
|
||||||
self.savedBoosterInfo = BoosterInfo.fromBooster(booster)
|
self.savedBoosterInfo = BoosterInfo.fromBooster(booster)
|
||||||
fit.boosters.remove(booster)
|
fit.boosters.remove(booster)
|
||||||
eos.db.commit()
|
if self.commit:
|
||||||
|
eos.db.commit()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def Undo(self):
|
def Undo(self):
|
||||||
pyfalog.debug('Undoing removal of booster {} on fit {}'.format(self.savedBoosterInfo, self.fitID))
|
pyfalog.debug('Undoing removal of booster {} on fit {}'.format(self.savedBoosterInfo, self.fitID))
|
||||||
from .add import CalcAddBoosterCommand
|
from .add import CalcAddBoosterCommand
|
||||||
cmd = CalcAddBoosterCommand(fitID=self.fitID, boosterInfo=self.savedBoosterInfo, position=self.position)
|
cmd = CalcAddBoosterCommand(
|
||||||
|
fitID=self.fitID,
|
||||||
|
boosterInfo=self.savedBoosterInfo,
|
||||||
|
position=self.position,
|
||||||
|
commit=self.commit)
|
||||||
return cmd.Do()
|
return cmd.Do()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import wx
|
import wx
|
||||||
|
|
||||||
|
import eos.db
|
||||||
import gui.mainFrame
|
import gui.mainFrame
|
||||||
from gui import globalEvents as GE
|
from gui import globalEvents as GE
|
||||||
from gui.fitCommands.calc.booster.remove import CalcRemoveBoosterCommand
|
from gui.fitCommands.calc.booster.remove import CalcRemoveBoosterCommand
|
||||||
@@ -7,23 +8,28 @@ from gui.fitCommands.helpers import InternalCommandHistory
|
|||||||
from service.fit import Fit
|
from service.fit import Fit
|
||||||
|
|
||||||
|
|
||||||
class GuiRemoveBoosterCommand(wx.Command):
|
class GuiRemoveBoostersCommand(wx.Command):
|
||||||
|
|
||||||
def __init__(self, fitID, position):
|
def __init__(self, fitID, positions):
|
||||||
wx.Command.__init__(self, True, 'Remove Booster')
|
wx.Command.__init__(self, True, 'Remove Boosters')
|
||||||
self.internalHistory = InternalCommandHistory()
|
self.internalHistory = InternalCommandHistory()
|
||||||
self.fitID = fitID
|
self.fitID = fitID
|
||||||
self.position = position
|
self.positions = positions
|
||||||
|
|
||||||
def Do(self):
|
def Do(self):
|
||||||
cmd = CalcRemoveBoosterCommand(fitID=self.fitID, position=self.position)
|
results = []
|
||||||
success = self.internalHistory.submit(cmd)
|
for position in sorted(self.positions, reverse=True):
|
||||||
|
cmd = CalcRemoveBoosterCommand(fitID=self.fitID, position=position, commit=False)
|
||||||
|
results.append(self.internalHistory.submit(cmd))
|
||||||
|
success = any(results)
|
||||||
|
eos.db.commit()
|
||||||
Fit.getInstance().recalc(self.fitID)
|
Fit.getInstance().recalc(self.fitID)
|
||||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||||
return success
|
return success
|
||||||
|
|
||||||
def Undo(self):
|
def Undo(self):
|
||||||
success = self.internalHistory.undoAll()
|
success = self.internalHistory.undoAll()
|
||||||
|
eos.db.commit()
|
||||||
Fit.getInstance().recalc(self.fitID)
|
Fit.getInstance().recalc(self.fitID)
|
||||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||||
return success
|
return success
|
||||||
|
|||||||
Reference in New Issue
Block a user