Просмотр исходного кода

Consolidate updates from status to same approach as for lsdir

Closes datalad/datalad-gooey#107
Michael Hanke 1 год назад
Родитель
Сommit
eae109a804
2 измененных файлов с 39 добавлено и 19 удалено
  1. 7 19
      datalad_gooey/fsbrowser.py
  2. 32 0
      datalad_gooey/fsbrowser_item.py

+ 7 - 19
datalad_gooey/fsbrowser.py

@@ -294,26 +294,14 @@ class GooeyFilesystemBrowser(QObject):
         if path is None:
             # nothing that we could handle
             return
-        state = res.get('state')
-        if res.get('status') == 'error' and 'message' in res and state is None:
-            # something went wrong, we got no state info, but we have a message
-            state = res['message']
-        if state is None:
-            # nothing to show for
-            return
-        storage = 'file-annex'
-        annex_key = res.get('key')
-        if annex_key is None:
-            storage = 'file-git'
-        self._annotate_item(
-            # TODO it could well be gone by now, double-check
-            self._get_item_from_trace(
-                res['gooey_parent_item'],
-                # the parent will only ever be the literal parent directory
-                [Path(path).name],
-            ),
-            dict(state=state, storage=storage),
+
+        # TODO it could well be gone by now, double-check
+        target_item = self._get_item_from_trace(
+            res['gooey_parent_item'],
+            # the parent will only ever be the literal parent directory
+            [Path(path).name],
         )
+        target_item.update_from_status_result(res)
 
     def _annotate_item(self, item, props):
         changed = False

+ 32 - 0
datalad_gooey/fsbrowser_item.py

@@ -69,7 +69,39 @@ class FSBrowserItem(QTreeWidgetItem):
         for c in [self.child(ci) for ci in range(self.childCount())]:
             yield c
 
+    def update_from_status_result(self, res: Dict):
+        state = res.get('state')
+        if res.get('status') == 'error' and 'message' in res and state is None:
+            # something went wrong, we got no state info, but we have a message
+            state = res['message']
+
+        state_icon = 'file-annex'
+        if res.get('key'):
+            state_icon = 'file-git'
+
+        if state:
+            self.setData(2, Qt.EditRole, state)
+            icon = self._getIcon(state)
+            if icon:
+                self.setIcon(2, self._getIcon(state))
+
+        type_ = res.get('type')
+        if type_ == 'file':
+            # get the right icon, fall back on 'file'
+            self.setIcon(0, self._getIcon(state_icon))
+
+        if type_:
+            self.setData(1, Qt.EditRole, type_)
+
     def update_from_lsdir_result(self, res: Dict):
+        # This sets
+        # - type column
+        # - child indicator
+        # - icons TODO check which and how
+        # - disabled-mode
+        #
+        # Resets
+        # - state column for directories
         path_type = res['type']
         self.setData(1, Qt.EditRole, path_type)
         self._setItemIcons(res)