Adding support for Enable/Disable Undo/Redo
authorgreg
Mon, 04 May 2009 09:35:47 +0200
changeset 350 f7958989e055
parent 349 96cc6179b918
child 351 160ff73c0ac7
Adding support for Enable/Disable Undo/Redo
PLCOpenEditor.py
--- a/PLCOpenEditor.py	Mon May 04 09:35:17 2009 +0200
+++ b/PLCOpenEditor.py	Mon May 04 09:35:47 2009 +0200
@@ -67,10 +67,10 @@
 [ID_PLCOPENEDITORFILEMENUGENERATE, 
 ] = [wx.NewId() for _init_coll_FileMenu_Items in range(1)]
 
-[ID_PLCOPENEDITOREDITMENUADDDATATYPE, ID_PLCOPENEDITOREDITMENUADDFUNCTION,
- ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK, ID_PLCOPENEDITOREDITMENUADDPROGRAM,
- ID_PLCOPENEDITOREDITMENUADDCONFIGURATION, 
-] = [wx.NewId() for _init_coll_EditMenu_Items in range(5)]
+[ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, ID_PLCOPENEDITOREDITMENUADDDATATYPE, 
+ ID_PLCOPENEDITOREDITMENUADDFUNCTION, ID_PLCOPENEDITOREDITMENUADDFUNCTIONBLOCK, 
+ ID_PLCOPENEDITOREDITMENUADDPROGRAM, ID_PLCOPENEDITOREDITMENUADDCONFIGURATION, 
+] = [wx.NewId() for _init_coll_EditMenu_Items in range(6)]
 
 
 #-------------------------------------------------------------------------------
@@ -259,6 +259,8 @@
               kind=wx.ITEM_NORMAL, text=u'Undo\tCTRL+Z')
         AppendMenu(parent, help='', id=wx.ID_REDO,
               kind=wx.ITEM_NORMAL, text=u'Redo\tCTRL+Y')
+        AppendMenu(parent, help='', id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO,
+              kind=wx.ITEM_CHECK, text=u'Enable Undo/Redo')
         parent.AppendSeparator()
         AppendMenu(parent, help='', id=wx.ID_CUT,
               kind=wx.ITEM_NORMAL, text=u'Cut\tCTRL+X')
@@ -285,6 +287,7 @@
               kind=wx.ITEM_NORMAL, text=u'Delete')
         self.Bind(wx.EVT_MENU, self.OnUndoMenu, id=wx.ID_UNDO)
         self.Bind(wx.EVT_MENU, self.OnRedoMenu, id=wx.ID_REDO)
+        self.Bind(wx.EVT_MENU, self.OnEnableUndoRedoMenu, id=ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO)
         self.Bind(wx.EVT_MENU, self.OnCutMenu, id=wx.ID_CUT)
         self.Bind(wx.EVT_MENU, self.OnCopyMenu, id=wx.ID_COPY)
         self.Bind(wx.EVT_MENU, self.OnPasteMenu, id=wx.ID_PASTE)
@@ -1057,6 +1060,8 @@
 
     def RefreshEditMenu(self):
         if not self.Debug:
+            self.EditMenu.Check(ID_PLCOPENEDITOREDITMENUENABLEUNDOREDO, 
+                                self.Controler.IsProjectBufferEnabled())
             if self.Controler.HasOpenedProject():
                 undo, redo = self.Controler.GetBufferState()
                 self.EditMenu.Enable(wx.ID_UNDO, undo)
@@ -1095,7 +1100,7 @@
             if self.Controler.GetEditedElement(tagname, self.Debug) is None:
                 self.VariablePanelIndexer.RemoveVariablePanel(tagname)
                 self.TabsOpened.DeletePage(idx)
-        selected = self.TabsOpened.GetSelection()        
+        selected = self.TabsOpened.GetSelection()
         if selected != -1:
             window = self.TabsOpened.GetPage(selected)
             window.RefreshView()
@@ -1130,6 +1135,11 @@
         self.RefreshScaling()
         event.Skip()
 
