167
167
def _highlight_annotation(self, model, path, iter, now):
168
168
revision_id, = model.get(iter, REVISION_ID_COL)
169
169
revision = self.revisions[revision_id]
170
# XXX sinzui 2011-08-12: What does get_color return?
171
color = self.annotate_colormap.get_color(revision, now)
172
model.set_value(iter, HIGHLIGHT_COLOR_COL, color)
170
model.set(iter, HIGHLIGHT_COLOR_COL,
171
self.annotate_colormap.get_color(revision, now))
174
173
def _selected_revision(self):
175
174
(path, col) = self.annoview.get_cursor()
194
193
self.revisionview = self._create_log_view()
195
194
self.annoview = self._create_annotate_view()
197
vbox = Gtk.VBox(homogeneous=False, spacing=0)
196
vbox = gtk.VBox(False)
200
sw = Gtk.ScrolledWindow()
201
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
202
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)
203
202
sw.add(self.annoview)
204
203
self.annoview.gwindow = self
208
swbox.pack_start(sw, True, True, 0)
211
hbox = Gtk.HBox(homogeneous=False, spacing=6)
210
hbox = gtk.HBox(False, 6)
212
211
self.back_button = self._create_back_button()
213
hbox.pack_start(self.back_button, False, True, 0)
212
hbox.pack_start(self.back_button, expand=False, fill=True)
214
213
self.forward_button = self._create_forward_button()
215
hbox.pack_start(self.forward_button, False, True, 0)
214
hbox.pack_start(self.forward_button, expand=False, fill=True)
216
215
self.find_button = self._create_find_button()
217
hbox.pack_start(self.find_button, False, True, 0)
216
hbox.pack_start(self.find_button, expand=False, fill=True)
218
217
self.goto_button = self._create_goto_button()
219
hbox.pack_start(self.goto_button, False, True, 0)
218
hbox.pack_start(self.goto_button, expand=False, fill=True)
221
vbox.pack_start(hbox, False, True, 0)
220
vbox.pack_start(hbox, expand=False, fill=True)
223
self.pane = pane = Gtk.VPaned()
222
self.pane = pane = gtk.VPaned()
225
224
pane.add2(self.revisionview)
227
vbox.pack_start(pane, True, True, 0)
226
vbox.pack_start(pane, expand=True, fill=True)
229
228
self._search = SearchBox()
230
swbox.pack_start(self._search, False, True, 0)
231
accels = Gtk.AccelGroup()
232
accels.connect(Gdk.KEY_f, Gdk.ModifierType.CONTROL_MASK,
233
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,
234
233
self._search_by_text)
235
accels.connect(Gdk.KEY_g, Gdk.ModifierType.CONTROL_MASK,
236
Gtk.AccelFlags.LOCKED,
234
accels.connect_group(gtk.keysyms.g, gtk.gdk.CONTROL_MASK,
237
236
self._search_by_line)
238
237
self.add_accel_group(accels)
270
269
def _create_annotate_view(self):
272
271
tv.set_rules_hint(False)
273
272
tv.connect("cursor-changed", self._activate_selected_revision)
275
274
tv.connect("row-activated", self.line_diff)
277
cell = Gtk.CellRendererText()
276
cell = gtk.CellRendererText()
278
277
cell.set_property("xalign", 1.0)
279
278
cell.set_property("ypad", 0)
280
279
cell.set_property("family", "Monospace")
281
280
cell.set_property("cell-background-gdk",
282
tv.get_style().bg[Gtk.StateType.NORMAL])
283
col = Gtk.TreeViewColumn()
281
tv.get_style().bg[gtk.STATE_NORMAL])
282
col = gtk.TreeViewColumn()
284
283
col.set_resizable(False)
285
col.pack_start(cell, True)
284
col.pack_start(cell, expand=True)
286
285
col.add_attribute(cell, "text", LINE_NUM_COL)
287
286
tv.append_column(col)
289
cell = Gtk.CellRendererText()
288
cell = gtk.CellRendererText()
290
289
cell.set_property("ypad", 0)
291
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
290
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
292
291
cell.set_property("cell-background-gdk",
293
self.get_style().bg[Gtk.StateType.NORMAL])
294
col = Gtk.TreeViewColumn("Committer")
292
self.get_style().bg[gtk.STATE_NORMAL])
293
col = gtk.TreeViewColumn("Committer")
295
294
col.set_resizable(True)
296
col.pack_start(cell, True)
295
col.pack_start(cell, expand=True)
297
296
col.add_attribute(cell, "text", COMMITTER_COL)
298
297
tv.append_column(col)
300
cell = Gtk.CellRendererText()
299
cell = gtk.CellRendererText()
301
300
cell.set_property("xalign", 1.0)
302
301
cell.set_property("ypad", 0)
303
302
cell.set_property("cell-background-gdk",
304
self.get_style().bg[Gtk.StateType.NORMAL])
305
col = Gtk.TreeViewColumn("Revno")
303
self.get_style().bg[gtk.STATE_NORMAL])
304
col = gtk.TreeViewColumn("Revno")
306
305
col.set_resizable(False)
307
col.pack_start(cell, True)
306
col.pack_start(cell, expand=True)
308
307
col.add_attribute(cell, "markup", REVNO_COL)
309
308
tv.append_column(col)
311
cell = Gtk.CellRendererText()
310
cell = gtk.CellRendererText()
312
311
cell.set_property("ypad", 0)
313
312
cell.set_property("family", "Monospace")
314
col = Gtk.TreeViewColumn()
313
col = gtk.TreeViewColumn()
315
314
col.set_resizable(False)
316
col.pack_start(cell, True)
315
col.pack_start(cell, expand=True)
317
316
# col.add_attribute(cell, "foreground", HIGHLIGHT_COLOR_COL)
318
317
col.add_attribute(cell, "background", HIGHLIGHT_COLOR_COL)
319
318
col.add_attribute(cell, "text", TEXT_LINE_COL)
320
319
tv.append_column(col)
322
# interactive substring search
323
def search_equal_func(model, column, key, iter):
324
return model.get_value(iter, TEXT_LINE_COL).lower().find(key.lower()) == -1
326
tv.set_enable_search(True)
327
tv.set_search_equal_func(search_equal_func, None)
321
# FIXME: Now that C-f is now used for search by text we
322
# may as well disable the auto search.
323
tv.set_search_column(LINE_NUM_COL)
336
332
def _create_back_button(self):
337
button = Gtk.Button()
333
button = gtk.Button()
338
334
button.set_use_stock(True)
339
335
button.set_label("gtk-go-back")
340
336
button.connect("clicked", lambda w: self.go_back())
341
button.set_relief(Gtk.ReliefStyle.NONE)
337
button.set_relief(gtk.RELIEF_NONE)
345
341
def _create_forward_button(self):
346
button = Gtk.Button()
342
button = gtk.Button()
347
343
button.set_use_stock(True)
348
344
button.set_label("gtk-go-forward")
349
345
button.connect("clicked", lambda w: self.go_forward())
350
button.set_relief(Gtk.ReliefStyle.NONE)
346
button.set_relief(gtk.RELIEF_NONE)
352
348
button.set_sensitive(False)
355
351
def _create_find_button(self):
356
button = Gtk.Button()
352
button = gtk.Button()
357
353
button.set_use_stock(True)
358
354
button.set_label("gtk-find")
359
355
button.set_tooltip_text("Search for text (Ctrl+F)")
360
356
button.connect("clicked", self._search_by_text)
361
button.set_relief(Gtk.ReliefStyle.NONE)
357
button.set_relief(gtk.RELIEF_NONE)
363
359
button.set_sensitive(True)
366
362
def _create_goto_button(self):
367
button = Gtk.Button()
363
button = gtk.Button()
368
364
button.set_label("Goto Line")
369
365
button.set_tooltip_text("Scroll to a line by entering its number (Ctrl+G)")
370
366
button.connect("clicked", self._search_by_line)
371
button.set_relief(Gtk.ReliefStyle.NONE)
367
button.set_relief(gtk.RELIEF_NONE)
373
369
button.set_sensitive(True)
397
393
rev_id = self._selected_revision()
398
394
if self.file_id in target_tree:
399
395
offset = self.get_scroll_offset(target_tree)
400
path, col = self.annoview.get_cursor()
401
(row,) = path.get_indices()
396
(row,), col = self.annoview.get_cursor()
402
397
self.annotate(target_tree, self.branch, self.file_id)
403
398
new_row = row+offset
406
new_path = Gtk.TreePath(path=new_row)
407
self.annoview.set_cursor(new_path, None, False)
401
self.annoview.set_cursor(new_row)
456
449
self.__cache[revision_id] = revision
457
450
return self.__cache[revision_id]
460
class SearchBox(Gtk.HBox):
452
class SearchBox(gtk.HBox):
461
453
"""A button box for searching in text or lines of annotations"""
462
454
def __init__(self):
463
super(SearchBox, self).__init__(homogeneous=False, spacing=6)
455
gtk.HBox.__init__(self, False, 6)
466
button = Gtk.Button()
468
image.set_from_stock('gtk-stop', Gtk.IconSize.BUTTON)
458
button = gtk.Button()
460
image.set_from_stock('gtk-stop', gtk.ICON_SIZE_BUTTON)
469
461
button.set_image(image)
470
button.set_relief(Gtk.ReliefStyle.NONE)
471
button.connect("clicked", lambda w: self.hide())
472
self.pack_start(button, False, False, 0)
462
button.set_relief(gtk.RELIEF_NONE)
463
button.connect("clicked", lambda w: self.hide_all())
464
self.pack_start(button, expand=False, fill=False)
476
468
self._label = label
477
self.pack_start(label, False, False, 0)
469
self.pack_start(label, expand=False, fill=False)
480
472
self._entry = entry
481
473
entry.connect("activate", lambda w, d: self._do_search(d),
483
self.pack_start(entry, False, False, 0)
475
self.pack_start(entry, expand=False, fill=False)
485
477
# Next/previous buttons
486
button = Gtk.Button('_Next')
488
image.set_from_stock('gtk-go-forward', Gtk.IconSize.BUTTON)
478
button = gtk.Button('_Next')
480
image.set_from_stock('gtk-go-forward', gtk.ICON_SIZE_BUTTON)
489
481
button.set_image(image)
490
482
button.connect("clicked", lambda w, d: self._do_search(d),
492
self.pack_start(button, False, False, 0)
484
self.pack_start(button, expand=False, fill=False)
494
button = Gtk.Button('_Previous')
496
image.set_from_stock('gtk-go-back', Gtk.IconSize.BUTTON)
486
button = gtk.Button('_Previous')
488
image.set_from_stock('gtk-go-back', gtk.ICON_SIZE_BUTTON)
497
489
button.set_image(image)
498
490
button.connect("clicked", lambda w, d: self._do_search(d),
500
self.pack_start(button, False, False, 0)
492
self.pack_start(button, expand=False, fill=False)
503
check = Gtk.CheckButton('Match case')
495
check = gtk.CheckButton('Match case')
504
496
self._match_case = check
505
self.pack_start(check, False, False, 0)
497
self.pack_start(check, expand=False, fill=False)
507
check = Gtk.CheckButton('Regexp')
499
check = gtk.CheckButton('Regexp')
508
500
check.connect("toggled", lambda w: self._set_label())
509
501
self._regexp = check
510
self.pack_start(check, False, False, 0)
502
self.pack_start(check, expand=False, fill=False)
512
504
self._view = None
513
505
self._column = None