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

branch
eric7
changeset 9421
989ee2535d59
parent 9413
80c06d472826
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9420:92810aebc909 9421:989ee2535d59
9 9
10 import os 10 import os
11 11
12 from PyQt6.QtWidgets import QMenu, QDialog 12 from PyQt6.QtWidgets import QMenu, QDialog
13 13
14 from eric7.EricGui import EricPixmapCache
15
16 from eric7.EricWidgets import EricMessageBox
14 from eric7.EricWidgets.EricApplication import ericApp 17 from eric7.EricWidgets.EricApplication import ericApp
15 18
16 from eric7.Project.ProjectBrowserModel import ProjectBrowserFileItem 19 from eric7.Project.ProjectBrowserModel import ProjectBrowserFileItem
17 20
18 from eric7.VCS.ProjectBrowserHelper import VcsProjectBrowserHelper 21 from eric7.VCS.ProjectBrowserHelper import VcsProjectBrowserHelper
19
20 from eric7.EricGui import EricPixmapCache
21 22
22 23
23 class GitProjectBrowserHelper(VcsProjectBrowserHelper): 24 class GitProjectBrowserHelper(VcsProjectBrowserHelper):
24 """ 25 """
25 Class implementing the VCS project browser helper for Git. 26 Class implementing the VCS project browser helper for Git.
69 if self.browser.currentItem().data(1) == self.vcs.vcsName(): 70 if self.browser.currentItem().data(1) == self.vcs.vcsName():
70 for act in self.vcsMenuActions: 71 for act in self.vcsMenuActions:
71 act.setEnabled(True) 72 act.setEnabled(True)
72 for act in standardItems: 73 for act in standardItems:
73 act.setEnabled(False) 74 act.setEnabled(False)
75 # special conditions below
76 self.annotateSkipAct.setEnabled(os.path.exists(self.__skipListFileName()))
74 else: 77 else:
75 for act in self.vcsMenuActions: 78 for act in self.vcsMenuActions:
76 act.setEnabled(False) 79 act.setEnabled(False)
77 for act in standardItems: 80 for act in standardItems:
78 act.setEnabled(True) 81 act.setEnabled(True)
273 menu.addSeparator() 276 menu.addSeparator()
274 self.annotateAct = menu.addAction( 277 self.annotateAct = menu.addAction(
275 self.tr("Show annotated file"), self.__GitBlame 278 self.tr("Show annotated file"), self.__GitBlame
276 ) 279 )
277 self.vcsMenuActions.append(self.annotateAct) 280 self.vcsMenuActions.append(self.annotateAct)
281 self.annotateSkipAct = menu.addAction(
282 self.tr("Show annotated file with skip list"), self.__GitBlameSkip
283 )
284 self.vcsMenuActions.append(self.annotateSkipAct)
285 self.annotateSkipListAct = menu.addAction(
286 self.tr("Create skip list file"), self.__GitBlameSkipListFile
287 )
288 self.vcsMenuActions.append(self.annotateSkipListAct)
278 menu.addSeparator() 289 menu.addSeparator()
279 act = menu.addAction( 290 act = menu.addAction(
280 EricPixmapCache.getIcon("vcsRevert"), 291 EricPixmapCache.getIcon("vcsRevert"),
281 self.tr("Revert changes"), 292 self.tr("Revert changes"),
282 self.__GitRevert, 293 self.__GitRevert,
808 file. 819 file.
809 """ 820 """
810 itm = self.browser.currentItem() 821 itm = self.browser.currentItem()
811 fn = itm.fileName() 822 fn = itm.fileName()
812 self.vcs.gitBlame(fn) 823 self.vcs.gitBlame(fn)
824
825 def __GitBlameSkip(self):
826 """
827 Private slot called by the context menu to show the annotations of a
828 file with a project specific skip list.
829 """
830 itm = self.browser.currentItem()
831 fn = itm.fileName()
832 self.vcs.gitBlame(fn, skiplist=self.__skipListFileName())
833
834 def __GitBlameSkipListFile(self):
835 """
836 Private method to create an empty 'git blame' skip list file.
837 """
838 skipList = self.__skipListFileName()
839 res = (
840 EricMessageBox.yesNo(
841 self.browser,
842 self.tr("Create {0} file").format(skipList),
843 self.tr(
844 """<p>The file <b>{0}</b> exists already."""
845 """ Overwrite it?</p>"""
846 ).format(skipList),
847 icon=EricMessageBox.Warning,
848 )
849 if os.path.exists(skipList)
850 else True
851 )
852 if res:
853 try:
854 # create a .gitblame_skiplist file
855 with open(skipList, "w") as skip:
856 skip.write("\n")
857 status = True
858 except OSError:
859 status = False
860
861 if status:
862 self.vcs.vcsAdd(skipList, noDialog=True)
863 self.project.appendFile(skipList)
864
865 def __skipListFileName(self):
866 """
867 Private method to generate the file name for a 'git blame' skip list file.
868
869 @return name of the skip list file
870 @rtype str
871 """
872 return os.path.join(self.project.getProjectPath(), ".gitblame_skiplist")

eric ide

mercurial