Commits

Steve Borho committed 313a190

status: add file type and size columns

Comments (0)

Files changed (1)

tortoisehg/hgqt/status.py

 # working copy browser.
 
 # Technical Debt
-#  issue #1105 - columns for extension and size
 #  emit error strings to parent status bar
 #  We need a real icon set for file status types
 #  Add some initial drag distance before starting QDrag
 COL_STATUS = 1
 COL_MERGE_STATE = 2
 COL_PATH_DISPLAY = 3
+COL_EXTENSION = 4
+COL_SIZE = 5
 
 _colors = {}
 
         self.tv.setSortingEnabled(True)
         self.tv.setColumnHidden(COL_PATH, self.isMerge())
         self.tv.setColumnHidden(COL_MERGE_STATE, not tm.anyMerge())
-        for col in xrange(COL_PATH_DISPLAY):
+        for col in xrange(COL_SIZE):
             self.tv.resizeColumnToContents(col)
         self.connect(self.tv, SIGNAL('activated(QModelIndex)'), tm.toggleRow)
         self.connect(self.tv, SIGNAL('pressed(QModelIndex)'), tm.pressedRow)
     def refreshDiff(self):
         if self.curRow is None:
             return
-        path, status, mst, upath = self.curRow
+        path, status, mst, upath, ext, sz = self.curRow
         wfile = util.pconvert(path)
         self.fnamelabel.setText(statusMessage(status, mst, upath))
         showanyway = self.override.isChecked()
 class WctxModel(QAbstractTableModel):
     def __init__(self, wctx, ms, opts, checked, parent=None):
         QAbstractTableModel.__init__(self, parent)
+        repo = wctx._repo
         rows = []
+        def mkrow(fname, st):
+            ext, sizek = '', ''
+            try:
+                mst = fname in ms and ms[fname].upper() or ""
+                path = repo.wjoin(fname)
+                name, ext = os.path.splitext(fname)
+                sizebytes = os.path.getsize(path)
+                sizek = (sizebytes + 1023) // 1024
+            except EnvironmentError:
+                pass
+            return [fname, st, mst, hglib.tounicode(fname), ext[1:], sizek]
         if opts['modified']:
             for m in wctx.modified():
-                mst = m in ms and ms[m].upper() or ""
                 checked[m] = checked.get(m, True)
-                rows.append([m, 'M', mst, hglib.tounicode(m)])
+                rows.append(mkrow(m, 'M'))
         if opts['added']:
             for a in wctx.added():
-                mst = a in ms and ms[a].upper() or ""
                 checked[a] = checked.get(a, True)
-                rows.append([a, 'A', mst, hglib.tounicode(a)])
+                rows.append(mkrow(a, 'A'))
         if opts['removed']:
             for r in wctx.removed():
                 mst = r in ms and ms[r].upper() or ""
                 checked[r] = checked.get(r, True)
-                rows.append([r, 'R', mst, hglib.tounicode(r)])
+                rows.append(mkrow(r, 'R'))
         if opts['deleted']:
             for d in wctx.deleted():
                 mst = d in ms and ms[d].upper() or ""
                 checked[d] = checked.get(d, False)
-                rows.append([d, '!', mst, hglib.tounicode(d)])
+                rows.append(mkrow(d, '!'))
         if opts['unknown']:
             for u in wctx.unknown():
                 checked[u] = checked.get(u, False)
-            	rows.append([u, '?', '', hglib.tounicode(u)])
+                rows.append(mkrow(u, '?'))
         if opts['ignored']:
             for i in wctx.ignored():
                 checked[i] = checked.get(i, False)
-            	rows.append([i, 'I', '', hglib.tounicode(i)])
+                rows.append(mkrow(i, 'I'))
         if opts['clean']:
             for c in wctx.clean():
                 checked[c] = checked.get(c, False)
-            	rows.append([c, 'C', '', hglib.tounicode(c)])
+                rows.append(mkrow(c, 'C'))
         if opts['subrepo']:
             try:
                 for s in wctx.substate:
                     if wctx.sub(s).dirty():
                         checked[s] = checked.get(s, False)
-                        rows.append([s, 'S', '', hglib.tounicode(s)])
+                        rows.append(mkrow(s, 'S'))
             except (OSError, IOError, error.ConfigError), e:
                 self.status_error = str(e)
-        self.headers = ('*', _('Stat'), _('M'), _('Filename'))
+        self.headers = ('*', _('Stat'), _('M'), _('Filename'), 
+                        _('Type'), _('Size (KB)'))
         self.checked = checked
         self.unfiltered = rows
         self.rows = rows
         if not index.isValid():
             return QVariant()
 
-        path, status, mst, upath = self.rows[index.row()]
+        path, status, mst, upath, ext, sz = self.rows[index.row()]
         if index.column() == COL_PATH:
             if role == Qt.CheckStateRole:
                 # also Qt.PartiallyChecked
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.