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

filelistview: cleanup repo and context objects

The filelistmodel was given a repo even though it didn't use it anywhere,
meanwhile the filelistview had to reference the repo through the model.
Similarly, the current context was given directly to the model which was
then emitting the context to the view. Instead, the context now goes through
the HgFileListView.

Changeset b5b1ea8a0025

Parent 1ac53134b385

by Steve Borho

Changes to 4 files · Browse files at b5b1ea8a0025 Showing diff from parent 1ac53134b385 Diff from another changeset...

 
53
54
55
56
57
 
 
58
59
60
 
80
81
82
83
 
84
85
 
86
87
88
 
142
143
144
145
 
146
147
148
 
170
171
172
173
 
174
175
176
 
234
235
236
237
 
238
239
240
 
295
296
297
298
 
299
300
301
302
 
303
304
305
 
326
327
328
329
 
330
331
332
 
369
370
371
372
 
373
374
375
 
380
381
382
383
 
384
385
386
 
53
54
55
 
 
56
57
58
59
60
 
80
81
82
 
83
84
 
85
86
87
88
 
142
143
144
 
145
146
147
148
 
170
171
172
 
173
174
175
176
 
234
235
236
 
237
238
239
240
 
295
296
297
 
298
299
300
301
 
302
303
304
305
 
326
327
328
 
329
330
331
332
 
369
370
371
 
372
373
374
375
 
380
381
382
 
383
384
385
386
@@ -53,8 +53,8 @@
  self.splitter.setChildrenCollapsible(False)   self.layout().addWidget(self.splitter)   - self.filelist = filelistview.HgFileListView(self) - self.filelistmodel = filelistmodel.HgFileListModel(self.repo, self) + self.filelist = filelistview.HgFileListView(repo, self) + self.filelistmodel = filelistmodel.HgFileListModel(self)   self.filelist.setModel(self.filelistmodel)     self.fileListFrame = QFrame(self.splitter) @@ -80,9 +80,9 @@
    def timerEvent(self, event):   'Periodic poll of currently displayed patch or working file' - if not hasattr(self, 'filelistmodel'): + if not hasattr(self, 'filelist'):   return - ctx = self.filelistmodel._ctx + ctx = self.filelist.ctx   if ctx is None:   return   if isinstance(ctx, patchctx): @@ -142,7 +142,7 @@
  return ok     def editCurrentFile(self): - ctx = self.filelistmodel._ctx + ctx = self.filelist.ctx   if isinstance(ctx, patchctx):   path = ctx._path   else: @@ -170,7 +170,7 @@
  if not kchunks and qtlib.QuestionMsgBox(_('No chunks remain'),   _('Remove all file changes?')):   revertall = True - ctx = self.filelistmodel._ctx + ctx = self.filelist.ctx   if isinstance(ctx, patchctx):   repo.thgbackup(ctx._path)   fp = util.atomictempfile(ctx._path, 'wb') @@ -234,7 +234,7 @@
  return True   return False   repo = self.repo - ctx = self.filelistmodel._ctx + ctx = self.filelist.ctx   if isinstance(ctx, patchctx):   if wfile in ctx._files:   patchchunks = ctx._files[wfile] @@ -295,11 +295,11 @@
  return False     def getFileList(self): - return self.filelistmodel._ctx.files() + return self.filelist.ctx.files()     def removeFile(self, wfile):   repo = self.repo - ctx = self.filelistmodel._ctx + ctx = self.filelist.ctx   if isinstance(ctx, patchctx):   repo.thgbackup(ctx._path)   fp = util.atomictempfile(ctx._path, 'wb') @@ -326,7 +326,7 @@
    def getChunksForFile(self, wfile):   repo = self.repo - ctx = self.filelistmodel._ctx + ctx = self.filelist.ctx   if isinstance(ctx, patchctx):   if wfile in ctx._files:   return ctx._files[wfile] @@ -369,7 +369,7 @@
    def setContext(self, ctx):   self.diffbrowse.setContext(ctx) - self.filelistmodel.setContext(ctx) + self.filelist.setContext(ctx)   empty = len(ctx.files()) == 0   self.fileModelEmpty.emit(empty)   self.fileSelected.emit(not empty) @@ -380,7 +380,7 @@
  self.diffbrowse.updateSummary()     def refresh(self): - ctx = self.filelistmodel._ctx + ctx = self.filelist.ctx   if isinstance(ctx, patchctx):   # if patch mtime has not changed, it could return the same ctx   ctx = self.repo.changectx(ctx._path)
 
