##// END OF EJS Templates
extensions: support callbacks after another extension loads...
Gregory Szorc -
r24065:d8837ad6 default
parent child Browse files
Show More
@@ -10,6 +10,7 b' import util, cmdutil, error'
10 from i18n import _, gettext
10 from i18n import _, gettext
11
11
12 _extensions = {}
12 _extensions = {}
13 _aftercallbacks = {}
13 _order = []
14 _order = []
14 _ignore = ['hbisect', 'bookmarks', 'parentrevspec', 'interhg', 'inotify']
15 _ignore = ['hbisect', 'bookmarks', 'parentrevspec', 'interhg', 'inotify']
15
16
@@ -87,6 +88,8 b' def load(ui, name, path):'
87 mod = importh(name)
88 mod = importh(name)
88 _extensions[shortname] = mod
89 _extensions[shortname] = mod
89 _order.append(shortname)
90 _order.append(shortname)
91 for fn in _aftercallbacks.get(shortname, []):
92 fn(loaded=True)
90 return mod
93 return mod
91
94
92 def loadall(ui):
95 def loadall(ui):
@@ -123,6 +126,32 b' def loadall(ui):'
123 raise
126 raise
124 extsetup() # old extsetup with no ui argument
127 extsetup() # old extsetup with no ui argument
125
128
129 # Call aftercallbacks that were never met.
130 for shortname in _aftercallbacks:
131 if shortname in _extensions:
132 continue
133
134 for fn in _aftercallbacks[shortname]:
135 fn(loaded=False)
136
137 def afterloaded(extension, callback):
138 '''Run the specified function after a named extension is loaded.
139
140 If the named extension is already loaded, the callback will be called
141 immediately.
142
143 If the named extension never loads, the callback will be called after
144 all extensions have been loaded.
145
146 The callback receives the named argument ``loaded``, which is a boolean
147 indicating whether the dependent extension actually loaded.
148 '''
149
150 if extension in _extensions:
151 callback(loaded=False)
152 else:
153 _aftercallbacks.setdefault(extension, []).append(callback)
154
126 def wrapcommand(table, command, wrapper):
155 def wrapcommand(table, command, wrapper):
127 '''Wrap the command named `command' in table
156 '''Wrap the command named `command' in table
128
157
General Comments 0
You need to be logged in to leave comments. Login now