Commits

Yuya Nishihara committed f7136d8

reporegistry: move QAction instances for settings from workbench

This prepares to unify boolean flags and QAction instances.

  • Participants
  • Parent commits c3fad48

Comments (0)

Files changed (2)

tortoisehg/hgqt/reporegistry.py

         self.showSubrepos = showSubrepos
         self.showNetworkSubrepos = showNetworkSubrepos
         self.showShortPaths = showShortPaths
+        self._setupSettingActions()
 
         self.setFeatures(QDockWidget.DockWidgetClosable |
                          QDockWidget.DockWidgetMovable  |
         self._pendingReloadModel = False
         self._activeTabRepo = None
 
+    def _setupSettingActions(self):
+        def newaction(text, slot):
+            a = QAction(text, self, checkable=True)
+            a.toggled.connect(slot)
+            return a
+
+        self._actionShowPaths = newaction(_("Show Paths"), self.showPaths)
+        self._actionShowSubrepos = newaction(_("Show Subrepos on Registry"),
+                                             self.setShowSubrepos)
+        self._actionShowNetworkSubrepos = newaction(_("Show Subrepos for "
+                                                      "remote repositories"),
+                                                    self.setShowNetworkSubrepos)
+        self._actionShowShortPaths = newaction(_("Show Short Paths"),
+                                               self.setShowShortPaths)
+
+    def settingActions(self):
+        return [self._actionShowPaths, self._actionShowSubrepos,
+                self._actionShowNetworkSubrepos, self._actionShowShortPaths]
+
     def setShowSubrepos(self, show, reloadModel=True):
         if self.showSubrepos != show:
             self.showSubrepos = show

tortoisehg/hgqt/workbench.py

 
         newseparator(menu='view')
         self.menuViewregistryopts = self.menuView.addMenu(_('Repository Registry Options'))
-        self.actionShowPaths = \
-        newaction(_("Show Paths"), self.reporegistry.showPaths,
-                  checkable=True, menu='viewregistryopts')
-
-        self.actionShowSubrepos = \
-            newaction(_("Show Subrepos on Registry"),
-                self.reporegistry.setShowSubrepos,
-                  checkable=True, menu='viewregistryopts')
-
-        self.actionShowNetworkSubrepos = \
-            newaction(_("Show Subrepos for remote repositories"),
-                self.reporegistry.setShowNetworkSubrepos,
-                  checkable=True, menu='viewregistryopts')
-
-        self.actionShowShortPaths = \
-            newaction(_("Show Short Paths"),
-                self.reporegistry.setShowShortPaths,
-                  checkable=True, menu='viewregistryopts')
+        self.menuViewregistryopts.addActions(self.reporegistry.settingActions())
 
         newseparator(menu='view')
         newaction(_("Choose Log Columns..."), self.setHistoryColumns,
         wb = "Workbench/"
         s.setValue(wb + 'geometry', self.saveGeometry())
         s.setValue(wb + 'windowState', self.saveState())
-        s.setValue(wb + 'showPaths', self.actionShowPaths.isChecked())
-        s.setValue(wb + 'showSubrepos', self.actionShowSubrepos.isChecked())
+        s.setValue(wb + 'showPaths', self.reporegistry._actionShowPaths.isChecked())
+        s.setValue(wb + 'showSubrepos', self.reporegistry._actionShowSubrepos.isChecked())
         s.setValue(wb + 'showNetworkSubrepos',
-            self.actionShowNetworkSubrepos.isChecked())
-        s.setValue(wb + 'showShortPaths', self.actionShowShortPaths.isChecked())
+            self.reporegistry._actionShowNetworkSubrepos.isChecked())
+        s.setValue(wb + 'showShortPaths', self.reporegistry._actionShowShortPaths.isChecked())
         s.setValue(wb + 'saveRepos', self.actionSaveRepos.isChecked())
         repostosave = []
         lastactiverepo = ''
 
         # Note that calling setChecked will NOT reload the model if the new
         # setting is the same as the one in the repo registry
-        QTimer.singleShot(0, lambda: self.actionShowSubrepos.setChecked(ssr))
-        QTimer.singleShot(0, lambda: self.actionShowNetworkSubrepos.setChecked(snsr))
-        QTimer.singleShot(0, lambda: self.actionShowShortPaths.setChecked(ssp))
+        QTimer.singleShot(0, lambda: self.reporegistry._actionShowSubrepos.setChecked(ssr))
+        QTimer.singleShot(0, lambda: self.reporegistry._actionShowNetworkSubrepos.setChecked(snsr))
+        QTimer.singleShot(0, lambda: self.reporegistry._actionShowShortPaths.setChecked(ssp))
 
         # Manually reload the model now, to apply the settings
         self.reporegistry.reloadModel()
 
         # Allow repo registry to assemble itself before toggling path state
         sp = s.value(wb + 'showPaths').toBool()
-        QTimer.singleShot(0, lambda: self.actionShowPaths.setChecked(sp))
+        QTimer.singleShot(0, lambda: self.reporegistry._actionShowPaths.setChecked(sp))
 
     def goto(self, root, rev):
         for rw in self._findrepowidget(root):