/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: Jelmer Vernooij
  • Date: 2007-07-15 15:05:06 UTC
  • Revision ID: jelmer@samba.org-20070715150506-1uemecr5kt7d4kvg
Fix whitespace, add comment.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import gtk
13
13
import gobject
14
14
import pango
15
 
import treemodel
16
15
 
17
16
from bzrlib.osutils import format_date
18
17
 
19
 
from linegraph import linegraph, same_branch
 
18
from graph import distances, graph, same_branch
20
19
from graphcell import CellRendererGraph
21
 
from treemodel import TreeModel
22
20
 
23
21
 
24
22
class BranchWindow(gtk.Window):
77
75
        self.treeview.set_search_column(4)
78
76
        self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
79
77
        self.treeview.connect("row-activated", self._treeview_row_activated_cb)
80
 
        self.treeview.connect("button-release-event", 
81
 
                self._treeview_row_mouseclick)
82
78
        scrollwin.add(self.treeview)
83
79
        self.treeview.show()
84
80
 
85
 
        cell = gtk.CellRendererText()
86
 
        #cell.set_property("width-chars", 40)
87
 
        #cell.set_property("ellipsize", pango.ELLIPSIZE_END)
88
 
        column = gtk.TreeViewColumn("Revision No")
89
 
        column.set_resizable(True)
90
 
        column.pack_start(cell, expand=True)
91
 
        column.add_attribute(cell, "text", treemodel.REVNO)
92
 
        self.treeview.append_column(column)
93
 
 
94
81
        cell = CellRendererGraph()
95
82
        column = gtk.TreeViewColumn()
96
83
        column.set_resizable(True)
97
84
        column.pack_start(cell, expand=False)
98
 
        column.add_attribute(cell, "node", treemodel.NODE)
99
 
        column.add_attribute(cell, "in-lines", treemodel.LAST_LINES)
100
 
        column.add_attribute(cell, "out-lines", treemodel.LINES)
 
85
        column.add_attribute(cell, "node", 1)
 
86
        column.add_attribute(cell, "in-lines", 2)
 
87
        column.add_attribute(cell, "out-lines", 3)
101
88
        self.treeview.append_column(column)
102
89
 
103
90
        cell = gtk.CellRendererText()
106
93
        column = gtk.TreeViewColumn("Message")
107
94
        column.set_resizable(True)
108
95
        column.pack_start(cell, expand=True)
109
 
        column.add_attribute(cell, "text", treemodel.MESSAGE)
 
96
        column.add_attribute(cell, "text", 4)
110
97
        self.treeview.append_column(column)
111
98
 
112
99
        cell = gtk.CellRendererText()
115
102
        column = gtk.TreeViewColumn("Committer")
116
103
        column.set_resizable(True)
117
104
        column.pack_start(cell, expand=True)
118
 
        column.add_attribute(cell, "text", treemodel.COMMITER)
 
105
        column.add_attribute(cell, "text", 5)
119
106
        self.treeview.append_column(column)
120
107
 
121
108
        cell = gtk.CellRendererText()
123
110
        column = gtk.TreeViewColumn("Date")
124
111
        column.set_resizable(True)
125
112
        column.pack_start(cell, expand=True)
126
 
        column.add_attribute(cell, "text", treemodel.TIMESTAMP)
 
113
        column.add_attribute(cell, "text", 6)
127
114
        self.treeview.append_column(column)
128
115
 
129
116
        return scrollwin
159
146
    def construct_bottom(self):
160
147
        """Construct the bottom half of the window."""
161
148
        from bzrlib.plugins.gtk.logview import LogView
162
 
        self.logview = LogView(None, True, [], True)
 
149
        self.logview = LogView()
163
150
        (width, height) = self.get_size()
164
151
        self.logview.set_size_request(width, int(height / 2.5))
165
152
        self.logview.show()
169
156
 
170
157
    def set_branch(self, branch, start, maxnum):
171
158
        """Set the branch and start position for this window.
172
 
        
 
159
 
173
160
        Creates a new TreeModel and populates it with information about
174
161
        the new branch before updating the window title and model of the
175
162
        treeview itself.
176
163
        """
177
164
        self.branch = branch
 
165
 
 
166
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
 
167
        self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
 
168
                                   gobject.TYPE_PYOBJECT,
 
169
                                   gobject.TYPE_PYOBJECT,
 
170
                                   gobject.TYPE_PYOBJECT,
 
171
                                   str, str, str)
 
172
        self.index = {}
 
173
        index = 0
 
174
 
 
175
        last_lines = []
 
176
        (self.revisions, colours, self.children, self.parent_ids,
 
177
         merge_sorted) = distances(branch, start)
 
178
        for (index, (revision, node, lines)) in enumerate(graph(
 
179
                self.revisions, colours, merge_sorted)):
 
180
            # FIXME: at this point we should be able to show the graph order
 
181
            # and lines with no message or commit data - and then incrementally
 
182
            # fill the timestamp, committer etc data as desired.
 
183
            message = revision.message.split("\n")[0]
 
184
            if revision.committer is not None:
 
185
                timestamp = format_date(revision.timestamp, revision.timezone)
 
186
            else:
 
187
                timestamp = None
 
188
            self.model.append([revision, node, last_lines, lines,
 
189
                               message, revision.committer, timestamp])
 
190
            self.index[revision] = index
 
191
            last_lines = lines
 
192
            if maxnum is not None and index > maxnum:
 
193
                break
 
194
 
178
195
        self.set_title(branch.nick + " - bzrk")
179
 
        gobject.idle_add(self.populate_model, start, maxnum)
