/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 viz/branchwin.py

  • Committer: Daniel Schierbeck
  • Date: 2007-10-14 15:54:57 UTC
  • mto: This revision was merged to the branch mainline in revision 317.
  • Revision ID: daniel.schierbeck@gmail.com-20071014155457-m3ek29p4ima8ev7d
Added the new Window base class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from linegraph import linegraph, same_branch
21
21
from graphcell import CellRendererGraph
22
22
from treemodel import TreeModel
23
 
from treeview  import TreeView
 
23
 
24
24
 
25
25
class BranchWindow(Window):
26
26
    """Branch window.
29
29
    for a particular branch.
30
30
    """
31
31
 
32
 
    def __init__(self, branch, start, maxnum, parent=None):
 
32
    def __init__(self, parent=None):
33
33
        Window.__init__(self, parent=parent)
34
34
        self.set_border_width(0)
35
 
 
36
 
        self.branch = branch
37
 
        self.start  = start
38
 
        self.maxnum = maxnum
39
 
 
40
 
        self.set_title(branch.nick + " - revision history")
 
35
        self.set_title("Revision history")
41
36
 
42
37
        # Use three-quarters of the screen by default
43
38
        screen = self.get_screen()
92
87
 
93
88
    def construct_top(self):
94
89
        """Construct the top-half of the window."""
95
 
        self.treeview = TreeView(self.branch, self.start, self.maxnum)
96
 
 
97
 
        self.treeview.connect("revision-selected",
98
 
                self._treeselection_changed_cb)
99
 
 
100
 
        self.treeview.connect('revisions-loaded', 
101
 
                lambda x: self.loading_msg_box.hide())
102
 
 
 
90
        scrollwin = gtk.ScrolledWindow()
 
91
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
 
92
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
 
93
        scrollwin.show()
 
94
 
 
95
        self.treeview = gtk.TreeView()
 
96
        self.treeview.set_rules_hint(True)
 
97
        self.treeview.set_search_column(4)
 
98
        self.treeview.get_selection().connect("changed", self._treeselection_changed_cb)
 
99
        self.treeview.connect("row-activated", self._treeview_row_activated_cb)
 
100
        self.treeview.connect("button-release-event", 
 
101
                self._treeview_row_mouseclick)
 
102
        self.treeview.set_property('fixed-height-mode', True)
 
103
        scrollwin.add(self.treeview)
103
104
        self.treeview.show()
104
105
 
105
 
        return self.treeview
 
106
        cell = gtk.CellRendererText()
 
107
        cell.set_property("width-chars", 15)
 
108
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
 
109
        column = gtk.TreeViewColumn("Revision No")
 
110
        column.set_resizable(True)
 
111
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
112
        column.set_fixed_width(cell.get_size(self.treeview)[2])
 
113
        column.pack_start(cell, expand=True)
 
114
        column.add_attribute(cell, "text", treemodel.REVNO)
 
115
        self.treeview.append_column(column)
 
116
 
 
117
        self.graph_cell = CellRendererGraph()
 
118
        self.graph_column = gtk.TreeViewColumn()
 
119
        self.graph_column.set_resizable(True)
 
120
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
121
        self.graph_column.pack_start(self.graph_cell, expand=False)
 
122
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
 
123
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
 
124
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
 
125
        self.treeview.append_column(self.graph_column)
 
126
 
 
127
        cell = gtk.CellRendererText()
 
128
        cell.set_property("width-chars", 65)
 
129
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
 
130
        column = gtk.TreeViewColumn("Message")
 
131
        column.set_resizable(True)
 
132
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
133
        column.set_fixed_width(cell.get_size(self.treeview)[2])
 
134
        column.pack_start(cell, expand=True)
 
135
        column.add_attribute(cell, "text", treemodel.MESSAGE)
 
136
        self.treeview.append_column(column)
 
137
 
 
138
        cell = gtk.CellRendererText()
 
139
        cell.set_property("width-chars", 15)
 
140
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
 
141
        column = gtk.TreeViewColumn("Committer")
 
142
        column.set_resizable(True)
 
143
        column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
 
144
        column.set_fixed_width(cell.get_size(self.treeview)[2])
 
145
        column.pack_start(cell, expand=True)
 
146
        column.add_attribute(cell, "text", treemodel.COMMITER)
 
147
        self.treeview.append_column(column)
 
148
 
 
149
        return scrollwin
106
150
 
107
151
    def construct_navigation(self):
108
152
        """Construct the navigation buttons."""
142
186
        self.logview.set_show_callback(self._show_clicked_cb)
143
187
        self.logview.set_go_callback(self._go_clicked_cb)
144
188
        return self.logview
 
189
 
 
190
    def set_branch(self, branch, start, maxnum):
 
191
        """Set the branch and start position for this window.
 
192
 
 
193
        Creates a new TreeModel and populates it with information about
 
194
        the new branch before updating the window title and model of the
 
195
        treeview itself.
 
196
        """
 
197
        self.branch = branch
 
198
        self.set_title(branch.nick + " - revision history")
 
199
        gobject.idle_add(self.populate_model, start, maxnum)
 
200
 
 
201
    def populate_model(self, start, maxnum):
 
202
        (linegraphdata, index, columns_len) = linegraph(self.branch,
 
203
                                                        start,
 
204
                                                        maxnum)
 
205
        self.model = TreeModel(self.branch, linegraphdata)
 
