From 0c3fa53bcf3bae8b885ccc115bc15ebee980106f Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sat, 21 Jul 2018 14:46:25 -0400 Subject: [PATCH] Support undo/redo module add --- gui/builtinViews/fittingView.py | 6 ++---- gui/fitCommands/__init__.py | 3 ++- gui/fitCommands/moduleAdd.py | 29 +++++++++++++++++++++++++++++ service/fit.py | 2 +- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 gui/fitCommands/moduleAdd.py diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index 6ccc00c33..d25f2f097 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -382,14 +382,12 @@ class FittingView(d.Display): sFit.setAmmo(fitID, itemID, modules) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID)) else: - populate = sFit.appendModule(fitID, itemID) - if populate is not None: - self.slotsChanged() - wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID, action="modadd", typeID=itemID)) + self.mainFrame.command.Submit(cmd.FitModuleAddCommand(fitID, itemID)) event.Skip() def removeItem(self, event): + '''Double Left Click - remove module''' if event.CmdDown(): return row, _ = self.HitTest(event.Position) diff --git a/gui/fitCommands/__init__.py b/gui/fitCommands/__init__.py index 19100381e..fcb59fc63 100644 --- a/gui/fitCommands/__init__.py +++ b/gui/fitCommands/__init__.py @@ -1 +1,2 @@ -from .moduleStateChange import FitModuleStateChangeCommand \ No newline at end of file +from .moduleStateChange import FitModuleStateChangeCommand +from.moduleAdd import FitModuleAddCommand \ No newline at end of file diff --git a/gui/fitCommands/moduleAdd.py b/gui/fitCommands/moduleAdd.py new file mode 100644 index 000000000..c7f4e21f7 --- /dev/null +++ b/gui/fitCommands/moduleAdd.py @@ -0,0 +1,29 @@ +import wx +from service.fit import Fit + +import gui.mainFrame +from gui import globalEvents as GE + + +class FitModuleAddCommand(wx.Command): + def __init__(self, fitID, itemID): + # todo: instead of modules, needs to be positions. Dead objects are a thing + wx.Command.__init__(self, True, "Module Add") + self.mainFrame = gui.mainFrame.MainFrame.getInstance() + self.sFit = Fit.getInstance() + self.fitID = fitID + self.itemID = itemID + self.new_position = None + + def Do(self): + populate, self.new_position = self.sFit.appendModule(self.fitID, self.itemID) + if populate is not None: + # self.slotsChanged() # unsure how to handle this right now? Perhaps move this to the event itself? + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="modadd", typeID=self.itemID)) + return True + + def Undo(self): + # todo: self.slotsChanged() + result = self.sFit.removeModule(self.fitID, [self.new_position]) + wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel", typeID=self.itemID)) + return True diff --git a/service/fit.py b/service/fit.py index 3a4d044eb..245007dda 100644 --- a/service/fit.py +++ b/service/fit.py @@ -566,7 +566,7 @@ class Fit(object): fit.fill() eos.db.commit() - return numSlots != len(fit.modules) + return numSlots != len(fit.modules), m.modPosition else: return None