0d84d4ff42a1 draft — Alain Leufroy 11 months ago
♻️  controller: use a dedicated class to patchlist walker

I will add dedicated logics in it.
1 files changed, 47 insertions(+), 20 deletions(-)

M lairucrem/controler.py
M lairucrem/controler.py +47 -20
@@ 578,6 578,45 @@ class graphlistbox(
         return key
 
 
+class patchlistwalker(_multiwalker):
+
+    signals = ['jump_diff']
+
+    def __init__(self):
+        self.node = None
+        self._summary = summarywalker()
+        self._summaryextra = summaryextrawalker()
+        self._description = descriptionwalker()
+        self._diffstat = diffstatwalker()
+        self._diff = diffwalker()
+        super().__init__(
+            [self._summary, self._summaryextra, self._description,
+             self._diffstat, self._diff])
+        urwid.connect_signal(
+            self._diffstat, 'link',
+            lambda *args: urwid.emit_signal(self, 'jump_diff', *args)
+        )
+
+    def reset_node(self, node):
+        self.cancel()
+        self.node = node
+        self._summary.node = node
+        self._summaryextra.node = node
+        self._description.node = node
+        self._diffstat.node = node
+        self._diff.node = node
+
+    def get_diff_position(self):
+        return self.startof(self._diff)
+
+    def get_filtered_filename(self):
+        return self._diff.filename
+
+    def set_filtered_filename(self, filename):
+        self._diff.filename = filename
+        self._diffstat.filename = filename
+
+
 class patchlistbox(
         mixin.filterable_listbox,
         mixin.searchable_listbox, mixin.refreshable_listbox, _listbox):

          
@@ 585,22 624,16 @@ class patchlistbox(
 
     def __init__(self):
         self._search_pattern = ''
-        self._summary = summarywalker()
-        self._summaryextra = summaryextrawalker()
-        self._description = descriptionwalker()
-        self._diffstat = diffstatwalker()
-        self._diff = diffwalker()
         self.on_jump_to_diffline = ensure_one(self._on_jump_to_diffline)
         self.on_filter = ensure_one(self._on_filter)
-        super().__init__(
-            self._summary, self._summaryextra, self._description,
-            self._diffstat, self._diff)
+        super().__init__(patchlistwalker())
 
     def _connect_all(self):
         super()._connect_all()
         urwid.connect_signal(self, 'filter', self.on_filter.ensure)
+        # TODO: do not access private attribute.
         urwid.signals.connect_signal(
-            self._diffstat, 'link', self.on_jump_to_diffline.ensure)
+            self.body, 'jump_diff', self.on_jump_to_diffline.ensure)
         urwid.signals.connect_signal(self, 'refresh', lambda *a: self.ensure())
 
     def change_focus(self, *args, **kwargs):

          
@@ 614,14 647,9 @@ class patchlistbox(
         # resetonly if not CWD and changed. We always reset on cwd as
         # the user evently want to view changes while cset is expected
         # not to be modified outside the application.
-        if node is not None and node == self._summary.node:
+        if node is not None and node == self.body.node:
             return
-        self.body.cancel()
-        self._summary.node = node
-        self._summaryextra.node = node
-        self._description.node = node
-        self._diffstat.node = node
-        self._diff.node = node
+        self.body.reset_node(node)
         self.ensure()
 
     def _iter_widgets(self, startpos=None, forward=True):

          
@@ 644,16 672,15 @@ class patchlistbox(
         await self.wait.task    # wait until all loaded
         self._goto(
             lambda w, p: fname in w.text,
-            self.body.startof(self._diff))
+            self.body.get_diff_position())
 
     async def _on_filter(self, *args):
         edit = widgets.edit(
-            [('ui.label', 'file: ')], self._diff.filename or '')
+            [('ui.label', 'file: ')], self.body.get_filtered_filename() or '')
         choice = await dialog.ask(edit, title='FILTER PATCH', focus_content=True)
         if choice:
             val = edit.get_edit_text().strip() or None
-            self._diff.filename = val
-            self._diffstat.filename = val
+            self.body.set_filtered_filename(val)
             self.ensure()
 
     def keypress(self, size, key):