36 @param name name of this object (string) |
36 @param name name of this object (string) |
37 """ |
37 """ |
38 VcsProjectBrowserHelper.__init__(self, vcsObject, browserObject, |
38 VcsProjectBrowserHelper.__init__(self, vcsObject, browserObject, |
39 projectObject, isTranslationsBrowser, |
39 projectObject, isTranslationsBrowser, |
40 parent, name) |
40 parent, name) |
|
41 |
|
42 # instantiate the extensions |
|
43 from .ShelveExtension.ProjectBrowserHelper import \ |
|
44 ShelveProjectBrowserHelper |
|
45 self.__extensions = { |
|
46 "shelve": ShelveProjectBrowserHelper(vcsObject, browserObject, |
|
47 projectObject), |
|
48 } |
|
49 |
|
50 self.__extensionMenuTitles = {} |
|
51 for extension in self.__extensions: |
|
52 self.__extensionMenuTitles[ |
|
53 self.__extensions[extension].menuTitle()] = extension |
|
54 self.__extensionMenus = {} |
|
55 for extension in self.__extensions: |
|
56 self.__extensionMenus[extension] = \ |
|
57 self.__extensions[extension].initMenus() |
|
58 |
|
59 def __showExtensionMenu(self, key): |
|
60 """ |
|
61 Private slot showing the extensions menu. |
|
62 |
|
63 @param key menu key (string, one of 'mainMenu', 'multiMenu', |
|
64 'backMenu', 'dirMenu' or 'dirMultiMenu') |
|
65 """ |
|
66 for extensionName in self.__extensionMenus: |
|
67 if key in self.__extensionMenus[extensionName]: |
|
68 self.__extensionMenus[extensionName][key].setEnabled( |
|
69 self.vcs.isExtensionActive(extensionName)) |
|
70 if (not self.__extensionMenus[extensionName][key].isEnabled() |
|
71 and self.__extensionMenus[extensionName][key] |
|
72 .isTearOffMenuVisible()): |
|
73 self.__extensionMenus[extensionName][key].hideTearOffMenu() |
41 |
74 |
42 def showContextMenu(self, menu, standardItems): |
75 def showContextMenu(self, menu, standardItems): |
43 """ |
76 """ |
44 Slot called before the context menu is shown. |
77 Slot called before the context menu is shown. |
45 |
78 |
57 act.setEnabled(False) |
90 act.setEnabled(False) |
58 for act in standardItems: |
91 for act in standardItems: |
59 act.setEnabled(False) |
92 act.setEnabled(False) |
60 if not hasattr(self.browser.currentItem(), 'fileName'): |
93 if not hasattr(self.browser.currentItem(), 'fileName'): |
61 self.annotateAct.setEnabled(False) |
94 self.annotateAct.setEnabled(False) |
|
95 self.__showExtensionMenu("mainMenu") |
62 else: |
96 else: |
63 for act in self.vcsMenuActions: |
97 for act in self.vcsMenuActions: |
64 act.setEnabled(False) |
98 act.setEnabled(False) |
65 for act in self.vcsAddMenuActions: |
99 for act in self.vcsAddMenuActions: |
66 act.setEnabled(True) |
100 act.setEnabled(True) |
95 act.setEnabled(True) |
129 act.setEnabled(True) |
96 for act in self.vcsAddMultiMenuActions: |
130 for act in self.vcsAddMultiMenuActions: |
97 act.setEnabled(False) |
131 act.setEnabled(False) |
98 for act in standardItems: |
132 for act in standardItems: |
99 act.setEnabled(False) |
133 act.setEnabled(False) |
|
134 self.__showExtensionMenu("multiMenu") |
100 else: |
135 else: |
101 for act in self.vcsMultiMenuActions: |
136 for act in self.vcsMultiMenuActions: |
102 act.setEnabled(False) |
137 act.setEnabled(False) |
103 for act in self.vcsAddMultiMenuActions: |
138 for act in self.vcsAddMultiMenuActions: |
104 act.setEnabled(True) |
139 act.setEnabled(True) |
121 act.setEnabled(True) |
156 act.setEnabled(True) |
122 for act in self.vcsAddDirMenuActions: |
157 for act in self.vcsAddDirMenuActions: |
123 act.setEnabled(False) |
158 act.setEnabled(False) |
124 for act in standardItems: |
159 for act in standardItems: |
125 act.setEnabled(False) |
160 act.setEnabled(False) |
|
161 self.__showExtensionMenu("dirMenu") |
126 else: |
162 else: |
127 for act in self.vcsDirMenuActions: |
163 for act in self.vcsDirMenuActions: |
128 act.setEnabled(False) |
164 act.setEnabled(False) |
129 for act in self.vcsAddDirMenuActions: |
165 for act in self.vcsAddDirMenuActions: |
130 act.setEnabled(True) |
166 act.setEnabled(True) |
159 act.setEnabled(True) |
195 act.setEnabled(True) |
160 for act in self.vcsAddDirMultiMenuActions: |
196 for act in self.vcsAddDirMultiMenuActions: |
161 act.setEnabled(False) |
197 act.setEnabled(False) |
162 for act in standardItems: |
198 for act in standardItems: |
163 act.setEnabled(False) |
199 act.setEnabled(False) |
|
200 self.__showExtensionMenu("dirMultiMenu") |
164 else: |
201 else: |
165 for act in self.vcsDirMultiMenuActions: |
202 for act in self.vcsDirMultiMenuActions: |
166 act.setEnabled(False) |
203 act.setEnabled(False) |
167 for act in self.vcsAddDirMultiMenuActions: |
204 for act in self.vcsAddDirMultiMenuActions: |
168 act.setEnabled(True) |
205 act.setEnabled(True) |
169 for act in standardItems: |
206 for act in standardItems: |
170 act.setEnabled(True) |
207 act.setEnabled(True) |
171 |
208 |
172 ########################################################################### |
209 ########################################################################### |
173 # Protected menu generation methods below |
210 ## Private menu generation methods below |
174 ########################################################################### |
211 ########################################################################### |
175 |
212 |
|
213 def __addExtensionsMenu(self, menu, key): |
|
214 """ |
|
215 Private method to add an extension menu entry. |
|
216 |
|
217 @param menu menu to add it to (QMenu) |
|
218 @param key menu key (string, one of 'mainMenu', 'multiMenu', |
|
219 'backMenu', 'dirMenu' or 'dirMultiMenu') |
|
220 @return reference to the menu action (QAction) |
|
221 """ |
|
222 act = None |
|
223 if key in ['mainMenu', 'multiMenu', 'backMenu', 'dirMenu', |
|
224 'dirMultiMenu']: |
|
225 extensionsMenu = QMenu(self.tr("Extensions"), menu) |
|
226 extensionsMenu.setTearOffEnabled(True) |
|
227 for extensionMenuTitle in sorted(self.__extensionMenuTitles): |
|
228 extensionName = self.__extensionMenuTitles[extensionMenuTitle] |
|
229 if key in self.__extensionMenus[extensionName]: |
|
230 extensionsMenu.addMenu( |
|
231 self.__extensionMenus[extensionName][key]) |
|
232 if not extensionsMenu.isEmpty(): |
|
233 if not menu.isEmpty(): |
|
234 menu.addSeparator() |
|
235 act = menu.addMenu(extensionsMenu) |
|
236 return act |
|
237 |
|
238 ########################################################################### |
|
239 ## Protected menu generation methods below |
|
240 ########################################################################### |
|
241 |
176 def _addVCSMenu(self, mainMenu): |
242 def _addVCSMenu(self, mainMenu): |
177 """ |
243 """ |
178 Protected method used to add the VCS menu to all project browsers. |
244 Protected method used to add the VCS menu to all project browsers. |
179 |
245 |
180 @param mainMenu reference to the menu to be amended |
246 @param mainMenu reference to the menu to be amended |
197 act = menu.addAction( |
263 act = menu.addAction( |
198 UI.PixmapCache.getIcon("vcsCommit.png"), |
264 UI.PixmapCache.getIcon("vcsCommit.png"), |
199 self.tr('Commit changes to repository...'), |
265 self.tr('Commit changes to repository...'), |
200 self._VCSCommit) |
266 self._VCSCommit) |
201 self.vcsMenuActions.append(act) |
267 self.vcsMenuActions.append(act) |
|
268 act = self.__addExtensionsMenu(menu, 'mainMenu') |
|
269 if act: |
|
270 self.vcsMenuActions.append(act) |
202 menu.addSeparator() |
271 menu.addSeparator() |
203 act = menu.addAction( |
272 act = menu.addAction( |
204 UI.PixmapCache.getIcon("vcsAdd.png"), |
273 UI.PixmapCache.getIcon("vcsAdd.png"), |
205 self.tr('Add to repository'), |
274 self.tr('Add to repository'), |
206 self._VCSAdd) |
275 self._VCSAdd) |
305 act = menu.addAction( |
374 act = menu.addAction( |
306 UI.PixmapCache.getIcon("vcsCommit.png"), |
375 UI.PixmapCache.getIcon("vcsCommit.png"), |
307 self.tr('Commit changes to repository...'), |
376 self.tr('Commit changes to repository...'), |
308 self._VCSCommit) |
377 self._VCSCommit) |
309 self.vcsMultiMenuActions.append(act) |
378 self.vcsMultiMenuActions.append(act) |
|
379 act = self.__addExtensionsMenu(menu, 'multiMenu') |
|
380 if act: |
|
381 self.vcsMultiMenuActions.append(act) |
310 menu.addSeparator() |
382 menu.addSeparator() |
311 act = menu.addAction( |
383 act = menu.addAction( |
312 UI.PixmapCache.getIcon("vcsAdd.png"), |
384 UI.PixmapCache.getIcon("vcsAdd.png"), |
313 self.tr('Add to repository'), self._VCSAdd) |
385 self.tr('Add to repository'), self._VCSAdd) |
314 self.vcsAddMultiMenuActions.append(act) |
386 self.vcsAddMultiMenuActions.append(act) |
419 act = menu.addAction( |
491 act = menu.addAction( |
420 UI.PixmapCache.getIcon("vcsCommit.png"), |
492 UI.PixmapCache.getIcon("vcsCommit.png"), |
421 self.tr('Commit changes to repository...'), |
493 self.tr('Commit changes to repository...'), |
422 self._VCSCommit) |
494 self._VCSCommit) |
423 self.vcsDirMenuActions.append(act) |
495 self.vcsDirMenuActions.append(act) |
|
496 act = self.__addExtensionsMenu(menu, 'dirMenu') |
|
497 if act: |
|
498 self.vcsDirMenuActions.append(act) |
424 menu.addSeparator() |
499 menu.addSeparator() |
425 act = menu.addAction( |
500 act = menu.addAction( |
426 UI.PixmapCache.getIcon("vcsAdd.png"), |
501 UI.PixmapCache.getIcon("vcsAdd.png"), |
427 self.tr('Add to repository'), self._VCSAdd) |
502 self.tr('Add to repository'), self._VCSAdd) |
428 self.vcsAddDirMenuActions.append(act) |
503 self.vcsAddDirMenuActions.append(act) |
510 act = menu.addAction( |
585 act = menu.addAction( |
511 UI.PixmapCache.getIcon("vcsCommit.png"), |
586 UI.PixmapCache.getIcon("vcsCommit.png"), |
512 self.tr('Commit changes to repository...'), |
587 self.tr('Commit changes to repository...'), |
513 self._VCSCommit) |
588 self._VCSCommit) |
514 self.vcsDirMultiMenuActions.append(act) |
589 self.vcsDirMultiMenuActions.append(act) |
|
590 act = self.__addExtensionsMenu(menu, 'dirMultiMenu') |
|
591 if act: |
|
592 self.vcsDirMultiMenuActions.append(act) |
515 menu.addSeparator() |
593 menu.addSeparator() |
516 act = menu.addAction( |
594 act = menu.addAction( |
517 UI.PixmapCache.getIcon("vcsAdd.png"), |
595 UI.PixmapCache.getIcon("vcsAdd.png"), |
518 self.tr('Add to repository'), self._VCSAdd) |
596 self.tr('Add to repository'), self._VCSAdd) |
519 self.vcsAddDirMultiMenuActions.append(act) |
597 self.vcsAddDirMultiMenuActions.append(act) |
559 mainMenu.addSeparator() |
637 mainMenu.addSeparator() |
560 mainMenu.addMenu(menu) |
638 mainMenu.addMenu(menu) |
561 self.menuDirMulti = menu |
639 self.menuDirMulti = menu |
562 |
640 |
563 ########################################################################### |
641 ########################################################################### |
564 # Menu handling methods below |
642 ## Menu handling methods below |
565 ########################################################################### |
643 ########################################################################### |
566 |
644 |
567 def __HgRevert(self): |
645 def __HgRevert(self): |
568 """ |
646 """ |
569 Protected slot called by the context menu to revert changes made. |
647 Protected slot called by the context menu to revert changes made. |