# HG changeset patch # User laurent # Date 1335172600 -7200 # Node ID 47b9ad1471ccc706ab45da7b04a32e0210bf9fe3 # Parent c9ccacf35cf131892ab5d50405e3eaa4563897a5 Fix bug with highlighting in pragma and drag'n drop of function in TextViewer diff -r c9ccacf35cf1 -r 47b9ad1471cc 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: