|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the fetch extension project helper. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import QObject |
|
11 from PyQt4.QtGui import QMenu |
|
12 |
|
13 from E5Gui.E5Action import E5Action |
|
14 from E5Gui import E5MessageBox |
|
15 |
|
16 import UI.PixmapCache |
|
17 |
|
18 |
|
19 class FetchProjectHelper(QObject): |
|
20 """ |
|
21 Class implementing the fetch extension project helper. |
|
22 """ |
|
23 def __init__(self): |
|
24 """ |
|
25 Constructor |
|
26 """ |
|
27 QObject.__init__(self) |
|
28 |
|
29 self.actions = [] |
|
30 |
|
31 self.initActions() |
|
32 |
|
33 def setObjects(self, vcsObject, projectObject): |
|
34 """ |
|
35 Public method to set references to the vcs and project objects. |
|
36 |
|
37 @param vcsObject reference to the vcs object |
|
38 @param projectObject reference to the project object |
|
39 """ |
|
40 self.vcs = vcsObject |
|
41 self.project = projectObject |
|
42 |
|
43 def getActions(self): |
|
44 """ |
|
45 Public method to get a list of all actions. |
|
46 |
|
47 @return list of all actions (list of E5Action) |
|
48 """ |
|
49 return self.actions[:] |
|
50 |
|
51 def initActions(self): |
|
52 """ |
|
53 Public method to generate the action objects. |
|
54 """ |
|
55 self.hgFetchAct = E5Action(self.trUtf8('Fetch changes'), |
|
56 UI.PixmapCache.getIcon("vcsUpdate.png"), |
|
57 self.trUtf8('Fetch changes'), |
|
58 0, 0, self, 'mercurial_fetch') |
|
59 self.hgFetchAct.setStatusTip(self.trUtf8( |
|
60 'Fetch changes from a remote repository' |
|
61 )) |
|
62 self.hgFetchAct.setWhatsThis(self.trUtf8( |
|
63 """<b>Fetch changes</b>""" |
|
64 """<p>This pulls changes from a remote repository into the """ |
|
65 """local repository. If the pulled changes add a new branch head,""" |
|
66 """ the head is automatically merged, and the result of the merge""" |
|
67 """ is committed. Otherwise, the working directory is updated to""" |
|
68 """ include the new changes.</p>""" |
|
69 )) |
|
70 self.hgFetchAct.triggered[()].connect(self.__hgFetch) |
|
71 self.actions.append(self.hgFetchAct) |
|
72 |
|
73 def initMenu(self, mainMenu): |
|
74 """ |
|
75 Public method to generate the extension menu. |
|
76 |
|
77 @param mainMenu reference to the main menu (QMenu) |
|
78 @return populated menu (QMenu) |
|
79 """ |
|
80 menu = QMenu(self.trUtf8("Fetch"), mainMenu) |
|
81 |
|
82 menu.addAction(self.hgFetchAct) |
|
83 |
|
84 return menu |
|
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(None, |
|
94 self.trUtf8("Fetch"), |
|
95 self.trUtf8("""The project should be reread. Do this now?"""), |
|
96 yesDefault=True) |
|
97 if res: |
|
98 self.project.reopenProject() |