PageRenderTime 15ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tortoisehg/hgqt/revert.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 72 lines | 53 code | 13 blank | 6 comment | 4 complexity | 5dc5b59c51bec217c581791650aa2631 MD5 | raw file
 1# revert.py - File revert dialog for TortoiseHg
 2#
 3# Copyright 2010 Steve Borho <steve@borho.org>
 4#
 5# This software may be used and distributed according to the terms of the
 6# GNU General Public License version 2, incorporated herein by reference.
 7
 8import os
 9
10from PyQt4.QtCore import *
11from PyQt4.QtGui import *
12
13from mercurial import util, error
14
15from tortoisehg.util import hglib
16from tortoisehg.hgqt.i18n import _
17from tortoisehg.hgqt import cmdui, qtlib
18
19class RevertDialog(QDialog):
20    def __init__(self, repo, wfile, rev, parent):
21        super(RevertDialog, self).__init__(parent)
22        self.setWindowTitle(_('Revert - %s') % repo.displayname)
23
24        f = self.windowFlags()
25        self.setWindowFlags(f & ~Qt.WindowContextHelpButtonHint)
26        self.repo = repo
27        self.wfile = repo.wjoin(wfile)
28        self.rev = str(rev)
29
30        self.setLayout(QVBoxLayout())
31
32        lbl = QLabel(_('<b>Revert %s to its contents at revision %d?</b>') % (
33            wfile, rev))
34        self.layout().addWidget(lbl)
35
36        self.allchk = QCheckBox(_('Revert all files to this revision'))
37        self.layout().addWidget(self.allchk)
38
39        self.cmd = cmdui.Widget()
40        self.cmd.setShowOutput(False)
41        self.cmd.stbar.setVisible(False)
42        self.cmd.commandFinished.connect(self.finished)
43        self.layout().addWidget(self.cmd, 1)
44
45        BB = QDialogButtonBox
46        bbox = QDialogButtonBox(BB.Ok|BB.Cancel)
47        bbox.accepted.connect(self.accept)
48        bbox.rejected.connect(self.reject)
49        self.layout().addWidget(bbox)
50        self.bbox = bbox
51
52    def accept(self):
53        if self.allchk.isChecked():
54            if not qtlib.QuestionMsgBox(_('Confirm Revert'),
55                     _('Reverting all files will discard changes and '
56                       'leave affected files in a modified state.<br>'
57                       '<br>Are you sure you want to use revert?<br><br>'
58                       '(use update to checkout another revision)'),
59                       parent=self):
60                return
61            cmdline = ['revert', '--repository', self.repo.root, '--all']
62        else:
63            cmdline = ['revert', '--repository', self.repo.root, self.wfile]
64        cmdline += ['--rev', self.rev]
65        self.cmd.setShowOutput(True)
66        self.cmd.stbar.setVisible(True)
67        self.cmd.run(cmdline)
68
69    def finished(self, ret):
70        if ret == 0:
71            self.bbox.button(QDialogButtonBox.Ok).setVisible(False)
72            self.bbox.button(QDialogButtonBox.Cancel).setText(_('Close'))