diff --git a/gui/builtinContextMenus/tacticalMode.py b/gui/builtinContextMenus/tacticalMode.py index 94bfc1076..b9b51ae8c 100644 --- a/gui/builtinContextMenus/tacticalMode.py +++ b/gui/builtinContextMenus/tacticalMode.py @@ -61,7 +61,7 @@ class TacticalMode(ContextMenu): return fitID = self.mainFrame.getActiveFit() - self.mainFrame.command.Submit(cmd.GuiSetModeCommand(fitID, self.modeIds[event.Id])) + self.mainFrame.command.Submit(cmd.GuiSetModeCommand(fitID, self.modeIds[event.Id].item.ID)) TacticalMode.register() diff --git a/gui/builtinShipBrowser/fitItem.py b/gui/builtinShipBrowser/fitItem.py index c0bd9c07b..9fbfe44b9 100644 --- a/gui/builtinShipBrowser/fitItem.py +++ b/gui/builtinShipBrowser/fitItem.py @@ -14,6 +14,7 @@ import gui.utils.color as colorUtils import gui.utils.draw as drawUtils import gui.utils.fonts as fonts from gui.bitmap_loader import BitmapLoader +from gui.builtinShipBrowser.events import EVT_FIT_RENAMED from gui.builtinShipBrowser.pfBitmapFrame import PFBitmapFrame from service.fit import Fit from .events import BoosterListUpdated, FitRemoved, FitSelected, ImportSelected, SearchSelected, Stage3Selected @@ -121,6 +122,7 @@ class FitItem(SFItem.SFBrowserItem): self.tcFitName.Bind(wx.EVT_KILL_FOCUS, self.editLostFocus) self.tcFitName.Bind(wx.EVT_KEY_DOWN, self.editCheckEsc) self.Bind(wx.EVT_MOUSE_CAPTURE_LOST, self.OnMouseCaptureLost) + self.mainFrame.Bind(EVT_FIT_RENAMED, self.OnFitRename) self.animTimerId = wx.NewId() self.animTimer = wx.Timer(self, self.animTimerId) @@ -325,11 +327,17 @@ class FitItem(SFItem.SFBrowserItem): self.editWasShown = 0 fitName = self.tcFitName.GetValue() if fitName: - self.fitName = fitName - self.mainFrame.command.Submit(cmd.GuiFitRenameCommand(self.fitID, self.fitName)) + self.mainFrame.command.Submit(cmd.GuiFitRenameCommand(self.fitID, fitName)) else: self.tcFitName.SetValue(self.fitName) + def OnFitRename(self, event): + if event.fitID == self.fitID: + fit = Fit.getInstance().getFit(self.fitID) + self.fitName = fit.name + self.Refresh() + event.Skip() + def deleteBtnCB(self): if self.tcFitName.IsShown(): self.RestoreEditButton() diff --git a/gui/fitCommands/calc/fitChangeProjectedDroneAmount.py b/gui/fitCommands/calc/fitChangeProjectedDroneAmount.py index fc49b6450..2d87d8bf5 100644 --- a/gui/fitCommands/calc/fitChangeProjectedDroneAmount.py +++ b/gui/fitCommands/calc/fitChangeProjectedDroneAmount.py @@ -28,6 +28,8 @@ class FitChangeProjectedDroneAmountCommand(wx.Command): pyfalog.warning('Cannot find projected drone') return False self.savedDroneInfo = DroneInfo.fromDrone(drone) + if self.amount == self.savedDroneInfo.amount: + return False drone.amount = self.amount if drone.amountActive > 0: difference = self.amount - self.savedDroneInfo.amount diff --git a/gui/fitCommands/calc/fitChangeProjectedFitAmount.py b/gui/fitCommands/calc/fitChangeProjectedFitAmount.py index c5252c510..49e3b23cb 100644 --- a/gui/fitCommands/calc/fitChangeProjectedFitAmount.py +++ b/gui/fitCommands/calc/fitChangeProjectedFitAmount.py @@ -30,7 +30,10 @@ class FitChangeProjectedFitAmountCommand(wx.Command): return False self.savedAmount = projectionInfo.amount # Limit to [1, 20] - projectionInfo.amount = min(20, max(1, self.amount)) + confinedAmount = min(20, max(1, self.amount)) + if confinedAmount == self.savedAmount: + return False + projectionInfo.amount = confinedAmount eos.db.commit() return True diff --git a/gui/fitCommands/calc/fitRename.py b/gui/fitCommands/calc/fitRename.py index 78c09dd91..fc66d4421 100644 --- a/gui/fitCommands/calc/fitRename.py +++ b/gui/fitCommands/calc/fitRename.py @@ -18,7 +18,7 @@ class FitRenameCommand(wx.Command): def Do(self): pyfalog.debug('Doing renaming of fit {} to {}'.format(self.fitID, self.name)) - fit = eos.db.getFit(self.fitID) + fit = Fit.getInstance().getFit(self.fitID) self.savedName = fit.name fit.name = self.name eos.db.commit() diff --git a/gui/fitCommands/calc/fitReplaceModule.py b/gui/fitCommands/calc/fitReplaceModule.py index 9130bd38b..60c48e740 100644 --- a/gui/fitCommands/calc/fitReplaceModule.py +++ b/gui/fitCommands/calc/fitReplaceModule.py @@ -26,6 +26,8 @@ class FitReplaceModuleCommand(wx.Command): oldMod = fit.modules[self.position] if not oldMod.isEmpty: self.oldModInfo = ModuleInfo.fromModule(oldMod) + if self.newModInfo == self.oldModInfo: + return False newMod = self.newModInfo.toModule(fallbackState=stateLimit(self.newModInfo.itemID)) if newMod is None: return False diff --git a/gui/fitCommands/calc/fitSetMode.py b/gui/fitCommands/calc/fitSetMode.py index 750be78dd..1077b1e51 100644 --- a/gui/fitCommands/calc/fitSetMode.py +++ b/gui/fitCommands/calc/fitSetMode.py @@ -1,28 +1,33 @@ import wx -import eos.db from logbook import Logger + +import eos.db +from eos.saveddata.mode import Mode +from service.fit import Fit +from service.market import Market + + pyfalog = Logger(__name__) class FitSetModeCommand(wx.Command): - """" - from sFit.setMode - """ - def __init__(self, fitID, mode): - wx.Command.__init__(self, True, "Cargo add") + + def __init__(self, fitID, itemID): + wx.Command.__init__(self, True, 'Set Mode') self.fitID = fitID - self.mode = mode - self.old_mode = None + self.itemID = itemID + self.savedItemID = None def Do(self): - pyfalog.debug("Set mode for fit ID: {0}", self.fitID) - fit = eos.db.getFit(self.fitID) - self.old_mode = fit.mode - fit.mode = self.mode + pyfalog.debug('Doing setting mode {} for fit {}'.format(self.itemID, self.fitID)) + fit = Fit.getInstance().getFit(self.fitID) + self.savedItemID = fit.modeID + item = Market.getInstance().getItem(self.itemID) + mode = Mode(item) + fit.mode = mode eos.db.commit() return True def Undo(self): - cmd = FitSetModeCommand(self.fitID, self.old_mode) - cmd.Do() - return True + cmd = FitSetModeCommand(self.fitID, self.savedItemID) + return cmd.Do() diff --git a/gui/fitCommands/guiSetMode.py b/gui/fitCommands/guiSetMode.py index f7e5e09be..b55b284e3 100644 --- a/gui/fitCommands/guiSetMode.py +++ b/gui/fitCommands/guiSetMode.py @@ -7,16 +7,16 @@ from .calc.fitSetMode import FitSetModeCommand class GuiSetModeCommand(wx.Command): - def __init__(self, fitID, mode): + def __init__(self, fitID, itemID): wx.Command.__init__(self, True, "Mode Set") self.mainFrame = gui.mainFrame.MainFrame.getInstance() self.sFit = Fit.getInstance() self.internal_history = wx.CommandProcessor() self.fitID = fitID - self.mode = mode + self.itemID = itemID def Do(self): - if self.internal_history.Submit(FitSetModeCommand(self.fitID, self.mode)): + if self.internal_history.Submit(FitSetModeCommand(self.fitID, self.itemID)): self.sFit.recalc(self.fitID) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) return True diff --git a/gui/fitCommands/helpers.py b/gui/fitCommands/helpers.py index 10a6ff0af..6165b093e 100644 --- a/gui/fitCommands/helpers.py +++ b/gui/fitCommands/helpers.py @@ -85,6 +85,19 @@ class ModuleInfo: return mod + def __eq__(self, other): + if not isinstance(other, ModuleInfo): + return False + return all(( + self.itemID == other.itemID, + self.baseItemID == other.baseItemID, + self.mutaplasmidID == other.mutaplasmidID, + self.mutations == other.mutations, + self.chargeID == other.chargeID, + self.state == other.state, + self.spoolType == other.spoolType, + self.spoolAmount == other.spoolAmount)) + def __repr__(self): return makeReprStr(self, [ 'itemID', 'baseItemID', 'mutaplasmidID', 'mutations', diff --git a/gui/mainMenuBar.py b/gui/mainMenuBar.py index 5fd09eae0..ad0dd7053 100644 --- a/gui/mainMenuBar.py +++ b/gui/mainMenuBar.py @@ -26,6 +26,7 @@ from service.fit import Fit import gui.graphFrame import gui.globalEvents as GE from gui.bitmap_loader import BitmapLoader +from gui.builtinShipBrowser.events import EVT_FIT_RENAMED from logbook import Logger @@ -171,6 +172,7 @@ class MainMenuBar(wx.MenuBar): helpMenu.Append(self.devToolsId, "Open &Dev Tools", "Dev Tools") self.mainFrame.Bind(GE.FIT_CHANGED, self.fitChanged) + self.mainFrame.Bind(EVT_FIT_RENAMED, self.fitRenamed) def fitChanged(self, event): enable = event.fitID is not None @@ -178,14 +180,7 @@ class MainMenuBar(wx.MenuBar): self.Enable(wx.ID_COPY, enable) self.Enable(self.exportSkillsNeededId, enable) - command = self.mainFrame.command - self.Enable(wx.ID_UNDO, False) - self.Enable(wx.ID_REDO, False) - - if command.CanUndo(): - self.Enable(wx.ID_UNDO, True) - if command.CanRedo(): - self.Enable(wx.ID_REDO, True) + self.refreshUndo() sChar = Character.getInstance() charID = self.mainFrame.charSelection.getActiveCharacter() @@ -208,3 +203,16 @@ class MainMenuBar(wx.MenuBar): self.ignoreRestrictionItem.SetItemLabel("Disable Fitting Re&strictions") event.Skip() + + def fitRenamed(self, event): + self.refreshUndo() + event.Skip() + + def refreshUndo(self): + command = self.mainFrame.command + self.Enable(wx.ID_UNDO, False) + self.Enable(wx.ID_REDO, False) + if command.CanUndo(): + self.Enable(wx.ID_UNDO, True) + if command.CanRedo(): + self.Enable(wx.ID_REDO, True)