PageRenderTime 53ms CodeModel.GetById 38ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/tortoisehg/hgtk/p4pending.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 115 lines | 84 code | 21 blank | 10 comment | 8 complexity | 7a8ce553f1e46e5b3b266c4d7969f472 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
  9import gtk
 10import gobject
 11
 12from mercurial import error
 13
 14from tortoisehg.util.i18n import _
 15from tortoisehg.hgtk import gtklib, gdialog, cslist
 16
 17
 18class PerforcePending(gdialog.GDialog):
 19    'Dialog for selecting a revision'
 20    def __init__(self, repo, pending, graphview):
 21        gdialog.GDialog.__init__(self, resizable=True)
 22        self.repo = repo
 23        self.graphview = graphview
 24        self.pending = pending
 25
 26    def get_icon(self):
 27        return 'menulog.ico'
 28
 29    def get_title(self, reponame):
 30        return _('Pending Perforce Changelists - %s') % reponame
 31
 32    def get_defsize(self):
 33        return (500, 380)
 34
 35    def get_body(self, vbox):
 36        # layout table
 37        self.table = table = gtklib.LayoutTable()
 38        vbox.pack_start(table, True, True, 2)
 39
 40        ## changelist combo
 41        clcombo = gtk.combo_box_new_text()
 42        clcombo.connect('changed', self.changelist_selected)
 43        table.add_row(_('Changelist:'), clcombo)
 44
 45        ## changeset list
 46        self.cslist = cslist.ChangesetList()
 47        self.cslist.set_activatable_enable(True)
 48        self.cslist.connect('item-activated', self.item_activated)
 49        table.add_row(None, self.cslist, padding=False,
 50                      yopt=gtk.FILL|gtk.EXPAND)
 51
 52        ### fill combo list
 53        for changelist in self.pending:
 54            clcombo.append_text(changelist)
 55        clcombo.set_active(0)
 56
 57    def item_activated(self, cslist, hash, *args):
 58        try:
 59            rev = self.repo[hash].rev()
 60        except error.LookupError:
 61            return
 62        if self.graphview:
 63            self.graphview.set_revision_id(rev)
 64
 65    def get_buttons(self):
 66        return [('submit', _('Submit'), gtk.RESPONSE_OK),
 67                ('revert', _('Revert'), gtk.RESPONSE_CANCEL),
 68                ('close', gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)]
 69
 70    def get_default_button(self):
 71        return 'submit'
 72
 73    def get_action_map(self):
 74        return {gtk.RESPONSE_OK: self.submit,
 75                gtk.RESPONSE_CANCEL: self.revert}
 76
 77    def changelist_selected(self, combo):
 78        'User has selected a changelist, fill cslist'
 79        curcl = combo.get_active_text()
 80        try:
 81            revs = [self.repo[hash] for hash in self.pending[curcl]]
 82        except error.Abort, e:
 83            revs = []
 84        self.cslist.clear()
 85        self.cslist.update(revs, self.repo)
 86        sensitive = not curcl.endswith('(submitted)')
 87        self.buttons['submit'].set_property('sensitive', sensitive)
 88        self.buttons['revert'].set_property('sensitive', sensitive)
 89        self.curcl = curcl
 90
 91    def switch_to(self, normal, working, cmd):
 92        self.table.set_sensitive(normal)
 93        self.buttons['submit'].set_property('visible', normal)
 94        self.buttons['revert'].set_property('visible', normal)
 95        self.buttons['close'].set_property('visible', normal)
 96        if normal:
 97            self.buttons['close'].grab_focus()
 98
 99    def command_done(self, returncode, useraborted, *args):
100        if returncode == 0:
101            self.cmd.set_result(_('Finished'), style='ok')
102        elif useraborted:
103            self.cmd.set_result(_('Canceled'), style='error')
104        else:
105            self.cmd.set_result(_('Failed'), style='error')
106
107    def submit(self):
108        assert(self.curcl.endswith('(pending)'))
109        cmdline = ['hg', 'p4submit', '--verbose', self.curcl[:-10]]
110        self.execute_command(cmdline)
111
112    def revert(self):
113        assert(self.curcl.endswith('(pending)'))
114        cmdline = ['hg', 'p4revert', '--verbose', self.curcl[:-10]]
115        self.execute_command(cmdline)