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

status: add patch context menu for copy-to-clipboard

Changeset 8bc88bffb8fb

Parent e3fdbb14ca5b

by Steve Borho

Changes to one file · Browse files at 8bc88bffb8fb Showing diff from parent e3fdbb14ca5b Diff from another changeset...

Change 1 of 4 Show Entire File hggtk/​status.py Stacked
 
304
305
306
 
 
 
 
307
308
309
 
314
315
316
 
 
317
318
319
 
334
335
336
 
337
338
339
 
357
358
359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
361
362
 
304
305
306
307
308
309
310
311
312
313
 
318
319
320
321
322
323
324
325
 
340
341
342
343
344
345
346
 
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
@@ -304,6 +304,10 @@
    if self.count_revs() == 2 or len(self.repo.changectx(None).parents()) == 1:   # use treeview to diff hunks + + sel = (os.name == 'nt') and 'CLIPBOARD' or 'PRIMARY' + self.clipboard = gtk.Clipboard(selection=sel) +   self.diff_model = gtk.ListStore(bool, bool, str, bool, int)   self.diff_tree = gtk.TreeView(self.diff_model)   self.diff_tree.get_selection().set_mode(gtk.SELECTION_MULTIPLE) @@ -314,6 +318,8 @@
  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)     diff_hunk_cell = gtk.CellRendererText()   diff_hunk_cell.set_property('cell-background', '#EEEEEE') @@ -334,6 +340,7 @@
  diff_frame.add(vbox)   else:   # display merge diffs in simple text view + self.clipboard = None   self.merge_diff_text = gtk.TextView()   self.merge_diff_text.set_wrap_mode(gtk.WRAP_NONE)   self.merge_diff_text.set_editable(False) @@ -357,6 +364,38 @@
  self.tree.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): + fp = cStringIO.StringIO() + for row, in paths: + chunkid = self.diff_model[row][DM_CHUNK_ID] + self._shelve_chunks[chunkid].write(fp) + fp.seek(0) + self.clipboard.set_text(fp.read())     def _toggle_rejects(self, widget, diffcol, cell):   diffcol.clear_attributes(cell)