]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/samples/ide/activegrid/tool/CodeEditor.py
Docview and IDE patch from Morag Hua with fix for bug #1217890
[wxWidgets.git] / wxPython / samples / ide / activegrid / tool / CodeEditor.py
index 09a96abf53789867a7aea49282d919908d5519bf..de0fbaf86e1669f1bb1280b28cc45120ba8650db 100644 (file)
@@ -117,7 +117,6 @@ class CodeView(STCTextEditor.TextView):
     def ProcessUpdateUIEvent(self, event):
         if not self.GetCtrl():
             return False
     def ProcessUpdateUIEvent(self, event):
         if not self.GetCtrl():
             return False
-        hasText = self.GetCtrl().GetTextLength() > 0
         id = event.GetId()
         if id == EXPAND_TEXT_ID:
             event.Enable(self.GetCtrl().CanLineExpand(self.GetCtrl().GetCurrentLine()))
         id = event.GetId()
         if id == EXPAND_TEXT_ID:
             event.Enable(self.GetCtrl().CanLineExpand(self.GetCtrl().GetCurrentLine()))
@@ -125,49 +124,29 @@ class CodeView(STCTextEditor.TextView):
         elif id == COLLAPSE_TEXT_ID:
             event.Enable(self.GetCtrl().CanLineCollapse(self.GetCtrl().GetCurrentLine()))
             return True
         elif id == COLLAPSE_TEXT_ID:
             event.Enable(self.GetCtrl().CanLineCollapse(self.GetCtrl().GetCurrentLine()))
             return True
-        elif id == EXPAND_TOP_ID:
-            event.Enable(hasText)
-            return True
-        elif id == COLLAPSE_TOP_ID:
-            event.Enable(hasText)
-            return True
-        elif id == EXPAND_ALL_ID:
-            event.Enable(hasText)
-            return True
-        elif id == COLLAPSE_ALL_ID:
-            event.Enable(hasText)
+        elif (id == EXPAND_TOP_ID
+        or id == COLLAPSE_TOP_ID
+        or id == EXPAND_ALL_ID
+        or id == COLLAPSE_ALL_ID
+        or id == AUTO_COMPLETE_ID
+        or id == CLEAN_WHITESPACE
+        or id == INDENT_LINES_ID
+        or id == DEDENT_LINES_ID
+        or id == COMMENT_LINES_ID
+        or id == UNCOMMENT_LINES_ID):
+            event.Enable(self.GetCtrl().GetTextLength() > 0)
             return True
         elif id == CHECK_CODE_ID:
             event.Enable(False)
             return True
             return True
         elif id == CHECK_CODE_ID:
             event.Enable(False)
             return True
-        elif id == AUTO_COMPLETE_ID:
-            event.Enable(hasText)
-            return True
-        elif id == CLEAN_WHITESPACE:
-            event.Enable(hasText)
-            return True
-        elif id == SET_INDENT_WIDTH_ID:
+        elif (id == SET_INDENT_WIDTH_ID
+        or id == FOLDING_ID):
             event.Enable(True)
             return True
         elif id == USE_TABS_ID:
             event.Enable(True)
             event.Check(self.GetCtrl().GetUseTabs())
             return True
             event.Enable(True)
             return True
         elif id == USE_TABS_ID:
             event.Enable(True)
             event.Check(self.GetCtrl().GetUseTabs())
             return True
-        elif id == INDENT_LINES_ID:
-            event.Enable(hasText)
-            return True
-        elif id == DEDENT_LINES_ID:
-            event.Enable(hasText)
-            return True
-        elif id == COMMENT_LINES_ID:
-            event.Enable(hasText)
-            return True
-        elif id == UNCOMMENT_LINES_ID:
-            event.Enable(hasText)
-            return True
-        elif id == FOLDING_ID:
-            event.Enable(True)
-            return True
         else:
             return STCTextEditor.TextView.ProcessUpdateUIEvent(self, event)
 
         else:
             return STCTextEditor.TextView.ProcessUpdateUIEvent(self, event)
 
@@ -324,7 +303,7 @@ class CodeView(STCTextEditor.TextView):
                 self.GetCtrl().SetSelection(pos, pos)
                 self._GetParentFrame().SetStatusText(_("Syntax Error: %s") % message)
             except:
                 self.GetCtrl().SetSelection(pos, pos)
                 self._GetParentFrame().SetStatusText(_("Syntax Error: %s") % message)
             except:
-                self._GetParentFrame().SetStatusText(sys.exc_info()[0])
+                self._GetParentFrame().SetStatusText("%s: %s" % (sys.exc_info()[0], sys.exc_info()[1]))
 
 
     def OnAutoComplete(self):
 
 
     def OnAutoComplete(self):
@@ -625,52 +604,22 @@ class CodeService(STCTextEditor.TextService):
 
     def ProcessUpdateUIEvent(self, event):
         id = event.GetId()
 
     def ProcessUpdateUIEvent(self, event):
         id = event.GetId()
