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

chunks: add a specialized context menu for shelve tool

Changeset 13b060ecd253

Parent 146c72c0420f

by Steve Borho

Changes to one file · Browse files at 13b060ecd253 Showing diff from parent 146c72c0420f Diff from another changeset...

 
15
16
17
18
 
19
20
21
 
36
37
38
 
 
39
40
41
 
56
57
58
 
 
 
59
60
61
 
78
79
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
 
378
379
380
 
 
 
381
382
383
 
384
385
386
 
15
16
17
 
18
19
20
21
 
36
37
38
39
40
41
42
43
 
58
59
60
61
62
63
64
65
66
 
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
 
201
202
203
 
204
205
206
207
 
229
230
231
 
232
233
234
235
 
293
294
295
 
296
297
298
299
 
354
355
356
 
357
358
359
360
 
361
362
363
364
 
385
386
387
 
388
389
390
391
 
437
438
439
440
441
442
443
444
 
445
446
447
448
@@ -15,7 +15,7 @@
 from tortoisehg.util import hglib  from tortoisehg.util.patchctx import patchctx  from tortoisehg.hgqt.i18n import _ -from tortoisehg.hgqt import qtlib, thgrepo, qscilib, lexers +from tortoisehg.hgqt import qtlib, thgrepo, qscilib, lexers, visdiff, revert  from tortoisehg.hgqt import filelistmodel, filelistview, filedata    from PyQt4.QtCore import * @@ -36,6 +36,8 @@
  fileModelEmpty = pyqtSignal(bool)   fileModified = pyqtSignal()   + contextmenu = None +   def __init__(self, repo, parent):   QWidget.__init__(self, parent)   @@ -56,6 +58,9 @@
  self.filelist = filelistview.HgFileListView(repo, self)   self.filelistmodel = filelistmodel.HgFileListModel(self)   self.filelist.setModel(self.filelistmodel) + self.filelist.setContextMenuPolicy(Qt.CustomContextMenu) + self.filelist.customContextMenuRequested.connect(self.menuRequest) + self.filelist.doubleClicked.connect(self.vdiff)     self.fileListFrame = QFrame(self.splitter)   self.fileListFrame.setFrameShape(QFrame.NoFrame) @@ -78,11 +83,65 @@
  self.splitter.setStretchFactor(1, 3)   self.timerevent = self.startTimer(500)   + self._actions = {} + for name, desc, icon, key, tip, cb in [ + ('diff', _('Visual Diff'), 'visualdiff', 'Ctrl+D', + _('View file changes in external diff tool'), self.vdiff), + ('edit', _('Edit Local'), 'edit-file', 'Shift+Ctrl+E', + _('Edit current file in working copy'), self.editCurrentFile), + ('revert', _('Revert to Revision'), 'hg-revert', 'Alt+Ctrl+T', + _('Revert file(s) to contents at this revision'), + self.revertfile), + ]: + act = QAction(desc, self) + if icon: + act.setIcon(qtlib.getmenuicon(icon)) + if key: + act.setShortcut(key) + if tip: + act.setStatusTip(tip) + if cb: + act.triggered.connect(cb) + self._actions[name] = act + self.addAction(act) + + @pyqtSlot(QPoint) + def menuRequest(self, point): + actionlist = ['diff', 'edit', 'revert'] + if not self.contextmenu: + menu = QMenu(self) + for act in actionlist: + menu.addAction(self._actions[act]) + self.contextmenu = menu + self.contextmenu.exec_(self.filelist.mapToGlobal(point)) + + def vdiff(self): + filename = self.filelist.currentFile() + if filename is None: + return + pats = [filename] + opts = {'change':self.ctx.rev()} + dlg = visdiff.visualdiff(self.repo.ui, self.repo, pats, opts) + if dlg: + dlg.exec_() + dlg.deleteLater() + + def revertfile(self): + filename = self.filelist.currentFile() + if filename is None: + return + rev = self.ctx.rev() + if rev is None: + rev = self.ctx.p1().rev() + dlg = revert.RevertDialog(self.repo, filename, rev, self) + dlg.exec_() + dlg.deleteLater() +   def timerEvent(self, event):   'Periodic poll of currently displayed patch or working file'   if not hasattr(self, 'filelist'):   return - ctx = self.filelist.ctx + ctx = self.ctx   if ctx is None:   return   if isinstance(ctx, patchctx): @@ -142,7 +201,7 @@
  return ok     def editCurrentFile(self): - ctx = self.filelist.ctx + ctx = self.ctx   if isinstance(ctx, patchctx):   path = ctx._path   else: @@ -170,7 +229,7 @@
  if not kchunks and qtlib.QuestionMsgBox(_('No chunks remain'),   _('Remove all file changes?')):   revertall = True - ctx = self.filelist.ctx + ctx = self.ctx   if isinstance(ctx, patchctx):   repo.thgbackup(ctx._path)   fp = util.atomictempfile(ctx._path, 'wb') @@ -234,7 +293,7 @@
  return True   return False   repo = self.repo - ctx = self.filelist.ctx + ctx = self.ctx   if isinstance(ctx, patchctx):   if wfile in ctx._files:   patchchunks = ctx._files[wfile] @@ -295,11 +354,11 @@
  return False     def getFileList(self): - return self.filelist.ctx.files() + return self.ctx.files()     def removeFile(self, wfile):   repo = self.repo - ctx = self.filelist.ctx + ctx = self.ctx   if isinstance(ctx, patchctx):   repo.thgbackup(ctx._path)   fp = util.atomictempfile(ctx._path, 'wb') @@ -326,7 +385,7 @@
    def getChunksForFile(self, wfile):   repo = self.repo - ctx = self.filelist.ctx + ctx = self.ctx   if isinstance(ctx, patchctx):   if wfile in ctx._files:   return ctx._files[wfile] @@ -378,9 +437,12 @@
  self.diffbrowse.clearDisplay()   self.diffbrowse.clearChunks()   self.diffbrowse.updateSummary() + self.ctx = ctx + for act in ['diff', 'revert']: + self._actions[act].setEnabled(ctx.rev() is None)     def refresh(self): - ctx = self.filelist.ctx + ctx = self.ctx   if isinstance(ctx, patchctx):   # if patch mtime has not changed, it could return the same ctx   ctx = self.repo.changectx(ctx._path)