File: auto_load.py

package info (click to toggle)
gnat-gps 18-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,716 kB
  • sloc: ada: 362,679; python: 31,031; xml: 9,597; makefile: 1,030; ansic: 917; sh: 264; java: 17
file content (41 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
This plugin load <project>.ide.py when <project>.gpr is open.
User provides initialize_project_plugin and finalize_project_plugin functions
to initialize/finalize per project plugin properly.

Trivial example of <project>.ide.py:

import GPS

def initialize_project_plugin():
    GPS.MDI.dialog ("initialize_project_plugin")

def finalize_project_plugin():
    GPS.MDI.dialog ("finalize_project_plugin")

"""

import GPS
import os.path
from gps_utils import hook

# functions to initialize/finalize current per project plugin
# to be changed in per project plugin:
initialize_project_plugin = (lambda: None)
finalize_project_plugin = (lambda: None)


@hook('project_changed')
def __on_project_changed():
    global initialize_project_plugin
    global finalize_project_plugin
    # finalize previous plugin
    finalize_project_plugin()
    finalize_project_plugin = (lambda: None)

    project = GPS.Project.root().file()
    plugin_name = project.name()[0:-4] + ".ide.py"
    if os.path.exists(plugin_name):
        execfile(plugin_name, globals())
        initialize_project_plugin()
        initialize_project_plugin = (lambda: None)