[qt] add an action to export changeset metadata to clipboard (closes #101945)

This is available through the changeset context menu and the Ctrl+C keybinding.

The ecport content can be configured using hgview.exporttemplate option.

authorAlain Leufroy <alain.leufroy@logilab.fr>
changesetfc542bd01f56
branchdefault
phasepublic
hiddenno
parent revision#732b464cf33d merge back stable 1.6.2
child revision#b5ece8a50c03 [qt] clean: remove unused code
files modified by this revision
hgviewlib/config.py
hgviewlib/qt4/hgrepoview.py
# HG changeset patch
# User Alain Leufroy <alain.leufroy@logilab.fr>
# Date 1350674398 -7200
# Fri Oct 19 21:19:58 2012 +0200
# Node ID fc542bd01f56993d9c7e55c1a977badc1a46a23f
# Parent 732b464cf33dfbaba23f3a02ec35b2f67a9cc709
[qt] add an action to export changeset metadata to clipboard (closes #101945)

This is available through the changeset context menu and the Ctrl+C keybinding.

The ecport content can be configured using `hgview.exporttemplate` option.

diff --git a/hgviewlib/config.py b/hgviewlib/config.py
@@ -331,10 +331,20 @@
1          """
2          showobsolete: display obsolete relations
3          """
4          return bool(self._fromconfig('showobsolete', default))
5 
6 +    @cached
7 +    def getExportTemplate(self):
8 +        """
9 +        exporttemplate: template used to serialise changeset metadata
10 +                        while exporting into the window manager clipboard.
11 +                        (default to `ui.logtemplate`)
12 +        """
13 +        return self._fromconfig('exporttemplate', None) or \
14 +               self.ui.config('ui', 'logtemplate')
15 +
16  _HgConfig = HgConfig
17  # HgConfig is instanciated only once (singleton)
18  #
19  # this 'factory' is used to manage this (not using heavy guns of
20  # metaclass or so)
diff --git a/hgviewlib/qt4/hgrepoview.py b/hgviewlib/qt4/hgrepoview.py
@@ -16,11 +16,13 @@
21  Qt4 high level widgets for hg repo changelogs and filelogs
22  """
23  import sys
24  from collections import namedtuple
25 
26 +from mercurial import cmdutil, ui
27  from mercurial.node import hex, short as short_hex, bin as short_bin
28 +
29  try:
30      from mercurial.error import RepoError
31  except ImportError: # old API
32      from mercurial.repo import RepoError #pylint: disable=E0611
33 
@@ -151,10 +153,16 @@
34              def __repr__(self):
35                  out = super(ActDef, self).__repr__()
36                  return out[:-1] + 'name=%r' % self.name + out[-1:]
37 
38          return [
39 +            ActDef(name="copycs",
40 +                   desc=self.tr("Export to clipboard"),
41 +                   icon=None,
42 +                   tip=self.tr("Export changeset metadata the window manager clipboard [see configuration entry 'copytemplate']"),
43 +                   keys=None, # XXX shall be specified after general shortcuts refactorization
44 +                   cb=self.copy_cs_to_clipboard),
45              ActDef(name="back",
46                     desc=self.tr("Previous visited"),
47                     icon='back',
48                     tip=self.tr("Barward to the previous visited changeset"),
49                     keys=[QtGui.QKeySequence(QtGui.QKeySequence.Back)],
@@ -213,10 +221,20 @@
50          connect(self, SIGNAL('startFromRev'), self.update_filter_action)
51 
52      def update_filter_action(self, rev=None, follow=None):
53          self._actions['unfilter'].setEnabled(rev is not None)
54 
55 +    def copy_cs_to_clipboard(self):
56 +        """ Copy changeset metada into the window manager clipboard."""
57 +        repo = self.model().repo
58 +        ctx = repo[self.current_rev]
59 +        u = ui.ui(repo.ui)
60 +        template = HgConfig(u).getExportTemplate()
61 +        u.pushbuffer()
62 +        cmdutil.show_changeset(u, repo, {'template':template}, False).show(ctx)
63 +        QtGui.QApplication.clipboard().setText(u.popbuffer())
64 +
65      def showAtRev(self):
66          self.emit(SIGNAL('revisionActivated'), self.current_rev)
67 
68      def startFromRev(self):
69          self.emit(SIGNAL('startFromRev'), self.current_rev, False)
@@ -227,11 +245,14 @@
70      def removeFilter(self):
71          self.emit(SIGNAL('startFromRev'))
72 
73      def contextMenuEvent(self, event):
74          menu = QtGui.QMenu(self)
75 -        for act in ['manifest', None, 'start', 'follow', 'unfilter', None, 'back', 'forward']:
76 +        for act in ['copycs', None,
77 +                    'manifest', None,
78 +                    'start', 'follow', 'unfilter', None,
79 +                    'back', 'forward']:
80              if act:
81                  menu.addAction(self._actions[act])
82              else:
83                  menu.addSeparator()
84          menu.exec_(event.globalPos())