/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: 2006-09-30 10:21:43 UTC
  • Revision ID: jelmer@samba.org-20060930102143-c0ef64d6ca860c21
Merge some files from Olive and bzr-gtk.

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
 
from bzrlib import (errors, ui)
27
 
 
28
 
class RevisionPopupMenu(gtk.Menu):
29
 
    def __init__(self, repository, revids, branch=None):
30
 
        super(RevisionPopupMenu, self).__init__()
31
 
        self.branch = branch
32
 
        self.repository = repository
33
 
        self.revids = revids
34
 
        self.create_items()
35
 
 
36
 
    def create_items(self):
37
 
        if len(self.revids) == 1:
38
 
            item = gtk.MenuItem("View _Diff")
39
 
            item.connect('activate', self.show_diff)
40
 
            self.append(item)
41
 
            self.show_all()
42
 
 
43
 
            item = gtk.MenuItem("_Push")
44
 
            item.connect('activate', self.show_push)
45
 
            self.append(item)
46
 
            self.show_all()
47
 
 
48
 
            item = gtk.MenuItem("_Tag Revision")
49
 
            item.connect('activate', self.show_tag)
50
 
            self.append(item)
51
 
            self.show_all()
52
 
 
53
 
            item = gtk.MenuItem("_Merge Directive")
54
 
            item.connect('activate', self.store_merge_directive)
55
 
            # FIXME: self.append(item)
56
 
            self.show_all()
57
 
            
58
 
            self.bzrdir = self.branch.bzrdir
59
 
            self.wt = None
60
 
            try:
61
 
                self.wt = self.bzrdir.open_workingtree()
62
 
            except errors.NoWorkingTree:
63
 
                return False
64
 
            if self.wt :
65
 
                item = gtk.MenuItem("_Revert to this revision")
66
 
                item.connect('activate', self.revert)
67
 
                self.append(item)
68
 
                self.show_all()
69
 
 
70
 
    def store_merge_directive(self, item):
71
 
        from bzrlib.plugins.gtk.mergedirective import CreateMergeDirectiveDialog
72
 
        window = CreateMergeDirectiveDialog(self.branch, self.revids[0])
73
 
        window.show()
74
 
 
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)
82
 
        window.show()
83
 
 
84
 
    def show_push(self, item):
85
 
        from bzrlib.plugins.gtk.push import PushDialog
86
 
        dialog = PushDialog(self.repository, self.revids[0], self.branch)
87
 
        dialog.run()
88
 
 
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:
94
 
            dialog.hide()
95
 
        
96
 
            if response == gtk.RESPONSE_OK:
97
 
                self.branch.lock_write()
98
 
                self.branch.tags.set_tag(dialog.tagname, dialog._revid)
99
 
                self.branch.unlock()
100
 
            
101
 
            dialog.destroy()
102
 
    
103
 
    def revert(self, item):
104
 
        pb = ui.ui_factory.nested_progress_bar()
105
 
        revision_tree = self.branch.repository.revision_tree(self.revids[0])
106
 
        try:
107
 
            self.wt.revert(old_tree = revision_tree, pb = pb)
108
 
        finally:
109
 
            pb.finished()