2017-06-27 15:35:51 +02:00
|
|
|
# This script sets the background color of .adb files and .ads files
|
|
|
|
|
# automatically when they are loaded.
|
|
|
|
|
# It demonstrates the use of hooks, and the setting of preferences in GPS
|
2004-09-27 12:29:09 +00:00
|
|
|
|
2004-09-27 13:14:51 +00:00
|
|
|
import GPS
|
2004-09-27 12:29:09 +00:00
|
|
|
|
2017-06-27 15:35:51 +02:00
|
|
|
|
|
|
|
|
def set_bg_color(hook_name, file):
|
|
|
|
|
name = file.name()
|
2024-06-05 14:41:24 +04:00
|
|
|
if name[len(name) - 4 :] == ".adb":
|
2017-06-27 15:35:51 +02:00
|
|
|
GPS.Editor.set_background_color(
|
2024-06-05 14:41:24 +04:00
|
|
|
file.name(), GPS.Preference("custom-adb-file-color").get()
|
|
|
|
|
)
|
|
|
|
|
elif name[len(name) - 4 :] == ".ads":
|
2017-06-27 15:35:51 +02:00
|
|
|
GPS.Editor.set_background_color(
|
2024-06-05 14:41:24 +04:00
|
|
|
file.name(), GPS.Preference("custom-ads-file-color").get()
|
|
|
|
|
)
|
2004-09-27 12:29:09 +00:00
|
|
|
|
|
|
|
|
|
2024-06-05 14:41:24 +04:00
|
|
|
GPS.parse_xml(
|
|
|
|
|
"""
|
2004-09-27 12:29:09 +00:00
|
|
|
<preference name="custom-adb-file-color"
|
|
|
|
|
label="Background color for .adb files"
|
|
|
|
|
page="Editor:Fonts & Colors"
|
|
|
|
|
default="yellow"
|
|
|
|
|
type="color" />
|
|
|
|
|
<preference name="custom-ads-file-color"
|
|
|
|
|
label="Background color for .ads files"
|
|
|
|
|
page="Editor:Fonts & Colors"
|
|
|
|
|
default="red"
|
|
|
|
|
type="color" />
|
2024-06-05 14:41:24 +04:00
|
|
|
"""
|
|
|
|
|
)
|
2004-09-27 12:29:09 +00:00
|
|
|
|
2017-06-27 15:35:51 +02:00
|
|
|
GPS.Hook("file_edited").add(set_bg_color)
|