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

branch
eric7
changeset 9421
989ee2535d59
parent 9413
80c06d472826
child 9473
3f23dbf37dbe
--- a/src/eric7/Plugins/VcsPlugins/vcsMercurial/ProjectBrowserHelper.py	Tue Oct 18 17:48:03 2022 +0200
+++ b/src/eric7/Plugins/VcsPlugins/vcsMercurial/ProjectBrowserHelper.py	Wed Oct 19 13:39:16 2022 +0200
@@ -11,14 +11,15 @@
 
 from PyQt6.QtWidgets import QMenu, QDialog
 
+from eric7.EricGui import EricPixmapCache
+
+from eric7.EricWidgets import EricMessageBox
 from eric7.EricWidgets.EricApplication import ericApp
 
 from eric7.Project.ProjectBrowserModel import ProjectBrowserFileItem
 
 from eric7.VCS.ProjectBrowserHelper import VcsProjectBrowserHelper
 
-from eric7.EricGui import EricPixmapCache
-
 
 class HgProjectBrowserHelper(VcsProjectBrowserHelper):
     """
@@ -122,8 +123,11 @@
                 act.setEnabled(False)
             for act in standardItems:
                 act.setEnabled(False)
-            if not hasattr(self.browser.currentItem(), "fileName"):
-                self.annotateAct.setEnabled(False)
+            self.annotateAct.setEnabled(hasattr(self.browser.currentItem(), "fileName"))
+            self.annotateSkipAct.setEnabled(
+                os.path.exists(self.__skipListFileName())
+                and hasattr(self.browser.currentItem(), "fileName")
+            )
         else:
             controlled = False
             for act in self.vcsMenuActions:
@@ -370,10 +374,19 @@
             self.__HgSbsExtendedDiff,
         )
         self.vcsMenuActions.append(act)
+        menu.addSeparator()
         self.annotateAct = menu.addAction(
             self.tr("Show annotated file"), self.__HgAnnotate
         )
         self.vcsMenuActions.append(self.annotateAct)
+        self.annotateSkipAct = menu.addAction(
+            self.tr("Show annotated file with skip list"), self.__HgAnnotateSkip
+        )
+        self.vcsMenuActions.append(self.annotateSkipAct)
+        self.annotateSkipListAct = menu.addAction(
+            self.tr("Create skip list file"), self.__HgAnnotateSkipListFile
+        )
+        self.vcsMenuActions.append(self.annotateSkipListAct)
         menu.addSeparator()
         act = menu.addAction(
             EricPixmapCache.getIcon("vcsRevert"),
@@ -861,6 +874,55 @@
         fn = itm.fileName()
         self.vcs.hgAnnotate(fn)
 
+    def __HgAnnotateSkip(self):
+        """
+        Private slot called by the context menu to show the annotations of a
+        file with a project specific skip list.
+        """
+        itm = self.browser.currentItem()
+        fn = itm.fileName()
+        self.vcs.hgAnnotate(fn, skiplist=self.__skipListFileName())
+
+    def __HgAnnotateSkipListFile(self):
+        """
+        Private method to create an empty 'hg annotate' skip list file.
+        """
+        skipList = self.__skipListFileName()
+        res = (
+            EricMessageBox.yesNo(
+                self.browser,
+                self.tr("Create {0} file").format(skipList),
+                self.tr(
+                    """<p>The file <b>{0}</b> exists already."""
+                    """ Overwrite it?</p>"""
+                ).format(skipList),
+                icon=EricMessageBox.Warning,
+            )
+            if os.path.exists(skipList)
+            else True
+        )
+        if res:
+            try:
+                # create a .hgannotate_skiplist file
+                with open(skipList, "w") as skip:
+                    skip.write("\n")
+                status = True
+            except OSError:
+                status = False
+
+            if status:
+                self.vcs.vcsAdd(skipList, noDialog=True)
+                self.project.appendFile(skipList)
+
+    def __skipListFileName(self):
+        """
+        Private method to generate the file name for a 'hg annotate' skip list file.
+
+        @return name of the skip list file
+        @rtype str
+        """
+        return os.path.join(self.project.getProjectPath(), ".hgannotate_skiplist")
+
     def __HgResolved(self):
         """
         Private slot called by the context menu to mark conflicts of a file

eric ide

mercurial