Commits

Marek Stój  committed 1b9a5a4

workbench: keyboard accelerators in main menu and shortcuts for task widgets

  • Participants
  • Parent commits bd9e46d

Comments (0)

Files changed (1)

File tortoisehg/hgqt/workbench.py

 from PyQt4.QtGui import *
 from PyQt4.QtNetwork import QLocalServer, QLocalSocket
 
+from collections import OrderedDict
+
 class ThgTabBar(QTabBar):
     def mouseReleaseEvent(self, event):
 
         self.menuRepository = self.menubar.addMenu(_("&Repository"))
         self.menuHelp = self.menubar.addMenu(_("&Help"))
 
-        self.edittbar = QToolBar(_("Edit Toolbar"), objectName='edittbar')
+        self.edittbar = QToolBar(_("&Edit Toolbar"), objectName='edittbar')
         self.addToolBar(self.edittbar)
-        self.docktbar = QToolBar(_("Dock Toolbar"), objectName='docktbar')
+        self.docktbar = QToolBar(_("&Dock Toolbar"), objectName='docktbar')
         self.addToolBar(self.docktbar)
-        self.synctbar = QToolBar(_('Sync Toolbar'), objectName='synctbar')
+        self.synctbar = QToolBar(_('&Sync Toolbar'), objectName='synctbar')
         self.addToolBar(self.synctbar)
-        self.tasktbar = QToolBar(_('Task Toolbar'), objectName='taskbar')
+        self.tasktbar = QToolBar(_('&Task Toolbar'), objectName='taskbar')
         self.addToolBar(self.tasktbar)
-        self.customtbar = QToolBar(_('Custom Toolbar'), objectName='custombar')
+        self.customtbar = QToolBar(_('&Custom Toolbar'), objectName='custombar')
         self.addToolBar(self.customtbar)
 
         # availability map of actions; applied by updateMenu()
         newseparator(menu='file')
         newaction(_("&New Repository..."), self.newRepository,
                   shortcut='New', menu='file', icon='hg-init')
