Commits

Anonymous committed 2ee363b

filedialogs: add "Revert to revision" and "View file at revision" commands to context menu (closes #683)

  • Participants
  • Parent commits 373e8e2
  • Branches stable

Comments (0)

Files changed (1)

File tortoisehg/hgqt/filedialogs.py

 Qt4 dialogs to display hg revisions of a file
 """
 
+import os
 import difflib
 
 from tortoisehg.util import hglib
 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt import qtlib, visdiff, filerevmodel, blockmatcher, lexers
-from tortoisehg.hgqt import fileview, repoview, revpanel
+from tortoisehg.hgqt import fileview, repoview, revpanel, revert
 
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
             a = menu.addAction(_('Diff file to local...'))
             a.setIcon(qtlib.getmenuicon('ldiff'))
             a.triggered.connect(self.onVisualDiffFileToLocal)
+            menu.addSeparator()
+            a = menu.addAction(_('Revert to revision...'))
+            a.setIcon(qtlib.getmenuicon('hg-revert'))
+            a.triggered.connect(self.onRevertFileToRevision)
+            a = menu.addAction(_('View at revision...'))
+            a.setIcon(qtlib.getmenuicon('view-at-revision'))
+            a.triggered.connect(self.onViewFileAtRevision)
         self.selection = selection
         self.menu.exec_(point)
 
             dlg.exec_()
             dlg.deleteLater()
 
+    def onRevertFileToRevision(self):
+        rev = self.selection[0]
+        if rev is None:
+            rev = self.repo['.'].rev()
+        fileSelection = [self.filerevmodel.graph.filename(rev)]
+        if len(fileSelection) == 0:
+            return
+        dlg = revert.RevertDialog(self.repo, fileSelection, rev, self)
+        if dlg:
+            dlg.exec_()
+            dlg.deleteLater()
+
+
+    def onViewFileAtRevision(self):
+        rev = self.selection[0]
+        filenames = [self.filerevmodel.graph.filename(rev)]
+        if not filenames:
+            return
+        if rev is None:
+            qtlib.editfiles(self.repo, filenames, parent=self)
+        else:
+            base, _ = visdiff.snapshot(self.repo, filenames, self.repo[rev])
+            files = [os.path.join(base, filename)
+                     for filename in filenames]
+            qtlib.editfiles(self.repo, files, parent=self)
+
+
     @pyqtSlot(QString)
     def onLinkActivated(self, link):
         link = unicode(link)