1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the fetch extension project helper. |
|
8 """ |
|
9 |
|
10 |
|
11 from PyQt5.QtWidgets import QMenu |
|
12 |
|
13 from E5Gui.E5Action import E5Action |
|
14 from E5Gui import E5MessageBox |
|
15 |
|
16 from ..HgExtensionProjectHelper import HgExtensionProjectHelper |
|
17 |
|
18 import UI.PixmapCache |
|
19 |
|
20 |
|
21 class FetchProjectHelper(HgExtensionProjectHelper): |
|
22 """ |
|
23 Class implementing the fetch extension project helper. |
|
24 """ |
|
25 def __init__(self): |
|
26 """ |
|
27 Constructor |
|
28 """ |
|
29 super(FetchProjectHelper, self).__init__() |
|
30 |
|
31 def initActions(self): |
|
32 """ |
|
33 Public method to generate the action objects. |
|
34 """ |
|
35 self.hgFetchAct = E5Action( |
|
36 self.tr('Fetch changes'), |
|
37 UI.PixmapCache.getIcon("vcsUpdate"), |
|
38 self.tr('Fetch changes'), |
|
39 0, 0, self, 'mercurial_fetch') |
|
40 self.hgFetchAct.setStatusTip(self.tr( |
|
41 'Fetch changes from a remote repository' |
|
42 )) |
|
43 self.hgFetchAct.setWhatsThis(self.tr( |
|
44 """<b>Fetch changes</b>""" |
|
45 """<p>This pulls changes from a remote repository into the """ |
|
46 """local repository. If the pulled changes add a new branch""" |
|
47 """ head, the head is automatically merged, and the result of""" |
|
48 """ the merge is committed. Otherwise, the working directory""" |
|
49 """ is updated to include the new changes.</p>""" |
|
50 )) |
|
51 self.hgFetchAct.triggered.connect(self.__hgFetch) |
|
52 self.actions.append(self.hgFetchAct) |
|
53 |
|
54 def initMenu(self, mainMenu): |
|
55 """ |
|
56 Public method to generate the extension menu. |
|
57 |
|
58 @param mainMenu reference to the main menu (QMenu) |
|
59 @return populated menu (QMenu) |
|
60 """ |
|
61 menu = QMenu(self.menuTitle(), mainMenu) |
|
62 menu.setIcon(UI.PixmapCache.getIcon("vcsUpdate")) |
|
63 menu.setTearOffEnabled(True) |
|
64 |
|
65 menu.addAction(self.hgFetchAct) |
|
66 |
|
67 menu.aboutToShow.connect(self.__aboutToShowMenu) |
|
68 |
|
69 return menu |
|
70 |
|
71 def __aboutToShowMenu(self): |
|
72 """ |
|
73 Private slot to handle the aboutToShow signal of the background menu. |
|
74 """ |
|
75 self.hgFetchAct.setEnabled(self.vcs.canPull()) |
|
76 |
|
77 def menuTitle(self): |
|
78 """ |
|
79 Public method to get the menu title. |
|
80 |
|
81 @return title of the menu (string) |
|
82 """ |
|
83 return self.tr("Fetch") |
|
84 |
|
85 def __hgFetch(self): |
|
86 """ |
|
87 Private slot used to fetch changes from a remote repository. |
|
88 """ |
|
89 shouldReopen = self.vcs.getExtensionObject("fetch").hgFetch( |
|
90 self.project.getProjectPath()) |
|
91 if shouldReopen: |
|
92 res = E5MessageBox.yesNo( |
|
93 None, |
|
94 self.tr("Fetch"), |
|
95 self.tr("""The project should be reread. Do this now?"""), |
|
96 yesDefault=True) |
|
97 if res: |
|
98 self.project.reopenProject() |
|