-        newaction(_("Clone Repository..."), self.cloneRepository,
+        newaction(_("C&lone Repository..."), self.cloneRepository,
                   shortcut=modifiedkeysequence('New', modifier='Shift'),
                   menu='file', icon='hg-clone')
         newseparator(menu='file')
         newaction(_("E&xit"), self.close, shortcut='Quit', menu='file')
 
         a = self.reporegistry.toggleViewAction()
-        a.setText(_('Show Repository Registry'))
+        a.setText(_('Show Repository Reg&istry'))
         a.setShortcut('Ctrl+Shift+O')
         a.setIcon(qtlib.geticon('thg-reporegistry'))
         self.docktbar.addAction(a)
         self.menuView.addAction(a)
 
         a = self.mqpatches.toggleViewAction()
-        a.setText(_('Show Patch Queue'))
+        a.setText(_('Show Patch &Queue'))
         a.setIcon(qtlib.geticon('thg-mq'))
         self.docktbar.addAction(a)
         self.menuView.addAction(a)
         self.menuView.addAction(a)
 
         newseparator(menu='view')
-        self.menuViewregistryopts = self.menuView.addMenu(_('Repository Registry Options'))
+        self.menuViewregistryopts = self.menuView.addMenu(_('Repository Registry Optio&ns'))
         self.actionShowPaths = \
-        newaction(_("Show Paths"), self.reporegistry.showPaths,
+        newaction(_("Show &Paths"), self.reporegistry.showPaths,
                   checkable=True, menu='viewregistryopts')
 
         self.actionShowSubrepos = \
-            newaction(_("Show Subrepos on Registry"),
+            newaction(_("Show &Subrepos on Registry"),
                 self.reporegistry.setShowSubrepos,
                   checkable=True, menu='viewregistryopts')
 
         self.actionShowNetworkSubrepos = \
-            newaction(_("Show Subrepos for remote repositories"),
+            newaction(_("Show Subrepos for &remote repositories"),
                 self.reporegistry.setShowNetworkSubrepos,
                   checkable=True, menu='viewregistryopts')
 
         self.actionShowShortPaths = \
-            newaction(_("Show Short Paths"),
+            newaction(_("Show Shor&t Paths"),
                 self.reporegistry.setShowShortPaths,
                   checkable=True, menu='viewregistryopts')
 
         newseparator(menu='view')
-        newaction(_("Choose Log Columns..."), self.setHistoryColumns,
+        newaction(_("Choos&e Log Columns..."), self.setHistoryColumns,
                   menu='view')
         self.actionSaveRepos = \
-        newaction(_("Save Open Repositories On Exit"), checkable=True,
+        newaction(_("Save Open Repositories On E&xit"), checkable=True,
                   menu='view')
         newseparator(menu='view')
 
         self.actionGroupTaskView = QActionGroup(self)
         self.actionGroupTaskView.triggered.connect(self.onSwitchRepoTaskTab)
-        def addtaskview(icon, label, name):
+        def addtaskview(icon, label, name, shortcut=None):
             a = newaction(label, icon=None, checkable=True, data=name,
                           enabled='repoopen', menu='view')
             a.setIcon(qtlib.geticon(icon))
+            if shortcut:
+                a.setShortcut(shortcut)
             self.actionGroupTaskView.addAction(a)
             self.tasktbar.addAction(a)
             return a
 
         # note that 'grep' and 'search' are equivalent
         taskdefs = {
-            'commit': ('hg-commit', _('&Commit')),
-            'mq': ('thg-qrefresh', _('MQ Patch')),
-            'pbranch': ('branch', _('&Patch Branch')),
-            'log': ('hg-log', _("Revision &Details")),
-            'manifest': ('hg-annotate', _('&Manifest')),
-            'grep': ('hg-grep', _('&Search')),
-            'sync': ('thg-sync', _('S&ynchronize')),
+            'commit': ('hg-commit', _('&Commit'), 'Alt+2'),
+            'mq': ('thg-qrefresh', _('MQ Patch'), None),
+            'pbranch': ('branch', _('&Patch Branch'), None),
+            'log': ('hg-log', _("Revision &Details"), 'Alt+1'),
+            'manifest': ('hg-annotate', _('&Manifest'), 'Alt+4'),
+            'grep': ('hg-grep', _('&Search'), 'Alt+5'),
+            'sync': ('thg-sync', _('S&ynchronize'), 'Alt+3'),
         }
         tasklist = self.ui.configlist(
             'tortoisehg', 'workbench.task-toolbar', [])
             tasklist = ['log', 'commit', 'mq', 'sync', 'manifest',
                 'grep', 'pbranch']
 
+        synctaskdefs = OrderedDict(sorted({
+            '00-incoming': (_('&Incoming'), 'incoming', 'hg-incoming', _('Check for incoming changes from selected URL')),
+            '01-pull': (_('Pu&ll'), 'pull', 'hg-pull', _('Pull incoming changes from selected URL')),
+            '02-outgoing': (_('&Outgoing'), 'outgoing', 'hg-outgoing', _('Detect outgoing changes to selected URL')),
+            '03-push': (_('&Push'), 'push', 'hg-push', _('Push outgoing changes to selected URL')),
+        }.items(), key=lambda k: k[0]))
+
         self.actionSelectTaskMQ = None
         self.actionSelectTaskPbranch = None
 
             if taskinfo is None:
                 newseparator(toolbar='task')
                 continue
-            tbar = addtaskview(taskinfo[0], taskinfo[1], taskname)
+            shortcut = taskinfo[2] if len(taskinfo) >= 3 else None
+            tbar = addtaskview(taskinfo[0], taskinfo[1], taskname, shortcut)
             if taskname == 'mq':
                 self.actionSelectTaskMQ = tbar
             elif taskname == 'pbranch':
                   shortcut=modifiedkeysequence('Refresh', modifier='Shift'),
                   tooltip=_('Refresh only the current task tab'),
                   menu='view')
-        newaction(_("Load all revisions"), self.loadall,
+        newaction(_("Load &all revisions"), self.loadall,
                   enabled='repoopen', menu='view', shortcut='Shift+Ctrl+A',
                   tooltip=_('Load all revisions into graph'))
         newaction(_("&Goto revision..."), self.gotorev,
                   enabled='repoopen', menu='view', shortcut='Ctrl+/',
                   tooltip=_('Go to a specific revision'))
 
-        newaction(_("Web Server..."), self.serve, enabled='repoopen',
+        newaction(_("&Web Server..."), self.serve, enabled='repoopen',
                   menu='repository')
         newseparator(menu='repository')
-        newaction(_("Shelve..."), self._repofwd('shelve'), icon='shelve',
+
+        for synctaskname in synctaskdefs:
+            synctaskdef = synctaskdefs.get(synctaskname)
+            newaction(synctaskdef[0], self._repofwd(synctaskdef[1]), icon=synctaskdef[2],
+                      tooltip=synctaskdef[3],
+                      enabled='repoopen', menu='repository')
+
+        newseparator(menu='repository')
+
+        newaction(_("S&helve..."), self._repofwd('shelve'), icon='shelve',
                   enabled='repoopen', menu='repository')
-        newaction(_("Import..."), self._repofwd('thgimport'), icon='hg-import',
+        newaction(_("Impor&t..."), self._repofwd('thgimport'), icon='hg-import',
                   enabled='repoopen', menu='repository')
         newseparator(menu='repository')
-        newaction(_("Verify"), self._repofwd('verify'), enabled='repoopen',
+        newaction(_("&Verify"), self._repofwd('verify'), enabled='repoopen',
                   menu='repository')
-        newaction(_("Recover"), self._repofwd('recover'),
+        newaction(_("&Recover"), self._repofwd('recover'),
                   enabled='repoopen', menu='repository')
         newseparator(menu='repository')
-        newaction(_("Resolve..."), self._repofwd('resolve'), icon='hg-merge',
+        newaction(_("Re&solve..."), self._repofwd('resolve'), icon='hg-merge',
                   enabled='repoopen', menu='repository')
         newseparator(menu='repository')
-        newaction(_("Rollback/Undo..."), self._repofwd('rollback'),
+        newaction(_("Rollback/&Undo..."), self._repofwd('rollback'),
                   shortcut='Ctrl+u',
                   enabled='repoopen', menu='repository')
         newseparator(menu='repository')
-        newaction(_("Purge..."), self._repofwd('purge'), enabled='repoopen',
+        newaction(_("Pur&ge..."), self._repofwd('purge'), enabled='repoopen',
                   icon='hg-purge', menu='repository')
         newseparator(menu='repository')
-        newaction(_("Bisect..."), self._repofwd('bisect'),
+        newaction(_("Bise&ct..."), self._repofwd('bisect'),
                   enabled='repoopen', menu='repository')
         newseparator(menu='repository')
-        newaction(_("Explore"), self.explore, shortcut='Shift+Ctrl+X',
+        newaction(_("E&xplore"), self.explore, shortcut='Shift+Ctrl+X',
                   icon='system-file-manager', enabled='repoopen',
                   menu='repository')
-        newaction(_("Terminal"), self.terminal, shortcut='Shift+Ctrl+T',
+        newaction(_("Ter&minal"), self.terminal, shortcut='Shift+Ctrl+T',
                   icon='utilities-terminal', enabled='repoopen',
                   menu='repository')
 
-        newaction(_("Help"), self.onHelp, menu='help', icon='help-browser')
+        newaction(_("&Help"), self.onHelp, menu='help', icon='help-browser')
         visiblereadme = 'repoopen'
         if  self.ui.config('tortoisehg', 'readme', None):
             visiblereadme = True
-        newaction(_("README"), self.onReadme, menu='help', icon='help-readme',
+        newaction(_("&README"), self.onReadme, menu='help', icon='help-readme',
                   visible=visiblereadme, shortcut='Ctrl+F1')
         newseparator(menu='help')
-        newaction(_("About Qt"), QApplication.aboutQt, menu='help')
-        newaction(_("About TortoiseHg"), self.onAbout, menu='help',
+        newaction(_("About &Qt"), QApplication.aboutQt, menu='help')
+        newaction(_("About &TortoiseHg"), self.onAbout, menu='help',
                   icon='thg-logo')
 
         newseparator(toolbar='edit')
         newseparator(toolbar='edit', menu='View')
 
         self.filtertbaction = \
-        newaction(_('Filter Toolbar'), self._repotogglefwd('toggleFilterBar'),
+        newaction(_('&Filter Toolbar'), self._repotogglefwd('toggleFilterBar'),
                   icon='view-filter', shortcut='Ctrl+S', enabled='repoopen',
                   toolbar='edit', menu='View', checkable=True,
                   tooltip=_('Filter graph with revision sets or branches'))
 
-        menu = QMenu(_('Workbench Toolbars'), self)
+        menu = QMenu(_('Workbench Tool&bars'), self)
         menu.addAction(self.edittbar.toggleViewAction())
         menu.addAction(self.docktbar.toggleViewAction())
         menu.addAction(self.synctbar.toggleViewAction())
         menu.addAction(self.customtbar.toggleViewAction())
         self.menuView.addMenu(menu)
 
-        newaction(_('Incoming'), self._repofwd('incoming'), icon='hg-incoming',
-                  tooltip=_('Check for incoming changes from selected URL'),
-                  enabled='repoopen', toolbar='sync')
-        newaction(_('Pull'), self._repofwd('pull'), icon='hg-pull',
-                  tooltip=_('Pull incoming changes from selected URL'),
-                  enabled='repoopen', toolbar='sync')
-        newaction(_('Outgoing'), self._repofwd('outgoing'), icon='hg-outgoing',
-                   tooltip=_('Detect outgoing changes to selected URL'),
-                   enabled='repoopen', toolbar='sync')
-        newaction(_('Push'), self._repofwd('push'), icon='hg-push',
-                  tooltip=_('Push outgoing changes to selected URL'),
-                  enabled='repoopen', toolbar='sync')
+        for synctaskname in synctaskdefs:
+            synctaskdef = synctaskdefs.get(synctaskname)
+            newaction(synctaskdef[0], self._repofwd(synctaskdef[1]), icon=synctaskdef[2],
+                      tooltip=synctaskdef[3],
+                      enabled='repoopen', toolbar='sync')
 
         self.updateMenu()