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."""
26
from bzrlib import (errors, ui)
28
class RevisionPopupMenu(gtk.Menu):
29
def __init__(self, repository, revids, branch=None):
30
super(RevisionPopupMenu, self).__init__()
32
self.repository = repository
36
def create_items(self):
37
if len(self.revids) == 1:
38
item = gtk.MenuItem("View _Diff")
39
item.connect('activate', self.show_diff)
43
item = gtk.MenuItem("_Push")
44
item.connect('activate', self.show_push)
48
item = gtk.MenuItem("_Tag Revision")
49
item.connect('activate', self.show_tag)
53
item = gtk.MenuItem("_Merge Directive")
54
item.connect('activate', self.store_merge_directive)
55
# FIXME: self.append(item)
58
self.bzrdir = self.branch.bzrdir
61
self.wt = self.bzrdir.open_workingtree()
62
except errors.NoWorkingTree:
65
item = gtk.MenuItem("_Revert to this revision")
66
item.connect('activate', self.revert)
70
def store_merge_directive(self, item):
71
from bzrlib.plugins.gtk.mergedirective import CreateMergeDirectiveDialog
72
window = CreateMergeDirectiveDialog(self.branch, self.revids[0])
75
def show_diff(self, item):
76
from bzrlib.plugins.gtk.diff import DiffWindow
77
window = DiffWindow(parent=self.parent)
78
parentid = self.repository.revision_parents(self.revids[0])[0]
79
(parent_tree, rev_tree) = self.repository.revision_trees(
80
[parentid, self.revids[0]])
81
window.set_diff(self.revids[0], rev_tree, parent_tree)
84
def show_push(self, item):
85
from bzrlib.plugins.gtk.push import PushDialog
86
dialog = PushDialog(self.repository, self.revids[0], self.branch)
89
def show_tag(self, item):
90
from bzrlib.plugins.gtk.tags import AddTagDialog
91
dialog = AddTagDialog(self.repository, self.revids[0], self.branch)
92
response = dialog.run()
93
if response != gtk.RESPONSE_NONE:
96
if response == gtk.RESPONSE_OK:
97
self.branch.lock_write()
98
self.branch.tags.set_tag(dialog.tagname, dialog._revid)
103
def revert(self, item):
104
pb = ui.ui_factory.nested_progress_bar()
105
revision_tree = self.branch.repository.revision_tree(self.revids[0])
107
self.wt.revert(old_tree = revision_tree, pb = pb)