show/hide changeset content at startup (closes #92204)

Changeset content located at the bottom is hidden at startup.

  • click on a changeset line to display content.
  • Hit Space to toggle content view.
  • toggle Content button in toolbar to tobble content view
  • add config entry to hide/show changeset content at startup
note:may be interesting to merge keybindings from GUI and TUI
authorAlain Leufroy <alain.leufroy@logilab.fr>
changeset501d4a29096b
branchdefault
phasepublic
hiddenno
parent revision#552064e111f8 [curses] improve signals patching (wip #92204)
child revision#7d31e2d9e190 [qt] hide toolBar_rev at startup (closes #78370)
files modified by this revision
README
hgviewlib/config.py
hgviewlib/curses/hgrepoviewer.py
hgviewlib/hgviewhelp.py
hgviewlib/qt4/hgqv.qrc
hgviewlib/qt4/hgrepoviewer.py
hgviewlib/qt4/icons/README
hgviewlib/qt4/icons/content.png
# HG changeset patch
# User Alain Leufroy <alain.leufroy@logilab.fr>
# Date 1327679836 -3600
# Fri Jan 27 16:57:16 2012 +0100
# Node ID 501d4a29096bdfb9cdd3d61a93368d22030c89cc
# Parent 552064e111f84a473ad0abf7535365cdf898c94e
show/hide changeset content at startup (closes #92204)

Changeset content located at the bottom is hidden at startup.

* click on a changeset line to display content.
* Hit Space to toggle content view.
* toggle Content button in toolbar to tobble content view
* add config entry to hide/show changeset content at startup

:note: may be interesting to merge keybindings from GUI and TUI

diff --git a/README b/README
@@ -68,5 +68,6 @@
1  =================
2 
3  See `hg help hgview` for more informations on available configuration
4  options.
5 
6 +alain
diff --git a/hgviewlib/config.py b/hgviewlib/config.py
@@ -272,10 +272,17 @@
7          mqhidetags: hide mq tags
8          """
9          return self.ui.config(self.section, 'mqhidetags', default)
10 
11      @cached
12 +    def getContentAtStartUp(self, default=True):
13 +        """
14 +        contentatstartup: show the content of changeset at startup (bottom part)
15 +        """
16 +        return bool(self.ui.config(self.section, 'contentatstartup', default))
17 +
18 +    @cached
19      def getShowHidden(self, default=False):
20          """
21          showhidden: show hidden changeset at startup
22          """
23          return bool(self.ui.config(self.section, 'showhidden', default))
diff --git a/hgviewlib/curses/hgrepoviewer.py b/hgviewlib/curses/hgrepoviewer.py
@@ -26,10 +26,11 @@
24 
25  import urwid
26  from urwid import AttrWrap, Pile, Columns, SolidFill, signals
27  from urwid.util import is_mouse_press
28 
29 +from hgviewlib.config import HgConfig
30  from hgviewlib.hggraph import HgRepoListWalker
31  from hgviewlib.util import exec_flag_changed, isbfile
32 
33  from hgviewlib.curses.graphlog import RevisionsWalker
34  from hgviewlib.curses.manifest import ManifestWalker
@@ -276,20 +277,23 @@
35 
36      CONTEXT_SIZE = 0.5
37 
38      def __init__(self, repo, *args, **kwargs):
39          self.repo = repo
40 +        self.cfg = HgConfig(repo.ui)
41          self._show_context = 0 # O:hide, 1:half, 2:maximized
42 
43          walker = HgRepoListWalker(repo)
44          self.graphlog = GraphlogViewer(walker=walker)
45          self.context = ContextViewer(walker=walker)
46 
47          widget_list = [('weight', 1 - self.CONTEXT_SIZE, self.graphlog),]
48 
49          super(RepoViewer, self).__init__(widget_list=widget_list, focus_item=0,
50                                           *args, **kwargs)
51 +        if self.cfg.getContentAtStartUp():
52 +            self.show_context()
53 
54      def update_context(self, ctx):
55          """Change the current displayed context"""
56          self.context.manifest_walker.ctx = ctx
57 
diff --git a/hgviewlib/hgviewhelp.py b/hgviewlib/hgviewhelp.py
@@ -34,10 +34,13 @@
58  ------------
59 
60  The main revision graph display the repository history as a graph,
61  sorted by revision number.
62 
63 +Hit Space key or click on a revision item to display/hide the revision
64 +content.
65 +
66  The color of the node of each revision depends on the named branch the
67  revision belongs to.
68 
69  The color of the links (between nodes) is randomly chosen.
70 
diff --git a/hgviewlib/qt4/hgqv.qrc b/hgviewlib/qt4/hgqv.qrc
@@ -17,7 +17,8 @@
71      <file>icons/clean.svg</file>
72      <file>icons/mqdiff.svg</file>
73      <file>icons/mqdiff_x.svg</file>
74      <file>icons/mqpatch.svg</file>
75      <file>icons/mqpatch_x.svg</file>
76 +    <file>icons/content.png</file>
77    </qresource>
78  </RCC>
diff --git a/hgviewlib/qt4/hgrepoviewer.py b/hgviewlib/qt4/hgrepoviewer.py
@@ -61,10 +61,13 @@
79          self.menubar.hide()
80 
81          self.splitter_2.setStretchFactor(0, 2)
82          self.splitter_2.setStretchFactor(1, 1)
83 
84 +        # hide bottom at startup
85 +        self.frame_maincontent.setVisible(self.cfg.getContentAtStartUp())
86 +
87          self.createActions()
88          self.createToolbars()
89 
90          self.textview_status.setFont(self._font)
91          connect(self.textview_status, SIGNAL('showMessage'),
@@ -130,10 +133,11 @@
92                  Qt.QueuedConnection)
93 
94          self.attachQuickBar(self.find_toolbar)
95 
96          # navigation toolbar
97 +        self.toolBar_edit.addAction(self.actionShowMainContent)
98          self.toolBar_edit.addAction(self.tableView_revisions._actions['back'])
99          self.toolBar_edit.addAction(self.tableView_revisions._actions['forward'])
100 
101          findaction = self.find_toolbar.toggleViewAction()
102          findaction.setIcon(geticon('find'))
@@ -158,18 +162,11 @@
103          self.toolBar_treefilters.layout().setSpacing(3)
104 
105          self.branch_label_action = self.toolBar_treefilters.addWidget(self.branch_label)
106          self.branch_comboBox_action = self.toolBar_treefilters.addWidget(self.branch_comboBox)
107          # hidden changeset action
108 -        self.hidden_action = QtGui.QAction(self.tr('Show Hidden'), self)
109 -        self.hidden_action.setCheckable(True)
110 -        self.hidden_action.setChecked(self.cfg.getShowHidden())
111 -        self.hidden_action.setToolTip(self.tr('Show hidden changeset'))
112 -        self.hidden_action.setStatusTip(self.tr('Show hidden changeset'))
113 -        self.toolBar_treefilters.addAction(self.hidden_action)
114 -        connect(self.hidden_action, SIGNAL('triggered()'),
115 -                self.refreshRevisionTable)
116 +        self.toolBar_treefilters.addAction(self.actionShowHidden)
117          # separator
118          self.toolBar_treefilters.addSeparator()
119 
120          self.startrev_label = QtGui.QToolButton()
121          self.startrev_label.setText("Start rev.")
@@ -229,10 +226,29 @@
122          self.actionHelp.setShortcut(Qt.Key_F1)
123          self.actionHelp.setIcon(geticon('help'))
124          connect(self.actionHelp, SIGNAL('triggered()'),
125                  self.on_help)
126 
127 +        self.actionShowHidden = QtGui.QAction(self.tr('Show Hidden'), self)
128 +        self.actionShowHidden.setCheckable(True)
129 +        self.actionShowHidden.setChecked(self.cfg.getShowHidden())
130 +        self.actionShowHidden.setToolTip(self.tr('Show hidden changeset'))
131 +        self.actionShowHidden.setStatusTip(self.tr('Show hidden changeset'))
132 +        connect(self.actionShowHidden, SIGNAL('triggered()'),
133 +                self.refreshRevisionTable)
134 +
135 +        self.actionShowMainContent = QtGui.QAction('Content', self)
136 +        self.actionShowMainContent.setIcon(geticon('content'))
137 +        self.actionShowMainContent.setCheckable(True)
138 +        self.actionShowMainContent.setChecked(self.cfg.getContentAtStartUp())
139 +        tip = self.tr('Show/Hide changeset content')
140 +        self.actionShowMainContent.setToolTip(tip)
141 +        self.actionShowMainContent.setStatusTip(tip)
142 +        self.actionShowMainContent.setShortcut(Qt.Key_Space)
143 +        connect(self.actionShowMainContent, SIGNAL('triggered()'),
144 +                self.toggleMainContent)
145 +
146          # Next/Prev diff (in full file mode)
147          self.actionNextDiff = QtGui.QAction(geticon('down'), 'Next diff', self)
148          self.actionNextDiff.setShortcut('Alt+Down')
149          self.actionPrevDiff = QtGui.QAction(geticon('up'), 'Previous diff', self)
150          self.actionPrevDiff.setShortcut('Alt+Up')
@@ -330,10 +346,21 @@
151          self.actionClearStartAtRev.setShortcuts([Qt.SHIFT + Qt.Key_Backspace,])
152          connect(self.actionClearStartAtRev, SIGNAL('triggered()'),
153                  self.clearStartAtRev)
154          self.addAction(self.actionClearStartAtRev)
155 
156 +    def toggleMainContent(self, visible=None):
157 +        if visible is None:
158 +            visible = self.actionShowMainContent.isChecked()
159 +        visible = bool(visible)
160 +        if visible == self.frame_maincontent.isVisible():
161 +            return
162 +        self.actionShowMainContent.setChecked(visible)
163 +        self.frame_maincontent.setVisible(visible)
164 +        if visible:
165 +            self.revision_selected(-1)
166 +
167      def startAtCurrentRev(self):
168          crev = self.tableView_revisions.current_rev
169          if crev:
170              self.startrev_entry.setText(str(crev))
171              # XXX workaround: see refreshRevisionTable method
@@ -403,10 +430,12 @@
172              self.textview_status.displayFile(filename, rev)
173 
174      def setupRevisionTable(self):
175          view = self.tableView_revisions
176          view.installEventFilter(self)
177 +        connect(view, SIGNAL('clicked (const QModelIndex &)'),
178 +                self.toggleMainContent)
179          connect(view, SIGNAL('revisionSelected'), self.revision_selected)
180          connect(view, SIGNAL('revisionActivated'), self.revision_activated)
181          connect(self.textview_header, SIGNAL('revisionSelected'), view.goto)
182          connect(self.textview_header, SIGNAL('parentRevisionSelected'), self.textview_status.displayDiff)
183          self.attachQuickBar(view.goto_toolbar)
@@ -450,10 +479,11 @@
184          """
185          Callback called when a revision is double-clicked in the revisions table
186          """
187          if rev is None:
188              rev = self.tableView_revisions.current_rev
189 +        self.toggleMainContent(True)
190          self._manifestdlg = ManifestViewer(self.repo, rev)
191          self._manifestdlg.show()
192 
193      def file_displayed(self, filename):
194          self.actionPrevDiff.setEnabled(False)
@@ -462,18 +492,26 @@
195                                                                   and self.textview_status.nDiffs()))
196 
197      def revision_selected(self, rev):
198          """
199          Callback called when a revision is selected in the revisions table
200 +        if rev == -1: refresh the current selected revision
201          """
202 -        if self.repomodel.graph:
203 -            ctx = self.repomodel.repo[rev]
204 -            self.textview_status.setContext(ctx)
205 -            self.textview_header.displayRevision(ctx)
206 -            self.filelistmodel.setSelectedRev(ctx)
207 -            if len(self.filelistmodel):
208 -                self.tableView_filelist.selectRow(0)
209 +        if not self.frame_maincontent.isVisible() or not self.repomodel.graph:
210 +            return
211 +        if rev == -1:
212 +            view = self.tableView_revisions
213 +            indexes = view.selectedIndexes()
214 +            if not indexes:
215 +                return
216 +            rev = view.revFromindex(indexes[0])
217 +        ctx = self.repomodel.repo[rev]
218 +        self.textview_status.setContext(ctx)
219 +        self.textview_header.displayRevision(ctx)
220 +        self.filelistmodel.setSelectedRev(ctx)
221 +        if len(self.filelistmodel):
222 +            self.tableView_filelist.selectRow(0)
223 
224      def goto(self, rev):
225          if len(self.tableView_revisions.model().graph):
226              self.tableView_revisions.goto(rev)
227          else:
@@ -521,11 +559,11 @@
228          sender = kw.get('sender') or self.sender()
229          if sender is self.startrev_follow_action and startrev is None:
230              return
231          startrev = self.repo.changectx(startrev).rev()
232          follow = self.startrev_follow_action.isChecked()
233 -        self.repomodel.show_hidden = self.hidden_action.isChecked()
234 +        self.repomodel.show_hidden = self.actionShowHidden.isChecked()
235          self.revscompl_model.setStringList(self.repo.tags().keys())
236 
237          self.repomodel.setRepo(self.repo, branch=branch, fromhead=startrev,
238                                 follow=follow)
239 
diff --git a/hgviewlib/qt4/icons/README b/hgviewlib/qt4/icons/README
@@ -1,1 +1,2 @@
240  Most of the icons used here are from the Tango Icon Theme. Some of them have been modified.
241 +content.png: by PC (Creative Common)
diff --git a/hgviewlib/qt4/icons/content.png b/hgviewlib/qt4/icons/content.png