Changeset 13b060ecd253…
Parent 146c72c0420f…
by
Changes to one file · Browse files at 13b060ecd253 Showing diff from parent 146c72c0420f Diff from another changeset...
|
@@ -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)
|
Loading...