Add multi-selection support to command fit remove command
This commit is contained in:
@@ -101,8 +101,8 @@ class CommandView(d.Display):
|
||||
if row != -1:
|
||||
commandFit = self.get(row)
|
||||
if commandFit is not None:
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveCommandFitCommand(
|
||||
fitID=fitID, commandFitID=commandFit.ID))
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveCommandFitsCommand(
|
||||
fitID=fitID, commandFitIDs=[commandFit.ID]))
|
||||
|
||||
def handleDrag(self, type, fitID):
|
||||
# Those are drags coming from pyfa sources, NOT builtin wx drags
|
||||
@@ -214,4 +214,4 @@ class CommandView(d.Display):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
thing = self.get(row)
|
||||
if thing: # thing doesn't exist if it's the dummy value
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveCommandFitCommand(fitID, thing.ID))
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveCommandFitsCommand(fitID=fitID, commandFitIDs=[thing.ID]))
|
||||
|
||||
@@ -147,8 +147,8 @@ class RemoveItem(ContextMenuCombined):
|
||||
|
||||
def __handleCommandFit(self, mainItem, selection):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveCommandFitCommand(
|
||||
fitID=fitID, commandFitID=mainItem.ID))
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveCommandFitsCommand(
|
||||
fitID=fitID, commandFitIDs=[mainItem.ID]))
|
||||
|
||||
|
||||
RemoveItem.register()
|
||||
|
||||
@@ -8,7 +8,7 @@ from .gui.cargo.changeAmount import GuiChangeCargoAmountCommand
|
||||
from .gui.cargo.changeMeta import GuiChangeCargoMetaCommand
|
||||
from .gui.cargo.remove import GuiRemoveCargosCommand
|
||||
from .gui.commandFit.add import GuiAddCommandFitCommand
|
||||
from .gui.commandFit.remove import GuiRemoveCommandFitCommand
|
||||
from .gui.commandFit.remove import GuiRemoveCommandFitsCommand
|
||||
from .gui.commandFit.toggleState import GuiToggleCommandFitStateCommand
|
||||
from .gui.fitRename import GuiRenameFitCommand
|
||||
from .gui.implant.add import GuiAddImplantCommand
|
||||
|
||||
@@ -10,11 +10,12 @@ pyfalog = Logger(__name__)
|
||||
|
||||
class CalcAddCommandCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, commandFitID, state=None):
|
||||
def __init__(self, fitID, commandFitID, state=None, commit=True):
|
||||
wx.Command.__init__(self, True, 'Add Command Fit')
|
||||
self.fitID = fitID
|
||||
self.commandFitID = commandFitID
|
||||
self.state = state
|
||||
self.commit = commit
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing addition of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
|
||||
@@ -46,7 +47,8 @@ class CalcAddCommandCommand(wx.Command):
|
||||
return False
|
||||
fitCommandInfo.active = self.state
|
||||
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
@@ -56,6 +58,6 @@ class CalcAddCommandCommand(wx.Command):
|
||||
commandFit = Fit.getInstance().getFit(self.commandFitID)
|
||||
if commandFit is None:
|
||||
return True
|
||||
from .remove import CalcRemoveCommandCommand
|
||||
cmd = CalcRemoveCommandCommand(fitID=self.fitID, commandFitID=self.commandFitID)
|
||||
from .remove import CalcRemoveCommandFitCommand
|
||||
cmd = CalcRemoveCommandFitCommand(fitID=self.fitID, commandFitID=self.commandFitID, commit=self.commit)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -8,12 +8,13 @@ from service.fit import Fit
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcRemoveCommandCommand(wx.Command):
|
||||
class CalcRemoveCommandFitCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, commandFitID):
|
||||
def __init__(self, fitID, commandFitID, commit=True):
|
||||
wx.Command.__init__(self, True, 'Remove Command Fit')
|
||||
self.fitID = fitID
|
||||
self.commandFitID = commandFitID
|
||||
self.commit = commit
|
||||
self.savedState = None
|
||||
|
||||
def Do(self):
|
||||
@@ -35,11 +36,16 @@ class CalcRemoveCommandCommand(wx.Command):
|
||||
pyfalog.warning('Unable to find commanding fit in command dict')
|
||||
return False
|
||||
del fit.commandFitDict[commandFit.ID]
|
||||
eos.db.commit()
|
||||
if self.commit:
|
||||
eos.db.commit()
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing removal of command fit {} for fit {}'.format(self.commandFitID, self.fitID))
|
||||
from .add import CalcAddCommandCommand
|
||||
cmd = CalcAddCommandCommand(fitID=self.fitID, commandFitID=self.commandFitID, state=self.savedState)
|
||||
cmd = CalcAddCommandCommand(
|
||||
fitID=self.fitID,
|
||||
commandFitID=self.commandFitID,
|
||||
state=self.savedState,
|
||||
commit=self.commit)
|
||||
return cmd.Do()
|
||||
|
||||
@@ -1,29 +1,35 @@
|
||||
import wx
|
||||
|
||||
import eos.db
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.commandFit.remove import CalcRemoveCommandCommand
|
||||
from gui.fitCommands.calc.commandFit.remove import CalcRemoveCommandFitCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiRemoveCommandFitCommand(wx.Command):
|
||||
class GuiRemoveCommandFitsCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, commandFitID):
|
||||
wx.Command.__init__(self, True, 'Remove Command Fit')
|
||||
def __init__(self, fitID, commandFitIDs):
|
||||
wx.Command.__init__(self, True, 'Remove Command Fits')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.commandFitID = commandFitID
|
||||
self.commandFitIDs = commandFitIDs
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcRemoveCommandCommand(fitID=self.fitID, commandFitID=self.commandFitID)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
results = []
|
||||
for commandFitID in self.commandFitIDs:
|
||||
cmd = CalcRemoveCommandFitCommand(fitID=self.fitID, commandFitID=commandFitID, 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
|
||||
|
||||
def Undo(self):
|
||||
success = self.internalHistory.undoAll()
|
||||
eos.db.commit()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
Reference in New Issue
Block a user