-        if id == EXPAND_TEXT_ID:
-            event.Enable(False)
-            return True
-        elif id == COLLAPSE_TEXT_ID:
-            event.Enable(False)
-            return True
-        elif id == EXPAND_TOP_ID:
-            event.Enable(False)
-            return True
-        elif id == COLLAPSE_TOP_ID:
-            event.Enable(False)
-            return True
-        elif id == EXPAND_ALL_ID:
-            event.Enable(False)
-            return True
-        elif id == COLLAPSE_ALL_ID:
-            event.Enable(False)
-            return True
-        elif id == CHECK_CODE_ID:
-            event.Enable(False)
-            return True
-        elif id == AUTO_COMPLETE_ID:
-            event.Enable(False)
-            return True
-        elif id == CLEAN_WHITESPACE:
-            event.Enable(False)
-            return True
-        elif id == SET_INDENT_WIDTH_ID:
-            event.Enable(False)
-            return True
-        elif id == USE_TABS_ID:
-            event.Enable(False)
-            return True
-        elif id == INDENT_LINES_ID:
-            event.Enable(False)
-            return True
-        elif id == DEDENT_LINES_ID:
-            event.Enable(False)
-            return True
-        elif id == COMMENT_LINES_ID:
-            event.Enable(False)
-            return True
-        elif id == UNCOMMENT_LINES_ID:
-            event.Enable(False)
-            return True
-        elif id == FOLDING_ID:
+        if (id == EXPAND_TEXT_ID
+        or id == COLLAPSE_TEXT_ID
+        or id == EXPAND_TOP_ID
+        or id == COLLAPSE_TOP_ID
+        or id == EXPAND_ALL_ID
+        or id == COLLAPSE_ALL_ID
+        or id == CHECK_CODE_ID
+        or id == AUTO_COMPLETE_ID
+        or id == CLEAN_WHITESPACE
+        or id == SET_INDENT_WIDTH_ID
+        or id == USE_TABS_ID
+        or id == INDENT_LINES_ID
+        or id == DEDENT_LINES_ID
+        or id == COMMENT_LINES_ID
+        or id == UNCOMMENT_LINES_ID
+        or id == FOLDING_ID):
             event.Enable(False)
             return True
         else:
             event.Enable(False)
             return True
         else:
@@ -684,10 +633,8 @@ class CodeCtrl(STCTextEditor.TextCtrl):
     BREAKPOINT_MARKER_MASK = 0x2
     
             
     BREAKPOINT_MARKER_MASK = 0x2
     
             
-    def __init__(self, parent, ID = -1, style = wx.NO_FULL_REPAINT_ON_RESIZE):
-        if ID == -1:
-            ID = wx.NewId()
-        STCTextEditor.TextCtrl.__init__(self, parent, ID, style)
+    def __init__(self, parent, id=-1, style = wx.NO_FULL_REPAINT_ON_RESIZE):
+        STCTextEditor.TextCtrl.__init__(self, parent, id, style)
         
         self.UsePopUp(False)
         self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
         
         self.UsePopUp(False)
         self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
@@ -723,10 +670,10 @@ class CodeCtrl(STCTextEditor.TextCtrl):
         if _WINDOWS:  # should test to see if menu item exists, if it does, add this workaround
             self.CmdKeyClear(wx.stc.STC_KEY_TAB, 0)  # menu item "Indent Lines" from CodeService.InstallControls() generates another INDENT_LINES_ID event, so we'll explicitly disable the tab processing in the editor
 
         if _WINDOWS:  # should test to see if menu item exists, if it does, add this workaround
             self.CmdKeyClear(wx.stc.STC_KEY_TAB, 0)  # menu item "Indent Lines" from CodeService.InstallControls() generates another INDENT_LINES_ID event, so we'll explicitly disable the tab processing in the editor
 
-        wx.stc.EVT_STC_MARGINCLICK(self, ID, self.OnMarginClick)
+        wx.stc.EVT_STC_MARGINCLICK(self, self.GetId(), self.OnMarginClick)
         wx.EVT_KEY_DOWN(self, self.OnKeyPressed)
         if self.GetMatchingBraces(): 
         wx.EVT_KEY_DOWN(self, self.OnKeyPressed)
         if self.GetMatchingBraces(): 
-            wx.stc.EVT_STC_UPDATEUI(self, ID, self.OnUpdateUI)
+            wx.stc.EVT_STC_UPDATEUI(self, self.GetId(), self.OnUpdateUI)
 
         self.StyleClearAll()
         self.UpdateStyles()
 
         self.StyleClearAll()
         self.UpdateStyles()
@@ -771,7 +718,8 @@ class CodeCtrl(STCTextEditor.TextCtrl):
                 item = menuBar.FindItemById(itemID)
                 if item:
                     menu.Append(itemID, item.GetLabel())
                 item = menuBar.FindItemById(itemID)
                 if item:
                     menu.Append(itemID, item.GetLabel())
-
+                    wx.EVT_MENU(self, itemID, self.DSProcessEvent)  # wxHack: for customized right mouse menu doesn't work with new DynamicSashWindow
+                    wx.EVT_UPDATE_UI(self, itemID, self.DSProcessUpdateUIEvent)  # wxHack: for customized right mouse menu doesn't work with new DynamicSashWindow
         return menu
                 
 
         return menu
                 
 
@@ -885,6 +833,7 @@ class CodeCtrl(STCTextEditor.TextCtrl):
 
     def DoIndent(self):
         self.AddText('\n')
 
     def DoIndent(self):
         self.AddText('\n')
+        self.EnsureCaretVisible()
         # Need to do a default one for all languges
 
 
         # Need to do a default one for all languges