/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
226 by Jelmer Vernooij
Add context menu in bzrk.
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
313.2.1 by Gary van der Merwe
Add a revert option to the revision menu.
26
from bzrlib import (errors, ui)
330.4.3 by Daniel Schierbeck
Switched to using NULL_REVISION instead of None.
27
from bzrlib.revision import NULL_REVISION
226 by Jelmer Vernooij
Add context menu in bzrk.
28
29
class RevisionPopupMenu(gtk.Menu):
328 by Jelmer Vernooij
Use repository instead of branch in more places, to make it easier to support multiple branches in viz.
30
    def __init__(self, repository, revids, branch=None, wt=None):
226 by Jelmer Vernooij
Add context menu in bzrk.
31
        super(RevisionPopupMenu, self).__init__()
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
32
        self.branch = branch
226 by Jelmer Vernooij
Add context menu in bzrk.
33
        self.repository = repository
328 by Jelmer Vernooij
Use repository instead of branch in more places, to make it easier to support multiple branches in viz.
34
        self.wt = wt
230 by Jelmer Vernooij
Initial work towards supporting multiple revisions.
35
        self.revids = revids
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
36
        self.create_items()
226 by Jelmer Vernooij
Add context menu in bzrk.
37
38
    def create_items(self):
230 by Jelmer Vernooij
Initial work towards supporting multiple revisions.
39
        if len(self.revids) == 1:
343 by Daniel Schierbeck
Renamed diff into changes.
40
            item = gtk.MenuItem("View _Changes")
230 by Jelmer Vernooij
Initial work towards supporting multiple revisions.
41
            item.connect('activate', self.show_diff)
42
            self.append(item)
43
            self.show_all()
44
45
            item = gtk.MenuItem("_Push")
46
            item.connect('activate', self.show_push)
47
            self.append(item)
48
            self.show_all()
226 by Jelmer Vernooij
Add context menu in bzrk.
49
232 by Jelmer Vernooij
Make 'Add tag' dialog accessible from bzrk.
50
            item = gtk.MenuItem("_Tag Revision")
51
            item.connect('activate', self.show_tag)
52
            self.append(item)
53
            self.show_all()
54
254.1.1 by Jelmer Vernooij
Add Merge Directive option to revision menu.
55
            item = gtk.MenuItem("_Merge Directive")
56
            item.connect('activate', self.store_merge_directive)
270 by Jelmer Vernooij
Hie merge directive menu for now.
57
            # FIXME: self.append(item)
254.1.1 by Jelmer Vernooij
Add Merge Directive option to revision menu.
58
            self.show_all()
313.2.1 by Gary van der Merwe
Add a revert option to the revision menu.
59
            
328 by Jelmer Vernooij
Use repository instead of branch in more places, to make it easier to support multiple branches in viz.
60
            if self.wt:
318.1.1 by Gary van der Merwe
* Adjust ui test according to review comments.
61
                item = gtk.MenuItem("_Revert to this revision")
313.2.1 by Gary van der Merwe
Add a revert option to the revision menu.
62
                item.connect('activate', self.revert)
63
                self.append(item)
64
                self.show_all()
254.1.1 by Jelmer Vernooij
Add Merge Directive option to revision menu.
65
66
    def store_merge_directive(self, item):
67
        from bzrlib.plugins.gtk.mergedirective import CreateMergeDirectiveDialog
68
        window = CreateMergeDirectiveDialog(self.branch, self.revids[0])
69
        window.show()
70
226 by Jelmer Vernooij
Add context menu in bzrk.
71
    def show_diff(self, item):
72
        from bzrlib.plugins.gtk.diff import DiffWindow
313 by Daniel Schierbeck
Fixed bug in the revision menu, where the parent property was not set on the diff window.
73
        window = DiffWindow(parent=self.parent)
330.4.2 by Daniel Schierbeck
Made it work when right-clicking, too.
74
        parentids = self.repository.revision_parents(self.revids[0])
75
76
        if len(parentids) == 0:
330.4.3 by Daniel Schierbeck
Switched to using NULL_REVISION instead of None.
77
            parentid = NULL_REVISION
330.4.2 by Daniel Schierbeck
Made it work when right-clicking, too.
78
        else:
79
            parentid = parentids[0]
80
81
        rev_tree    = self.repository.revision_tree(self.revids[0])
82
        parent_tree = self.repository.revision_tree(parentid)
230 by Jelmer Vernooij
Initial work towards supporting multiple revisions.
83
        window.set_diff(self.revids[0], rev_tree, parent_tree)
226 by Jelmer Vernooij
Add context menu in bzrk.
84
        window.show()
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
85
86
    def show_push(self, item):
87
        from bzrlib.plugins.gtk.push import PushDialog
230 by Jelmer Vernooij
Initial work towards supporting multiple revisions.
88
        dialog = PushDialog(self.repository, self.revids[0], self.branch)
401 by Daniel Schierbeck
Made the push dialog close when the cancel button is clicked.
89
        response = dialog.run()
90
91
        if response != gtk.RESPONSE_NONE:
92
            dialog.destroy()
232 by Jelmer Vernooij
Make 'Add tag' dialog accessible from bzrk.
93
94
    def show_tag(self, item):
95
        from bzrlib.plugins.gtk.tags import AddTagDialog
96
        dialog = AddTagDialog(self.repository, self.revids[0], self.branch)
97
        response = dialog.run()
401 by Daniel Schierbeck
Made the push dialog close when the cancel button is clicked.
98
232 by Jelmer Vernooij
Make 'Add tag' dialog accessible from bzrk.
99
        if response != gtk.RESPONSE_NONE:
100
            dialog.hide()
101
        
102
            if response == gtk.RESPONSE_OK:
366 by Daniel Schierbeck
Made revision menu use a try-finally block when locking the branch.
103
                try:
104
                    self.branch.lock_write()
105
                    self.branch.tags.set_tag(dialog.tagname, dialog._revid)
106
                finally:
107
                    self.branch.unlock()
232 by Jelmer Vernooij
Make 'Add tag' dialog accessible from bzrk.
108
            
109
            dialog.destroy()
313.2.1 by Gary van der Merwe
Add a revert option to the revision menu.
110
    
111
    def revert(self, item):
112
        pb = ui.ui_factory.nested_progress_bar()
113
        revision_tree = self.branch.repository.revision_tree(self.revids[0])
114
        try:
115
            self.wt.revert(old_tree = revision_tree, pb = pb)
116
        finally:
117
            pb.finished()