Added the ability to remove charges and projected items using the itemRemove built in context menu. In this commit I fixed a minor bug in the projected view that caused the right clicked item not to be SHOWN as selected until after the context menu had been spawned and closed. I also removed all parent references from the ContextMenu class and sub classes. I am instead using the fit service to do all the work of removing the items in the itemRemove class.
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
from gui.contextMenu import ContextMenu
|
|
import gui.mainFrame
|
|
import service
|
|
import wx
|
|
import gui.globalEvents as GE
|
|
|
|
class ItemRemove(ContextMenu):
|
|
def __init__(self):
|
|
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
|
|
|
def display(self, srcContext, selection):
|
|
return srcContext in ("fittingModule", "fittingCharge", "droneItem", "implantItem", "boosterItem", "projectedModule", "projectedCharge",
|
|
"projectedFit", "projectedDrone")
|
|
|
|
def getText(self, itmContext, selection):
|
|
return "Remove {0}".format(itmContext if itmContext is not None else "Item")
|
|
|
|
def activate(self, fullContext, selection, i):
|
|
srcContext = fullContext[0]
|
|
sFit = service.Fit.getInstance()
|
|
fitID = self.mainFrame.getActiveFit()
|
|
cFit = sFit.getFit(fitID)
|
|
|
|
if srcContext == "fittingModule":
|
|
for module in selection:
|
|
if module is not None:
|
|
sFit.removeModule(fitID,cFit.modules.index(module))
|
|
elif srcContext in ("fittingCharge" , "projectedCharge"):
|
|
sFit.setAmmo(fitID, None, selection)
|
|
elif srcContext == "droneItem":
|
|
sFit.removeDrone(fitID, cFit.drones.index(selection[0]))
|
|
elif srcContext == "implantItem":
|
|
sFit.removeImplant(fitID, cFit.implants.index(selection[0]))
|
|
elif srcContext == "boosterItem":
|
|
sFit.removeBooster(fitID, cFit.boosters.index(selection[0]))
|
|
else:
|
|
sFit.removeProjected(fitID, selection[0])
|
|
|
|
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
|
|
|
|
|
|
|
|
|
ItemRemove.register()
|