49
50
self._branch = branch
51
Window.__init__(self, parent)
52
super(GAnnotateWindow, self).__init__(parent=parent)
53
self.set_icon(self.render_icon(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
55
self.render_icon_pixbuf(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
54
56
self.annotate_colormap = AnnotateColorSaturation()
130
self.annoview.set_cursor(row)
131
self.annoview.scroll_to_cell(row, use_align=True)
132
tree_path = Gtk.TreePath(path=row)
133
self.annoview.set_cursor(tree_path, None, False)
134
self.annoview.scroll_to_cell(tree_path, use_align=True)
134
136
def _annotate(self, tree, file_id):
135
137
current_revision = FakeRevision(CURRENT_REVISION)
165
167
def _highlight_annotation(self, model, path, iter, now):
166
168
revision_id, = model.get(iter, REVISION_ID_COL)
167
169
revision = self.revisions[revision_id]
168
model.set(iter, HIGHLIGHT_COLOR_COL,
169
self.annotate_colormap.get_color(revision, now))
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)
171
174
def _selected_revision(self):
172
175
(path, col) = self.annoview.get_cursor()
205
208
swbox.pack_start(sw, True, True, 0)
208
hbox = Gtk.HBox(False, 6)
211
hbox = Gtk.HBox(homogeneous=False, spacing=6)
209
212
self.back_button = self._create_back_button()
210
hbox.pack_start(self.back_button, expand=False, fill=True)
213
hbox.pack_start(self.back_button, False, True, 0)
211
214
self.forward_button = self._create_forward_button()
212
hbox.pack_start(self.forward_button, expand=False, fill=True)
215
hbox.pack_start(self.forward_button, False, True, 0)
213
216
self.find_button = self._create_find_button()
214
hbox.pack_start(self.find_button, expand=False, fill=True)
217
hbox.pack_start(self.find_button, False, True, 0)
215
218
self.goto_button = self._create_goto_button()
216
hbox.pack_start(self.goto_button, expand=False, fill=True)
219
hbox.pack_start(self.goto_button, False, True, 0)
218
vbox.pack_start(hbox, expand=False, fill=True)
221
vbox.pack_start(hbox, False, True, 0)
220
223
self.pane = pane = Gtk.VPaned()
222
225
pane.add2(self.revisionview)
224
vbox.pack_start(pane, expand=True, fill=True)
227
vbox.pack_start(pane, True, True, 0)
226
229
self._search = SearchBox()
227
swbox.pack_start(self._search, expand=False, fill=True)
230
swbox.pack_start(self._search, False, True, 0)
228
231
accels = Gtk.AccelGroup()
229
accels.connect_group(Gdk.KEY_f, Gdk.EventMask.CONTROL_MASK,
232
accels.connect(Gdk.KEY_f, Gdk.ModifierType.CONTROL_MASK,
233
Gtk.AccelFlags.LOCKED,
231
234
self._search_by_text)
232
accels.connect_group(Gdk.KEY_g, Gdk.EventMask.CONTROL_MASK,
235
accels.connect(Gdk.KEY_g, Gdk.ModifierType.CONTROL_MASK,
236
Gtk.AccelFlags.LOCKED,
234
237
self._search_by_line)
235
238
self.add_accel_group(accels)
245
248
self._search.set_target(self.annoview, LINE_NUM_COL)
247
250
def line_diff(self, tv, path, tvc):
251
row = path.get_indices()[0]
249
252
revision = self.annotations[row]
250
253
repository = self.branch.repository
251
254
if revision.revision_id == CURRENT_REVISION:
279
282
tv.get_style().bg[Gtk.StateType.NORMAL])
280
283
col = Gtk.TreeViewColumn()
281
284
col.set_resizable(False)
282
col.pack_start(cell, True, True, 0)
285
col.pack_start(cell, True)
283
286
col.add_attribute(cell, "text", LINE_NUM_COL)
284
287
tv.append_column(col)
290
293
self.get_style().bg[Gtk.StateType.NORMAL])
291
294
col = Gtk.TreeViewColumn("Committer")
292
295
col.set_resizable(True)
293
col.pack_start(cell, True, True, 0)
296
col.pack_start(cell, True)
294
297
col.add_attribute(cell, "text", COMMITTER_COL)
295
298
tv.append_column(col)
301
304
self.get_style().bg[Gtk.StateType.NORMAL])
302
305
col = Gtk.TreeViewColumn("Revno")
303
306
col.set_resizable(False)
304
col.pack_start(cell, True, True, 0)
307
col.pack_start(cell, True)
305
308
col.add_attribute(cell, "markup", REVNO_COL)
306
309
tv.append_column(col)
310
313
cell.set_property("family", "Monospace")
311
314
col = Gtk.TreeViewColumn()
312
315
col.set_resizable(False)
313
col.pack_start(cell, True, True, 0)
316
col.pack_start(cell, True)
314
317
# col.add_attribute(cell, "foreground", HIGHLIGHT_COLOR_COL)
315
318
col.add_attribute(cell, "background", HIGHLIGHT_COLOR_COL)
316
319
col.add_attribute(cell, "text", TEXT_LINE_COL)
394
397
rev_id = self._selected_revision()
395
398
if self.file_id in target_tree:
396
399
offset = self.get_scroll_offset(target_tree)
397
(row,), col = self.annoview.get_cursor()
400
path, col = self.annoview.get_cursor()
401
(row,) = path.get_indices()
398
402
self.annotate(target_tree, self.branch, self.file_id)
399
403
new_row = row+offset
402
self.annoview.set_cursor(new_row)
406
new_path = Gtk.TreePath(path=new_row)
407
self.annoview.set_cursor(new_path, None, False)
407
412
def get_scroll_offset(self, tree):
408
413
old = self.tree.get_file(self.file_id)
409
414
new = tree.get_file(self.file_id)
410
(row,), col = self.annoview.get_cursor()
415
path, col = self.annoview.get_cursor()
416
(row,) = path.get_indices()
411
417
matcher = patiencediff.PatienceSequenceMatcher(None, old.readlines(),
413
419
for i, j, n in matcher.get_matching_blocks():
450
456
self.__cache[revision_id] = revision
451
457
return self.__cache[revision_id]
453
460
class SearchBox(Gtk.HBox):
454
461
"""A button box for searching in text or lines of annotations"""
455
462
def __init__(self):
456
GObject.GObject.__init__(self, False, 6)
463
super(SearchBox, self).__init__(homogeneous=False, spacing=6)
459
466
button = Gtk.Button()
461
468
image.set_from_stock('gtk-stop', Gtk.IconSize.BUTTON)
462
469
button.set_image(image)
463
470
button.set_relief(Gtk.ReliefStyle.NONE)
464
button.connect("clicked", lambda w: self.hide_all())
465
self.pack_start(button, expand=False, fill=False)
471
button.connect("clicked", lambda w: self.hide())
472
self.pack_start(button, False, False, 0)
468
475
label = Gtk.Label()
469
476
self._label = label
470
self.pack_start(label, expand=False, fill=False)
477
self.pack_start(label, False, False, 0)
472
479
entry = Gtk.Entry()
473
480
self._entry = entry
474
481
entry.connect("activate", lambda w, d: self._do_search(d),
476
self.pack_start(entry, expand=False, fill=False)
483
self.pack_start(entry, False, False, 0)
478
485
# Next/previous buttons
479
486
button = Gtk.Button('_Next')
482
489
button.set_image(image)
483
490
button.connect("clicked", lambda w, d: self._do_search(d),
485
self.pack_start(button, expand=False, fill=False)
492
self.pack_start(button, False, False, 0)
487
494
button = Gtk.Button('_Previous')
488
495
image = Gtk.Image()
490
497
button.set_image(image)
491
498
button.connect("clicked", lambda w, d: self._do_search(d),
493
self.pack_start(button, expand=False, fill=False)
500
self.pack_start(button, False, False, 0)
496
503
check = Gtk.CheckButton('Match case')
497
504
self._match_case = check
498
self.pack_start(check, expand=False, fill=False)
505
self.pack_start(check, False, False, 0)
500
507
check = Gtk.CheckButton('Regexp')
501
508
check.connect("toggled", lambda w: self._set_label())
502
509
self._regexp = check
503
self.pack_start(check, expand=False, fill=False)
510
self.pack_start(check, False, False, 0)
505
512
self._view = None
506
513
self._column = None
586
593
for row in iterate(model, start):
587
594
if self._match(model, row, self._column):
588
595
path = model.get_path(row)
589
self._view.set_cursor(path)
596
self._view.set_cursor(path, None, False)
590
597
self._view.scroll_to_cell(path, use_align=True)