27
28
29
30
31
32
33
34
35
36
 
37
38
39
40
41
 
62
63
64
65
66
67
68
 
27
28
29
 
 
 
 
 
 
 
30
31
 
32
33
34
 
55
56
57
 
58
59
60
@@ -27,15 +27,8 @@
  """   Model used for listing (modified) files of a given Hg revision   """ - - contextChanged = pyqtSignal(object) - - def __init__(self, repo, parent): - """ - data is a HgHLRepo instance - """ + def __init__(self, parent):   QAbstractTableModel.__init__(self, parent) - self.repo = repo   self._boldfont = parent.font()   self._boldfont.setBold(True)   self._ctx = None @@ -62,7 +55,6 @@
  return self._files[row]['path']     def setContext(self, ctx): - self.contextChanged.emit(ctx)   reload = False   if not self._ctx:   reload = True
 
35
36
37
38
 
39
 
40
41
42
 
54
55
56
57
58
59
60
61
62
63
64
65
66
 
67
68
 
 
69
70
71
 
73
74
75
 
76
77
78
 
134
135
136
137
138
139
140
 
 
141
142
143
 
145
146
147
148
149
150
151
152
 
 
 
153
154
155
 
157
158
159
160
161
162
 
163
164
 
165
166
 
167
168
 
169
170
171
172
173
174
175
176
 
177
178
179
180
181
182
183
184
 
185
186
187
 
 
188
189
190
191
192
193
194
 
195
196
 
197
198
199
 
206
207
208
209
 
210
211
212
213
214
215
216
 
217
218
219
220
221
222
223
 
224
225
226
 
246
247
248
249
 
250
251
252
 
261
262
263
264
 
265
266
267
 
300
301
302
303
 
304
305
306
 
309
310
311
312
 
313
314
 
315
316
317
 
35
36
37
 
38
39
40
41
42
43
 
55
56
57
 
58
59
60
61
 
 
62
63
 
64
65
 
66
67
68
69
70
 
72
73
74
75
76
77
78
 
134
135
136
 
137
 
 
138
139
140
141
142
 
144
145
146
 
147
 
 
 
148
149
150
151
152
153
 
155
156
157
 
 
 
158
159
 
160
161
 
162
163
 
164
165
166
167
168
169
 
 
 
170
171
172
173
174
175
 
 
 
176
177
 
 
178
179
180
181
182
183
184
 
 
185
186
 
187
188
189
190
 
197
198
199
 
200
201
202
203
204
205
206
 
207
208
209
210
211
212
213
 
214
215
216
217
 
237
238
239
 
240
241
242
243
 
252
253
254
 
255
256
257
258
 
291
292
293
 
294
295
296
297
 
300
301
302
 
303
304
 
