src/eric7/Plugins/VcsPlugins/vcsMercurial/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 HgProjectBrowserHelper(VcsProjectBrowserHelper): 24 class HgProjectBrowserHelper(VcsProjectBrowserHelper):
24 """ 25 """
25 Class implementing the VCS project browser helper for Mercurial. 26 Class implementing the VCS project browser helper for Mercurial.
120 act.setEnabled(True) 121 act.setEnabled(True)
121 for act in self.vcsAddMenuActions: 122 for act in self.vcsAddMenuActions:
122 act.setEnabled(False) 123 act.setEnabled(False)
123 for act in standardItems: 124 for act in standardItems:
124 act.setEnabled(False) 125 act.setEnabled(False)
125 if not hasattr(self.browser.currentItem(), "fileName"): 126 self.annotateAct.setEnabled(hasattr(self.browser.currentItem(), "fileName"))
126 self.annotateAct.setEnabled(False) 127 self.annotateSkipAct.setEnabled(
128 os.path.exists(self.__skipListFileName())
129 and hasattr(self.browser.currentItem(), "fileName")
130 )
127 else: 131 else:
128 controlled = False 132 controlled = False
129 for act in self.vcsMenuActions: 133 for act in self.vcsMenuActions:
130 act.setEnabled(False) 134 act.setEnabled(False)
131 for act in self.vcsAddMenuActions: 135 for act in self.vcsAddMenuActions:
368 EricPixmapCache.getIcon("vcsSbsDiff"), 372 EricPixmapCache.getIcon("vcsSbsDiff"),
369 self.tr("Show differences side-by-side (extended)"), 373 self.tr("Show differences side-by-side (extended)"),
370 self.__HgSbsExtendedDiff, 374 self.__HgSbsExtendedDiff,
371 ) 375 )
372 self.vcsMenuActions.append(act) 376 self.vcsMenuActions.append(act)
377 menu.addSeparator()
373 self.annotateAct = menu.addAction( 378 self.annotateAct = menu.addAction(
374 self.tr("Show annotated file"), self.__HgAnnotate 379 self.tr("Show annotated file"), self.__HgAnnotate
375 ) 380 )
376 self.vcsMenuActions.append(self.annotateAct) 381 self.vcsMenuActions.append(self.annotateAct)
382 self.annotateSkipAct = menu.addAction(
383 self.tr("Show annotated file with skip list"), self.__HgAnnotateSkip
384 )
385 self.vcsMenuActions.append(self.annotateSkipAct)
386 self.annotateSkipListAct = menu.addAction(
387 self.tr("Create skip list file"), self.__HgAnnotateSkipListFile
388 )
389 self.vcsMenuActions.append(self.annotateSkipListAct)
377 menu.addSeparator() 390 menu.addSeparator()
378 act = menu.addAction( 391 act = menu.addAction(
379 EricPixmapCache.getIcon("vcsRevert"), 392 EricPixmapCache.getIcon("vcsRevert"),
380 self.tr("Revert changes"), 393 self.tr("Revert changes"),
381 self.__HgRevert, 394 self.__HgRevert,
859 """ 872 """
860 itm = self.browser.currentItem() 873 itm = self.browser.currentItem()
861 fn = itm.fileName() 874 fn = itm.fileName()
862 self.vcs.hgAnnotate(fn) 875 self.vcs.hgAnnotate(fn)
863 876
877 def __HgAnnotateSkip(self):
878 """
879 Private slot called by the context menu to show the annotations of a
880 file with a project specific skip list.
881 """
882 itm = self.browser.currentItem()
883 fn = itm.fileName()
884 self.vcs.hgAnnotate(fn, skiplist=self.__skipListFileName())
885
886 def __HgAnnotateSkipListFile(self):
887 """
888 Private method to create an empty 'hg annotate' skip list file.
889 """
890 skipList = self.__skipListFileName()
891 res = (
892 EricMessageBox.yesNo(
893 self.browser,
894 self.tr("Create {0} file").format(skipList),
895 self.tr(
896 """<p>The file <b>{0}</b> exists already."""
897 """ Overwrite it?</p>"""
898 ).format(skipList),
899 icon=EricMessageBox.Warning,
900 )
901 if os.path.exists(skipList)
902 else True
903 )
904 if res:
905 try:
906 # create a .hgannotate_skiplist file
907 with open(skipList, "w") as skip:
908 skip.write("\n")
909 status = True
910 except OSError:
911 status = False
912
913 if status:
914 self.vcs.vcsAdd(skipList, noDialog=True)
915 self.project.appendFile(skipList)
916
917 def __skipListFileName(self):
918 """
919 Private method to generate the file name for a 'hg annotate' skip list file.
920
921 @return name of the skip list file
922 @rtype str
923 """
924 return os.path.join(self.project.getProjectPath(), ".hgannotate_skiplist")
925
864 def __HgResolved(self): 926 def __HgResolved(self):
865 """ 927 """
866 Private slot called by the context menu to mark conflicts of a file 928 Private slot called by the context menu to mark conflicts of a file
867 as being resolved. 929 as being resolved.
868 """ 930 """

eric ide

mercurial