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."""
18
from gi.repository import Gtk
19
from gi.repository import GObject
21
from bzrlib.revision import NULL_REVISION
23
class RevisionMenu(Gtk.Menu):
27
GObject.SignalFlags.RUN_FIRST,
29
(GObject.TYPE_STRING, GObject.TYPE_STRING)
33
def __init__(self, repository, revids, branch=None, wt=None, parent=None):
34
super(RevisionMenu, self).__init__()
37
self.repository = repository
39
self.set_revision_ids(revids)
41
def set_revision_ids(self, revids):
42
assert isinstance(revids, list)
43
for c in self.get_children():
48
def create_items(self):
49
if len(self.revids) == 1:
50
item = Gtk.MenuItem.new_with_mnemonic("View _Changes")
51
item.connect('activate', self.show_diff)
54
item = Gtk.MenuItem.new_with_mnemonic("_Push")
55
item.connect('activate', self.show_push)
58
item = Gtk.MenuItem.new_with_mnemonic("_Tag Revision")
59
item.connect('activate', self.show_tag)
62
item = Gtk.MenuItem.new_with_mnemonic("_Merge Directive")
63
item.connect('activate', self.store_merge_directive)
64
# FIXME: self.append(item)
66
item = Gtk.MenuItem.new_with_mnemonic("_Send Merge Directive")
67
item.connect('activate', self.send_merge_directive)
71
item = Gtk.MenuItem.new_with_mnemonic(
72
"_Revert to this revision")
73
item.connect('activate', self.revert)
78
def store_merge_directive(self, item):
79
from bzrlib.plugins.gtk.mergedirective import CreateMergeDirectiveDialog
80
window = CreateMergeDirectiveDialog(self.branch, self.revids[0])
83
def send_merge_directive(self, item):
84
from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
85
from cStringIO import StringIO
86
window = SendMergeDirectiveDialog(self.branch, self.revids[0])
87
if window.run() == Gtk.ResponseType.OK:
89
outf.writelines(window.get_merge_directive().to_lines())
90
mail_client = self.branch.get_config().get_mail_client()
91
mail_client.compose_merge_request(window.get_mail_to(), "[MERGE]",
95
def show_diff(self, item):
96
from bzrlib.plugins.gtk.diff import DiffWindow
97
window = DiffWindow(parent=self._parent)
98
parentids = self.repository.get_revision(self.revids[0]).parent_ids
99
if len(parentids) == 0:
100
parentid = NULL_REVISION
102
parentid = parentids[0]
103
rev_tree = self.repository.revision_tree(self.revids[0])
104
parent_tree = self.repository.revision_tree(parentid)
105
window.set_diff(self.revids[0], rev_tree, parent_tree)
108
def show_push(self, item):
109
from bzrlib.plugins.gtk.push import PushDialog
110
dialog = PushDialog(self.repository, self.revids[0], self.branch)
111
response = dialog.run()
113
if response != Gtk.ResponseType.NONE:
116
def show_tag(self, item):
117
from bzrlib.plugins.gtk.tags import AddTagDialog
118
dialog = AddTagDialog(self.repository, self.revids[0], self.branch)
119
response = dialog.run()
121
if response != Gtk.ResponseType.NONE:
124
if response == Gtk.ResponseType.OK:
125
self.emit('tag-added', dialog.tagname, dialog._revid)
129
def revert(self, item):
130
pb = ui.ui_factory.nested_progress_bar()
131
revision_tree = self.branch.repository.revision_tree(self.revids[0])
133
self.wt.revert(old_tree = revision_tree, pb = pb)