Move the FitRenameCommand command

This commit is contained in:
blitzmann
2018-09-15 17:46:55 -04:00
parent 12b11d57ba
commit b08406b7d6
6 changed files with 77 additions and 31 deletions

View File

@@ -20,26 +20,6 @@ from service.fit import Fit
import gui.fitCommands as cmd
pyfalog = Logger(__name__)
class FitRenameCommand(wx.Command):
def __init__(self, fitID, newName):
wx.Command.__init__(self, True, "FitRename")
self.fitID = fitID
self.newName = newName
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.oldName = None
self.sFit = Fit.getInstance()
def Do(self):
self.oldName, _ = self.sFit.renameFit(self.fitID, self.newName)
wx.PostEvent(self.mainFrame, FitRenamed(fitID=self.fitID))
return True
def Undo(self):
self.sFit.renameFit(self.fitID, self.oldName)
wx.PostEvent(self.mainFrame, FitRenamed(fitID=self.fitID))
return True
class FitItem(SFItem.SFBrowserItem):
def __init__(self, parent, fitID=None, shipFittingInfo=("Test", "TestTrait", "cnc's avatar", 0, 0, None), shipID=None,
itemData=None, graphicID=None,
@@ -345,7 +325,7 @@ class FitItem(SFItem.SFBrowserItem):
fitName = self.tcFitName.GetValue()
if fitName:
self.fitName = fitName
self.mainFrame.command.Submit(FitRenameCommand(self.fitID, self.fitName))
self.mainFrame.command.Submit(cmd.GuiFitRenameCommand(self.fitID, self.fitName))
else:
self.tcFitName.SetValue(self.fitName)

View File

@@ -30,4 +30,5 @@ from .guiChangeCargoQty import GuiChangeCargoQty
from .guiChangeProjectedFitQty import GuiChangeProjectedFitQty
from .guiChangeDroneQty import GuiChangeDroneQty
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
from .guiToggleDrone import GuiToggleDroneCommand
from .guiToggleDrone import GuiToggleDroneCommand
from .guiFitRename import GuiFitRenameCommand

View File

@@ -0,0 +1,30 @@
import wx
from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
#from .helpers import ModuleInfoCache
from eos.saveddata.module import Module, State
import eos.db
from logbook import Logger
pyfalog = Logger(__name__)
class FitRenameCommand(wx.Command):
def __init__(self, fitID, newName):
wx.Command.__init__(self, True, "FitRename")
self.fitID = fitID
self.newName = newName
self.oldName = None
def Do(self):
pyfalog.debug("Renaming fit ({0}) to: {1}", self.fitID, self.newName)
fit = eos.db.getFit(self.fitID)
self.oldName = fit.name
fit.name = self.newName
eos.db.commit()
return True
def Undo(self):
cmd = FitRenameCommand(self.fitID, self.oldName)
return cmd.Do()

View File

@@ -0,0 +1,34 @@
import wx
import eos.db
import gui.mainFrame
from service.fit import Fit
from gui import globalEvents as GE
from .calc.fitRename import FitRenameCommand
from service.fit import Fit
from logbook import Logger
from gui.builtinShipBrowser.events import FitRenamed
pyfalog = Logger(__name__)
class GuiFitRenameCommand(wx.Command):
def __init__(self, fitID, newName):
wx.Command.__init__(self, True)
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.sFit = Fit.getInstance()
self.fitID = fitID
self.newName = newName
self.internal_history = wx.CommandProcessor()
def Do(self):
if self.internal_history.Submit(FitRenameCommand(self.fitID, self.newName)):
wx.PostEvent(self.mainFrame, FitRenamed(fitID=self.fitID))
return True
return False
def Undo(self):
pyfalog.debug("{} Undo()".format(self))
for _ in self.internal_history.Commands:
self.internal_history.Undo()
wx.PostEvent(self.mainFrame, FitRenamed(fitID=self.fitID))
return True

View File

@@ -185,15 +185,6 @@ class Fit(FitDeprecated):
fit.booster = not fit.booster
eos.db.commit()
@staticmethod
def renameFit(fitID, newName):
pyfalog.debug("Renaming fit ({0}) to: {1}", fitID, newName)
fit = eos.db.getFit(fitID)
old_name = fit.name
fit.name = newName
eos.db.commit()
return old_name, newName
@staticmethod
def deleteFit(fitID):
fit = eos.db.getFit(fitID)

View File

@@ -36,6 +36,16 @@ pyfalog = Logger(__name__)
class FitDeprecated(object):
@staticmethod
@deprecated
def renameFit(fitID, newName):
pyfalog.debug("Renaming fit ({0}) to: {1}", fitID, newName)
fit = eos.db.getFit(fitID)
old_name = fit.name
fit.name = newName
eos.db.commit()
return old_name, newName
@deprecated
def toggleDrone(self, fitID, i):
pyfalog.debug("Toggling drones for fit ID: {0}", fitID)