extensions: add uipopulate() support to exthelper
authorMatt Harbison <matt_harbison@yahoo.com>
Sun, 02 Dec 2018 16:48:05 +0100
changeset 4282 12e3f24f794b
parent 4281 ac4bb904f5d8
child 4283 5c707b54f8b1
extensions: add uipopulate() support to exthelper
hgext3rd/evolve/exthelper.py
--- a/hgext3rd/evolve/exthelper.py	Sun Dec 02 16:45:08 2018 +0100
+++ b/hgext3rd/evolve/exthelper.py	Sun Dec 02 16:48:05 2018 +0100
@@ -28,6 +28,7 @@
     """
 
     def __init__(self):
+        self._uipopulatecallables = []
         self._uicallables = []
         self._extcallables = []
         self._repocallables = []
@@ -58,6 +59,7 @@
 
     def merge(self, other):
         self._uicallables.extend(other._uicallables)
+        self._uipopulatecallables.extend(other._uipopulatecallables)
         self._extcallables.extend(other._extcallables)
         self._repocallables.extend(other._repocallables)
         self._revsetsymbols.extend(other._revsetsymbols)
@@ -104,6 +106,18 @@
         for c in self._uicallables:
             c(ui)
 
+    def final_uipopulate(self, ui):
+        """Method to be used as the extension uipopulate
+
+        This is called once per ui instance to:
+
+        - Set up additional ui members
+        - Update configuration by ``ui.setconfig()``
+        - Extend the class dynamically
+        """
+        for c in self._uipopulatecallables:
+            c(ui)
+
     def final_extsetup(self, ui):
         """Method to be used as a the extension extsetup
 
@@ -170,6 +184,18 @@
         self._uicallables.append(call)
         return call
 
+    def uipopulate(self, call):
+        """Decorated function will be executed during uipopulate
+
+        example::
+
+            @eh.uipopulate
+            def setupfoo(ui):
+                print 'this is uipopulate!'
+        """
+        self._uipopulatecallables.append(call)
+        return call
+
     def extsetup(self, call):
         """Decorated function will be executed during extsetup