305
306
307
308
@@ -35,8 +35,9 @@
  filecontextmenu = None   subrepocontextmenu = None   - def __init__(self, parent=None): + def __init__(self, repo, parent):   QTableView.__init__(self, parent) + self.repo = repo   self.setShowGrid(False)   self.horizontalHeader().hide()   self.verticalHeader().hide() @@ -54,18 +55,16 @@
  def setModel(self, model):   QTableView.setModel(self, model)   model.layoutChanged.connect(self.layoutChanged) - model.contextChanged.connect(self.contextChanged)   self.selectionModel().currentRowChanged.connect(self.onRowChange)   self.horizontalHeader().setResizeMode(1, QHeaderView.Stretch)   self.actionShowAllMerge.setChecked(False)   self.actionShowAllMerge.toggled.connect(model.toggleFullFileList) - if model._ctx is not None: - self.contextChanged(model._ctx)     def setRepo(self, repo): - self.model().repo = repo + self.repo = repo   - def contextChanged(self, ctx): + def setContext(self, ctx): + self.ctx = ctx   real = type(ctx.rev()) is int   wd = ctx.rev() is None   for act in ['navigate', 'diffnavigate', 'ldiff', 'edit']: @@ -73,6 +72,7 @@
  for act in ['diff', 'revert']:   self._actions[act].setEnabled(real or wd)   self.actionShowAllMerge.setEnabled(len(ctx.parents()) == 2) + self.model().setContext(ctx)     def currentFile(self):   index = self.currentIndex() @@ -134,10 +134,9 @@
  filename = self.currentFile()   if filename is None:   return - model = self.model()   pats = [filename] - opts = {'change':model._ctx.rev()} - dlg = visdiff.visualdiff(model.repo.ui, model.repo, pats, opts) + opts = {'change':self.ctx.rev()} + dlg = visdiff.visualdiff(self.repo.ui, self.repo, pats, opts)   if dlg:   dlg.exec_()   @@ -145,11 +144,10 @@
  filename = self.currentFile()   if filename is None:   return - model = self.model()   pats = [filename] - assert type(model._ctx.rev()) is int - opts = {'rev':['rev(%d)' % (model._ctx.rev())]} - dlg = visdiff.visualdiff(model.repo.ui, model.repo, pats, opts) + assert type(self.ctx.rev()) is int + opts = {'rev':['rev(%d)' % (self.ctx.rev())]} + dlg = visdiff.visualdiff(self.repo.ui, self.repo, pats, opts)   if dlg:   dlg.exec_()   @@ -157,43 +155,36 @@
  filename = self.currentFile()   if filename is None:   return - model = self.model() - repo = model.repo - rev = model._ctx.rev() + rev = self.ctx.rev()   if rev is None: - qtlib.editfiles(repo, [filename], parent=self) + qtlib.editfiles(self.repo, [filename], parent=self)   else: - base, _ = visdiff.snapshot(repo, [filename], repo[rev]) + base, _ = visdiff.snapshot(self.repo, [filename], self.ctx)   files = [os.path.join(base, filename)] - qtlib.editfiles(repo, files, parent=self) + qtlib.editfiles(self.repo, files, parent=self)     def editlocal(self):   filename = self.currentFile()   if filename is None:   return - model = self.model() - repo = model.repo - qtlib.editfiles(repo, [filename], parent=self) + qtlib.editfiles(self.repo, [filename], parent=self)     def revertfile(self):   filename = self.currentFile()   if filename is None:   return - model = self.model() - repo = model.repo - rev = model._ctx.rev() + rev = self.ctx.rev()   if rev is None: - rev = model._ctx.p1().rev() - dlg = revert.RevertDialog(repo, filename, rev, self) + rev = self.ctx.p1().rev() + dlg = revert.RevertDialog(self.repo, filename, rev, self)   dlg.exec_()     def _navigate(self, filename, dlgclass, dlgdict):   if not filename:   filename = self.currentFile() - model = self.model() - if filename is not None and len(model.repo.file(filename))>0: + if filename is not None and len(self.repo.file(filename))>0:   if filename not in dlgdict: - dlg = dlgclass(model.repo, filename, + dlg = dlgclass(self.repo, filename,   repoviewer=self.window())   dlgdict[filename] = dlg   ufname = hglib.tounicode(filename) @@ -206,21 +197,21 @@
  dlg.activateWindow()     def opensubrepo(self): - path = os.path.join(self.model().repo.root, self.currentFile()) + path = os.path.join(self.repo.root, self.currentFile())   if os.path.isdir(path):   self.linkActivated.emit(u'subrepo:'+hglib.tounicode(path))   else:   QMessageBox.warning(self,   _("Cannot open subrepository"),   _("The selected subrepository does not exist on the working directory")) - +   def doubleClickHandler(self):   itemissubrepo = (self.model().dataFromIndex(self.currentIndex())['status'] == 'S')   if itemissubrepo:   self.opensubrepo()   else:   self.vdiff() - +   def createActions(self):   self.actionShowAllMerge = QAction(_('Show All'), self)   self.actionShowAllMerge.setToolTip( @@ -246,7 +237,7 @@
  ('revert', _('Revert to Revision'), 'hg-revert', 'Alt+Ctrl+T',   _('Revert file(s) to contents at this revision'),   self.revertfile), - ('opensubrepo', _('Open subrepository'), 'thg-repository-open', + ('opensubrepo', _('Open subrepository'), 'thg-repository-open',   'Alt+Ctrl+O', _('Open the selected subrepository'),   self.opensubrepo),   ]: @@ -261,7 +252,7 @@
  act.triggered.connect(cb)   self._actions[name] = act   self.addAction(act) - +   def contextMenuEvent(self, event):   itemissubrepo = (self.model().dataFromIndex(self.currentIndex())['status'] == 'S')   @@ -300,7 +291,7 @@
  return self.selectionModel().selectedRows()     def dragObject(self): - ctx = self.model()._ctx + ctx = self.ctx   if type(ctx.rev()) == str:   return   paths = [] @@ -309,9 +300,9 @@
  if not paths:   return   if ctx.rev() is None: - base = ctx._repo.root + base = self.repo.root   else: - base, _ = visdiff.snapshot(ctx._repo, paths, ctx) + base, _ = visdiff.snapshot(self.repo, paths, ctx)   urls = []   for path in paths:   urls.append(QUrl.fromLocalFile(os.path.join(base, path)))
 
89
90
91
92
 
93
94
95
 
175
176
177
 
 
 
 
178
179
180
 
207
208
209
210
211
212
213
214
215
216
217
218
219
 
223
224
225
226
 
227
228
229
 
89
90
91
 
92
93
94
95
 
175
176
177
178
179
180
181
182
183
184
 
211
212
213
 
 
 
 
 
 
 
214
215
216
 
220
221
222
 
223
224
225
226
@@ -89,7 +89,7 @@
    self.filelistToolbar = QToolBar(_('File List Toolbar'))   self.filelistToolbar.setIconSize(QSize(16,16)) - self.filelist = HgFileListView() + self.filelist = HgFileListView(self.repo, self)   self.filelist.linkActivated.connect(self.linkActivated)     self.tbarFileListFrame = QFrame(self.filelist_splitter) @@ -175,6 +175,10 @@
  def forwardFont(self, font):   self.message.setFont(font)   + def setupModels(self): + self.filelistmodel = HgFileListModel(self) + self.filelist.setModel(self.filelistmodel) +   def createActions(self):   def fileActivated():   idx = self.filelist.currentIndex() @@ -207,13 +211,6 @@
  self.actionPrevCol.triggered.connect(self.fileview.prevCol)   self.addAction(self.actionPrevCol)   - def create_models(self): - self.filelistmodel = HgFileListModel(self.repo, self) - - def setupModels(self): - self.create_models() - self.filelist.setModel(self.filelistmodel) -   def onRevisionSelected(self, rev):   'called by repowidget when repoview changes revisions'   self._last_rev = rev @@ -223,7 +220,7 @@
  self.message.setHtml('<pre>%s</pre>'   % self._deschtmlize(ctx.description()))   self.fileview.setContext(ctx) - self.filelistmodel.setContext(ctx) + self.filelist.setContext(ctx)     @pyqtSlot()   def _updatedeschtmlizer(self):