Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

extract manifestmodel.py

Changeset 9f41137eedcd

Parent c0c9c00ece40

by Adrian Buehlmann

Changes to 3 files · Browse files at 9f41137eedcd Showing diff from parent c0c9c00ece40 Diff from another changeset...

 
31
32
33
34
 
35
36
37
 
39
40
41
42
 
43
44
45
 
31
32
33
 
34
35
36
37
 
39
40
41
 
42
43
44
45
@@ -31,7 +31,7 @@
   from tortoisehg.hgqt import icon as geticon  from tortoisehg.hgqt.dialogmixin import HgDialogMixin -from tortoisehg.hgqt.repomodel import ManifestModel +from tortoisehg.hgqt.manifestmodel import ManifestModel  from tortoisehg.hgqt.lexers import get_lexer    connect = QtCore.QObject.connect @@ -39,7 +39,7 @@
 SIGNAL = QtCore.SIGNAL  nullvariant = QtCore.QVariant()   - +  class ManifestDialog(QtGui.QMainWindow, HgDialogMixin):   """   Qt4 dialog to display all files of a repo at a given revision
Change 1 of 1 Show Entire File tortoisehg/​hgqt/​manifestmodel.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
@@ -0,0 +1,122 @@
+# Copyright (c) 2009-2010 LOGILAB S.A. (Paris, FRANCE). +# http://www.logilab.fr/ -- mailto:contact@logilab.fr +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +import os, os.path as osp + +from mercurial.node import short as short_hex + +from PyQt4 import QtCore + +from tortoisehg.hgqt.repomodel import TreeItem + + +class ManifestModel(QtCore.QAbstractItemModel): + """ + Qt model to display a hg manifest, ie. the tree of files at a + given revision. To be used with a QTreeView. + """ + def __init__(self, repo, rev, parent=None): + QtCore.QAbstractItemModel.__init__(self, parent) + + self.repo = repo + self.changectx = self.repo.changectx(rev) + self.setupModelData() + + def data(self, index, role): + if not index.isValid(): + return QtCore.QVariant() + + if role != QtCore.Qt.DisplayRole: + return QtCore.QVariant() + + item = index.internalPointer() + return QtCore.QVariant(item.data(index.column())) + + def flags(self, index): + if not index.isValid(): + return QtCore.Qt.ItemIsEnabled + return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable + + def headerData(self, section, orientation, role): + if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole: + return QtCore.QVariant(self.rootItem.data(section)) + return QtCore.QVariant() + + def index(self, row, column, parent): + if row < 0 or column < 0 or row >= self.rowCount(parent) or column >= self.columnCount(parent): + return QtCore.QModelIndex() + + if not parent.isValid(): + parentItem = self.rootItem + else: + parentItem = parent.internalPointer() + childItem = parentItem.child(row) + if childItem is not None: + return self.createIndex(row, column, childItem) + else: + return QtCore.QModelIndex() + + def parent(self, index): + if not index.isValid(): + return QtCore.QModelIndex() + + childItem = index.internalPointer() + parentItem = childItem.parent() + + if parentItem == self.rootItem: + return QtCore.QModelIndex() + + return self.createIndex(parentItem.row(), 0, parentItem) + + def rowCount(self, parent): + if parent.column() > 0: + return 0 + + if not parent.isValid(): + parentItem = self.rootItem + else: + parentItem = parent.internalPointer() + return parentItem.childCount() + + def columnCount(self, parent): + if parent.isValid(): + return parent.internalPointer().columnCount() + else: + return self.rootItem.columnCount() + + def setupModelData(self): + rootData = ["rev %s:%s" % (self.changectx.rev(), + short_hex(self.changectx.node()))] + self.rootItem = TreeItem(rootData) + + for path in sorted(self.changectx.manifest()): + path = path.split(osp.sep) + node = self.rootItem + + for p in path: + for ch in node: + if ch.data(0) == p: + node = ch + break + else: + node = node.addChild(TreeItem([p], node)) + + def pathFromIndex(self, index): + idxs = [] + while index.isValid(): + idxs.insert(0, index) + index = self.parent(index) + return osp.sep.join([index.internalPointer().data(0) for index in idxs])
 
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
 
803
804
805
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
806
807
808
@@ -803,105 +803,6 @@
  yield ch     -class ManifestModel(QtCore.QAbstractItemModel): - """ - Qt model to display a hg manifest, ie. the tree of files at a - given revision. To be used with a QTreeView. - """ - def __init__(self, repo, rev, parent=None): - QtCore.QAbstractItemModel.__init__(self, parent) - - self.repo = repo - self.changectx = self.repo.changectx(rev) - self.setupModelData() - - def data(self, index, role): - if not index.isValid(): - return QtCore.QVariant() - - if role != QtCore.Qt.DisplayRole: - return QtCore.QVariant() - - item = index.internalPointer() - return QtCore.QVariant(item.data(index.column())) - - def flags(self, index): - if not index.isValid(): - return QtCore.Qt.ItemIsEnabled - return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable - - def headerData(self, section, orientation, role): - if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole: - return QtCore.QVariant(self.rootItem.data(section)) - return QtCore.QVariant() - - def index(self, row, column, parent): - if row < 0 or column < 0 or row >= self.rowCount(parent) or column >= self.columnCount(parent): - return QtCore.QModelIndex() - - if not parent.isValid(): - parentItem = self.rootItem - else: - parentItem = parent.internalPointer() - childItem = parentItem.child(row) - if childItem is not None: - return self.createIndex(row, column, childItem) - else: - return QtCore.QModelIndex() - - def parent(self, index): - if not index.isValid(): - return QtCore.QModelIndex() - - childItem = index.internalPointer() - parentItem = childItem.parent() - - if parentItem == self.rootItem: - return QtCore.QModelIndex() - - return self.createIndex(parentItem.row(), 0, parentItem) - - def rowCount(self, parent): - if parent.column() > 0: - return 0 - - if not parent.isValid(): - parentItem = self.rootItem - else: - parentItem = parent.internalPointer() - return parentItem.childCount() - - def columnCount(self, parent): - if parent.isValid(): - return parent.internalPointer().columnCount() - else: - return self.rootItem.columnCount() - - def setupModelData(self): - rootData = ["rev %s:%s" % (self.changectx.rev(), - short_hex(self.changectx.node()))] - self.rootItem = TreeItem(rootData) - - for path in sorted(self.changectx.manifest()): - path = path.split(osp.sep) - node = self.rootItem - - for p in path: - for ch in node: - if ch.data(0) == p: - node = ch - break - else: - node = node.addChild(TreeItem([p], node)) - - def pathFromIndex(self, index): - idxs = [] - while index.isValid(): - idxs.insert(0, index) - index = self.parent(index) - return osp.sep.join([index.internalPointer().data(0) for index in idxs]) - -  if __name__ == "__main__":   from mercurial import ui, hg   from optparse import OptionParser