Patchwork [2,of,6] extensions: add uipopulate() support to exthelper

login
register
mail settings
Submitter Matt Harbison
Date Dec. 1, 2018, 4:10 a.m.
Message ID <4242a302a762fb0d3029.1543637456@Envy>
Download mbox | patch
Permalink /patch/36887/
State New
Headers show

Comments

Matt Harbison - Dec. 1, 2018, 4:10 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1543631898 18000
#      Fri Nov 30 21:38:18 2018 -0500
# Node ID 4242a302a762fb0d30298885f982d2e769cbbbd8
# Parent  d5a04a8016a270dce028bddb2483509e0429f113
extensions: add uipopulate() support to exthelper

Patch

diff --git a/mercurial/exthelper.py b/mercurial/exthelper.py
--- a/mercurial/exthelper.py
+++ b/mercurial/exthelper.py
@@ -23,6 +23,7 @@  class exthelper(object):
     """
 
     def __init__(self):
+        self._uipopulatecallables = []
         self._uicallables = []
         self._extcallables = []
         self._repocallables = []
@@ -53,6 +54,7 @@  class exthelper(object):
 
     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)
@@ -99,6 +101,18 @@  class exthelper(object):
         for c in self._uicallables:
             c(ui)
 
+    def finaluipopulate(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 finalextsetup(self, ui):
         """Method to be used as a the extension extsetup
 
@@ -167,6 +181,18 @@  class exthelper(object):
         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