From 4d31c8bb38ad0a28a7732cce593522454fb20ac0 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Tue, 16 Apr 2019 15:01:02 +0300 Subject: [PATCH] Send proper modadd/moddel events when changing mod meta level --- .../gui/localModule/changeMetas.py | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/gui/fitCommands/gui/localModule/changeMetas.py b/gui/fitCommands/gui/localModule/changeMetas.py index 1a2d2d01b..e7adbc34b 100644 --- a/gui/fitCommands/gui/localModule/changeMetas.py +++ b/gui/fitCommands/gui/localModule/changeMetas.py @@ -16,15 +16,20 @@ class GuiChangeLocalModuleMetasCommand(wx.Command): self.fitID = fitID self.positions = positions self.newItemID = newItemID + self.relacedItemIDs = None def Do(self): sFit = Fit.getInstance() fit = sFit.getFit(self.fitID) commands = [] + self.replacedItemIDs = set() for position in self.positions: module = fit.modules[position] + if module.isEmpty: + continue if module.itemID == self.newItemID: continue + self.replacedItemIDs.add(module.itemID) info = ModuleInfo.fromModule(module) info.itemID = self.newItemID cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=info, unloadInvalidCharges=True, commit=False) @@ -34,12 +39,28 @@ class GuiChangeLocalModuleMetasCommand(wx.Command): success = self.internalHistory.submitBatch(*commands) eos.db.commit() sFit.recalc(fit) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + events = [] + if success and self.replacedItemIDs: + events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.replacedItemIDs)) + if success: + events.append(GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.newItemID)) + if not events: + events.append(GE.FitChanged(fitID=self.fitID)) + for event in events: + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event) return success def Undo(self): success = self.internalHistory.undoAll() eos.db.commit() Fit.getInstance().recalc(self.fitID) - wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID)) + events = [] + if success: + events.append(GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.newItemID)) + if success and self.replacedItemIDs: + events.append(GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.replacedItemIDs)) + if not events: + events.append(GE.FitChanged(fitID=self.fitID)) + for event in events: + wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), event) return success