diff -r 45d70748e45a -r fc2d6cbb8b39 TextViewer.py --- a/TextViewer.py Tue Aug 12 18:15:35 2008 +0200 +++ b/TextViewer.py Tue Aug 12 18:16:09 2008 +0200 @@ -41,7 +41,7 @@ LETTERS.append(chr(ord('A') + i)) [STC_PLC_WORD, STC_PLC_COMMENT, STC_PLC_NUMBER, STC_PLC_VARIABLE, - STC_PLC_FUNCTION, STC_PLC_JUMP] = range(6) + STC_PLC_FUNCTION, STC_PLC_JUMP, STC_PLC_ERROR] = range(7) [SPACE, WORD, NUMBER, COMMENT] = range(4) [ID_TEXTVIEWER, @@ -140,6 +140,7 @@ self.StyleSetSpec(STC_PLC_COMMENT, "fore:#7F7F7F,size:%(size)d" % faces) self.StyleSetSpec(STC_PLC_NUMBER, "fore:#007F7F,size:%(size)d" % faces) self.StyleSetSpec(STC_PLC_JUMP, "fore:#007F00,size:%(size)d" % faces) + self.StyleSetSpec(STC_PLC_ERROR, "fore:#FF0000,back:#FFFF00,size:%(size)d" % faces) # Indicators styles self.IndicatorSetStyle(0, wx.stc.STC_INDIC_SQUIGGLE) @@ -165,6 +166,7 @@ self.TextSyntax = "ST" self.CurrentAction = None self.TagName = tagname + self.Errors = [] self.ParentWindow = window self.Controler = controler @@ -294,7 +296,7 @@ self.EnumeratedValues.append(value.upper()) self.Colourise(0, -1) - + def RefreshScaling(self, refresh=True): pass @@ -302,118 +304,119 @@ self.TextChanged = True line = self.LineFromPosition(self.GetEndStyled()) if line == 0: - start_pos = 0 - else: - start_pos = self.GetLineEndPosition(line - 1) + 1 + start_pos = last_styled_pos = 0 + else: + start_pos = last_styled_pos = self.GetLineEndPosition(line - 1) + 1 end_pos = event.GetPosition() self.StartStyling(start_pos, 0xff) - i = start_pos + current_pos = last_styled_pos state = SPACE line = "" word = "" - while i < end_pos: - char = chr(self.GetCharAt(i)).upper() + while current_pos < end_pos: + char = chr(self.GetCharAt(current_pos)).upper() line += char if char == NEWLINE: if state == COMMENT: - self.SetStyling(i - start_pos + 1, STC_PLC_COMMENT) + self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_COMMENT) elif state == NUMBER: - self.SetStyling(i - start_pos, STC_PLC_NUMBER) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) elif state == WORD: if word in self.Keywords: - self.SetStyling(i - start_pos, STC_PLC_WORD) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) elif word in self.Variables: - self.SetStyling(i - start_pos, STC_PLC_VARIABLE) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) elif word in self.Functions: - self.SetStyling(i - start_pos, STC_PLC_FUNCTION) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) elif word in self.Jumps: - self.SetStyling(i - start_pos, STC_PLC_JUMP) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) elif word in self.EnumeratedValues: - self.SetStyling(i - start_pos, STC_PLC_NUMBER) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) else: - self.SetStyling(i - start_pos, 31) - if self.GetCurrentPos() < start_pos or self.GetCurrentPos() > i: - self.StartStyling(start_pos, wx.stc.STC_INDICS_MASK) - self.SetStyling(i - start_pos, wx.stc.STC_INDIC0_MASK) - self.StartStyling(i, 0xff) + self.SetStyling(current_pos - last_styled_pos, 31) + if self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos: + self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) + self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) + self.StartStyling(current_pos, 0xff) else: - self.SetStyling(i - start_pos, 31) - start_pos = i + self.SetStyling(current_pos - last_styled_pos, 31) + last_styled_pos = current_pos state = SPACE line = "" elif line.endswith("(*") and state != COMMENT: - self.SetStyling(i - start_pos - 1, 31) - start_pos = i + self.SetStyling(current_pos - last_styled_pos - 1, 31) + last_styled_pos = current_pos state = COMMENT elif state == COMMENT: if line.endswith("*)"): - self.SetStyling(i - start_pos + 2, STC_PLC_COMMENT) - start_pos = i + 1 + self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) + last_styled_pos = current_pos + 1 state = SPACE elif char in LETTERS: if state == NUMBER: word = "#" state = WORD elif state == SPACE: - self.SetStyling(i - start_pos, 31) + self.SetStyling(current_pos - last_styled_pos, 31) word = char - start_pos = i + last_styled_pos = current_pos state = WORD else: word += char elif char in NUMBERS or char == '.' and state != WORD: if state == SPACE: - self.SetStyling(i - start_pos, 31) - start_pos = i + self.SetStyling(current_pos - last_styled_pos, 31) + last_styled_pos = current_pos state = NUMBER if state == WORD and char != '.': word += char else: if state == WORD: if word in self.Keywords: - self.SetStyling(i - start_pos, STC_PLC_WORD) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) elif word in self.Variables: - self.SetStyling(i - start_pos, STC_PLC_VARIABLE) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) elif word in self.Functions: - self.SetStyling(i - start_pos, STC_PLC_FUNCTION) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) elif word in self.Jumps: - self.SetStyling(i - start_pos, STC_PLC_JUMP) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) elif word in self.EnumeratedValues: - self.SetStyling(i - start_pos, STC_PLC_NUMBER) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) else: - self.SetStyling(i - start_pos, 31) - if self.GetCurrentPos() < start_pos or self.GetCurrentPos() > i: - self.StartStyling(start_pos, wx.stc.STC_INDICS_MASK) - self.SetStyling(i - start_pos, wx.stc.STC_INDIC0_MASK) - self.StartStyling(i, 0xff) + self.SetStyling(current_pos - last_styled_pos, 31) + if self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos: + self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) + self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) + self.StartStyling(current_pos, 0xff) word = "" - start_pos = i + last_styled_pos = current_pos state = SPACE elif state == NUMBER: - self.SetStyling(i - start_pos, STC_PLC_NUMBER) - start_pos = i + self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) + last_styled_pos = current_pos state = SPACE - i += 1 + current_pos += 1 if state == COMMENT: - self.SetStyling(i - start_pos + 2, STC_PLC_COMMENT) + self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) elif state == NUMBER: - self.SetStyling(i - start_pos, STC_PLC_NUMBER) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) elif state == WORD: if word in self.Keywords: - self.SetStyling(i - start_pos, STC_PLC_WORD) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) elif word in self.Variables: - self.SetStyling(i - start_pos, STC_PLC_VARIABLE) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) elif word in self.Functions: - self.SetStyling(i - start_pos, STC_PLC_FUNCTION) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) elif word in self.Jumps: - self.SetStyling(i - start_pos, STC_PLC_JUMP) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) elif word in self.EnumeratedValues: - self.SetStyling(i - start_pos, STC_PLC_NUMBER) - else: - self.SetStyling(i - start_pos, 31) - else: - self.SetStyling(i - start_pos, 31) + self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) + else: + self.SetStyling(current_pos - last_styled_pos, 31) + else: + self.SetStyling(current_pos - start_pos, 31) + self.ShowErrors(start_pos, end_pos) event.Skip() def Cut(self): @@ -480,3 +483,28 @@ self.AutoCompCancel() event.Skip() +#------------------------------------------------------------------------------- +# Errors showing functions +#------------------------------------------------------------------------------- + + def ClearErrors(self): + self.Errors = [] + self.RefreshView() + + def AddShownError(self, infos, start, end): + if infos[0] == "body": + self.Errors.append((infos[1], start, end)) + + def ShowErrors(self, start_pos, end_pos): + for indent, start, end in self.Errors: + if start[0] == 0: + error_start_pos = start[1] - indent + else: + error_start_pos = self.GetLineEndPosition(start[0] - 1) + start[1] - indent + 1 + if end[0] == 0: + error_end_pos = end[1] - indent + 1 + else: + error_end_pos = self.GetLineEndPosition(end[0] - 1) + end[1] - indent + 2 + if start_pos <= error_start_pos <= end_pos or start_pos <= error_end_pos <= end_pos: + self.StartStyling(error_start_pos, 0xff) + self.SetStyling(error_end_pos - error_start_pos, STC_PLC_ERROR)