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

authorAlain Leufroy <alain@leufroy.fr>
changeset2708aff00d8c
branchdefault
phasedraft
hiddenyes
parent revision#e83eb0d1e6c6 [qt4] make pylint a little more happy
child revision#addb07711aa2 [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 1368250597 -7200
# Sat May 11 07:36:37 2013 +0200
# Node ID 2708aff00d8c1c1c1bdf186037718e87a5e7da7e
# Parent e83eb0d1e6c618e73a7224f6a3460e5ad9363ccf
[qt4] add an intuitive link to display heavy files (closes #109862)

diff --git a/hgviewlib/hggraph.py b/hgviewlib/hggraph.py
@@ -520,11 +520,11 @@
1                      val = int(filesize / (2 ** (div * 10)))
2                  except AttributeError: # py<2.7
3                      val = filesize
4                      sym = ''
5                  data = "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
@@ -219,11 +219,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()
@@ -338,11 +341,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):
@@ -366,11 +369,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,10 +22,11 @@
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      <file>icons/openeditor.png</file>
69    </qresource>
70  </RCC>
diff --git a/hgviewlib/qt4/icons/heavy_small.png b/hgviewlib/qt4/icons/heavy_small.png