eric6/Plugins/VcsPlugins/vcsMercurial/StripExtension/ProjectHelper.py

Mon, 12 Oct 2020 18:23:44 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 12 Oct 2020 18:23:44 +0200
changeset 7780
41420f82c0ac
parent 7533
88261c96484b
child 7923
91e843545d9a
permissions
-rw-r--r--

Performed some code cleanup.

5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7257
diff changeset
3 # Copyright (c) 2016 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the strip extension project helper.
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt5.QtWidgets import QMenu
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from E5Gui.E5Action import E5Action
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from E5Gui import E5MessageBox
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from ..HgExtensionProjectHelper import HgExtensionProjectHelper
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import UI.PixmapCache
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class StripProjectHelper(HgExtensionProjectHelper):
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing the strip extension project helper.
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 def __init__(self):
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 super(StripProjectHelper, self).__init__()
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 def initActions(self):
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Public method to generate the action objects.
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.hgStripAct = E5Action(
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.tr('Strip changesets'),
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
36 UI.PixmapCache.getIcon("fileDelete"),
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.tr('Strip changesets'),
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 0, 0, self, 'mercurial_strip')
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.hgStripAct.setStatusTip(self.tr(
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 'Strip changesets from a repository'
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 ))
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.hgStripAct.setWhatsThis(self.tr(
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 """<b>Strip changesets</b>"""
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """<p>This deletes a changeset and all its descendants"""
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """ from a repository. Each removed changeset will be"""
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """ stored in .hg/strip-backup as a bundle file.</p>"""
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 ))
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.hgStripAct.triggered.connect(self.__hgStrip)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.actions.append(self.hgStripAct)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 def initMenu(self, mainMenu):
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 Public method to generate the extension menu.
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
5270
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
55 @param mainMenu reference to the main menu
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
56 @type QMenu
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @return populated menu (QMenu)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 menu = QMenu(self.menuTitle(), mainMenu)
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
60 menu.setIcon(UI.PixmapCache.getIcon("fileDelete"))
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 menu.setTearOffEnabled(True)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 menu.addAction(self.hgStripAct)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 return menu
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 def menuTitle(self):
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 Public method to get the menu title.
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
5270
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
71 @return title of the menu
7758f0c7d9f6 Added support for the strip and fetch extensions to the log browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5268
diff changeset
72 @rtype str
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 return self.tr("Strip")
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 def __hgStrip(self):
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 """
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 Private slot used to strip revisions from a repository.
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
80 shouldReopen = self.vcs.getExtensionObject("strip").hgStrip(
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
81 self.project.getProjectPath())
5268
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 if shouldReopen:
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 res = E5MessageBox.yesNo(
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 None,
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.tr("Strip"),
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.tr("""The project should be reread. Do this now?"""),
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 yesDefault=True)
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 if res:
748e4c50523b Added support for the Mercurial strip extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.project.reopenProject()

eric ide

mercurial