Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
authorlaurent
Mon, 23 Apr 2012 11:16:40 +0200
changeset 671 47b9ad1471cc
parent 670 c9ccacf35cf1
child 672 d751b1c609b3
Fix bug with highlighting in pragma and drag'n drop of function in TextViewer
TextViewer.py
--- a/TextViewer.py	Mon Apr 16 22:54:07 2012 +0200
+++ b/TextViewer.py	Mon Apr 23 11:16:40 2012 +0200
@@ -47,7 +47,7 @@
 [STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_STRING, 
  STC_PLC_VARIABLE, STC_PLC_PARAMETER, STC_PLC_FUNCTION, STC_PLC_JUMP, 
  STC_PLC_ERROR, STC_PLC_SEARCH_RESULT] = range(10)
-[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT] = range(6)
+[SPACE, WORD, NUMBER, STRING, WSTRING, COMMENT, PRAGMA] = range(7)
 
 [ID_TEXTVIEWER, ID_TEXTVIEWERTEXTCTRL,
 ] = [wx.NewId() for _init_ctrls in range(2)]
@@ -274,13 +274,14 @@
             if values[1] in ["program", "debug"]:
                 event.SetDragText("")
             elif values[1] in ["functionBlock", "function"]:
+                blocktype = values[0]
                 blockname = values[2]
                 if len(values) > 3:
                     blockinputs = values[3]
                 else:
                     blockinputs = None
                 if values[1] != "function": 
-                    if  blockname == "":
+                    if blockname == "":
                         dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE)
                         if dialog.ShowModal() == wx.ID_OK:
                             blockname = dialog.GetValue()
@@ -295,11 +296,14 @@
                         self.Controler.AddEditedElementPouVar(self.TagName, values[0], blockname)
                         self.RefreshVariablePanel()
                         self.RefreshVariableTree()
-                blockinfo = self.Controler.GetBlockType(values[0], blockinputs, self.Debug)
+                blockinfo = self.Controler.GetBlockType(blocktype, blockinputs, self.Debug)
                 hint = ',\n    '.join(
                             [ " " + fctdecl[0]+" := (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["inputs"]] +
                             [ " " + fctdecl[0]+" => (*"+fctdecl[1]+"*)" for fctdecl in blockinfo["outputs"]])
-                event.SetDragText(blockname+"(\n    "+hint+")")
+                if values[1] == "function":
+                    event.SetDragText(blocktype+"(\n    "+hint+")")
+                else:
+                    event.SetDragText(blockname+"(\n    "+hint+")")
             elif values[1] == "location":
                 pou_name, pou_type = self.Controler.GetEditedElementType(self.TagName, self.Debug)
                 if len(values) > 2 and pou_type == "program":
@@ -558,12 +562,23 @@
                 if state == WORD:
                     current_context = self.Variables
                 state = COMMENT
+            elif line.endswith("{") and state != PRAGMA:
+                self.SetStyling(current_pos - last_styled_pos - 1, 31)
+                last_styled_pos = current_pos
+                if state == WORD:
+                    current_context = self.Variables
+                state = PRAGMA
             elif state == COMMENT:
                 if line.endswith("*)"):
                     self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT)
                     last_styled_pos = current_pos + 1
                     state = SPACE
-            elif (line.endswith("'") or line.endswith('"')) and state not in [COMMENT, STRING, WSTRING]:
+            elif state == PRAGMA:
+                if line.endswith("}"):
+                    self.SetStyling(current_pos - last_styled_pos + 2, 31)
+                    last_styled_pos = current_pos + 1
+                    state = SPACE
+            elif (line.endswith("'") or line.endswith('"')) and state not in [STRING, WSTRING]:
                 self.SetStyling(current_pos - last_styled_pos, 31)
                 last_styled_pos = current_pos
                 if state == WORD: