Commits

Anonymous committed bb2ffe5

manifest: show file icons according to the file type

Rather than showing a generic "file icon" on the manifest, show the icon that
corresponds to each file type.

This seems to also speed up the manifest dialog, particularly when it comes to
filtering the manifest file list contents. The speed up is due to the catching
of the icon object for each tree element, whereas before it was being constantly
recreated.

  • Participants
  • Parent commits 8647161

Comments (0)

Files changed (1)

tortoisehg/hgqt/manifestmodel.py

     StatusRole = Qt.UserRole + 1
     """Role for file change status"""
 
+    _fileiconprovider = QFileIconProvider()
+    _icons = {}
+
     def __init__(self, repo, rev=None, namefilter=None, statusfilter='MASC',
                  parent=None):
         QAbstractItemModel.__init__(self, parent)
 
+        self._diricon = QApplication.style().standardIcon(QStyle.SP_DirIcon)
+        self._fileicon = QApplication.style().standardIcon(QStyle.SP_FileIcon)
         self._repo = repo
         self._rev = rev
         self._subinfo = {}
             return None
 
     def fileIcon(self, index):
-        ic = QApplication.style().standardIcon(
-            self.isDir(index) and QStyle.SP_DirIcon or QStyle.SP_FileIcon)
         if not index.isValid():
-            return ic
+            if self.isDir(index):
+                return self._diricon
+            else:
+                return self._fileicon
         e = index.internalPointer()
+        ic = e.icon
+        if not ic:
+            if self.isDir(index):
+                ic = self._diricon
+            else:
+                ext = os.path.splitext(e.path)[1]
+                if not ext:
+                    ic = self._fileicon
+                else:
+                    ic = self._icons.get(ext, None)
+                    if not ic:
+                        ic = self._fileiconprovider.icon(QFileInfo(self._repo.wjoin(e.path)))
+                        if not ic.availableSizes():
+                            ic = self._fileicon
+                        self._icons[ext] = ic
+            e.seticon(ic)
+
         if not e.status:
             return ic
         st = status.statusTypes[e.status]
         self._name = name
         self._parent = parent
         self._status = None
+        self._icon = None
         self._child = {}
         self._nameindex = []
 
         return self._name
 
     @property
+    def icon(self):
+        return self._icon
+
+    def seticon(self, icon):
+        self._icon = icon
+
+    @property
     def status(self):
         """Return file change status"""
         return self._status