292 self.EnumeratedValues = [] |
294 self.EnumeratedValues = [] |
293 for value in self.Controler.GetEnumeratedDataValues(): |
295 for value in self.Controler.GetEnumeratedDataValues(): |
294 self.EnumeratedValues.append(value.upper()) |
296 self.EnumeratedValues.append(value.upper()) |
295 |
297 |
296 self.Colourise(0, -1) |
298 self.Colourise(0, -1) |
297 |
299 |
298 def RefreshScaling(self, refresh=True): |
300 def RefreshScaling(self, refresh=True): |
299 pass |
301 pass |
300 |
302 |
301 def OnStyleNeeded(self, event): |
303 def OnStyleNeeded(self, event): |
302 self.TextChanged = True |
304 self.TextChanged = True |
303 line = self.LineFromPosition(self.GetEndStyled()) |
305 line = self.LineFromPosition(self.GetEndStyled()) |
304 if line == 0: |
306 if line == 0: |
305 start_pos = 0 |
307 start_pos = last_styled_pos = 0 |
306 else: |
308 else: |
307 start_pos = self.GetLineEndPosition(line - 1) + 1 |
309 start_pos = last_styled_pos = self.GetLineEndPosition(line - 1) + 1 |
308 end_pos = event.GetPosition() |
310 end_pos = event.GetPosition() |
309 self.StartStyling(start_pos, 0xff) |
311 self.StartStyling(start_pos, 0xff) |
310 |
312 |
311 i = start_pos |
313 current_pos = last_styled_pos |
312 state = SPACE |
314 state = SPACE |
313 line = "" |
315 line = "" |
314 word = "" |
316 word = "" |
315 while i < end_pos: |
317 while current_pos < end_pos: |
316 char = chr(self.GetCharAt(i)).upper() |
318 char = chr(self.GetCharAt(current_pos)).upper() |
317 line += char |
319 line += char |
318 if char == NEWLINE: |
320 if char == NEWLINE: |
319 if state == COMMENT: |
321 if state == COMMENT: |
320 self.SetStyling(i - start_pos + 1, STC_PLC_COMMENT) |
322 self.SetStyling(current_pos - last_styled_pos + 1, STC_PLC_COMMENT) |
321 elif state == NUMBER: |
323 elif state == NUMBER: |
322 self.SetStyling(i - start_pos, STC_PLC_NUMBER) |
324 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
323 elif state == WORD: |
325 elif state == WORD: |
324 if word in self.Keywords: |
326 if word in self.Keywords: |
325 self.SetStyling(i - start_pos, STC_PLC_WORD) |
327 self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
326 elif word in self.Variables: |
328 elif word in self.Variables: |
327 self.SetStyling(i - start_pos, STC_PLC_VARIABLE) |
329 self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
328 elif word in self.Functions: |
330 elif word in self.Functions: |
329 self.SetStyling(i - start_pos, STC_PLC_FUNCTION) |
331 self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
330 elif word in self.Jumps: |
332 elif word in self.Jumps: |
331 self.SetStyling(i - start_pos, STC_PLC_JUMP) |
333 self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
332 elif word in self.EnumeratedValues: |
334 elif word in self.EnumeratedValues: |
333 self.SetStyling(i - start_pos, STC_PLC_NUMBER) |
335 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
334 else: |
336 else: |
335 self.SetStyling(i - start_pos, 31) |
337 self.SetStyling(current_pos - last_styled_pos, 31) |
336 if self.GetCurrentPos() < start_pos or self.GetCurrentPos() > i: |
338 if self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos: |
337 self.StartStyling(start_pos, wx.stc.STC_INDICS_MASK) |
339 self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
338 self.SetStyling(i - start_pos, wx.stc.STC_INDIC0_MASK) |
340 self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
339 self.StartStyling(i, 0xff) |
341 self.StartStyling(current_pos, 0xff) |
340 else: |
342 else: |
341 self.SetStyling(i - start_pos, 31) |
343 self.SetStyling(current_pos - last_styled_pos, 31) |
342 start_pos = i |
344 last_styled_pos = current_pos |
343 state = SPACE |
345 state = SPACE |
344 line = "" |
346 line = "" |
345 elif line.endswith("(*") and state != COMMENT: |
347 elif line.endswith("(*") and state != COMMENT: |
346 self.SetStyling(i - start_pos - 1, 31) |
348 self.SetStyling(current_pos - last_styled_pos - 1, 31) |
347 start_pos = i |
349 last_styled_pos = current_pos |
348 state = COMMENT |
350 state = COMMENT |
349 elif state == COMMENT: |
351 elif state == COMMENT: |
350 if line.endswith("*)"): |
352 if line.endswith("*)"): |
351 self.SetStyling(i - start_pos + 2, STC_PLC_COMMENT) |
353 self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
352 start_pos = i + 1 |
354 last_styled_pos = current_pos + 1 |
353 state = SPACE |
355 state = SPACE |
354 elif char in LETTERS: |
356 elif char in LETTERS: |
355 if state == NUMBER: |
357 if state == NUMBER: |
356 word = "#" |
358 word = "#" |
357 state = WORD |
359 state = WORD |
358 elif state == SPACE: |
360 elif state == SPACE: |
359 self.SetStyling(i - start_pos, 31) |
361 self.SetStyling(current_pos - last_styled_pos, 31) |
360 word = char |
362 word = char |
361 start_pos = i |
363 last_styled_pos = current_pos |
362 state = WORD |
364 state = WORD |
363 else: |
365 else: |
364 word += char |
366 word += char |
365 elif char in NUMBERS or char == '.' and state != WORD: |
367 elif char in NUMBERS or char == '.' and state != WORD: |
366 if state == SPACE: |
368 if state == SPACE: |
367 self.SetStyling(i - start_pos, 31) |
369 self.SetStyling(current_pos - last_styled_pos, 31) |
368 start_pos = i |
370 last_styled_pos = current_pos |
369 state = NUMBER |
371 state = NUMBER |
370 if state == WORD and char != '.': |
372 if state == WORD and char != '.': |
371 word += char |
373 word += char |
372 else: |
374 else: |
373 if state == WORD: |
375 if state == WORD: |
374 if word in self.Keywords: |
376 if word in self.Keywords: |
375 self.SetStyling(i - start_pos, STC_PLC_WORD) |
377 self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
376 elif word in self.Variables: |
378 elif word in self.Variables: |
377 self.SetStyling(i - start_pos, STC_PLC_VARIABLE) |
379 self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
378 elif word in self.Functions: |
380 elif word in self.Functions: |
379 self.SetStyling(i - start_pos, STC_PLC_FUNCTION) |
381 self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
380 elif word in self.Jumps: |
382 elif word in self.Jumps: |
381 self.SetStyling(i - start_pos, STC_PLC_JUMP) |
383 self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
382 elif word in self.EnumeratedValues: |
384 elif word in self.EnumeratedValues: |
383 self.SetStyling(i - start_pos, STC_PLC_NUMBER) |
385 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
384 else: |
386 else: |
385 self.SetStyling(i - start_pos, 31) |
387 self.SetStyling(current_pos - last_styled_pos, 31) |
386 if self.GetCurrentPos() < start_pos or self.GetCurrentPos() > i: |
388 if self.GetCurrentPos() < last_styled_pos or self.GetCurrentPos() > current_pos: |
387 self.StartStyling(start_pos, wx.stc.STC_INDICS_MASK) |
389 self.StartStyling(last_styled_pos, wx.stc.STC_INDICS_MASK) |
388 self.SetStyling(i - start_pos, wx.stc.STC_INDIC0_MASK) |
390 self.SetStyling(current_pos - last_styled_pos, wx.stc.STC_INDIC0_MASK) |
389 self.StartStyling(i, 0xff) |
391 self.StartStyling(current_pos, 0xff) |
390 word = "" |
392 word = "" |
391 start_pos = i |
393 last_styled_pos = current_pos |
392 state = SPACE |
394 state = SPACE |
393 elif state == NUMBER: |
395 elif state == NUMBER: |
394 self.SetStyling(i - start_pos, STC_PLC_NUMBER) |
396 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
395 start_pos = i |
397 last_styled_pos = current_pos |
396 state = SPACE |
398 state = SPACE |
397 i += 1 |
399 current_pos += 1 |
398 if state == COMMENT: |
400 if state == COMMENT: |
399 self.SetStyling(i - start_pos + 2, STC_PLC_COMMENT) |
401 self.SetStyling(current_pos - last_styled_pos + 2, STC_PLC_COMMENT) |
400 elif state == NUMBER: |
402 elif state == NUMBER: |
401 self.SetStyling(i - start_pos, STC_PLC_NUMBER) |
403 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
402 elif state == WORD: |
404 elif state == WORD: |
403 if word in self.Keywords: |
405 if word in self.Keywords: |
404 self.SetStyling(i - start_pos, STC_PLC_WORD) |
406 self.SetStyling(current_pos - last_styled_pos, STC_PLC_WORD) |
405 elif word in self.Variables: |
407 elif word in self.Variables: |
406 self.SetStyling(i - start_pos, STC_PLC_VARIABLE) |
408 self.SetStyling(current_pos - last_styled_pos, STC_PLC_VARIABLE) |
407 elif word in self.Functions: |
409 elif word in self.Functions: |
408 self.SetStyling(i - start_pos, STC_PLC_FUNCTION) |
410 self.SetStyling(current_pos - last_styled_pos, STC_PLC_FUNCTION) |
409 elif word in self.Jumps: |
411 elif word in self.Jumps: |
410 self.SetStyling(i - start_pos, STC_PLC_JUMP) |
412 self.SetStyling(current_pos - last_styled_pos, STC_PLC_JUMP) |
411 elif word in self.EnumeratedValues: |
413 elif word in self.EnumeratedValues: |
412 self.SetStyling(i - start_pos, STC_PLC_NUMBER) |
414 self.SetStyling(current_pos - last_styled_pos, STC_PLC_NUMBER) |
413 else: |
415 else: |
414 self.SetStyling(i - start_pos, 31) |
416 self.SetStyling(current_pos - last_styled_pos, 31) |
415 else: |
417 else: |
416 self.SetStyling(i - start_pos, 31) |
418 self.SetStyling(current_pos - start_pos, 31) |
|
419 self.ShowErrors(start_pos, end_pos) |
417 event.Skip() |
420 event.Skip() |
418 |
421 |
419 def Cut(self): |
422 def Cut(self): |
420 self.ResetBuffer() |
423 self.ResetBuffer() |
421 self.CmdKeyExecute(wx.stc.STC_CMD_CUT) |
424 self.CmdKeyExecute(wx.stc.STC_CMD_CUT) |