Commits

Yuya Nishihara committed 323e196

manifestmodel: add option to list files in the same level like revdetails

Comments (0)

Files changed (2)

tests/qt_manifestmodel_test.py

         self.assertEqual(['baz', 'bar', 'foo'],
                          alldata(m, m.indexFromPath('sub/nested')))
 
+    def test_flat_data(self):
+        m = self.new_model(0)
+        m.setFlat(True)
+        self.assertEqual(['bar', 'baz/bax', 'baz/box', 'foo'], alldata(m))
+
+    def test_flat_data_subrepo(self):
+        m = self.new_model(3)
+        m.setFlat(True)
+        self.assertEqual(['sub', '.hgsub', '.hgsubstate', 'bar', 'baz/bax'],
+                         alldata(m)[:5])
+
     def test_isdir(self):
         m = self.new_model(3)
         self.assertTrue(m.isDir(m.indexFromPath('')))
         self.assertFalse(m.isDir(m.indexFromPath('sub/foo')))
         self.assertTrue(m.isDir(m.indexFromPath('sub/baz')))
 
+    def test_flat_isdir_subrepo(self):
+        m = self.new_model(3)
+        m.setFlat(True)
+        self.assertTrue(m.isDir(m.indexFromPath('sub')))
+
     def test_rawfctx(self):
         m = self.new_model(5)
         self.check_rawfctx(m, 'foo', 5, 'foo')

tortoisehg/hgqt/manifestmodel.py

     """Role for file change status"""
 
     def __init__(self, repo, rev=None, namefilter=None, statusfilter='MASC',
-                 parent=None):
+                 flat=False, parent=None):
         QAbstractItemModel.__init__(self, parent)
 
         self._fileiconprovider = QFileIconProvider()
         self._namefilter = namefilter
         assert util.all(c in 'MARSC' for c in statusfilter)
         self._statusfilter = statusfilter
+        self._flat = flat
 
     def data(self, index, role=Qt.DisplayRole):
         if not index.isValid():
         """Return the current status filter"""
         return self._statusfilter
 
+    def isFlat(self):
+        """Whether all entries are listed in the same level or per directory"""
+        return self._flat
+
+    def setFlat(self, flat):
+        if self._flat == flat:
+            return
+        self._flat = flat
+        self._rebuildrootentry()
+
     def _wjoin(self, path):
         return os.path.join(hglib.tounicode(self._repo.root), unicode(path))
 
         roote.ctx = self._repo[self._rev]
         match = _makematcher(self._repo, roote.ctx,
                              hglib.fromunicode(self._namefilter))
-        _populaterepo(roote, self._repo, self._statusfilter, match)
+        if self._flat:
+            makenode = _makelist
+        else:
+            makenode = _maketree
+        _populaterepo(roote, self._repo, makenode, self._statusfilter, match)
         roote.sort()
         return roote
 
         return matchmod.exact(repo.root, cwd, [])
 
 
+def _makelist(e, path):
+    e.addchild(path)
+    return e[path]
+
 def _maketree(e, path):
     for p in path.split('/'):
         if p not in e:
         e = e[p]
     return e
 
-def _populaterepo(roote, repo, statusfilter, match):
+def _populaterepo(roote, repo, makenode, statusfilter, match):
     if 'S' in statusfilter:
-        _populatesubrepos(roote, statusfilter, match)
+        _populatesubrepos(roote, makenode, statusfilter, match)
 
     ctx = roote.ctx
     stat = repo.status(ctx.p1(), ctx, match, clean='C' in statusfilter)
             continue
         for path in files:
             path = repo.removeStandin(path)
-            e = _maketree(roote, hglib.tounicode(path))
+            e = makenode(roote, hglib.tounicode(path))
             e.status = st
 
-def _populatesubrepos(roote, statusfilter, match):
+def _populatesubrepos(roote, makenode, statusfilter, match):
     ctx = roote.ctx
     for path, substate in ctx.substate.iteritems():
-        e = _maketree(roote, hglib.tounicode(path))
+        e = makenode(roote, hglib.tounicode(path))
         e.status = 'S'
         e.subkind = substate[2]
 
         if srev in srepo:
             e.ctx = srepo[srev]
             smatch = matchmod.narrowmatcher(path, match)
-            _populaterepo(e, srepo, statusfilter, smatch)
+            _populaterepo(e, srepo, makenode, statusfilter, smatch)
 
 
 class ManifestCompleter(QCompleter):