206
        self.graph_cell.columns_len = columns_len
 
207
        width = self.graph_cell.get_size(self.treeview)[2]
 
208
        self.graph_column.set_fixed_width(width)
 
209
        self.graph_column.set_max_width(width)
 
210
        self.index = index
 
211
        self.treeview.set_model(self.model)
 
212
        self.treeview.get_selection().select_path(0)
 
213
        self.loading_msg_box.hide()
 
214
        return False
145
215
    
146
216
    def _treeselection_changed_cb(self, selection, *args):
147
 
        """callback for when the treeview changes."""
148
 
        revision = self.treeview.get_revision()
149
 
        parents  = self.treeview.get_parents()
150
 
        children = self.treeview.get_children()
151
 
 
152
 
        if revision is not None:
 
217
        """Callback for when the treeview changes."""
 
218
        (model, selected_rows) = selection.get_selected_rows()
 
219
        if len(selected_rows) > 0:
 
220
            iter = self.model.get_iter(selected_rows[0])
 
221
            revision = self.model.get_value(iter, treemodel.REVISION)
 
222
            parents = self.model.get_value(iter, treemodel.PARENTS)
 
223
            children = self.model.get_value(iter, treemodel.CHILDREN)
 
224
            
153
225
            self.back_button.set_sensitive(len(parents) > 0)
154
226
            self.fwd_button.set_sensitive(len(children) > 0)
155
227
            tags = []
161
233
 
162
234
    def _back_clicked_cb(self, *args):
163
235
        """Callback for when the back button is clicked."""
164
 
        self.treeview.back()
165
 
        
 
236
        (path, col) = self.treeview.get_cursor()
 
237
        revision = self.model[path][0]
 
238
        parents = self.model[path][4]
 
239
        if not len(parents):
 
240
            return
 
241
 
 
242
        for parent_id in parents:
 
243
            parent = self.revisions[self.index[parent_id]]
 
244
            if same_branch(revision, parent):
 
245
                self.treeview.set_cursor(self.index[parent_id])
 
246
                break
 
247
        else:
 
248
            self.treeview.set_cursor(self.index[parents[0]])
 
249
        self.treeview.grab_focus()
 
250
 
166
251
    def _fwd_clicked_cb(self, *args):
167
252
        """Callback for when the forward button is clicked."""
168
 
        self.treeview.forward()
 
253
        (path, col) = self.treeview.get_cursor()
 
254
        revision = self.model[path][0]
 
255
        children = self.model[path][5]
 
256
        if not len(children):
 
257
            return
 
258
 
 
259
        for child_id in children:
 
260
            child = self.revisions[self.index[child_id]]
 
261
            if same_branch(child, revision):
 
262
                self.treeview.set_cursor(self.index[child_id])
 
263
                break
 
264
        else:
 
265
            self.treeview.set_cursor(self.index[children[0]])
 
266
        self.treeview.grab_focus()
169
267
 
170
268
    def _go_clicked_cb(self, revid):
171
269
        """Callback for when the go button for a parent is clicked."""
172
 
        self.treeview.set_revision(revid)
 
270
        self.treeview.set_cursor(self.index[revid])
 
271
        self.treeview.grab_focus()
 
272
 
 
273
    def show_diff(self, branch, revid, parentid):
 
274
        """Open a new window to show a diff between the given revisions."""
 
275
        from bzrlib.plugins.gtk.diff import DiffWindow
 
276
        window = DiffWindow(parent=self)
 
277
        (parent_tree, rev_tree) = branch.repository.revision_trees([parentid, 
 
278
                                                                   revid])
 
279
        description = revid + " - " + branch.nick
 
280
        window.set_diff(description, rev_tree, parent_tree)
 
281
        window.show()
173
282
 
174
283
    def _show_clicked_cb(self, revid, parentid):
175
284
        """Callback for when the show button for a parent is clicked."""
176
 
        self.treeview.show_diff(self.branch, revid, parentid)
177
 
        self.treeview.grab_focus()
178
 
 
 
285
        self.show_diff(self.branch, revid, parentid)
 
286
        self.treeview.grab_focus()
 
287
 
 
288
    def _treeview_row_mouseclick(self, widget, event):
 
289
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
 
290
        if event.button == 3:
 
291
            menu = RevisionPopupMenu(self.branch.repository, 
 
292
                [x.revision_id for x in self.selected_revisions()],
 
293
                self.branch)
 
294
            menu.popup(None, None, None, event.button, event.get_time())
 
295
 
 
296
    def selected_revision(self, path):
 
297
        return self.model[path][treemodel.REVISION]
 
298
 
 
299
    def selected_revisions(self):
 
300
        return [self.selected_revision(path) for path in \
 
301
                self.treeview.get_selection().get_selected_rows()[1]]
 
302
 
 
303
    def _treeview_row_activated_cb(self, widget, path, col):
 
304
        # TODO: more than one parent
 
305
        """Callback for when a treeview row gets activated."""
 
306
        revision_id = self.model[path][treemodel.REVID]
 
307
        parents = self.model[path][treemodel.PARENTS]
 
308
        if len(parents) == 0:
 
309
            # Ignore revisions without parent
 
310
            return
 
311
        parent_id = parents[0]
 
312
        self.show_diff(self.branch, revision_id, parent_id)
 
313
        self.treeview.grab_focus()