168
167
def _highlight_annotation(self, model, path, iter, now):
169
168
revision_id, = model.get(iter, REVISION_ID_COL)
170
169
revision = self.revisions[revision_id]
171
# XXX sinzui 2011-08-12: What does get_color return?
172
color = self.annotate_colormap.get_color(revision, now)
173
model.set_value(iter, HIGHLIGHT_COLOR_COL, color)
170
model.set(iter, HIGHLIGHT_COLOR_COL,
171
self.annotate_colormap.get_color(revision, now))
175
173
def _selected_revision(self):
176
174
(path, col) = self.annoview.get_cursor()
195
193
self.revisionview = self._create_log_view()
196
194
self.annoview = self._create_annotate_view()
198
vbox = Gtk.VBox(homogeneous=False, spacing=0)
196
vbox = gtk.VBox(False)
201
sw = Gtk.ScrolledWindow()
202
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
203
sw.set_shadow_type(Gtk.ShadowType.IN)
199
sw = gtk.ScrolledWindow()
200
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
201
sw.set_shadow_type(gtk.SHADOW_IN)
204
202
sw.add(self.annoview)
205
203
self.annoview.gwindow = self
209
swbox.pack_start(sw, True, True, 0)
212
hbox = Gtk.HBox(homogeneous=False, spacing=6)
210
hbox = gtk.HBox(False, 6)
213
211
self.back_button = self._create_back_button()
214
hbox.pack_start(self.back_button, False, True, 0)
212
hbox.pack_start(self.back_button, expand=False, fill=True)
215
213
self.forward_button = self._create_forward_button()
216
hbox.pack_start(self.forward_button, False, True, 0)
214
hbox.pack_start(self.forward_button, expand=False, fill=True)
217
215
self.find_button = self._create_find_button()
218
hbox.pack_start(self.find_button, False, True, 0)
216
hbox.pack_start(self.find_button, expand=False, fill=True)
219
217
self.goto_button = self._create_goto_button()
220
hbox.pack_start(self.goto_button, False, True, 0)
218
hbox.pack_start(self.goto_button, expand=False, fill=True)
222
vbox.pack_start(hbox, False, True, 0)
220
vbox.pack_start(hbox, expand=False, fill=True)
224
self.pane = pane = Gtk.Paned.new(Gtk.Orientation.VERTICAL)
222
self.pane = pane = gtk.VPaned()
226
224
pane.add2(self.revisionview)
228
vbox.pack_start(pane, True, True, 0)
226
vbox.pack_start(pane, expand=True, fill=True)
230
228
self._search = SearchBox()
231
swbox.pack_start(self._search, False, True, 0)
232
accels = Gtk.AccelGroup()
233
accels.connect(Gdk.KEY_f, Gdk.ModifierType.CONTROL_MASK,
234
Gtk.AccelFlags.LOCKED,
229
swbox.pack_start(self._search, expand=False, fill=True)
230
accels = gtk.AccelGroup()
231
accels.connect_group(gtk.keysyms.f, gtk.gdk.CONTROL_MASK,
235
233
self._search_by_text)
236
accels.connect(Gdk.KEY_g, Gdk.ModifierType.CONTROL_MASK,
237
Gtk.AccelFlags.LOCKED,
234
accels.connect_group(gtk.keysyms.g, gtk.gdk.CONTROL_MASK,
238
236
self._search_by_line)
239
237
self.add_accel_group(accels)
271
269
def _create_annotate_view(self):
273
271
tv.set_rules_hint(False)
274
272
tv.connect("cursor-changed", self._activate_selected_revision)
276
274
tv.connect("row-activated", self.line_diff)
278
cell = Gtk.CellRendererText()
276
cell = gtk.CellRendererText()
279
277
cell.set_property("xalign", 1.0)
280
278
cell.set_property("ypad", 0)
281
279
cell.set_property("family", "Monospace")
282
280
cell.set_property("cell-background-gdk",
283
tv.get_style().bg[Gtk.StateType.NORMAL])
284
col = Gtk.TreeViewColumn()
281
tv.get_style().bg[gtk.STATE_NORMAL])
282
col = gtk.TreeViewColumn()
285
283
col.set_resizable(False)
286
col.pack_start(cell, True)
284
col.pack_start(cell, expand=True)
287
285
col.add_attribute(cell, "text", LINE_NUM_COL)
288
286
tv.append_column(col)
290
cell = Gtk.CellRendererText()
288
cell = gtk.CellRendererText()
291
289
cell.set_property("ypad", 0)
292
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
290
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
293
291
cell.set_property("cell-background-gdk",
294
self.get_style().bg[Gtk.StateType.NORMAL])
295
col = Gtk.TreeViewColumn("Committer")
292
self.get_style().bg[gtk.STATE_NORMAL])
293
col = gtk.TreeViewColumn("Committer")
296
294
col.set_resizable(True)
297
col.pack_start(cell, True)
295
col.pack_start(cell, expand=True)
298
296
col.add_attribute(cell, "text", COMMITTER_COL)
299
297
tv.append_column(col)
301
cell = Gtk.CellRendererText()
299
cell = gtk.CellRendererText()
302
300
cell.set_property("xalign", 1.0)
303
301
cell.set_property("ypad", 0)
304
302
cell.set_property("cell-background-gdk",
305
self.get_style().bg[Gtk.StateType.NORMAL])
306
col = Gtk.TreeViewColumn("Revno")
303
self.get_style().bg[gtk.STATE_NORMAL])
304
col = gtk.TreeViewColumn("Revno")
307
305
col.set_resizable(False)
308
col.pack_start(cell, True)
306
col.pack_start(cell, expand=True)
309
307
col.add_attribute(cell, "markup", REVNO_COL)
310
308
tv.append_column(col)
312
cell = Gtk.CellRendererText()
310
cell = gtk.CellRendererText()
313
311
cell.set_property("ypad", 0)
314
312
cell.set_property("family", "Monospace")
315
col = Gtk.TreeViewColumn()
313
col = gtk.TreeViewColumn()
316
314
col.set_resizable(False)
317
col.pack_start(cell, True)
315
col.pack_start(cell, expand=True)
318
316
# col.add_attribute(cell, "foreground", HIGHLIGHT_COLOR_COL)
319
317
col.add_attribute(cell, "background", HIGHLIGHT_COLOR_COL)
320
318
col.add_attribute(cell, "text", TEXT_LINE_COL)
337
335
def _create_back_button(self):
338
button = Gtk.Button()
336
button = gtk.Button()
339
337
button.set_use_stock(True)
340
338
button.set_label("gtk-go-back")
341
339
button.connect("clicked", lambda w: self.go_back())
342
button.set_relief(Gtk.ReliefStyle.NONE)
340
button.set_relief(gtk.RELIEF_NONE)
346
344
def _create_forward_button(self):
347
button = Gtk.Button()
345
button = gtk.Button()
348
346
button.set_use_stock(True)
349
347
button.set_label("gtk-go-forward")
350
348
button.connect("clicked", lambda w: self.go_forward())
351
button.set_relief(Gtk.ReliefStyle.NONE)
349
button.set_relief(gtk.RELIEF_NONE)
353
351
button.set_sensitive(False)
356
354
def _create_find_button(self):
357
button = Gtk.Button()
355
button = gtk.Button()
358
356
button.set_use_stock(True)
359
357
button.set_label("gtk-find")
360
358
button.set_tooltip_text("Search for text (Ctrl+F)")
361
359
button.connect("clicked", self._search_by_text)
362
button.set_relief(Gtk.ReliefStyle.NONE)
360
button.set_relief(gtk.RELIEF_NONE)
364
362
button.set_sensitive(True)
367
365
def _create_goto_button(self):
368
button = Gtk.Button()
366
button = gtk.Button()
369
367
button.set_label("Goto Line")
370
368
button.set_tooltip_text("Scroll to a line by entering its number (Ctrl+G)")
371
369
button.connect("clicked", self._search_by_line)
372
button.set_relief(Gtk.ReliefStyle.NONE)
370
button.set_relief(gtk.RELIEF_NONE)
374
372
button.set_sensitive(True)
398
396
rev_id = self._selected_revision()
399
397
if self.file_id in target_tree:
400
398
offset = self.get_scroll_offset(target_tree)
401
path, col = self.annoview.get_cursor()
402
(row,) = path.get_indices()
399
(row,), col = self.annoview.get_cursor()
403
400
self.annotate(target_tree, self.branch, self.file_id)
404
401
new_row = row+offset
407
new_path = Gtk.TreePath(path=new_row)
408
self.annoview.set_cursor(new_path, None, False)
404
self.annoview.set_cursor(new_row)
413
409
def get_scroll_offset(self, tree):
414
410
old = self.tree.get_file(self.file_id)
415
411
new = tree.get_file(self.file_id)
416
path, col = self.annoview.get_cursor()
417
(row,) = path.get_indices()
412
(row,), col = self.annoview.get_cursor()
418
413
matcher = patiencediff.PatienceSequenceMatcher(None, old.readlines(),
420
415
for i, j, n in matcher.get_matching_blocks():
457
452
self.__cache[revision_id] = revision
458
453
return self.__cache[revision_id]
461
class SearchBox(Gtk.HBox):
455
class SearchBox(gtk.HBox):
462
456
"""A button box for searching in text or lines of annotations"""
463
457
def __init__(self):
464
super(SearchBox, self).__init__(homogeneous=False, spacing=6)
458
gtk.HBox.__init__(self, False, 6)
467
button = Gtk.Button()
469
image.set_from_stock('gtk-stop', Gtk.IconSize.BUTTON)
461
button = gtk.Button()
463
image.set_from_stock('gtk-stop', gtk.ICON_SIZE_BUTTON)
470
464
button.set_image(image)
471
button.set_relief(Gtk.ReliefStyle.NONE)
472
button.connect("clicked", lambda w: self.hide())
473
self.pack_start(button, False, False, 0)
465
button.set_relief(gtk.RELIEF_NONE)
466
button.connect("clicked", lambda w: self.hide_all())
467
self.pack_start(button, expand=False, fill=False)
477
471
self._label = label
478
self.pack_start(label, False, False, 0)
472
self.pack_start(label, expand=False, fill=False)
481
475
self._entry = entry
482
476
entry.connect("activate", lambda w, d: self._do_search(d),
484
self.pack_start(entry, False, False, 0)
478
self.pack_start(entry, expand=False, fill=False)
486
480
# Next/previous buttons
487
button = Gtk.Button(_i18n('_Next'), use_underline=True)
489
image.set_from_stock('gtk-go-forward', Gtk.IconSize.BUTTON)
481
button = gtk.Button('_Next')
483
image.set_from_stock('gtk-go-forward', gtk.ICON_SIZE_BUTTON)
490
484
button.set_image(image)
491
485
button.connect("clicked", lambda w, d: self._do_search(d),
493
self.pack_start(button, False, False, 0)
487
self.pack_start(button, expand=False, fill=False)
495
button = Gtk.Button(_i18n('_Previous'), use_underline=True)
497
image.set_from_stock('gtk-go-back', Gtk.IconSize.BUTTON)
489
button = gtk.Button('_Previous')
491
image.set_from_stock('gtk-go-back', gtk.ICON_SIZE_BUTTON)
498
492
button.set_image(image)
499
493
button.connect("clicked", lambda w, d: self._do_search(d),
501
self.pack_start(button, False, False, 0)
495
self.pack_start(button, expand=False, fill=False)
504
check = Gtk.CheckButton('Match case')
498
check = gtk.CheckButton('Match case')
505
499
self._match_case = check
506
self.pack_start(check, False, False, 0)
500
self.pack_start(check, expand=False, fill=False)
508
check = Gtk.CheckButton('Regexp')
502
check = gtk.CheckButton('Regexp')
509
503
check.connect("toggled", lambda w: self._set_label())
510
504
self._regexp = check
511
self.pack_start(check, False, False, 0)
505
self.pack_start(check, expand=False, fill=False)
513
507
self._view = None
514
508
self._column = None