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

branch
eric7
changeset 9421
989ee2535d59
parent 9413
80c06d472826
child 9473
3f23dbf37dbe
--- a/src/eric7/Plugins/VcsPlugins/vcsGit/ProjectBrowserHelper.py	Tue Oct 18 17:48:03 2022 +0200
+++ b/src/eric7/Plugins/VcsPlugins/vcsGit/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 GitProjectBrowserHelper(VcsProjectBrowserHelper):
     """
@@ -71,6 +72,8 @@
                 act.setEnabled(True)
             for act in standardItems:
                 act.setEnabled(False)
+            # special conditions below
+            self.annotateSkipAct.setEnabled(os.path.exists(self.__skipListFileName()))
         else:
             for act in self.vcsMenuActions:
                 act.setEnabled(False)
@@ -275,6 +278,14 @@
             self.tr("Show annotated file"), self.__GitBlame
         )
         self.vcsMenuActions.append(self.annotateAct)
+        self.annotateSkipAct = menu.addAction(
+            self.tr("Show annotated file with skip list"), self.__GitBlameSkip
+        )
+        self.vcsMenuActions.append(self.annotateSkipAct)
+        self.annotateSkipListAct = menu.addAction(
+            self.tr("Create skip list file"), self.__GitBlameSkipListFile
+        )
+        self.vcsMenuActions.append(self.annotateSkipListAct)
         menu.addSeparator()
         act = menu.addAction(
             EricPixmapCache.getIcon("vcsRevert"),
@@ -810,3 +821,52 @@
         itm = self.browser.currentItem()
         fn = itm.fileName()
         self.vcs.gitBlame(fn)
+
+    def __GitBlameSkip(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.gitBlame(fn, skiplist=self.__skipListFileName())
+
+    def __GitBlameSkipListFile(self):
+        """
+        Private method to create an empty 'git blame' 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 .gitblame_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 'git blame' skip list file.
+
+        @return name of the skip list file
+        @rtype str
+        """
+        return os.path.join(self.project.getProjectPath(), ".gitblame_skiplist")

eric ide

mercurial