/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to revisionmenu.py

  • Committer: Jelmer Vernooij
  • Date: 2010-05-25 17:09:02 UTC
  • mto: This revision was merged to the branch mainline in revision 691.
  • Revision ID: jelmer@samba.org-20100525170902-3to8g5iw7ovw79kh
Split out olive into a separate directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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."""
 
17
 
 
18
try:
 
19
    import pygtk
 
20
    pygtk.require("2.0")
 
21
except:
 
22
    pass
 
23
 
 
24
import bzrlib
 
25
import gtk
 
26
import gobject
 
27
from bzrlib import (errors, ui)
 
28
from bzrlib.revision import NULL_REVISION
 
29
 
 
30
class RevisionMenu(gtk.Menu):
 
31
 
 
32
    __gsignals__ = {
 
33
            'tag-added': (
 
34
                gobject.SIGNAL_RUN_FIRST,
 
35
                gobject.TYPE_NONE,
 
36
                (gobject.TYPE_STRING, gobject.TYPE_STRING)
 
37
            )
 
38
    }
 
39
 
 
40
    def __init__(self, repository, revids, branch=None, wt=None, parent=None):
 
41
        super(RevisionMenu, self).__init__()
 
42
        self._parent = parent
 
43
        self.branch = branch
 
44
        self.repository = repository
 
45
        self.wt = wt
 
46
        self.set_revision_ids(revids)
 
47
 
 
48
    def set_revision_ids(self, revids):
 
49
        assert isinstance(revids, list)
 
50
        for c in self.get_children():
 
51
            self.remove(c)
 
52
        self.revids = revids
 
53
        self.create_items()
 
54
 
 
55
    def create_items(self):
 
56
        if len(self.revids) == 1:
 
57
            item = gtk.MenuItem("View _Changes")
 
58
            item.connect('activate', self.show_diff)
 
59
            self.append(item)
 
60
 
 
61
            item = gtk.MenuItem("_Push")
 
62
            item.connect('activate', self.show_push)
 
63
            self.append(item)
 
64
 
 
65
            item = gtk.MenuItem("_Tag Revision")
 
66
            item.connect('activate', self.show_tag)
 
67
            self.append(item)
 
68
 
 
69
            item = gtk.MenuItem("_Merge Directive")
 
70
            item.connect('activate', self.store_merge_directive)
 
71
            # FIXME: self.append(item)
 
72
 
 
73
            item = gtk.MenuItem("_Send Merge Directive")
 
74
            item.connect('activate', self.send_merge_directive)
 
75
            self.append(item)
 
76
            
 
77
            if self.wt:
 
78
                item = gtk.MenuItem("_Revert to this revision")
 
79
                item.connect('activate', self.revert)
 
80
                self.append(item)
 
81
 
 
82
        self.show_all()
 
83
 
 
84
    def store_merge_directive(self, item):
 
85
        from bzrlib.plugins.gtk.mergedirective import CreateMergeDirectiveDialog
 
86
        window = CreateMergeDirectiveDialog(self.branch, self.revids[0])
 
87
        window.show()
 
88
 
 
89
    def send_merge_directive(self, item):
 
90
        from bzrlib.plugins.gtk.mergedirective import SendMergeDirectiveDialog
 
91
        from cStringIO import StringIO
 
92
        window = SendMergeDirectiveDialog(self.branch, self.revids[0])
 
93
        if window.run() == gtk.RESPONSE_OK:
 
94
            outf = StringIO()
 
95
            outf.writelines(window.get_merge_directive().to_lines())
 
96
            mail_client = self.branch.get_config().get_mail_client()
 
97
            mail_client.compose_merge_request(window.get_mail_to(), "[MERGE]",
 
98
                                              outf.getvalue())
 
99
        window.destroy()
 
100
 
 
101
    def show_diff(self, item):
 
102
        from bzrlib.plugins.gtk.diff import DiffWindow
 
103
        window = DiffWindow(parent=self._parent)
 
104
        parentids = self.repository.get_revision(self.revids[0]).parent_ids
 
105
        if len(parentids) == 0:
 
106
            parentid = NULL_REVISION
 
107
        else:
 
108
            parentid = parentids[0]
 
109
        rev_tree    = self.repository.revision_tree(self.revids[0])
 
110
        parent_tree = self.repository.revision_tree(parentid)
 
111
        window.set_diff(self.revids[0], rev_tree, parent_tree)
 
112
        window.show()
 
113
 
 
114
    def show_push(self, item):
 
115
        from bzrlib.plugins.gtk.push import PushDialog
 
116
        dialog = PushDialog(self.repository, self.revids[0], self.branch)
 
117
        response = dialog.run()
 
118
 
 
119
        if response != gtk.RESPONSE_NONE:
 
120
            dialog.destroy()
 
121
 
 
122
    def show_tag(self, item):
 
123
        from bzrlib.plugins.gtk.tags import AddTagDialog
 
124
        dialog = AddTagDialog(self.repository, self.revids[0], self.branch)
 
125
        response = dialog.run()
 
126
 
 
127
        if response != gtk.RESPONSE_NONE:
 
128
            dialog.hide()
 
129
        
 
130
            if response == gtk.RESPONSE_OK:
 
131
                self.emit('tag-added', dialog.tagname, dialog._revid)
 
132
            
 
133
            dialog.destroy()
 
134
    
 
135
    def revert(self, item):
 
136
        pb = ui.ui_factory.nested_progress_bar()
 
137
        revision_tree = self.branch.repository.revision_tree(self.revids[0])
 
138
        try:
 
139
            self.wt.revert(old_tree = revision_tree, pb = pb)
 
140
        finally:
 
141
            pb.finished()