Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.7, 0.7.1, and 0.7.2

status: replace context menu with ctrl-c accel for clipboard copy

Changeset c1aec97f2463

Parent 5a851216b2c0

by Steve Borho

Changes to one file · Browse files at c1aec97f2463 Showing diff from parent 5a851216b2c0 Diff from another changeset...

Change 1 of 3 Show Entire File hggtk/​status.py Stacked
 
336
337
338
 
 
 
 
 
 
339
 
 
 
 
 
 
 
 
 
340
341
342
 
344
345
346
347
348
349
 
350
351
352
 
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
 
 
 
 
 
425
426
427
428
 
 
 
 
 
 
 
 
 
 
 
429
430
431
 
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
 
359
360
361
 
 
 
362
363
364
365
 
409
410
411
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
413
414
415
416
417
 
 
 
418
419
420
421
422
423
424
425
426
427
428
429
430
431
@@ -336,7 +336,22 @@
    self.diff_model = gtk.ListStore(bool, str, str, str, bool, int,   pango.FontDescription) + + # Create a new signal for our purposes + newsigname = 'copy-clipboard' + gobject.signal_new(newsigname, gtk.TreeView, + gobject.SIGNAL_ACTION, gobject.TYPE_NONE, ()) +   self.diff_tree = gtk.TreeView(self.diff_model) + self.diff_tree.connect(newsigname, self.copy_to_clipboard) + + # set CTRL-c accelerator for copy-clipboard + accelgroup = gtk.AccelGroup() + self.add_accel_group(accelgroup) + key, modifier = gtk.accelerator_parse('<Control>c') + self.diff_tree.add_accelerator(newsigname, accelgroup, key, + modifier, gtk.ACCEL_VISIBLE) +   self.diff_tree.get_selection().set_mode(gtk.SELECTION_MULTIPLE)   self.diff_tree.set_headers_visible(False)   self.diff_tree.set_property('enable-grid-lines', True) @@ -344,9 +359,7 @@
  self._diff_tree_row_act)   self.diff_tree.set_enable_search(False)   self.diff_tree.set_headers_visible(False) - self.diff_tree.connect('button-release-event', - self._patch_button_release) - +   cell = gtk.CellRendererText()   diffcol = gtk.TreeViewColumn('diff', cell)   diffcol.set_resizable(True) @@ -396,36 +409,23 @@
  self.filetree.set_headers_clickable(True)   return self._diffpane   - def _patch_button_release(self, widget, event): - '''Detect release of right mouse button on diff tree''' - if event.button == 3 and not (event.state & gtk.gdk.CONTROL_MASK): - self._diff_popup_menu(widget, event) - return False - - def _diff_popup_menu(self, tree, event): - sel = tree.get_selection() - model, paths = sel.get_selected_rows() - path = tree.get_path_at_pos(int(event.x), int(event.y))[0] - if path not in paths: - sel.unselect_all() - sel.select_path(path) - paths = [path] - if not self.clipboard: - return - - menu = gtk.Menu() - menuitem = gtk.MenuItem('Copy to Clipboard', True) - menuitem.connect('activate', self.copy_to_clipboard, paths) - menuitem.set_border_width(1) - menu.append(menuitem) - menu.show_all() - menu.popup(None, None, None, 0, 0) - - def copy_to_clipboard(self, menu, paths): + def copy_to_clipboard(self, treeview): + 'Write highlighted hunks to the clipboard' + model, paths = treeview.get_selection().get_selected_rows() + cids = [ model[row][DM_CHUNK_ID] for row, in paths ] + headers = {}   fp = cStringIO.StringIO() - for row, in paths: - chunkid = self.diff_model[row][DM_CHUNK_ID] - self._shelve_chunks[chunkid].write(fp) + for cid in cids: + chunk = self._shelve_chunks[cid] + wfile = chunk.filename() + if not isinstance(chunk, hgshelve.header): + # Ensure each hunk has a file header + if wfile not in headers: + hrow = self._filechunks[wfile][0] + hcid = model[hrow][DM_CHUNK_ID] + self._shelve_chunks[hcid].write(fp) + headers[wfile] = cid + chunk.write(fp)   fp.seek(0)   self.clipboard.set_text(fp.read())