[qt4] add an intuitive link to display heavy files (closes #109862)

Actually one could display heavy file diffs using the dedicated button in the toolbar or the corresponding entry in the context menu. These actions toggle the file size checking.

There is 2 improvements in this changeset:

  • I've added a more explicite message that appears near the file path with a link that helps the user displaying the file data.
  • Just display the file content without "permanently" modifying the file size checking.

Note:

This is the simplest implementation I've found. Next changesets are dedicated to make the message more visible and to add more information.
authorAlain Leufroy <alain@leufroy.fr>
changesete9b42264ad82
branchdefault
phasedraft
hiddenyes
parent revision#137a62f8554e [qt4] make pylint a little more happy
child revision#fecd2ccae785 [qt4] hide text area on heavy file
files modified by this revision
hgviewlib/hggraph.py
hgviewlib/qt4/hgfileview.py
hgviewlib/qt4/hgqv.qrc
hgviewlib/qt4/icons/heavy_small.png
# HG changeset patch
# User Alain Leufroy <alain@leufroy.fr>
# Date 1369503369 -7200
# Sat May 25 19:36:09 2013 +0200
# Node ID e9b42264ad821688850180d9986bd2a48eb0da8b
# Parent 137a62f8554ef6a99fc0b540c02c87abecb12494
[qt4] add an intuitive link to display heavy files (closes #109862)

Actually one could display heavy file diffs using the dedicated button
in the toolbar or the corresponding entry in the context menu.
These actions toggle the file size checking.


There is 2 improvements in this changeset:

- I've added a more explicite message that appears near the file path
with a link that helps the user displaying the file data.

- Just display the file content without "permanently" modifying the
file size checking.

Note:

This is the simplest implementation I've found. Next changesets are
dedicated to make the message more visible and to add more
information.

diff --git a/hgviewlib/hggraph.py b/hgviewlib/hggraph.py
@@ -512,11 +512,11 @@
1                      val = int(filesize / (2 ** (div * 10)))
2                  except AttributeError: # py<2.7
3                      val = filesize
4                      sym = ''
5                  data = u"File too big ! (~%i%so)" % (val, sym)
6 -                return flag, data
7 +                return 'file too big', data
8              if flag == "+" or mode == 'file':
9                  flag = '+'
10                  # return the whole file
11                  data = fctx.data()
12                  if util.binary(data):
diff --git a/hgviewlib/qt4/hgfileview.py b/hgviewlib/qt4/hgfileview.py
@@ -217,11 +217,14 @@
13          self.topLayout = QtGui.QVBoxLayout()
14          self.filenamelabel = QtGui.QLabel()
15          self.filenamelabel.setWordWrap(True)
16          self.filenamelabel.setTextInteractionFlags(
17              QtCore.Qt.TextSelectableByKeyboard|
18 -            QtCore.Qt.TextSelectableByMouse)
19 +            QtCore.Qt.TextSelectableByMouse|
20 +            QtCore.Qt.LinksAccessibleByMouse)
21 +        self.filenamelabel.linkActivated.connect(
22 +            lambda link: self.displayFile(show_big_file=True))
23          self.execflaglabel = QtGui.QLabel()
24          self.execflaglabel.setWordWrap(True)
25          self.topLayout.addWidget(self.filenamelabel)
26          self.topLayout.addWidget(self.execflaglabel)
27          self.execflaglabel.hide()
@@ -335,11 +338,11 @@
28 
29      def displayDiff(self, rev):
30          if rev != self._p_rev:
31              self.displayFile(rev=rev)
32 
33 -    def displayFile(self, filename=None, rev=None):
34 +    def displayFile(self, filename=None, rev=None, show_big_file=None):
35          if filename is None:
36              filename = self._filename
37 
38          self._realfilename = filename
39          if isbfile(filename):
@@ -363,11 +366,19 @@
40              return
41          if self._mode == 'diff' and self._p_rev is not None:
42              mode = self._p_rev
43          else:
44              mode = self._mode
45 -        flag, data = self._model.graph.filedata(filename, self._ctx.rev(), mode)
46 +        if show_big_file:
47 +            flag, data = self._model.graph.filedata(filename, self._ctx.rev(), mode, maxfilesize=-1)
48 +        else:
49 +            flag, data = self._model.graph.filedata(filename, self._ctx.rev(), mode)
50 +        if flag == 'file too big':
51 +            self.filenamelabel.setText(
52 +                '%s %s' %
53 +                (data, '<a href="show-big-file">Click to display anyway <img src=":/icons/heavy_small.png" width="16" height="16" title="Display heavy file">.</a>'))
54 +            return
55          if flag == '-':
56              return
57          if flag == '':
58              return
59 
diff --git a/hgviewlib/qt4/hgqv.qrc b/hgviewlib/qt4/hgqv.qrc
@@ -22,9 +22,10 @@
60      <file>icons/showhide.png</file>
61      <file>icons/content.png</file>
62      <file>icons/unfilter.png</file>
63      <file>icons/diffmode.png</file>
64      <file>icons/heavy.png</file>
65 +    <file>icons/heavy_small.png</file>
66      <file>icons/valid.png</file>
67      <file>icons/loading.png</file>
68    </qresource>
69  </RCC>
diff --git a/hgviewlib/qt4/icons/heavy_small.png b/hgviewlib/qt4/icons/heavy_small.png