1
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
"""Simple popup menu for revisions."""
27
from bzrlib.revision import NULL_REVISION
29
class RevisionMenu(gtk.Menu):
33
gobject.SIGNAL_RUN_FIRST,
35
(gobject.TYPE_STRING, gobject.TYPE_STRING)
39
def __init__(self, repository, revids, branch=None, wt=None, parent=None):
40
super(RevisionMenu, self).__init__()
43
self.repository = repository
45
self.set_revision_ids(revids)
47
def set_revision_ids(self, revids):
48
assert isinstance(revids, list)
49
for c in self.get_children():
54
def create_items(self):
55
if len(self.revids) == 1:
56
item = gtk.MenuItem("View _Changes")
57
item.connect('activate', self.show_diff)
60
item = gtk.MenuItem("_Push")
61
item.connect('activate', self.show_push)
64
item = gtk.MenuItem("_Tag Revision")
65
item.connect('activate', self.show_tag)
68
item = gtk.MenuItem("_Merge Directive")
69
item.connect('activate', self.store_merge_directive)
70
# FIXME: self.append(item)
72
item = gtk.MenuItem("_Send Merge Directive")
73
item.connect('activate', self.send_merge_directive)
77
item = gtk.MenuItem("_Revert to this revision")
78
item.connect('activate', self.revert)
83
def store_merge_directive(self, item):
84
from bzrlib.plugins.gtk.mergedirective import CreateMergeDirectiveDialog
85
window = CreateMergeDirectiveDialog(self.branch, self.revids[0])
88
def send_merge_directive(self, item):
89
from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
90
from cStringIO import StringIO
91
window = SendMergeDirectiveDialog(self.branch, self.revids[0])
92
if window.run() == gtk.RESPONSE_OK:
94
outf.writelines(window.get_merge_directive().to_lines())
95
mail_client = self.branch.get_config().get_mail_client()
96
mail_client.compose_merge_request(window.get_mail_to(), "[MERGE]",
100
def show_diff(self, item):
101
from bzrlib.plugins.gtk.diff import DiffWindow
102
window = DiffWindow(parent=self._parent)
103
parentids = self.repository.get_revision(self.revids[0]).parent_ids
104
if len(parentids) == 0:
105
parentid = NULL_REVISION
107
parentid = parentids[0]
108
rev_tree = self.repository.revision_tree(self.revids[0])
109
parent_tree = self.repository.revision_tree(parentid)
110
window.set_diff(self.revids[0], rev_tree, parent_tree)
113
def show_push(self, item):
114
from bzrlib.plugins.gtk.push import PushDialog
115
dialog = PushDialog(self.repository, self.revids[0], self.branch)
116
response = dialog.run()
118
if response != gtk.RESPONSE_NONE:
121
def show_tag(self, item):
122
from bzrlib.plugins.gtk.tags import AddTagDialog
123
dialog = AddTagDialog(self.repository, self.revids[0], self.branch)
124
response = dialog.run()
126
if response != gtk.RESPONSE_NONE:
129
if response == gtk.RESPONSE_OK:
130
self.emit('tag-added', dialog.tagname, dialog._revid)
134
def revert(self, item):
135
pb = ui.ui_factory.nested_progress_bar()
136
revision_tree = self.branch.repository.revision_tree(self.revids[0])
138
self.wt.revert(old_tree = revision_tree, pb = pb)