src/eric7/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py

branch
eric7
changeset 10215
d476667171a1
parent 10214
de0718b80010
child 10372
1444b4bee64b
diff -r de0718b80010 -r d476667171a1 src/eric7/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py
--- a/src/eric7/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py	Mon Sep 25 12:09:23 2023 +0200
+++ b/src/eric7/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py	Tue Sep 26 18:26:21 2023 +0200
@@ -26,6 +26,7 @@
 )
 from PyQt6.QtWidgets import (
     QApplication,
+    QDialog,
     QDialogButtonBox,
     QHeaderView,
     QInputDialog,
@@ -224,6 +225,7 @@
         self.__initData()
 
         self.__allBranchesFilter = self.tr("All")
+        self.__branchesFilterList = []  # list of branches to retrieve via hg
 
         self.fromDate.setDisplayFormat("yyyy-MM-dd")
         self.toDate.setDisplayFormat("yyyy-MM-dd")
@@ -290,10 +292,52 @@
         """
         Private method to initialize the actions menu.
         """
+        # create the "View" submenu
+        self.__viewMenu = QMenu(self.tr("View"))
+        self.__viewMenu.addAction(
+            self.tr("Select Branches"), lambda: self.__selectBranches(stateFilter=None)
+        ).setToolTip(
+            self.tr(
+                "Select the branches to be shown from a list of all branches and"
+                " refresh the display"
+            )
+        )
+        self.__viewMenu.addAction(
+            self.tr("Select Branches (active branches only)"),
+            lambda: self.__selectBranches(stateFilter=[""]),
+        ).setToolTip(
+            self.tr(
+                "Select the branches to be shown from a list of active branches and"
+                " refresh the display"
+            )
+        )
+        self.__viewMenu.addAction(
+            self.tr("Select Branches (inactive branches only)"),
+            lambda: self.__selectBranches(stateFilter=["I"]),
+        ).setToolTip(
+            self.tr(
+                "Select the branches to be shown from a list of inactive branches and"
+                " refresh the display"
+            )
+        )
+        self.__viewMenu.addAction(
+            self.tr("Select Branches (closed branches only)"),
+            lambda: self.__selectBranches(stateFilter=["C"]),
+        ).setToolTip(
+            self.tr(
+                "Select the branches to be shown from a list of closed branches and"
+                " refresh the display"
+            )
+        )
+
+        # create the main actions menu
         self.__actionsMenu = QMenu()
         self.__actionsMenu.setTearOffEnabled(True)
         self.__actionsMenu.setToolTipsVisible(True)
 
+        self.__actionsMenu.addMenu(self.__viewMenu)
+        self.__actionsMenu.addSeparator()
+
         self.__graftAct = self.__actionsMenu.addAction(
             EricPixmapCache.getIcon("vcsGraft"),
             self.tr("Copy Changesets"),
@@ -1086,6 +1130,8 @@
                     "logBrowserBookmarkPhase.tmpl",
                 )
             )
+            for branch in self.__branchesFilterList:
+                args.extend(["--branch", branch])
             if self.commandMode == "incoming":
                 if self.__bundle:
                     args.append(self.__bundle)
@@ -2899,3 +2945,44 @@
             if scheme == "sbsdiff" and "_" in path:
                 rev1, rev2 = path.split("_", 1)
                 self.vcs.vcsSbsDiff(self.__filename, revisions=(rev1, rev2))
+
+    def __selectBranches(self, stateFilter=None):
+        """
+        Private slot to select the branches to be shown.
+
+        @param stateFilter list of state filters ("", "C" or "I") to be presented for
+            selection (None or empty list  means all) (defaults to None)
+        @type list of str (optional)
+        """
+        from eric7.EricWidgets.EricListSelectionDialog import EricListSelectionDialog
+
+        states = {
+            "C": self.tr("closed"),
+            "I": self.tr("inactive"),
+        }
+
+        if not stateFilter:
+            stateFilter = ["", "C", "I"]
+
+        rawBranchesList = self.vcs.hgGetBranchesList(withState=True, withDefault=True)
+        branchesList = sorted(
+            (
+                b[0] if b[1] == "" else self.tr("{0} ({1})").format(b[0], states[b[1]]),
+                b[0],
+            )
+            for b in rawBranchesList
+            if b[1] in stateFilter
+        )
+        dlg = EricListSelectionDialog(
+            branchesList,
+            title=self.tr("Select Branches"),
+            message=self.tr("Select the branches to be shown (none for 'All'):"),
+            checkBoxSelection=True,
+            emptySelectionOk=True,
+            showSelectAll=True,
+            parent=self,
+        )
+        dlg.setSelection(self.__branchesFilterList)
+        if dlg.exec() == QDialog.DialogCode.Accepted:
+            self.__branchesFilterList = [b[1] for b in dlg.getSelection()]
+            self.on_refreshButton_clicked()

eric ide

mercurial