/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
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
17
try:
18
    import pygtk
19
    pygtk.require("2.0")
20
except:
21
    pass
22
23
import gobject
24
import gtk
25
26
from bzrlib.osutils import format_date
27
28
29
class RevisionBrowser(gtk.Dialog):
30
    """ Revision Browser main window. """
31
    def __init__(self, branch, parent=None):
32
        gtk.Dialog.__init__(self, title="Revision Browser - Olive",
33
                                  parent=parent,
34
                                  flags=gtk.DIALOG_MODAL,
35
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
36
    
37
        # Get arguments
38
        self.branch = branch
39
        
40
        # Create the widgets
41
        self._label_select = gtk.Label(_("Please select a revision"))
42
        self._scrolledwindow = gtk.ScrolledWindow()
43
        self._treeview = gtk.TreeView()
44
        self._button_select = gtk.Button(_("_Select"), use_underline=True)
45
        
46
        # Set callbacks
47
        self._button_select.connect('clicked', self._on_select_clicked)
48
        self._treeview.connect('row-activated', self._on_treeview_row_activated)
49
        
50
        # Set properties
51
        self._scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC,
52
                                        gtk.POLICY_AUTOMATIC)
53
        self.vbox.set_spacing(3)
54
        self.set_default_size(600, 400)
55
        
56
        # Construct the TreeView columns
57
        self._treeview.append_column(gtk.TreeViewColumn(_('Revno'),
58
                                     gtk.CellRendererText(), text=0))
59
        self._treeview.append_column(gtk.TreeViewColumn(_('Summary'),
60
                                     gtk.CellRendererText(), text=1))
61
        self._treeview.append_column(gtk.TreeViewColumn(_('Committer'),
62
                                     gtk.CellRendererText(), text=2))
63
        self._treeview.append_column(gtk.TreeViewColumn(_('Time'),
64
                                     gtk.CellRendererText(), text=3))
65
        self._treeview.get_column(1).get_cell_renderers()[0].set_property("width-chars", 40)
66
        self._treeview.get_column(2).get_cell_renderers()[0].set_property("width-chars", 40)
67
        self._treeview.get_column(3).get_cell_renderers()[0].set_property("width-chars", 40)
68
        
69
        # Construct the dialog
70
        self.action_area.pack_end(self._button_select)
71
        
72
        self._scrolledwindow.add(self._treeview)
73
        
74
        self.vbox.pack_start(self._label_select, False, False)
75
        self.vbox.pack_start(self._scrolledwindow, True, True)
76
        
77
        # Fill up with revisions
78
        self._fill_revisions()
79
        
80
        # Show the dialog
81
        self.vbox.show_all()
82
83
    def _fill_revisions(self):
84
        """ Fill up the treeview with the revisions. """
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
85
        # [ revno, message, committer, timestamp, revid ]
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
86
        self.model = gtk.ListStore(gobject.TYPE_STRING,
87
                                   gobject.TYPE_STRING,
88
                                   gobject.TYPE_STRING,
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
89
                                   gobject.TYPE_STRING,
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
90
                                   gobject.TYPE_STRING)
91
        self._treeview.set_model(self.model)
92
        repo = self.branch.repository
93
        revs = self.branch.revision_history()
94
        r = repo.get_revisions(revs)
95
        r.reverse()
96
        for rev in r:
97
            if rev.committer is not None:
98
                timestamp = format_date(rev.timestamp, rev.timezone)
99
            else:
100
                timestamp = None
101
            self.model.append([ self.branch.revision_id_to_revno(rev.revision_id),
102
                                rev.get_summary(),
103
                                rev.committer,
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
104
                                timestamp,
105
                                rev.revision_id ])
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
106
    
107
    def _get_selected_revno(self):
108
        """ Return the selected revision's revno. """
109
        treeselection = self._treeview.get_selection()
110
        (model, iter) = treeselection.get_selected()
111
        
112
        if iter is None:
113
            return None
114
        else:
115
            return model.get_value(iter, 0)
116
    
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
117
    def _get_selected_revid(self):
118
        """ Return the selected revision's revid. """
119
        treeselection = self._treeview.get_selection()
120
        (model, iter) = treeselection.get_selected()
121
        
122
        if iter is None:
123
            return None
124
        else:
125
            return model.get_value(iter, 4)
126
    
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
127
    def _on_treeview_row_activated(self, treeview, path, column):
128
        """ Double-click on a row should also select a revision. """
129
        self._on_select_clicked(treeview)
130
    
131
    def _on_select_clicked(self, widget):
132
        """ Select button clicked handler. """
133
        self.selected_revno = self._get_selected_revno()
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
134
        self.selected_revid = self._get_selected_revid()
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
135
        self.response(gtk.RESPONSE_OK)