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  | 
import gtk.glade  | 
|
26  | 
||
27  | 
from bzrlib.osutils import format_date  | 
|
28  | 
||
29  | 
||
30  | 
class RevisionBrowser(gtk.Dialog):  | 
|
31  | 
""" Revision Browser main window. """  | 
|
32  | 
def __init__(self, branch, parent=None):  | 
|
33  | 
gtk.Dialog.__init__(self, title="Revision Browser - Olive",  | 
|
34  | 
parent=parent,  | 
|
35  | 
flags=gtk.DIALOG_MODAL,  | 
|
36  | 
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))  | 
|
37  | 
||
38  | 
        # Get arguments
 | 
|
39  | 
self.branch = branch  | 
|
40  | 
||
41  | 
        # Create the widgets
 | 
|
42  | 
self._label_select = gtk.Label(_("Please select a revision"))  | 
|
43  | 
self._scrolledwindow = gtk.ScrolledWindow()  | 
|
44  | 
self._treeview = gtk.TreeView()  | 
|
45  | 
self._button_select = gtk.Button(_("_Select"), use_underline=True)  | 
|
46  | 
||
47  | 
        # Set callbacks
 | 
|
48  | 
self._button_select.connect('clicked', self._on_select_clicked)  | 
|
49  | 
self._treeview.connect('row-activated', self._on_treeview_row_activated)  | 
|
50  | 
||
51  | 
        # Set properties
 | 
|
52  | 
self._scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC,  | 
|
53  | 
gtk.POLICY_AUTOMATIC)  | 
|
54  | 
self.vbox.set_spacing(3)  | 
|
55  | 
self.set_default_size(600, 400)  | 
|
56  | 
||
57  | 
        # Construct the TreeView columns
 | 
|
58  | 
self._treeview.append_column(gtk.TreeViewColumn(_('Revno'),  | 
|
59  | 
gtk.CellRendererText(), text=0))  | 
|
60  | 
self._treeview.append_column(gtk.TreeViewColumn(_('Summary'),  | 
|
61  | 
gtk.CellRendererText(), text=1))  | 
|
62  | 
self._treeview.append_column(gtk.TreeViewColumn(_('Committer'),  | 
|
63  | 
gtk.CellRendererText(), text=2))  | 
|
64  | 
self._treeview.append_column(gtk.TreeViewColumn(_('Time'),  | 
|
65  | 
gtk.CellRendererText(), text=3))  | 
|
66  | 
self._treeview.get_column(1).get_cell_renderers()[0].set_property("width-chars", 40)  | 
|
67  | 
self._treeview.get_column(2).get_cell_renderers()[0].set_property("width-chars", 40)  | 
|
68  | 
self._treeview.get_column(3).get_cell_renderers()[0].set_property("width-chars", 40)  | 
|
69  | 
||
70  | 
        # Construct the dialog
 | 
|
71  | 
self.action_area.pack_end(self._button_select)  | 
|
72  | 
||
73  | 
self._scrolledwindow.add(self._treeview)  | 
|
74  | 
||
75  | 
self.vbox.pack_start(self._label_select, False, False)  | 
|
76  | 
self.vbox.pack_start(self._scrolledwindow, True, True)  | 
|
77  | 
||
78  | 
        # Fill up with revisions
 | 
|
79  | 
self._fill_revisions()  | 
|
80  | 
||
81  | 
        # Show the dialog
 | 
|
82  | 
self.vbox.show_all()  | 
|
83  | 
||
84  | 
def _fill_revisions(self):  | 
|
85  | 
""" Fill up the treeview with the revisions. """  | 
|
86  | 
        # [ revno, message, committer, timestamp ]
 | 
|
87  | 
self.model = gtk.ListStore(gobject.TYPE_STRING,  | 
|
88  | 
gobject.TYPE_STRING,  | 
|
89  | 
gobject.TYPE_STRING,  | 
|
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,  | 
|
104  | 
timestamp ])  | 
|
105  | 
||
106  | 
def _get_selected_revno(self):  | 
|
107  | 
""" Return the selected revision's revno. """  | 
|
108  | 
treeselection = self._treeview.get_selection()  | 
|
109  | 
(model, iter) = treeselection.get_selected()  | 
|
110  | 
||
111  | 
if iter is None:  | 
|
112  | 
return None  | 
|
113  | 
else:  | 
|
114  | 
return model.get_value(iter, 0)  | 
|
115  | 
||
116  | 
def _on_treeview_row_activated(self, treeview, path, column):  | 
|
117  | 
""" Double-click on a row should also select a revision. """  | 
|
118  | 
self._on_select_clicked(treeview)  | 
|
119  | 
||
120  | 
def _on_select_clicked(self, widget):  | 
|
121  | 
""" Select button clicked handler. """  | 
|
122  | 
self.selected_revno = self._get_selected_revno()  | 
|
123  | 
self.response(gtk.RESPONSE_OK)  |