15 from EricWidgets.EricApplication import ericApp |
15 from EricWidgets.EricApplication import ericApp |
16 |
16 |
17 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog |
17 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog |
18 |
18 |
19 from Project.ProjectBrowserModel import ( |
19 from Project.ProjectBrowserModel import ( |
20 ProjectBrowserSimpleDirectoryItem, ProjectBrowserFileItem, |
20 ProjectBrowserSimpleDirectoryItem, |
21 ProjectBrowserDirectoryItem |
21 ProjectBrowserFileItem, |
|
22 ProjectBrowserDirectoryItem, |
22 ) |
23 ) |
23 |
24 |
24 import Preferences |
25 import Preferences |
25 |
26 |
26 |
27 |
27 class VcsProjectBrowserHelper(QObject): |
28 class VcsProjectBrowserHelper(QObject): |
28 """ |
29 """ |
29 Class implementing the base class of the VCS project browser helper. |
30 Class implementing the base class of the VCS project browser helper. |
30 """ |
31 """ |
31 def __init__(self, vcsObject, browserObject, projectObject, |
32 |
32 isTranslationsBrowser, parent=None, name=None): |
33 def __init__( |
|
34 self, |
|
35 vcsObject, |
|
36 browserObject, |
|
37 projectObject, |
|
38 isTranslationsBrowser, |
|
39 parent=None, |
|
40 name=None, |
|
41 ): |
33 """ |
42 """ |
34 Constructor |
43 Constructor |
35 |
44 |
36 @param vcsObject reference to the vcs object |
45 @param vcsObject reference to the vcs object |
37 @param browserObject reference to the project browser object |
46 @param browserObject reference to the project browser object |
38 @param projectObject reference to the project object |
47 @param projectObject reference to the project object |
39 @param isTranslationsBrowser flag indicating, the helper is requested |
48 @param isTranslationsBrowser flag indicating, the helper is requested |
40 for the translations browser (this needs some special treatment) |
49 for the translations browser (this needs some special treatment) |
42 @param name name of this object (string) |
51 @param name name of this object (string) |
43 """ |
52 """ |
44 super().__init__(parent) |
53 super().__init__(parent) |
45 if name: |
54 if name: |
46 self.setObjectName(name) |
55 self.setObjectName(name) |
47 |
56 |
48 self.vcs = vcsObject |
57 self.vcs = vcsObject |
49 self.browser = browserObject |
58 self.browser = browserObject |
50 self.isTranslationsBrowser = isTranslationsBrowser |
59 self.isTranslationsBrowser = isTranslationsBrowser |
51 self.project = projectObject |
60 self.project = projectObject |
52 |
61 |
53 def addVCSMenus(self, mainMenu, multiMenu, backMenu, dirMenu, |
62 def addVCSMenus(self, mainMenu, multiMenu, backMenu, dirMenu, dirMultiMenu): |
54 dirMultiMenu): |
|
55 """ |
63 """ |
56 Public method to add the VCS entries to the various project browser |
64 Public method to add the VCS entries to the various project browser |
57 menus. |
65 menus. |
58 |
66 |
59 @param mainMenu reference to the main menu (QPopupMenu) |
67 @param mainMenu reference to the main menu (QPopupMenu) |
60 @param multiMenu reference to the multiple selection menu (QPopupMenu) |
68 @param multiMenu reference to the multiple selection menu (QPopupMenu) |
61 @param backMenu reference to the background menu (QPopupMenu) |
69 @param backMenu reference to the background menu (QPopupMenu) |
62 @param dirMenu reference to the directory menu (QPopupMenu) |
70 @param dirMenu reference to the directory menu (QPopupMenu) |
63 @param dirMultiMenu reference to the multiple selection directory |
71 @param dirMultiMenu reference to the multiple selection directory |
66 self._addVCSMenu(mainMenu) |
74 self._addVCSMenu(mainMenu) |
67 self._addVCSMenuMulti(multiMenu) |
75 self._addVCSMenuMulti(multiMenu) |
68 self._addVCSMenuBack(backMenu) |
76 self._addVCSMenuBack(backMenu) |
69 self._addVCSMenuDir(dirMenu) |
77 self._addVCSMenuDir(dirMenu) |
70 self._addVCSMenuDirMulti(dirMultiMenu) |
78 self._addVCSMenuDirMulti(dirMultiMenu) |
71 |
79 |
72 def showContextMenu(self, menu, standardItems): |
80 def showContextMenu(self, menu, standardItems): |
73 """ |
81 """ |
74 Public slot called before the context menu is shown. |
82 Public slot called before the context menu is shown. |
75 |
83 |
76 It enables/disables the VCS menu entries depending on the overall |
84 It enables/disables the VCS menu entries depending on the overall |
77 VCS status and the file status. |
85 VCS status and the file status. |
78 |
86 |
79 @param menu reference to the menu to be shown |
87 @param menu reference to the menu to be shown |
80 @param standardItems array of standard items that need |
88 @param standardItems array of standard items that need |
81 activation/deactivation depending on the overall VCS status |
89 activation/deactivation depending on the overall VCS status |
82 @exception RuntimeError to indicate that this method must be |
90 @exception RuntimeError to indicate that this method must be |
83 implemented by a subclass |
91 implemented by a subclass |
84 """ |
92 """ |
85 raise RuntimeError('Not implemented') |
93 raise RuntimeError("Not implemented") |
86 |
94 |
87 def showContextMenuMulti(self, menu, standardItems): |
95 def showContextMenuMulti(self, menu, standardItems): |
88 """ |
96 """ |
89 Public slot called before the context menu (multiple selections) is |
97 Public slot called before the context menu (multiple selections) is |
90 shown. |
98 shown. |
91 |
99 |
92 It enables/disables the VCS menu entries depending on the overall |
100 It enables/disables the VCS menu entries depending on the overall |
93 VCS status and the files status. |
101 VCS status and the files status. |
94 |
102 |
95 @param menu reference to the menu to be shown |
103 @param menu reference to the menu to be shown |
96 @param standardItems array of standard items that need |
104 @param standardItems array of standard items that need |
97 activation/deactivation depending on the overall VCS status |
105 activation/deactivation depending on the overall VCS status |
98 @exception RuntimeError to indicate that this method must be |
106 @exception RuntimeError to indicate that this method must be |
99 implemented by a subclass |
107 implemented by a subclass |
100 """ |
108 """ |
101 raise RuntimeError('Not implemented') |
109 raise RuntimeError("Not implemented") |
102 |
110 |
103 def showContextMenuDir(self, menu, standardItems): |
111 def showContextMenuDir(self, menu, standardItems): |
104 """ |
112 """ |
105 Public slot called before the context menu is shown. |
113 Public slot called before the context menu is shown. |
106 |
114 |
107 It enables/disables the VCS menu entries depending on the overall |
115 It enables/disables the VCS menu entries depending on the overall |
108 VCS status and the directory status. |
116 VCS status and the directory status. |
109 |
117 |
110 @param menu reference to the menu to be shown |
118 @param menu reference to the menu to be shown |
111 @param standardItems array of standard items that |
119 @param standardItems array of standard items that |
112 need activation/deactivation depending on the overall VCS status |
120 need activation/deactivation depending on the overall VCS status |
113 @exception RuntimeError to indicate that this method must be |
121 @exception RuntimeError to indicate that this method must be |
114 implemented by a subclass |
122 implemented by a subclass |
115 """ |
123 """ |
116 raise RuntimeError('Not implemented') |
124 raise RuntimeError("Not implemented") |
117 |
125 |
118 def showContextMenuDirMulti(self, menu, standardItems): |
126 def showContextMenuDirMulti(self, menu, standardItems): |
119 """ |
127 """ |
120 Public slot called before the context menu is shown. |
128 Public slot called before the context menu is shown. |
121 |
129 |
122 It enables/disables the VCS menu entries depending on the overall |
130 It enables/disables the VCS menu entries depending on the overall |
123 VCS status and the directory status. |
131 VCS status and the directory status. |
124 |
132 |
125 @param menu reference to the menu to be shown |
133 @param menu reference to the menu to be shown |
126 @param standardItems array of standard items that need |
134 @param standardItems array of standard items that need |
127 activation/deactivation depending on the overall VCS status |
135 activation/deactivation depending on the overall VCS status |
128 @exception RuntimeError to indicate that this method must be |
136 @exception RuntimeError to indicate that this method must be |
129 implemented by a subclass |
137 implemented by a subclass |
130 """ |
138 """ |
131 raise RuntimeError('Not implemented') |
139 raise RuntimeError("Not implemented") |
132 |
140 |
133 ########################################################################### |
141 ########################################################################### |
134 ## General menu handling methods below |
142 ## General menu handling methods below |
135 ########################################################################### |
143 ########################################################################### |
136 |
144 |
137 def _VCSUpdate(self): |
145 def _VCSUpdate(self): |
138 """ |
146 """ |
139 Protected slot called by the context menu to update a file from the |
147 Protected slot called by the context menu to update a file from the |
140 VCS repository. |
148 VCS repository. |
141 """ |
149 """ |
142 if self.isTranslationsBrowser: |
150 if self.isTranslationsBrowser: |
143 names = [itm.dirName() |
151 names = [ |
144 for itm in self.browser.getSelectedItems( |
152 itm.dirName() |
145 [ProjectBrowserSimpleDirectoryItem])] |
153 for itm in self.browser.getSelectedItems( |
|
154 [ProjectBrowserSimpleDirectoryItem] |
|
155 ) |
|
156 ] |
146 if not names: |
157 if not names: |
147 names = [itm.fileName() |
158 names = [ |
148 for itm in self.browser.getSelectedItems( |
159 itm.fileName() |
149 [ProjectBrowserFileItem])] |
160 for itm in self.browser.getSelectedItems([ProjectBrowserFileItem]) |
|
161 ] |
150 else: |
162 else: |
151 names = [] |
163 names = [] |
152 for itm in self.browser.getSelectedItems(): |
164 for itm in self.browser.getSelectedItems(): |
153 try: |
165 try: |
154 name = itm.fileName() |
166 name = itm.fileName() |
155 except AttributeError: |
167 except AttributeError: |
156 name = itm.dirName() |
168 name = itm.dirName() |
157 names.append(name) |
169 names.append(name) |
158 self.vcs.vcsUpdate(names) |
170 self.vcs.vcsUpdate(names) |
159 |
171 |
160 def _VCSCommit(self): |
172 def _VCSCommit(self): |
161 """ |
173 """ |
162 Protected slot called by the context menu to commit the changes to the |
174 Protected slot called by the context menu to commit the changes to the |
163 VCS repository. |
175 VCS repository. |
164 """ |
176 """ |
165 if self.isTranslationsBrowser: |
177 if self.isTranslationsBrowser: |
166 names = [itm.dirName() |
178 names = [ |
167 for itm in self.browser.getSelectedItems( |
179 itm.dirName() |
168 [ProjectBrowserSimpleDirectoryItem])] |
180 for itm in self.browser.getSelectedItems( |
|
181 [ProjectBrowserSimpleDirectoryItem] |
|
182 ) |
|
183 ] |
169 if not names: |
184 if not names: |
170 names = [itm.fileName() |
185 names = [ |
171 for itm in self.browser.getSelectedItems( |
186 itm.fileName() |
172 [ProjectBrowserFileItem])] |
187 for itm in self.browser.getSelectedItems([ProjectBrowserFileItem]) |
|
188 ] |
173 else: |
189 else: |
174 names = [] |
190 names = [] |
175 for itm in self.browser.getSelectedItems(): |
191 for itm in self.browser.getSelectedItems(): |
176 try: |
192 try: |
177 name = itm.fileName() |
193 name = itm.fileName() |
251 name = itm.dirName() |
266 name = itm.dirName() |
252 names.append(name) |
267 names.append(name) |
253 self.vcs.vcsAddTree(names) |
268 self.vcs.vcsAddTree(names) |
254 for fn in names: |
269 for fn in names: |
255 self._updateVCSStatus(fn) |
270 self._updateVCSStatus(fn) |
256 |
271 |
257 def _VCSRemove(self): |
272 def _VCSRemove(self): |
258 """ |
273 """ |
259 Protected slot called by the context menu to remove the selected file |
274 Protected slot called by the context menu to remove the selected file |
260 from the VCS repository. |
275 from the VCS repository. |
261 """ |
276 """ |
262 if self.isTranslationsBrowser: |
277 if self.isTranslationsBrowser: |
263 items = self.browser.getSelectedItems( |
278 items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem]) |
264 [ProjectBrowserSimpleDirectoryItem]) |
|
265 if items: |
279 if items: |
266 return # not supported |
280 return # not supported |
267 |
281 |
268 isRemoveDirs = False |
282 isRemoveDirs = False |
269 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) |
283 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) |
270 names = [itm.fileName() for itm in items] |
284 names = [itm.fileName() for itm in items] |
271 |
285 |
272 dlg = DeleteFilesConfirmationDialog( |
286 dlg = DeleteFilesConfirmationDialog( |
273 self.parent(), |
287 self.parent(), |
274 QCoreApplication.translate( |
288 QCoreApplication.translate( |
275 "VcsProjectBrowserHelper", |
289 "VcsProjectBrowserHelper", "Remove from repository (and disk)" |
276 "Remove from repository (and disk)"), |
290 ), |
277 QCoreApplication.translate( |
291 QCoreApplication.translate( |
278 "VcsProjectBrowserHelper", |
292 "VcsProjectBrowserHelper", |
279 "Do you really want to remove these translation files from" |
293 "Do you really want to remove these translation files from" |
280 " the repository (and disk)?"), |
294 " the repository (and disk)?", |
281 names) |
295 ), |
|
296 names, |
|
297 ) |
282 else: |
298 else: |
283 items = self.browser.getSelectedItems() |
299 items = self.browser.getSelectedItems() |
284 isRemoveDirs = ( |
300 isRemoveDirs = len(items) == self.browser.getSelectedItemsCount( |
285 len(items) == self.browser.getSelectedItemsCount( |
301 [ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem] |
286 [ProjectBrowserSimpleDirectoryItem, |
|
287 ProjectBrowserDirectoryItem]) |
|
288 ) |
302 ) |
289 if isRemoveDirs: |
303 if isRemoveDirs: |
290 names = [itm.dirName() for itm in items] |
304 names = [itm.dirName() for itm in items] |
291 else: |
305 else: |
292 names = [itm.fileName() for itm in items] |
306 names = [itm.fileName() for itm in items] |
293 files = [self.browser.project.getRelativePath(name) |
307 files = [self.browser.project.getRelativePath(name) for name in names] |
294 for name in names] |
308 |
295 |
|
296 dlg = DeleteFilesConfirmationDialog( |
309 dlg = DeleteFilesConfirmationDialog( |
297 self.parent(), |
310 self.parent(), |
298 QCoreApplication.translate( |
311 QCoreApplication.translate( |
299 "VcsProjectBrowserHelper", |
312 "VcsProjectBrowserHelper", "Remove from repository (and disk)" |
300 "Remove from repository (and disk)"), |
313 ), |
301 QCoreApplication.translate( |
314 QCoreApplication.translate( |
302 "VcsProjectBrowserHelper", |
315 "VcsProjectBrowserHelper", |
303 "Do you really want to remove these files/directories" |
316 "Do you really want to remove these files/directories" |
304 " from the repository (and disk)?"), |
317 " from the repository (and disk)?", |
305 files) |
318 ), |
306 |
319 files, |
|
320 ) |
|
321 |
307 if dlg.exec() == QDialog.DialogCode.Accepted: |
322 if dlg.exec() == QDialog.DialogCode.Accepted: |
308 status = self.vcs.vcsRemove(names) |
323 status = self.vcs.vcsRemove(names) |
309 if status: |
324 if status: |
310 if isRemoveDirs: |
325 if isRemoveDirs: |
311 self.browser._removeDir() |
326 self.browser._removeDir() |
312 # remove directories from Project |
327 # remove directories from Project |
313 else: |
328 else: |
314 self.browser._removeFile() # remove file(s) from project |
329 self.browser._removeFile() # remove file(s) from project |
315 |
330 |
316 def _VCSLogBrowser(self): |
331 def _VCSLogBrowser(self): |
317 """ |
332 """ |
318 Protected slot called by the context menu to show the log browser for a |
333 Protected slot called by the context menu to show the log browser for a |
319 file. |
334 file. |
320 """ |
335 """ |