Files
pyfa/gui/builtinContextMenus/itemRemove.py
blitzmann d5aeb0913d Start refactoring the refactor that was started with command pattern refactoring.
Instead of attempting to keep all the Fit service functionality, move these into specific "Fitting Commands" that are designed to define a unit of work and it's undo. Then, we will have "GUI Commands" which are defined as actions taken by the user themselves - these will usually use one or more "Fitting Commands".
2018-07-24 01:29:57 -04:00

62 lines
2.6 KiB
Python

from gui.contextMenu import ContextMenu
import gui.mainFrame
# noinspection PyPackageRequirements
import wx
import gui.globalEvents as GE
from service.fit import Fit
from service.settings import ContextMenuSettings
import gui.fitCommands as cmd
class ItemRemove(ContextMenu):
def __init__(self):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.settings = ContextMenuSettings.getInstance()
def display(self, srcContext, selection):
if not self.settings.get('itemRemove'):
return False
return srcContext in ("fittingModule", "fittingCharge",
"droneItem", "implantItem",
"boosterItem", "projectedModule",
"projectedCharge", "cargoItem",
"projectedFit", "projectedDrone",
"fighterItem", "projectedFighter",
"commandFit")
def getText(self, itmContext, selection):
return u"Remove {0}".format(itmContext if itmContext is not None else "Item")
def activate(self, fullContext, selection, i):
srcContext = fullContext[0]
sFit = Fit.getInstance()
fitID = self.mainFrame.getActiveFit()
fit = sFit.getFit(fitID)
if srcContext == "fittingModule":
modules = [module for module in selection if module is not None]
self.mainFrame.command.Submit(cmd.GuiModuleRemoveCommand(fitID, modules))
return # the command takes care of the PostEvent
elif srcContext in ("fittingCharge", "projectedCharge"):
self.mainFrame.command.Submit(cmd.GuiModuleAddChargeCommand(fitID, None, selection))
elif srcContext == "droneItem":
sFit.removeDrone(fitID, fit.drones.index(selection[0]))
elif srcContext == "fighterItem":
sFit.removeFighter(fitID, fit.fighters.index(selection[0]))
elif srcContext == "implantItem":
sFit.removeImplant(fitID, fit.implants.index(selection[0]))
elif srcContext == "boosterItem":
sFit.removeBooster(fitID, fit.boosters.index(selection[0]))
elif srcContext == "cargoItem":
sFit.removeCargo(fitID, fit.cargo.index(selection[0]))
elif srcContext in ("projectedFit", "projectedModule", "projectedDrone", "projectedFighter"):
sFit.removeProjected(fitID, selection[0])
elif srcContext == "commandFit":
sFit.removeCommand(fitID, selection[0])
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
ItemRemove.register()