+    def OnEnableUndoRedoMenu(self, event):
+        self.Controler.EnableProjectBuffer(event.IsChecked())
+        self.RefreshEditMenu()
+        event.Skip()
+
     def OnCutMenu(self, event):
         control = self.FindFocus()
         if isinstance(control, (Viewer, TextViewer)):
@@ -1177,7 +1187,7 @@
                         self.Controler.ProjectRemoveDataType(name)
                         tagname = self.Controler.ComputeDataTypeName(name)
                     else:
-                        message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
+                        message = wx.MessageDialog(self, "\"%s\" is used by one or more POUs. It can't be removed!"%name, "Error", wx.OK|wx.ICON_ERROR)
                         message.ShowModal()
                         message.Destroy()
                 elif type == ITEM_POU:
@@ -1186,7 +1196,7 @@
                         self.Controler.ProjectRemovePou(name)
                         tagname = self.Controler.ComputePouName(name)
                     else:
-                        message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
+                        message = wx.MessageDialog(self, "\"%s\" is used by one or more POUs. It can't be removed!"%name, "Error", wx.OK|wx.ICON_ERROR)
                         message.ShowModal()
                         message.Destroy()
                 elif type in [ITEM_TRANSITION, ITEM_ACTION]:
@@ -1603,9 +1613,10 @@
                 event.Veto()
             else:
                 wx.CallAfter(self.RefreshTypesTree)
-                selected = self.TabsOpened.GetSelection()
-                if selected != -1:
-                    self.TabsOpened.GetPage(selected).RefreshView()
+                self.RefreshEditor()
+                self.RefreshFileMenu()
+                self.RefreshEditMenu()
+                self.RefreshTitle()
                 event.Skip()
     
     def OnTypesTreeItemActivated(self, event):
@@ -1747,7 +1758,6 @@
                 window = self.TabsOpened.GetPage(i)
                 if window.GetTagName() == tagname:
                     self.TabsOpened.SetSelection(i)
-                    window.RefreshView()
                     window.SetFocus()
                     self.RefreshPageTitles()
                     self.RefreshFileMenu()
@@ -1940,7 +1950,6 @@
                     if old_selected >= 0:
                         self.TabsOpened.GetPage(old_selected).ResetBuffer()
                     self.TabsOpened.SetSelection(openedidx)
-                self.TabsOpened.GetPage(openedidx).RefreshView()
             elif selected_infos[1] is not None:
                 bodytype = self.Controler.GetEditedElementBodyType(selected_infos[1], self.Debug)
                 if bodytype == "FBD":
@@ -1960,7 +1969,6 @@
                     else:
                         new_window.SetKeywords(ST_KEYWORDS)
                 self.AddPage(new_window, "")
-                new_window.RefreshView()
                 new_window.SetFocus()
                 self.RefreshPageTitles()
         if selected_item is not None and selected_infos[0] in ITEMS_VARIABLE:
@@ -2351,9 +2359,6 @@
             if dialog.ShowModal() == wx.ID_OK:
                 values = dialog.GetValues()
                 self.Controler.ProjectAddPou(values["pouName"], values["pouType"], values["language"])
-                selected = self.TabsOpened.GetSelection()
-                if selected != -1:
-                    self.TabsOpened.GetPage(selected).RefreshView()
                 self.RefreshTitle()
                 self.RefreshEditMenu()
                 self.RefreshTypesTree()
@@ -2468,7 +2473,7 @@
                 self.RefreshTypesTree()
                 self.RefreshToolBar()
             else:
-                message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
+                message = wx.MessageDialog(self, "\"%s\" is used by one or more POUs. It can't be removed!"%name, "Error", wx.OK|wx.ICON_ERROR)
                 message.ShowModal()
                 message.Destroy()
         event.Skip()
@@ -2497,7 +2502,7 @@
                 self.RefreshLibraryTree()
                 self.RefreshToolBar()
             else:
-                message = wx.MessageDialog(self, "%s is used by one or more POUs. It can't be removed!"%selected, "Error", wx.OK|wx.ICON_ERROR)
+                message = wx.MessageDialog(self, "\"%s\" is used by one or more POUs. It can't be removed!"%name, "Error", wx.OK|wx.ICON_ERROR)
                 message.ShowModal()
                 message.Destroy()
         event.Skip()