|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the VCS project browser helper for Git. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtWidgets import QMenu, QDialog |
|
15 |
|
16 from E5Gui.E5Application import e5App |
|
17 |
|
18 from Project.ProjectBrowserModel import ProjectBrowserFileItem |
|
19 |
|
20 from VCS.ProjectBrowserHelper import VcsProjectBrowserHelper |
|
21 |
|
22 import UI.PixmapCache |
|
23 |
|
24 |
|
25 class GitProjectBrowserHelper(VcsProjectBrowserHelper): |
|
26 """ |
|
27 Class implementing the VCS project browser helper for Git. |
|
28 """ |
|
29 def __init__(self, vcsObject, browserObject, projectObject, |
|
30 isTranslationsBrowser, parent=None, name=None): |
|
31 """ |
|
32 Constructor |
|
33 |
|
34 @param vcsObject reference to the vcs object |
|
35 @param browserObject reference to the project browser object |
|
36 @param projectObject reference to the project object |
|
37 @param isTranslationsBrowser flag indicating, the helper is requested |
|
38 for the translations browser (this needs some special treatment) |
|
39 @param parent parent widget (QWidget) |
|
40 @param name name of this object (string) |
|
41 """ |
|
42 VcsProjectBrowserHelper.__init__(self, vcsObject, browserObject, |
|
43 projectObject, isTranslationsBrowser, |
|
44 parent, name) |
|
45 |
|
46 def showContextMenu(self, menu, standardItems): |
|
47 """ |
|
48 Public slot called before the context menu is shown. |
|
49 |
|
50 It enables/disables the VCS menu entries depending on the overall |
|
51 VCS status and the file status. |
|
52 |
|
53 @param menu reference to the menu to be shown |
|
54 @param standardItems array of standard items that need |
|
55 activation/deactivation depending on the overall VCS status |
|
56 """ |
|
57 if self.browser.currentItem().data(1) == self.vcs.vcsName(): |
|
58 for act in self.vcsMenuActions: |
|
59 act.setEnabled(True) |
|
60 for act in standardItems: |
|
61 act.setEnabled(False) |
|
62 else: |
|
63 for act in self.vcsMenuActions: |
|
64 act.setEnabled(False) |
|
65 for act in standardItems: |
|
66 act.setEnabled(True) |
|
67 |
|
68 def showContextMenuMulti(self, menu, standardItems): |
|
69 """ |
|
70 Public slot called before the context menu (multiple selections) is |
|
71 shown. |
|
72 |
|
73 It enables/disables the VCS menu entries depending on the overall |
|
74 VCS status and the files status. |
|
75 |
|
76 @param menu reference to the menu to be shown |
|
77 @param standardItems array of standard items that need |
|
78 activation/deactivation depending on the overall VCS status |
|
79 """ |
|
80 vcsName = self.vcs.vcsName() |
|
81 items = self.browser.getSelectedItems() |
|
82 vcsItems = 0 |
|
83 # determine number of selected items under VCS control |
|
84 for itm in items: |
|
85 if itm.data(1) == vcsName: |
|
86 vcsItems += 1 |
|
87 |
|
88 if vcsItems > 0: |
|
89 if vcsItems != len(items): |
|
90 for act in self.vcsMultiMenuActions: |
|
91 act.setEnabled(False) |
|
92 else: |
|
93 for act in self.vcsMultiMenuActions: |
|
94 act.setEnabled(True) |
|
95 for act in standardItems: |
|
96 act.setEnabled(False) |
|
97 else: |
|
98 for act in self.vcsMultiMenuActions: |
|
99 act.setEnabled(False) |
|
100 for act in standardItems: |
|
101 act.setEnabled(True) |
|
102 |
|
103 def showContextMenuDir(self, menu, standardItems): |
|
104 """ |
|
105 Public slot called before the context menu is shown. |
|
106 |
|
107 It enables/disables the VCS menu entries depending on the overall |
|
108 VCS status and the directory status. |
|
109 |
|
110 @param menu reference to the menu to be shown |
|
111 @param standardItems array of standard items that need |
|
112 activation/deactivation depending on the overall VCS status |
|
113 """ |
|
114 if self.browser.currentItem().data(1) == self.vcs.vcsName(): |
|
115 for act in self.vcsDirMenuActions: |
|
116 act.setEnabled(True) |
|
117 for act in standardItems: |
|
118 act.setEnabled(False) |
|
119 else: |
|
120 for act in self.vcsDirMenuActions: |
|
121 act.setEnabled(False) |
|
122 for act in standardItems: |
|
123 act.setEnabled(True) |
|
124 |
|
125 def showContextMenuDirMulti(self, menu, standardItems): |
|
126 """ |
|
127 Public slot called before the context menu is shown. |
|
128 |
|
129 It enables/disables the VCS menu entries depending on the overall |
|
130 VCS status and the directory status. |
|
131 |
|
132 @param menu reference to the menu to be shown |
|
133 @param standardItems array of standard items that need |
|
134 activation/deactivation depending on the overall VCS status |
|
135 """ |
|
136 vcsName = self.vcs.vcsName() |
|
137 items = self.browser.getSelectedItems() |
|
138 vcsItems = 0 |
|
139 # determine number of selected items under VCS control |
|
140 for itm in items: |
|
141 if itm.data(1) == vcsName: |
|
142 vcsItems += 1 |
|
143 |
|
144 if vcsItems > 0: |
|
145 if vcsItems != len(items): |
|
146 for act in self.vcsDirMultiMenuActions: |
|
147 act.setEnabled(False) |
|
148 else: |
|
149 for act in self.vcsDirMultiMenuActions: |
|
150 act.setEnabled(True) |
|
151 for act in standardItems: |
|
152 act.setEnabled(False) |
|
153 else: |
|
154 for act in self.vcsDirMultiMenuActions: |
|
155 act.setEnabled(False) |
|
156 for act in standardItems: |
|
157 act.setEnabled(True) |
|
158 |
|
159 ########################################################################### |
|
160 ## Protected menu generation methods below |
|
161 ########################################################################### |
|
162 |
|
163 def _addVCSMenu(self, mainMenu): |
|
164 """ |
|
165 Protected method used to add the VCS menu to all project browsers. |
|
166 |
|
167 @param mainMenu reference to the menu to be amended |
|
168 """ |
|
169 self.vcsMenuActions = [] |
|
170 self.vcsAddMenuActions = [] |
|
171 |
|
172 menu = QMenu(self.tr("Version Control")) |
|
173 |
|
174 act = menu.addAction( |
|
175 UI.PixmapCache.getIcon( |
|
176 os.path.join("VcsPlugins", "vcsGit", "icons", "git.png")), |
|
177 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
178 font = act.font() |
|
179 font.setBold(True) |
|
180 act.setFont(font) |
|
181 menu.addSeparator() |
|
182 |
|
183 act = menu.addAction( |
|
184 UI.PixmapCache.getIcon("vcsCommit.png"), |
|
185 self.tr('Commit changes to repository...'), |
|
186 self._VCSCommit) |
|
187 self.vcsMenuActions.append(act) |
|
188 menu.addSeparator() |
|
189 act = menu.addAction( |
|
190 UI.PixmapCache.getIcon("vcsAdd.png"), |
|
191 self.tr('Add/Stage to repository'), |
|
192 self._VCSAdd) |
|
193 act = menu.addAction( |
|
194 UI.PixmapCache.getIcon("vcsRevert.png"), |
|
195 self.tr('Unstage changes'), |
|
196 self.__GitUnstage) |
|
197 self.vcsMenuActions.append(act) |
|
198 menu.addSeparator() |
|
199 act = menu.addAction( |
|
200 UI.PixmapCache.getIcon("vcsRemove.png"), |
|
201 self.tr('Remove from repository (and disk)'), |
|
202 self._VCSRemove) |
|
203 self.vcsMenuActions.append(act) |
|
204 act = menu.addAction( |
|
205 UI.PixmapCache.getIcon("vcsRemove.png"), |
|
206 self.tr('Remove from repository only'), |
|
207 self.__GitForget) |
|
208 self.vcsMenuActions.append(act) |
|
209 menu.addSeparator() |
|
210 act = menu.addAction(self.tr('Copy'), self.__GitCopy) |
|
211 self.vcsMenuActions.append(act) |
|
212 act = menu.addAction(self.tr('Move'), self.__GitMove) |
|
213 self.vcsMenuActions.append(act) |
|
214 menu.addSeparator() |
|
215 act = menu.addAction( |
|
216 UI.PixmapCache.getIcon("vcsLog.png"), |
|
217 self.tr('Show log browser'), self._VCSLogBrowser) |
|
218 self.vcsMenuActions.append(act) |
|
219 menu.addSeparator() |
|
220 act = menu.addAction( |
|
221 UI.PixmapCache.getIcon("vcsStatus.png"), |
|
222 self.tr('Show status'), self._VCSStatus) |
|
223 self.vcsMenuActions.append(act) |
|
224 menu.addSeparator() |
|
225 act = menu.addAction( |
|
226 UI.PixmapCache.getIcon("vcsDiff.png"), |
|
227 self.tr('Show differences'), self._VCSDiff) |
|
228 self.vcsMenuActions.append(act) |
|
229 act = menu.addAction( |
|
230 UI.PixmapCache.getIcon("vcsSbsDiff.png"), |
|
231 self.tr('Show differences side-by-side'), self.__GitSbsDiff) |
|
232 self.vcsMenuActions.append(act) |
|
233 act = menu.addAction( |
|
234 UI.PixmapCache.getIcon("vcsDiff.png"), |
|
235 self.tr('Show differences (extended)'), |
|
236 self.__GitExtendedDiff) |
|
237 self.vcsMenuActions.append(act) |
|
238 act = menu.addAction( |
|
239 UI.PixmapCache.getIcon("vcsSbsDiff.png"), |
|
240 self.tr('Show differences side-by-side (extended)'), |
|
241 self.__GitSbsExtendedDiff) |
|
242 self.vcsMenuActions.append(act) |
|
243 menu.addSeparator() |
|
244 self.annotateAct = menu.addAction( |
|
245 self.tr('Show annotated file'), |
|
246 self.__GitBlame) |
|
247 self.vcsMenuActions.append(self.annotateAct) |
|
248 menu.addSeparator() |
|
249 act = menu.addAction( |
|
250 UI.PixmapCache.getIcon("vcsRevert.png"), |
|
251 self.tr('Revert changes'), self.__GitRevert) |
|
252 self.vcsMenuActions.append(act) |
|
253 menu.addSeparator() |
|
254 |
|
255 menu.addSeparator() |
|
256 menu.addAction(self.tr('Select all local file entries'), |
|
257 self.browser.selectLocalEntries) |
|
258 menu.addAction(self.tr('Select all versioned file entries'), |
|
259 self.browser.selectVCSEntries) |
|
260 menu.addAction(self.tr('Select all local directory entries'), |
|
261 self.browser.selectLocalDirEntries) |
|
262 menu.addAction(self.tr('Select all versioned directory entries'), |
|
263 self.browser.selectVCSDirEntries) |
|
264 menu.addSeparator() |
|
265 menu.addAction(self.tr("Configure..."), self.__GitConfigure) |
|
266 |
|
267 mainMenu.addSeparator() |
|
268 mainMenu.addMenu(menu) |
|
269 self.menu = menu |
|
270 |
|
271 def _addVCSMenuMulti(self, mainMenu): |
|
272 """ |
|
273 Protected method used to add the VCS menu for multi selection to all |
|
274 project browsers. |
|
275 |
|
276 @param mainMenu reference to the menu to be amended |
|
277 """ |
|
278 self.vcsMultiMenuActions = [] |
|
279 |
|
280 menu = QMenu(self.tr("Version Control")) |
|
281 |
|
282 act = menu.addAction( |
|
283 UI.PixmapCache.getIcon( |
|
284 os.path.join("VcsPlugins", "vcsGit", "icons", "git.png")), |
|
285 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
286 font = act.font() |
|
287 font.setBold(True) |
|
288 act.setFont(font) |
|
289 menu.addSeparator() |
|
290 |
|
291 act = menu.addAction( |
|
292 UI.PixmapCache.getIcon("vcsCommit.png"), |
|
293 self.tr('Commit changes to repository...'), |
|
294 self._VCSCommit) |
|
295 self.vcsMultiMenuActions.append(act) |
|
296 menu.addSeparator() |
|
297 act = menu.addAction( |
|
298 UI.PixmapCache.getIcon("vcsAdd.png"), |
|
299 self.tr('Add/Stage to repository'), self._VCSAdd) |
|
300 act = menu.addAction( |
|
301 UI.PixmapCache.getIcon("vcsRevert.png"), |
|
302 self.tr('Unstage changes'), |
|
303 self.__GitUnstage) |
|
304 self.vcsMultiMenuActions.append(act) |
|
305 menu.addSeparator() |
|
306 act = menu.addAction( |
|
307 UI.PixmapCache.getIcon("vcsRemove.png"), |
|
308 self.tr('Remove from repository (and disk)'), |
|
309 self._VCSRemove) |
|
310 self.vcsMultiMenuActions.append(act) |
|
311 act = menu.addAction( |
|
312 UI.PixmapCache.getIcon("vcsRemove.png"), |
|
313 self.tr('Remove from repository only'), |
|
314 self.__GitForget) |
|
315 self.vcsMultiMenuActions.append(act) |
|
316 menu.addSeparator() |
|
317 act = menu.addAction( |
|
318 UI.PixmapCache.getIcon("vcsStatus.png"), |
|
319 self.tr('Show status'), self._VCSStatus) |
|
320 self.vcsMultiMenuActions.append(act) |
|
321 menu.addSeparator() |
|
322 act = menu.addAction( |
|
323 UI.PixmapCache.getIcon("vcsDiff.png"), |
|
324 self.tr('Show differences'), self._VCSDiff) |
|
325 self.vcsMultiMenuActions.append(act) |
|
326 act = menu.addAction( |
|
327 UI.PixmapCache.getIcon("vcsDiff.png"), |
|
328 self.tr('Show differences (extended)'), |
|
329 self.__GitExtendedDiff) |
|
330 self.vcsMultiMenuActions.append(act) |
|
331 menu.addSeparator() |
|
332 act = menu.addAction( |
|
333 UI.PixmapCache.getIcon("vcsRevert.png"), |
|
334 self.tr('Revert changes'), self.__GitRevert) |
|
335 self.vcsMultiMenuActions.append(act) |
|
336 menu.addSeparator() |
|
337 |
|
338 menu.addSeparator() |
|
339 menu.addAction(self.tr('Select all local file entries'), |
|
340 self.browser.selectLocalEntries) |
|
341 menu.addAction(self.tr('Select all versioned file entries'), |
|
342 self.browser.selectVCSEntries) |
|
343 menu.addAction(self.tr('Select all local directory entries'), |
|
344 self.browser.selectLocalDirEntries) |
|
345 menu.addAction(self.tr('Select all versioned directory entries'), |
|
346 self.browser.selectVCSDirEntries) |
|
347 menu.addSeparator() |
|
348 menu.addAction(self.tr("Configure..."), self.__GitConfigure) |
|
349 |
|
350 mainMenu.addSeparator() |
|
351 mainMenu.addMenu(menu) |
|
352 self.menuMulti = menu |
|
353 |
|
354 def _addVCSMenuBack(self, mainMenu): |
|
355 """ |
|
356 Protected method used to add the VCS menu to all project browsers. |
|
357 |
|
358 @param mainMenu reference to the menu to be amended |
|
359 """ |
|
360 menu = QMenu(self.tr("Version Control")) |
|
361 |
|
362 act = menu.addAction( |
|
363 UI.PixmapCache.getIcon( |
|
364 os.path.join("VcsPlugins", "vcsGit", "icons", "git.png")), |
|
365 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
366 font = act.font() |
|
367 font.setBold(True) |
|
368 act.setFont(font) |
|
369 menu.addSeparator() |
|
370 |
|
371 menu.addAction(self.tr('Select all local file entries'), |
|
372 self.browser.selectLocalEntries) |
|
373 menu.addAction(self.tr('Select all versioned file entries'), |
|
374 self.browser.selectVCSEntries) |
|
375 menu.addAction(self.tr('Select all local directory entries'), |
|
376 self.browser.selectLocalDirEntries) |
|
377 menu.addAction(self.tr('Select all versioned directory entries'), |
|
378 self.browser.selectVCSDirEntries) |
|
379 menu.addSeparator() |
|
380 menu.addAction(self.tr("Configure..."), self.__GitConfigure) |
|
381 |
|
382 mainMenu.addSeparator() |
|
383 mainMenu.addMenu(menu) |
|
384 self.menuBack = menu |
|
385 |
|
386 def _addVCSMenuDir(self, mainMenu): |
|
387 """ |
|
388 Protected method used to add the VCS menu to all project browsers. |
|
389 |
|
390 @param mainMenu reference to the menu to be amended |
|
391 """ |
|
392 if mainMenu is None: |
|
393 return |
|
394 |
|
395 self.vcsDirMenuActions = [] |
|
396 self.vcsAddDirMenuActions = [] |
|
397 |
|
398 menu = QMenu(self.tr("Version Control")) |
|
399 |
|
400 act = menu.addAction( |
|
401 UI.PixmapCache.getIcon( |
|
402 os.path.join("VcsPlugins", "vcsGit", "icons", "git.png")), |
|
403 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
404 font = act.font() |
|
405 font.setBold(True) |
|
406 act.setFont(font) |
|
407 menu.addSeparator() |
|
408 |
|
409 act = menu.addAction( |
|
410 UI.PixmapCache.getIcon("vcsCommit.png"), |
|
411 self.tr('Commit changes to repository...'), |
|
412 self._VCSCommit) |
|
413 self.vcsDirMenuActions.append(act) |
|
414 menu.addSeparator() |
|
415 act = menu.addAction( |
|
416 UI.PixmapCache.getIcon("vcsAdd.png"), |
|
417 self.tr('Add/Stage to repository'), self._VCSAdd) |
|
418 act = menu.addAction( |
|
419 UI.PixmapCache.getIcon("vcsRevert.png"), |
|
420 self.tr('Unstage changes'), |
|
421 self.__GitUnstage) |
|
422 self.vcsDirMenuActions.append(act) |
|
423 menu.addSeparator() |
|
424 act = menu.addAction( |
|
425 UI.PixmapCache.getIcon("vcsRemove.png"), |
|
426 self.tr('Remove from repository (and disk)'), |
|
427 self._VCSRemove) |
|
428 self.vcsDirMenuActions.append(act) |
|
429 menu.addSeparator() |
|
430 act = menu.addAction(self.tr('Copy'), self.__GitCopy) |
|
431 self.vcsDirMenuActions.append(act) |
|
432 act = menu.addAction(self.tr('Move'), self.__GitMove) |
|
433 self.vcsDirMenuActions.append(act) |
|
434 menu.addSeparator() |
|
435 act = menu.addAction( |
|
436 UI.PixmapCache.getIcon("vcsLog.png"), |
|
437 self.tr('Show log browser'), self._VCSLogBrowser) |
|
438 self.vcsDirMenuActions.append(act) |
|
439 menu.addSeparator() |
|
440 act = menu.addAction( |
|
441 UI.PixmapCache.getIcon("vcsStatus.png"), |
|
442 self.tr('Show status'), self._VCSStatus) |
|
443 self.vcsDirMenuActions.append(act) |
|
444 menu.addSeparator() |
|
445 act = menu.addAction( |
|
446 UI.PixmapCache.getIcon("vcsDiff.png"), |
|
447 self.tr('Show differences'), self._VCSDiff) |
|
448 self.vcsDirMenuActions.append(act) |
|
449 act = menu.addAction( |
|
450 UI.PixmapCache.getIcon("vcsDiff.png"), |
|
451 self.tr('Show differences (extended)'), |
|
452 self.__GitExtendedDiff) |
|
453 self.vcsDirMenuActions.append(act) |
|
454 menu.addSeparator() |
|
455 act = menu.addAction( |
|
456 UI.PixmapCache.getIcon("vcsRevert.png"), |
|
457 self.tr('Revert changes'), self.__GitRevert) |
|
458 self.vcsDirMenuActions.append(act) |
|
459 menu.addSeparator() |
|
460 |
|
461 menu.addSeparator() |
|
462 menu.addAction(self.tr('Select all local file entries'), |
|
463 self.browser.selectLocalEntries) |
|
464 menu.addAction(self.tr('Select all versioned file entries'), |
|
465 self.browser.selectVCSEntries) |
|
466 menu.addAction(self.tr('Select all local directory entries'), |
|
467 self.browser.selectLocalDirEntries) |
|
468 menu.addAction(self.tr('Select all versioned directory entries'), |
|
469 self.browser.selectVCSDirEntries) |
|
470 menu.addSeparator() |
|
471 menu.addAction(self.tr("Configure..."), self.__GitConfigure) |
|
472 |
|
473 mainMenu.addSeparator() |
|
474 mainMenu.addMenu(menu) |
|
475 self.menuDir = menu |
|
476 |
|
477 def _addVCSMenuDirMulti(self, mainMenu): |
|
478 """ |
|
479 Protected method used to add the VCS menu to all project browsers. |
|
480 |
|
481 @param mainMenu reference to the menu to be amended |
|
482 """ |
|
483 if mainMenu is None: |
|
484 return |
|
485 |
|
486 self.vcsDirMultiMenuActions = [] |
|
487 |
|
488 menu = QMenu(self.tr("Version Control")) |
|
489 |
|
490 act = menu.addAction( |
|
491 UI.PixmapCache.getIcon( |
|
492 os.path.join("VcsPlugins", "vcsGit", "icons", "git.png")), |
|
493 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
494 font = act.font() |
|
495 font.setBold(True) |
|
496 act.setFont(font) |
|
497 menu.addSeparator() |
|
498 |
|
499 act = menu.addAction( |
|
500 UI.PixmapCache.getIcon("vcsCommit.png"), |
|
501 self.tr('Commit changes to repository...'), |
|
502 self._VCSCommit) |
|
503 self.vcsDirMultiMenuActions.append(act) |
|
504 menu.addSeparator() |
|
505 act = menu.addAction( |
|
506 UI.PixmapCache.getIcon("vcsAdd.png"), |
|
507 self.tr('Add/Stage to repository'), self._VCSAdd) |
|
508 act = menu.addAction( |
|
509 UI.PixmapCache.getIcon("vcsRevert.png"), |
|
510 self.tr('Unstage changes'), |
|
511 self.__GitUnstage) |
|
512 self.vcsDirMultiMenuActions.append(act) |
|
513 menu.addSeparator() |
|
514 act = menu.addAction( |
|
515 UI.PixmapCache.getIcon("vcsRemove.png"), |
|
516 self.tr('Remove from repository (and disk)'), |
|
517 self._VCSRemove) |
|
518 self.vcsDirMultiMenuActions.append(act) |
|
519 menu.addSeparator() |
|
520 act = menu.addAction( |
|
521 UI.PixmapCache.getIcon("vcsStatus.png"), |
|
522 self.tr('Show status'), self._VCSStatus) |
|
523 self.vcsDirMultiMenuActions.append(act) |
|
524 menu.addSeparator() |
|
525 act = menu.addAction( |
|
526 UI.PixmapCache.getIcon("vcsDiff.png"), |
|
527 self.tr('Show differences'), self._VCSDiff) |
|
528 self.vcsDirMultiMenuActions.append(act) |
|
529 act = menu.addAction( |
|
530 UI.PixmapCache.getIcon("vcsDiff.png"), |
|
531 self.tr('Show differences (extended)'), |
|
532 self.__GitExtendedDiff) |
|
533 self.vcsDirMultiMenuActions.append(act) |
|
534 menu.addSeparator() |
|
535 act = menu.addAction( |
|
536 UI.PixmapCache.getIcon("vcsRevert.png"), |
|
537 self.tr('Revert changes'), self.__GitRevert) |
|
538 self.vcsDirMultiMenuActions.append(act) |
|
539 menu.addSeparator() |
|
540 |
|
541 menu.addSeparator() |
|
542 menu.addAction(self.tr('Select all local file entries'), |
|
543 self.browser.selectLocalEntries) |
|
544 menu.addAction(self.tr('Select all versioned file entries'), |
|
545 self.browser.selectVCSEntries) |
|
546 menu.addAction(self.tr('Select all local directory entries'), |
|
547 self.browser.selectLocalDirEntries) |
|
548 menu.addAction(self.tr('Select all versioned directory entries'), |
|
549 self.browser.selectVCSDirEntries) |
|
550 menu.addSeparator() |
|
551 menu.addAction(self.tr("Configure..."), self.__GitConfigure) |
|
552 |
|
553 mainMenu.addSeparator() |
|
554 mainMenu.addMenu(menu) |
|
555 self.menuDirMulti = menu |
|
556 |
|
557 def __GitConfigure(self): |
|
558 """ |
|
559 Private method to open the configuration dialog. |
|
560 """ |
|
561 e5App().getObject("UserInterface")\ |
|
562 .showPreferences("zzz_gitPage") |
|
563 |
|
564 def __GitForget(self): |
|
565 """ |
|
566 Private slot called by the context menu to remove the selected file |
|
567 from the Git repository leaving a copy in the project directory. |
|
568 """ |
|
569 from UI.DeleteFilesConfirmationDialog import \ |
|
570 DeleteFilesConfirmationDialog |
|
571 if self.isTranslationsBrowser: |
|
572 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) |
|
573 names = [itm.fileName() for itm in items] |
|
574 |
|
575 dlg = DeleteFilesConfirmationDialog( |
|
576 self.parent(), |
|
577 self.tr("Remove from repository only"), |
|
578 self.tr( |
|
579 "Do you really want to remove these files" |
|
580 " from the repository?"), |
|
581 names) |
|
582 else: |
|
583 items = self.browser.getSelectedItems() |
|
584 names = [itm.fileName() for itm in items] |
|
585 files = [self.browser.project.getRelativePath(name) |
|
586 for name in names] |
|
587 |
|
588 dlg = DeleteFilesConfirmationDialog( |
|
589 self.parent(), |
|
590 self.tr("Remove from repository only"), |
|
591 self.tr( |
|
592 "Do you really want to remove these files" |
|
593 " from the repository?"), |
|
594 files) |
|
595 |
|
596 if dlg.exec_() == QDialog.Accepted: |
|
597 self.vcs.vcsRemove(names, stageOnly=True) |
|
598 |
|
599 for fn in names: |
|
600 self._updateVCSStatus(fn) |
|
601 |
|
602 def __GitCopy(self): |
|
603 """ |
|
604 Private slot called by the context menu to copy the selected file. |
|
605 """ |
|
606 itm = self.browser.currentItem() |
|
607 try: |
|
608 fn = itm.fileName() |
|
609 except AttributeError: |
|
610 fn = itm.dirName() |
|
611 self.vcs.gitCopy(fn, self.project) |
|
612 |
|
613 def __GitMove(self): |
|
614 """ |
|
615 Private slot called by the context menu to move the selected file. |
|
616 """ |
|
617 itm = self.browser.currentItem() |
|
618 try: |
|
619 fn = itm.fileName() |
|
620 except AttributeError: |
|
621 fn = itm.dirName() |
|
622 isFile = os.path.isfile(fn) |
|
623 movefiles = self.browser.project.getFiles(fn) |
|
624 if self.vcs.vcsMove(fn, self.project): |
|
625 if isFile: |
|
626 self.browser.closeSourceWindow.emit(fn) |
|
627 else: |
|
628 for mf in movefiles: |
|
629 self.browser.closeSourceWindow.emit(mf) |
|
630 |
|
631 def __GitExtendedDiff(self): |
|
632 """ |
|
633 Private slot called by the context menu to show the difference of a |
|
634 file to the repository. |
|
635 |
|
636 This gives the chance to enter the revisions to compare. |
|
637 """ |
|
638 names = [] |
|
639 for itm in self.browser.getSelectedItems(): |
|
640 try: |
|
641 names.append(itm.fileName()) |
|
642 except AttributeError: |
|
643 names.append(itm.dirName()) |
|
644 self.vcs.gitExtendedDiff(names) |
|
645 |
|
646 def __GitSbsDiff(self): |
|
647 """ |
|
648 Private slot called by the context menu to show the difference of a |
|
649 file to the repository side-by-side. |
|
650 """ |
|
651 itm = self.browser.currentItem() |
|
652 fn = itm.fileName() |
|
653 self.vcs.gitSbsDiff(fn) |
|
654 |
|
655 def __GitSbsExtendedDiff(self): |
|
656 """ |
|
657 Private slot called by the context menu to show the difference of a |
|
658 file to the repository side-by-side. |
|
659 |
|
660 It allows the selection of revisions to compare. |
|
661 """ |
|
662 itm = self.browser.currentItem() |
|
663 fn = itm.fileName() |
|
664 self.vcs.gitSbsDiff(fn, extended=True) |
|
665 |
|
666 def __GitUnstage(self): |
|
667 """ |
|
668 Private slot to unstage changes. |
|
669 """ |
|
670 names = [] |
|
671 for itm in self.browser.getSelectedItems(): |
|
672 try: |
|
673 name = itm.fileName() |
|
674 except AttributeError: |
|
675 name = itm.dirName() |
|
676 names.append(name) |
|
677 self.vcs.gitUnstage(names) |
|
678 |
|
679 def __GitRevert(self): |
|
680 """ |
|
681 Private slot to revert changes of the working area. |
|
682 """ |
|
683 names = [] |
|
684 for itm in self.browser.getSelectedItems(): |
|
685 try: |
|
686 name = itm.fileName() |
|
687 except AttributeError: |
|
688 name = itm.dirName() |
|
689 names.append(name) |
|
690 self.vcs.gitRevert(names) |
|
691 |
|
692 def __GitBlame(self): |
|
693 """ |
|
694 Private slot called by the context menu to show the annotations of a |
|
695 file. |
|
696 """ |
|
697 itm = self.browser.currentItem() |
|
698 fn = itm.fileName() |
|
699 self.vcs.gitBlame(fn) |