PageRenderTime 116ms CodeModel.GetById 103ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/tortoisehg/hgqt/p4pending.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 124 lines | 99 code | 19 blank | 6 comment | 5 complexity | 30b6518fae58b28a7d98186d24bb2277 MD5 | raw file
  1# p4pending.py - Display pending p4 changelists, created by perfarce extension
  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 error
 14
 15from tortoisehg.util import hglib
 16from tortoisehg.hgqt.i18n import _
 17from tortoisehg.hgqt import qtlib, cslist, cmdui
 18
 19
 20class PerforcePending(QDialog):
 21    'Dialog for selecting a revision'
 22
 23    output = pyqtSignal(QString, QString)
 24    makeLogVisible = pyqtSignal(bool)
 25    showMessage = pyqtSignal(unicode)
 26
 27    def __init__(self, repo, pending, url, parent):
 28        QDialog.__init__(self, parent)
 29        self.repo = repo
 30        self.url = url
 31        self.pending = pending # dict of changelist -> hash tuple
 32
 33        layout = QVBoxLayout()
 34        self.setLayout(layout)
 35
 36        clcombo = QComboBox()
 37        layout.addWidget(clcombo)
 38
 39        self.cslist = cslist.ChangesetList()
 40        layout.addWidget(self.cslist)
 41
 42        self.cmd = cmdui.Runner(parent=self)
 43        self.cmd.commandFinished.connect(self.commandFinished)
 44        self.cmd.output.connect(self.output)
 45        self.cmd.makeLogVisible.connect(self.makeLogVisible)
 46
 47        BB = QDialogButtonBox
 48        bb = QDialogButtonBox(BB.Ok|BB.Cancel|BB.Discard)
 49        bb.rejected.connect(self.reject)
 50        bb.button(BB.Discard).setText('Revert')
 51        bb.button(BB.Discard).setAutoDefault(False)
 52        bb.button(BB.Discard).clicked.connect(self.revert)
 53        bb.button(BB.Discard).setEnabled(False)
 54        bb.button(BB.Ok).setText('Submit')
 55        bb.button(BB.Ok).setAutoDefault(True)
 56        bb.button(BB.Ok).clicked.connect(self.submit)
 57        bb.button(BB.Ok).setEnabled(False)
 58        layout.addWidget(bb)
 59        self.bb = bb
 60
 61        clcombo.activated[QString].connect(self.p4clActivated)
 62        for changelist in self.pending:
 63            clcombo.addItem(hglib.tounicode(changelist))
 64        self.p4clActivated(clcombo.currentText())
 65
 66        self.setWindowTitle(_('Pending Perforce Changelists - %s') %
 67                            repo.displayname)
 68
 69    @pyqtSlot(QString)
 70    def p4clActivated(self, curcl):
 71        'User has selected a changelist, fill cslist'
 72        curcl = hglib.fromunicode(curcl)
 73        try:
 74            hashes = self.pending[curcl]
 75            revs = [self.repo[hash] for hash in hashes]
 76        except error.Abort, e:
 77            revs = []
 78        self.cslist.clear()
 79        self.cslist.update(self.repo, revs)
 80        sensitive = not curcl.endswith('(submitted)')
 81        self.bb.button(QDialogButtonBox.Ok).setEnabled(sensitive)
 82        self.bb.button(QDialogButtonBox.Discard).setEnabled(sensitive)
 83        self.curcl = curcl
 84
 85    def submit(self):
 86        assert(self.curcl.endswith('(pending)'))
 87        cmdline = ['p4submit', '--verbose',
 88                   '--config', 'extensions.perfarce=',
 89                   '--repository', self.url,
 90                   self.curcl[:-10]]
 91        self.repo.incrementBusyCount()
 92        self.bb.button(QDialogButtonBox.Ok).setEnabled(False)
 93        self.bb.button(QDialogButtonBox.Discard).setEnabled(False)
 94        self.showMessage.emit(_('Submitting p4 changelist...'))
 95        self.cmd.run(cmdline, useproc=True)
 96
 97    def revert(self):
 98        assert(self.curcl.endswith('(pending)'))
 99        cmdline = ['p4revert', '--verbose',
100                   '--config', 'extensions.perfarce=',
101                   '--repository', self.url,
102                   self.curcl[:-10]]
103        self.repo.incrementBusyCount()
104        self.bb.button(QDialogButtonBox.Ok).setEnabled(False)
105        self.bb.button(QDialogButtonBox.Discard).setEnabled(False)
106        self.showMessage.emit(_('Reverting p4 changelist...'))
107        self.cmd.run(cmdline, useproc=True)
108
109    def commandFinished(self, ret):
110        self.showMessage.emit('')
111        self.repo.decrementBusyCount()
112        self.bb.button(QDialogButtonBox.Ok).setEnabled(True)
113        self.bb.button(QDialogButtonBox.Discard).setEnabled(True)
114        if ret == 0:
115            self.reject()
116
117    def keyPressEvent(self, event):
118        if event.key() == Qt.Key_Escape:
119            if self.cmd.isRunning():
120                self.cmd.cancel()
121            else:
122                self.reject()
123        else:
124            return super(PerforcePending, self).keyPressEvent(event)