Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

fileview: remove rev argument to displayFile(), make remaining args non-optional

filelistmodel's revFromIndex was made redundant. In revdetails, the filelist
fileRevSelected signal is now connected directly to fileview.displayFile.

Changeset fd2662ea0068

Parent 84a059455d24

by Steve Borho

Changes to 7 files · Browse files at fd2662ea0068 Showing diff from parent 84a059455d24 Diff from another changeset...

 
216
217
218
219
 
220
221
222
 
216
217
218
 
219
220
221
222
@@ -216,7 +216,7 @@
  pos = self.textView.verticalScrollBar().value()   ctx = self.filerevmodel.repo.changectx(rev)   self.textView.setContext(ctx) - self.textView.displayFile(self.filerevmodel.graph.filename(rev)) + self.textView.displayFile(self.filerevmodel.graph.filename(rev), None)   self.textView.verticalScrollBar().setValue(pos)   self.revpanel.set_revision(rev)   self.revpanel.update(repo = self.repo)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
 # 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.    from tortoisehg.util import hglib    from tortoisehg.hgqt.qtlib import geticon    from PyQt4.QtCore import *  from PyQt4.QtGui import *    nullvariant = QVariant()    class HgFileListModel(QAbstractTableModel):   """   Model used for listing (modified) files of a given Hg revision   """     contextChanged = pyqtSignal(object)     def __init__(self, repo, parent):   """   data is a HgHLRepo instance   """   QAbstractTableModel.__init__(self, parent)   self.repo = repo   self._boldfont = parent.font()   self._boldfont.setBold(True)   self._ctx = None   self._files = []   self._filesdict = {}   self._fulllist = False     @pyqtSlot(bool)   def toggleFullFileList(self, value):   self._fulllist = value   self.loadFiles()   self.layoutChanged.emit()     def __len__(self):   return len(self._files)     def rowCount(self, parent=None):   return len(self)     def columnCount(self, parent=None):   return 1     def file(self, row):   return self._files[row]['path']     def setContext(self, ctx):   self.contextChanged.emit(ctx)   reload = False   if not self._ctx:   reload = True   elif self._ctx.rev() is None:   reload = True   elif ctx.thgid() != self._ctx.thgid():   reload = True   if reload:   self._ctx = ctx   self.loadFiles()   self.layoutChanged.emit()     def fileFromIndex(self, index):   if not index.isValid() or index.row()>=len(self) or not self._ctx:   return None   row = index.row()   return self._files[row]['path']   - def revFromIndex(self, index): - 'return revision for index. index is guarunteed to be valid' - if len(self._ctx.parents()) < 2: - return None - row = index.row() - if self._fulllist and self._files[row]['parent'] == 1: - return self._ctx.p2().rev() - else: - return self._ctx.p1().rev() -   def dataFromIndex(self, index):   if not index.isValid() or index.row()>=len(self) or not self._ctx:   return None   row = index.row()   return self._files[row]     def indexFromFile(self, filename):   if filename in self._filesdict:   row = self._files.index(self._filesdict[filename])   return self.index(row, 0)   return QModelIndex()     def _buildDesc(self, parent):   files = []   ctxfiles = self._ctx.files()   modified, added, removed = self._ctx.changesToParent(parent)   ismerge = bool(self._ctx.p2())   if self._fulllist and ismerge:   func = lambda x: True   else:   func = lambda x: x in ctxfiles   for lst, flag in ((added, 'A'), (modified, 'M'), (removed, 'R')):   for f in filter(func, lst):   wasmerged = ismerge and f in ctxfiles   files.append({'path': f, 'status': flag, 'parent': parent,   'wasmerged': wasmerged})   return files     def loadFiles(self):   self._files = []   self._files = self._buildDesc(0)   if bool(self._ctx.p2()):   _paths = [x['path'] for x in self._files]   _files = self._buildDesc(1)   self._files += [x for x in _files if x['path'] not in _paths]   self._filesdict = dict([(f['path'], f) for f in self._files])     def data(self, index, role):   if not index.isValid() or index.row()>len(self) or not self._ctx:   return nullvariant   if index.column() != 0:   return nullvariant     row = index.row()   column = index.column()     current_file_desc = self._files[row]   current_file = current_file_desc['path']     if role in (Qt.DisplayRole, Qt.ToolTipRole):   return QVariant(hglib.tounicode(current_file))   elif role == Qt.DecorationRole:   if self._fulllist and bool(self._ctx.p2()):   if current_file_desc['wasmerged']:   icn = geticon('thg-file-merged')   elif current_file_desc['parent'] == 0:   icn = geticon('thg-file-p0')   elif current_file_desc['parent'] == 1:   icn = geticon('thg-file-p1')   return QVariant(icn.pixmap(20,20))   elif current_file_desc['status'] == 'A':   return QVariant(geticon('fileadd'))   elif current_file_desc['status'] == 'R':   return QVariant(geticon('filedelete'))   #else:   # return QVariant(geticon('filemodify'))   elif role == Qt.FontRole:   if current_file_desc['wasmerged']:   return QVariant(self._boldfont)   else:   return nullvariant
 
29
30
31
32
 
33
34
35
 
53
54
55
56
 
57
58
59
 
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
 
104
105
106
107
108
 
 
 
 
109
110
111
 
29
30
31
 
32
33
34
35
 
53
54
55
 
56
57
58
59
 
78
79
80
 
81
82
83
84
 
85
86
87
88
89
90
 
91
92
 
93
94
95
96
97
 
 
98
99
100
101
 