180
 
 
181
 
    def populate_model(self, start, maxnum):
182
 
        (linegraphdata, index) = linegraph(self.branch,
183
 
                                           start,
184
 
                                           maxnum)
185
 
        self.model = TreeModel(self.branch, linegraphdata)
186
 
        self.index = index
187
196
        self.treeview.set_model(self.model)
188
197
 
189
198
    def _treeview_cursor_cb(self, *args):
190
199
        """Callback for when the treeview cursor changes."""
191
200
        (path, col) = self.treeview.get_cursor()
192
 
        iter = self.model.get_iter(path)
193
 
        revision = self.model.get_value(iter, treemodel.REVISION)
194
 
        parents = self.model.get_value(iter, treemodel.PARENTS)
195
 
        children = self.model.get_value(iter, treemodel.CHILDREN)
 
201
        revision = self.model[path][0]
196
202
 
197
 
        self.back_button.set_sensitive(len(parents) > 0)
198
 
        self.fwd_button.set_sensitive(len(children) > 0)
199
 
        tags = []
200
 
        if self.branch.supports_tags():
201
 
            tagdict = self.branch.tags.get_reverse_tag_dict()
202
 
            if tagdict.has_key(revision.revision_id):
203
 
                tags = tagdict[revision.revision_id]
204
 
        self.logview.set_revision(revision, tags, children)
 
203
        self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
 
204
        self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
 
205
        self.logview.set_revision(revision)
205
206
 
206
207
    def _back_clicked_cb(self, *args):
207
208
        """Callback for when the back button is clicked."""
208
209
        (path, col) = self.treeview.get_cursor()
209
210
        revision = self.model[path][0]
210
 
        parents = self.model[path][4]
211
 
        if not len(parents):
 
211
        if not len(self.parent_ids[revision]):
212
212
            return
213
213
 
214
 
        for parent_id in parents:
215
 
            parent = self.revisions[self.index[parent_id]]
 
214
        for parent_id in self.parent_ids[revision]:
 
215
            parent = self.revisions[parent_id]
216
216
            if same_branch(revision, parent):
217
 
                self.treeview.set_cursor(self.index[parent_id])
 
217
                self.treeview.set_cursor(self.index[parent])
218
218
                break
219
219
        else:
220
 
            self.treeview.set_cursor(self.index[parents[0]])
 
220
            next = self.revisions[self.parent_ids[revision][0]]
 
221
            self.treeview.set_cursor(self.index[next])
221
222
        self.treeview.grab_focus()
222
223
 
223
224
    def _fwd_clicked_cb(self, *args):
224
225
        """Callback for when the forward button is clicked."""
225
226
        (path, col) = self.treeview.get_cursor()
226
227
        revision = self.model[path][0]
227
 
        children = self.model[path][5]
228
 
        if not len(children):
 
228
        if not len(self.children[revision]):
229
229
            return
230
230
 
231
 
        for child_id in children:
232
 
            child = self.revisions[self.index[child_id]]
 
231
        for child in self.children[revision]:
233
232
            if same_branch(child, revision):
234
 
                self.treeview.set_cursor(self.index[child_id])
 
233
                self.treeview.set_cursor(self.index[child])
235
234
                break
236
235
        else:
237
 
            self.treeview.set_cursor(self.index[children[0]])
 
236
            prev = list(self.children[revision])[0]
 
237
            self.treeview.set_cursor(self.index[prev])
238
238
        self.treeview.grab_focus()
239
239
 
240
240
    def _go_clicked_cb(self, revid):
241
241
        """Callback for when the go button for a parent is clicked."""
242
 
        self.treeview.set_cursor(self.index[revid])
 
242
        self.treeview.set_cursor(self.index[self.revisions[revid]])
243
243
        self.treeview.grab_focus()
244
244
 
245
245
    def show_diff(self, branch, revid, parentid):
246
246
        """Open a new window to show a diff between the given revisions."""
247
247
        from bzrlib.plugins.gtk.diff import DiffWindow
248
248
        window = DiffWindow()
249
 
        (parent_tree, rev_tree) = branch.repository.revision_trees([parentid, 
250
 
                                                                   revid])
 
249
        rev_tree = branch.repository.revision_tree(revid)
 
250
        parent_tree = branch.repository.revision_tree(parentid)
251
251
        description = revid + " - " + branch.nick
252
252
        window.set_diff(description, rev_tree, parent_tree)
253
253
        window.show()
257
257
        self.show_diff(self.branch, revid, parentid)
258
258
        self.treeview.grab_focus()
259
259
 
260
 
    def _treeview_row_mouseclick(self, widget, event):
261
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
262
 
        if event.button == 3:
263
 
            menu = RevisionPopupMenu(self.branch.repository, 
264
 
                [x.revision_id for x in self.selected_revisions()],
265
 
                self.branch)
266
 
            menu.popup(None, None, None, event.button, event.get_time())
267
 
 
268
 
    def selected_revision(self, path):
269
 
        return self.model[path][0]
270
 
 
271
 
    def selected_revisions(self):
272
 
        return [self.selected_revision(path) for path in \
273
 
                self.treeview.get_selection().get_selected_rows()[1]]
274
 
 
275
260
    def _treeview_row_activated_cb(self, widget, path, col):
276
261
        # TODO: more than one parent
277
262
        """Callback for when a treeview row gets activated."""
278
 
        revision = self.selected_revision(path)
 
263
        revision = self.model[path][0]
279
264
        if len(self.parent_ids[revision]) == 0:
280
265
            # Ignore revisions without parent
281
266
            return