Source

thg-qt-mq / reporeg-moveactions.diff

Full commit
# HG changeset patch
# Parent 59b43c6684fb69066a0e6572c0a1ca7ef455a749
reporegistry: move QAction instances for settings from workbench

This prepares to unify boolean flags and QAction instances.

diff --git a/tortoisehg/hgqt/reporegistry.py b/tortoisehg/hgqt/reporegistry.py
--- a/tortoisehg/hgqt/reporegistry.py
+++ b/tortoisehg/hgqt/reporegistry.py
@@ -232,6 +232,7 @@ class RepoRegistryView(QDockWidget):
         self.showSubrepos = showSubrepos
         self.showNetworkSubrepos = showNetworkSubrepos
         self.showShortPaths = showShortPaths
+        self._setupSettingActions()
 
         self.setFeatures(QDockWidget.DockWidgetClosable |
                          QDockWidget.DockWidgetMovable  |
@@ -280,6 +281,25 @@ class RepoRegistryView(QDockWidget):
         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
diff --git a/tortoisehg/hgqt/workbench.py b/tortoisehg/hgqt/workbench.py
--- a/tortoisehg/hgqt/workbench.py
+++ b/tortoisehg/hgqt/workbench.py
@@ -203,24 +203,7 @@ class Workbench(QMainWindow):
 
         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,
@@ -1017,11 +1000,11 @@ class Workbench(QMainWindow):
         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 = ''
@@ -1064,9 +1047,9 @@ class Workbench(QMainWindow):
 
         # 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()
@@ -1103,7 +1086,7 @@ class Workbench(QMainWindow):
 
         # 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):