103
104
105
 
 
106
107
108
109
110
111
112
@@ -29,7 +29,7 @@
  A QTableView for displaying a HgFileListModel   """   - fileRevSelected = pyqtSignal(object, object, object) + fileSelected = pyqtSignal(QString, QString)   clearDisplay = pyqtSignal()   contextmenu = None   @@ -53,7 +53,7 @@
  QTableView.setModel(self, model)   model.layoutChanged.connect(self.layoutChanged)   model.contextChanged.connect(self.contextChanged) - self.selectionModel().currentRowChanged.connect(self.fileSelected) + self.selectionModel().currentRowChanged.connect(self.onRowChange)   self.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)   self.actionShowAllMerge.setChecked(False)   self.actionShowAllMerge.toggled.connect(model.toggleFullFileList) @@ -78,25 +78,24 @@
  index = self.currentIndex()   count = len(self.model())   if index.row() == -1: - # index is changing, fileSelected() called for us + # index is changing, onRowChange() called for us   self.selectRow(0)   elif index.row() >= count:   if count: - # index is changing, fileSelected() called for us + # index is changing, onRowChange() called for us   self.selectRow(count-1)   else:   self.clearDisplay.emit()   else:   # redisplay previous row - self.fileSelected() + self.onRowChange(index)   - def fileSelected(self, index=None, *args): + def onRowChange(self, index, *args):   if index is None:   index = self.currentIndex()   data = self.model().dataFromIndex(index)   if data: - fromRev = self.model().revFromIndex(index) - self.fileRevSelected.emit(data['path'], fromRev, data['status']) + self.fileSelected.emit(data['path'], data['status'])   else:   self.clearDisplay.emit()   @@ -104,8 +103,10 @@
  'Select given file, if found, else the first file'   index = self.model().indexFromFile(filename)   if index: - self.setCurrentIndex(index) - self.fileSelected(index) + if index != self.currentIndex(): + self.setCurrentIndex(index) + else: + self.onRowChange(index)   elif self.model().count():   self.selectRow(0)  
 
231
232
233
234
 
235
236
237
 
287
288
289
290
291
292
293
294
 
295
296
 
 
297
298
299
300
301
302
303
304
305
306
307
 
231
232
233
 
234
235
236
237
 
287
288
289
 
 
 
 
 
290
291
292
293
294
295
296
297
298
299
300
 
 
301
302
303
@@ -231,7 +231,7 @@
  self.actionPrevDiff.setEnabled(False)   self.blk.setVisible(mode == FileMode)   self.sci.setAnnotationEnabled(mode == AnnMode) - self.displayFile() + self.displayFile(self._filename, self._status)     def restrictModes(self, candiff, canfile, canann):   'Disable modes based on content constraints' @@ -287,21 +287,17 @@
  self.filenamelabel.setText(' ')   self.extralabel.hide()   - def displayFile(self, filename=None, rev=None, status=None): - if filename is None: - filename, status = self._filename, self._status - else: - self._filename, self._status = filename, status + def displayFile(self, filename, status):   if isinstance(filename, (unicode, QString)):   filename = hglib.fromunicode(filename) + status = hglib.fromunicode(status) + self._filename, self._status = filename, status     self.clearMarkup()   if filename is None:   self.restrictModes(False, False, False)   return   - if rev is not None: - self._p_rev = rev   if self._p_rev is not None:   ctx2 = self.repo[self._p_rev]   else:
 
352
353
354
355
 
356
357
358
 
376
377
378
379
 
380
381
382
 
352
353
354
 
355
356
357
358
 
376
377
378
 
379
380
381
382
@@ -352,7 +352,7 @@
  ctx = self._repo[rev]   if self.path in ctx:   self._fileview.setContext(ctx) - self._fileview.displayFile(path) + self._fileview.displayFile(path, self.status)   if line:   self._fileview.showLine(int(line) - 1)   else: @@ -376,7 +376,7 @@
  @pyqtSlot()   def _updatecontent(self):   self._fileview.setContext(self._repo[self._rev]) - self._fileview.displayFile(self.path, status=self.status) + self._fileview.displayFile(self.path, self.status)     @pyqtSlot()   def _emitPathChanged(self):
 
166
167
168
169
 
170
171
172
 
211
212
213
214
215
216
217
218
219
220
 
166
167
168
 
169
170
171
172
 
211
212
213
 
 
 
 
214
215
216
@@ -166,7 +166,7 @@
    revisiondetails_layout.addWidget(self.filelist_splitter)   - self.filelist.fileRevSelected.connect(self.onFileRevSelected) + self.filelist.fileSelected.connect(self.fileview.displayFile)   self.filelist.clearDisplay.connect(self.fileview.clearDisplay)     def forwardFont(self, font): @@ -211,10 +211,6 @@
  self.create_models()   self.filelist.setModel(self.filelistmodel)   - @pyqtSlot(object, object, object) - def onFileRevSelected(self, file, rev, status): - self.fileview.displayFile(file, rev, status) -   def onRevisionSelected(self, rev):   'called by repowidget when repoview changes revisions'   self._last_rev = rev
 
371
372
373
374
 
375
376
377
 
371
372
373
 
374
375
376
377
@@ -371,7 +371,7 @@
  path, status, mst, upath, ext, sz = row   wfile = util.pconvert(path)   self.fileview.setContext(self.repo[None]) - self.fileview.displayFile(wfile, status=status) + self.fileview.displayFile(wfile, status)      class StatusThread(QThread):