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