You've already forked gnatstudio
mirror of
https://github.com/AdaCore/gnatstudio.git
synced 2026-02-12 12:42:33 -08:00
from K401-001. Part of K428-015 git-svn-id: svn+ssh://svn.eu.adacore.com/Dev/trunk/gps@172941 936e1b1b-40f2-da11-902a-00137254ae57
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
"""This file makes every line between a --@generated and --@usercode comment
|
|
read only and the background colored in grey.
|
|
This is an example of using overlays"""
|
|
|
|
import GPS
|
|
import os.path
|
|
|
|
def on_open_generated_file(name, file):
|
|
|
|
ebuf = GPS.EditorBuffer.get()
|
|
|
|
def apply_overlay(overlay, from_line, to_line, line_len):
|
|
start_loc = GPS.EditorLocation(ebuf, from_line, 1)
|
|
end_loc = GPS.EditorLocation(ebuf, to_line, line_len)
|
|
ebuf.apply_overlay(overlay, start_loc, end_loc)
|
|
|
|
f_path = os.path.abspath(file.name())
|
|
f = open (f_path)
|
|
text = f.readlines()
|
|
f.close()
|
|
|
|
start = 0
|
|
start_found = False
|
|
|
|
if text[0].strip() == "--@generated":
|
|
|
|
grey = ebuf.create_overlay(f_path)
|
|
grey.set_property("background", "grey")
|
|
grey.set_property("editable", False)
|
|
|
|
for line_num, line in enumerate(text[0:]):
|
|
|
|
if not start_found and line.find('@usercode:') > -1:
|
|
apply_overlay(grey, start, line_num + 1, len(line))
|
|
start_found = True
|
|
|
|
elif start_found and line.find('@end') > -1:
|
|
start = line_num + 1
|
|
start_found = False
|
|
|
|
apply_overlay(grey, start, len(text), len(text[-1]))
|
|
|
|
GPS.Hook("file_edited").add(on_open_generated_file)
|