|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the project browser helper base for Mercurial extension |
|
8 interfaces. |
|
9 """ |
|
10 |
|
11 from PyQt5.QtCore import QObject |
|
12 from PyQt5.QtWidgets import QMenu |
|
13 |
|
14 |
|
15 class HgExtensionProjectBrowserHelper(QObject): |
|
16 """ |
|
17 Class implementing the project browser helper base for Mercurial extension |
|
18 interfaces. |
|
19 |
|
20 Note: The methods initMenus() and menuTitle() have to be reimplemented by |
|
21 derived classes. |
|
22 """ |
|
23 def __init__(self, vcsObject, browserObject, projectObject): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param vcsObject reference to the vcs object |
|
28 @param browserObject reference to the project browser object |
|
29 @param projectObject reference to the project object |
|
30 """ |
|
31 super().__init__() |
|
32 |
|
33 self.vcs = vcsObject |
|
34 self.browser = browserObject |
|
35 self.project = projectObject |
|
36 |
|
37 def initMenus(self): |
|
38 """ |
|
39 Public method to generate the extension menus. |
|
40 |
|
41 Note: Derived class must implement this method. |
|
42 |
|
43 @return dictionary of populated menu (dict of QMenu). The dict |
|
44 must have the keys 'mainMenu', 'multiMenu', 'backMenu', 'dirMenu' |
|
45 and 'dirMultiMenu'. |
|
46 @exception NotImplementedError raised if the class has not been |
|
47 reimplemented |
|
48 """ |
|
49 raise NotImplementedError |
|
50 |
|
51 return { |
|
52 'mainMenu': QMenu(), |
|
53 'multiMenu': QMenu(), |
|
54 'backMenu': QMenu(), |
|
55 'dirMenu': QMenu(), |
|
56 'dirMultiMenu': QMenu(), |
|
57 } |
|
58 |
|
59 def menuTitle(self): |
|
60 """ |
|
61 Public method to get the menu title. |
|
62 |
|
63 Note: Derived class must implement this method. |
|
64 |
|
65 @return title of the menu (string) |
|
66 @exception NotImplementedError raised if the class has not been |
|
67 reimplemented |
|
68 """ |
|
69 raise NotImplementedError |
|
70 |
|
71 return "" |
|
72 |
|
73 def showExtensionMenu(self, key, controlled): |
|
74 """ |
|
75 Public method to prepare the extension menu for display. |
|
76 |
|
77 Note: Derived class must implement this method to adjust the |
|
78 enabled states of its menus. |
|
79 |
|
80 @param key menu key (string, one of 'mainMenu', 'multiMenu', |
|
81 'backMenu', 'dirMenu' or 'dirMultiMenu') |
|
82 @param controlled flag indicating to prepare the menu for a |
|
83 version controlled entry or a non-version controlled entry |
|
84 (boolean) |
|
85 @exception NotImplementedError raised if the class has not been |
|
86 reimplemented |
|
87 """ |
|
88 raise NotImplementedError |
|
89 |
|
90 def _updateVCSStatus(self, name): |
|
91 """ |
|
92 Protected method to update the VCS status of an item. |
|
93 |
|
94 @param name filename or directoryname of the item to be updated |
|
95 (string) |
|
96 """ |
|
97 self.project.getModel().updateVCSStatus(name) |