Plugins/VcsPlugins/vcsMercurial/ProjectBrowserHelper.py

changeset 3008
7848489bcb92
parent 2841
1f79e88f18b7
child 3023
34ce20603bf7
child 3057
10516539f238
equal deleted inserted replaced
3007:bad2e89047e7 3008:7848489bcb92
20 20
21 class HgProjectBrowserHelper(VcsProjectBrowserHelper): 21 class HgProjectBrowserHelper(VcsProjectBrowserHelper):
22 """ 22 """
23 Class implementing the VCS project browser helper for Mercurial. 23 Class implementing the VCS project browser helper for Mercurial.
24 """ 24 """
25 def __init__(self, vcsObject, browserObject, projectObject, isTranslationsBrowser, 25 def __init__(self, vcsObject, browserObject, projectObject,
26 parent=None, name=None): 26 isTranslationsBrowser, parent=None, name=None):
27 """ 27 """
28 Constructor 28 Constructor
29 29
30 @param vcsObject reference to the vcs object 30 @param vcsObject reference to the vcs object
31 @param browserObject reference to the project browser object 31 @param browserObject reference to the project browser object
32 @param projectObject reference to the project object 32 @param projectObject reference to the project object
33 @param isTranslationsBrowser flag indicating, the helper is requested for the 33 @param isTranslationsBrowser flag indicating, the helper is requested
34 translations browser (this needs some special treatment) 34 for the translations browser (this needs some special treatment)
35 @param parent parent widget (QWidget) 35 @param parent parent widget (QWidget)
36 @param name name of this object (string) 36 @param name name of this object (string)
37 """ 37 """
38 VcsProjectBrowserHelper.__init__(self, vcsObject, browserObject, projectObject, 38 VcsProjectBrowserHelper.__init__(self, vcsObject, browserObject,
39 isTranslationsBrowser, parent, name) 39 projectObject, isTranslationsBrowser,
40 parent, name)
40 41
41 def showContextMenu(self, menu, standardItems): 42 def showContextMenu(self, menu, standardItems):
42 """ 43 """
43 Slot called before the context menu is shown. 44 Slot called before the context menu is shown.
44 45
45 It enables/disables the VCS menu entries depending on the overall 46 It enables/disables the VCS menu entries depending on the overall
46 VCS status and the file status. 47 VCS status and the file status.
47 48
48 @param menu reference to the menu to be shown 49 @param menu reference to the menu to be shown
49 @param standardItems array of standard items that need activation/deactivation 50 @param standardItems array of standard items that need
50 depending on the overall VCS status 51 activation/deactivation depending on the overall VCS status
51 """ 52 """
52 if self.browser.currentItem().data(1) == self.vcs.vcsName(): 53 if self.browser.currentItem().data(1) == self.vcs.vcsName():
53 for act in self.vcsMenuActions: 54 for act in self.vcsMenuActions:
54 act.setEnabled(True) 55 act.setEnabled(True)
55 for act in self.vcsAddMenuActions: 56 for act in self.vcsAddMenuActions:
72 73
73 It enables/disables the VCS menu entries depending on the overall 74 It enables/disables the VCS menu entries depending on the overall
74 VCS status and the files status. 75 VCS status and the files status.
75 76
76 @param menu reference to the menu to be shown 77 @param menu reference to the menu to be shown
77 @param standardItems array of standard items that need activation/deactivation 78 @param standardItems array of standard items that need
78 depending on the overall VCS status 79 activation/deactivation depending on the overall VCS status
79 """ 80 """
80 vcsName = self.vcs.vcsName() 81 vcsName = self.vcs.vcsName()
81 items = self.browser.getSelectedItems() 82 items = self.browser.getSelectedItems()
82 vcsItems = 0 83 vcsItems = 0
83 # determine number of selected items under VCS control 84 # determine number of selected items under VCS control
110 111
111 It enables/disables the VCS menu entries depending on the overall 112 It enables/disables the VCS menu entries depending on the overall
112 VCS status and the directory status. 113 VCS status and the directory status.
113 114
114 @param menu reference to the menu to be shown 115 @param menu reference to the menu to be shown
115 @param standardItems array of standard items that need activation/deactivation 116 @param standardItems array of standard items that need
116 depending on the overall VCS status 117 activation/deactivation depending on the overall VCS status
117 """ 118 """
118 if self.browser.currentItem().data(1) == self.vcs.vcsName(): 119 if self.browser.currentItem().data(1) == self.vcs.vcsName():
119 for act in self.vcsDirMenuActions: 120 for act in self.vcsDirMenuActions:
120 act.setEnabled(True) 121 act.setEnabled(True)
121 for act in self.vcsAddDirMenuActions: 122 for act in self.vcsAddDirMenuActions:
136 137
137 It enables/disables the VCS menu entries depending on the overall 138 It enables/disables the VCS menu entries depending on the overall
138 VCS status and the directory status. 139 VCS status and the directory status.
139 140
140 @param menu reference to the menu to be shown 141 @param menu reference to the menu to be shown
141 @param standardItems array of standard items that need activation/deactivation 142 @param standardItems array of standard items that need
142 depending on the overall VCS status 143 activation/deactivation depending on the overall VCS status
143 """ 144 """
144 vcsName = self.vcs.vcsName() 145 vcsName = self.vcs.vcsName()
145 items = self.browser.getSelectedItems() 146 items = self.browser.getSelectedItems()
146 vcsItems = 0 147 vcsItems = 0
147 # determine number of selected items under VCS control 148 # determine number of selected items under VCS control
166 for act in self.vcsAddDirMultiMenuActions: 167 for act in self.vcsAddDirMultiMenuActions:
167 act.setEnabled(True) 168 act.setEnabled(True)
168 for act in standardItems: 169 for act in standardItems:
169 act.setEnabled(True) 170 act.setEnabled(True)
170 171
171 ############################################################################ 172 ###########################################################################
172 # Protected menu generation methods below 173 # Protected menu generation methods below
173 ############################################################################ 174 ###########################################################################
174 175
175 def _addVCSMenu(self, mainMenu): 176 def _addVCSMenu(self, mainMenu):
176 """ 177 """
177 Protected method used to add the VCS menu to all project browsers. 178 Protected method used to add the VCS menu to all project browsers.
178 179
183 184
184 menu = QMenu(self.trUtf8("Version Control")) 185 menu = QMenu(self.trUtf8("Version Control"))
185 186
186 act = menu.addAction( 187 act = menu.addAction(
187 UI.PixmapCache.getIcon( 188 UI.PixmapCache.getIcon(
188 os.path.join("VcsPlugins", "vcsMercurial", "icons", "mercurial.png")), 189 os.path.join("VcsPlugins", "vcsMercurial", "icons",
190 "mercurial.png")),
189 self.vcs.vcsName(), self._VCSInfoDisplay) 191 self.vcs.vcsName(), self._VCSInfoDisplay)
190 font = act.font() 192 font = act.font()
191 font.setBold(True) 193 font.setBold(True)
192 act.setFont(font) 194 act.setFont(font)
193 menu.addSeparator() 195 menu.addSeparator()
245 self.vcsMenuActions.append(self.annotateAct) 247 self.vcsMenuActions.append(self.annotateAct)
246 menu.addSeparator() 248 menu.addSeparator()
247 act = menu.addAction(UI.PixmapCache.getIcon("vcsRevert.png"), 249 act = menu.addAction(UI.PixmapCache.getIcon("vcsRevert.png"),
248 self.trUtf8('Revert changes'), self.__HgRevert) 250 self.trUtf8('Revert changes'), self.__HgRevert)
249 self.vcsMenuActions.append(act) 251 self.vcsMenuActions.append(act)
250 act = menu.addAction(self.trUtf8('Conflict resolved'), self.__HgResolve) 252 act = menu.addAction(
253 self.trUtf8('Conflict resolved'), self.__HgResolve)
251 self.vcsMenuActions.append(act) 254 self.vcsMenuActions.append(act)
252 menu.addSeparator() 255 menu.addSeparator()
253 menu.addAction(self.trUtf8('Select all local file entries'), 256 menu.addAction(self.trUtf8('Select all local file entries'),
254 self.browser.selectLocalEntries) 257 self.browser.selectLocalEntries)
255 menu.addAction(self.trUtf8('Select all versioned file entries'), 258 menu.addAction(self.trUtf8('Select all versioned file entries'),
276 279
277 menu = QMenu(self.trUtf8("Version Control")) 280 menu = QMenu(self.trUtf8("Version Control"))
278 281
279 act = menu.addAction( 282 act = menu.addAction(
280 UI.PixmapCache.getIcon( 283 UI.PixmapCache.getIcon(
281 os.path.join("VcsPlugins", "vcsMercurial", "icons", "mercurial.png")), 284 os.path.join("VcsPlugins", "vcsMercurial", "icons",
285 "mercurial.png")),
282 self.vcs.vcsName(), self._VCSInfoDisplay) 286 self.vcs.vcsName(), self._VCSInfoDisplay)
283 font = act.font() 287 font = act.font()
284 font.setBold(True) 288 font.setBold(True)
285 act.setFont(font) 289 act.setFont(font)
286 menu.addSeparator() 290 menu.addSeparator()
315 self.vcsMultiMenuActions.append(act) 319 self.vcsMultiMenuActions.append(act)
316 menu.addSeparator() 320 menu.addSeparator()
317 act = menu.addAction(UI.PixmapCache.getIcon("vcsRevert.png"), 321 act = menu.addAction(UI.PixmapCache.getIcon("vcsRevert.png"),
318 self.trUtf8('Revert changes'), self.__HgRevert) 322 self.trUtf8('Revert changes'), self.__HgRevert)
319 self.vcsMultiMenuActions.append(act) 323 self.vcsMultiMenuActions.append(act)
320 act = menu.addAction(self.trUtf8('Conflict resolved'), self.__HgResolve) 324 act = menu.addAction(
325 self.trUtf8('Conflict resolved'), self.__HgResolve)
321 self.vcsMultiMenuActions.append(act) 326 self.vcsMultiMenuActions.append(act)
322 menu.addSeparator() 327 menu.addSeparator()
323 menu.addAction(self.trUtf8('Select all local file entries'), 328 menu.addAction(self.trUtf8('Select all local file entries'),
324 self.browser.selectLocalEntries) 329 self.browser.selectLocalEntries)
325 menu.addAction(self.trUtf8('Select all versioned file entries'), 330 menu.addAction(self.trUtf8('Select all versioned file entries'),
342 """ 347 """
343 menu = QMenu(self.trUtf8("Version Control")) 348 menu = QMenu(self.trUtf8("Version Control"))
344 349
345 act = menu.addAction( 350 act = menu.addAction(
346 UI.PixmapCache.getIcon( 351 UI.PixmapCache.getIcon(
347 os.path.join("VcsPlugins", "vcsMercurial", "icons", "mercurial.png")), 352 os.path.join("VcsPlugins", "vcsMercurial", "icons",
353 "mercurial.png")),
348 self.vcs.vcsName(), self._VCSInfoDisplay) 354 self.vcs.vcsName(), self._VCSInfoDisplay)
349 font = act.font() 355 font = act.font()
350 font.setBold(True) 356 font.setBold(True)
351 act.setFont(font) 357 act.setFont(font)
352 menu.addSeparator() 358 menu.addSeparator()
379 385
380 menu = QMenu(self.trUtf8("Version Control")) 386 menu = QMenu(self.trUtf8("Version Control"))
381 387
382 act = menu.addAction( 388 act = menu.addAction(
383 UI.PixmapCache.getIcon( 389 UI.PixmapCache.getIcon(
384 os.path.join("VcsPlugins", "vcsMercurial", "icons", "mercurial.png")), 390 os.path.join("VcsPlugins", "vcsMercurial", "icons",
391 "mercurial.png")),
385 self.vcs.vcsName(), self._VCSInfoDisplay) 392 self.vcs.vcsName(), self._VCSInfoDisplay)
386 font = act.font() 393 font = act.font()
387 font.setBold(True) 394 font.setBold(True)
388 act.setFont(font) 395 act.setFont(font)
389 menu.addSeparator() 396 menu.addSeparator()
426 self.vcsDirMenuActions.append(act) 433 self.vcsDirMenuActions.append(act)
427 menu.addSeparator() 434 menu.addSeparator()
428 act = menu.addAction(UI.PixmapCache.getIcon("vcsRevert.png"), 435 act = menu.addAction(UI.PixmapCache.getIcon("vcsRevert.png"),
429 self.trUtf8('Revert changes'), self.__HgRevert) 436 self.trUtf8('Revert changes'), self.__HgRevert)
430 self.vcsDirMenuActions.append(act) 437 self.vcsDirMenuActions.append(act)
431 act = menu.addAction(self.trUtf8('Conflict resolved'), self.__HgResolve) 438 act = menu.addAction(
439 self.trUtf8('Conflict resolved'), self.__HgResolve)
432 self.vcsDirMenuActions.append(act) 440 self.vcsDirMenuActions.append(act)
433 menu.addSeparator() 441 menu.addSeparator()
434 menu.addAction(self.trUtf8('Select all local file entries'), 442 menu.addAction(self.trUtf8('Select all local file entries'),
435 self.browser.selectLocalEntries) 443 self.browser.selectLocalEntries)
436 menu.addAction(self.trUtf8('Select all versioned file entries'), 444 menu.addAction(self.trUtf8('Select all versioned file entries'),
459 467
460 menu = QMenu(self.trUtf8("Version Control")) 468 menu = QMenu(self.trUtf8("Version Control"))
461 469
462 act = menu.addAction( 470 act = menu.addAction(
463 UI.PixmapCache.getIcon( 471 UI.PixmapCache.getIcon(
464 os.path.join("VcsPlugins", "vcsMercurial", "icons", "mercurial.png")), 472 os.path.join("VcsPlugins", "vcsMercurial", "icons",
473 "mercurial.png")),
465 self.vcs.vcsName(), self._VCSInfoDisplay) 474 self.vcs.vcsName(), self._VCSInfoDisplay)
466 font = act.font() 475 font = act.font()
467 font.setBold(True) 476 font.setBold(True)
468 act.setFont(font) 477 act.setFont(font)
469 menu.addSeparator() 478 menu.addSeparator()
494 self.vcsDirMultiMenuActions.append(act) 503 self.vcsDirMultiMenuActions.append(act)
495 menu.addSeparator() 504 menu.addSeparator()
496 act = menu.addAction(UI.PixmapCache.getIcon("vcsRevert.png"), 505 act = menu.addAction(UI.PixmapCache.getIcon("vcsRevert.png"),
497 self.trUtf8('Revert changes'), self.__HgRevert) 506 self.trUtf8('Revert changes'), self.__HgRevert)
498 self.vcsDirMultiMenuActions.append(act) 507 self.vcsDirMultiMenuActions.append(act)
499 act = menu.addAction(self.trUtf8('Conflict resolved'), self.__HgResolve) 508 act = menu.addAction(
509 self.trUtf8('Conflict resolved'), self.__HgResolve)
500 self.vcsDirMultiMenuActions.append(act) 510 self.vcsDirMultiMenuActions.append(act)
501 menu.addSeparator() 511 menu.addSeparator()
502 menu.addAction(self.trUtf8('Select all local file entries'), 512 menu.addAction(self.trUtf8('Select all local file entries'),
503 self.browser.selectLocalEntries) 513 self.browser.selectLocalEntries)
504 menu.addAction(self.trUtf8('Select all versioned file entries'), 514 menu.addAction(self.trUtf8('Select all versioned file entries'),
511 521
512 mainMenu.addSeparator() 522 mainMenu.addSeparator()
513 mainMenu.addMenu(menu) 523 mainMenu.addMenu(menu)
514 self.menuDirMulti = menu 524 self.menuDirMulti = menu
515 525
516 ############################################################################ 526 ###########################################################################
517 # Menu handling methods below 527 # Menu handling methods below
518 ############################################################################ 528 ###########################################################################
519 529
520 def __HgRevert(self): 530 def __HgRevert(self):
521 """ 531 """
522 Protected slot called by the context menu to revert changes made. 532 Protected slot called by the context menu to revert changes made.
523 """ 533 """
559 for mf in movefiles: 569 for mf in movefiles:
560 self.browser.closeSourceWindow.emit(mf) 570 self.browser.closeSourceWindow.emit(mf)
561 571
562 def __HgExtendedDiff(self): 572 def __HgExtendedDiff(self):
563 """ 573 """
564 Private slot called by the context menu to show the difference of a file to 574 Private slot called by the context menu to show the difference of a
565 the repository. 575 file to the repository.
566 576
567 This gives the chance to enter the revisions to compare. 577 This gives the chance to enter the revisions to compare.
568 """ 578 """
569 names = [] 579 names = []
570 for itm in self.browser.getSelectedItems(): 580 for itm in self.browser.getSelectedItems():
574 names.append(itm.dirName()) 584 names.append(itm.dirName())
575 self.vcs.hgExtendedDiff(names) 585 self.vcs.hgExtendedDiff(names)
576 586
577 def __HgSbsDiff(self): 587 def __HgSbsDiff(self):
578 """ 588 """
579 Private slot called by the context menu to show the difference of a file to 589 Private slot called by the context menu to show the difference of a
580 the repository side-by-side. 590 file to the repository side-by-side.
581 """ 591 """
582 itm = self.browser.currentItem() 592 itm = self.browser.currentItem()
583 fn = itm.fileName() 593 fn = itm.fileName()
584 self.vcs.hgSbsDiff(fn) 594 self.vcs.hgSbsDiff(fn)
585 595
586 def __HgSbsExtendedDiff(self): 596 def __HgSbsExtendedDiff(self):
587 """ 597 """
588 Private slot called by the context menu to show the difference of a file to 598 Private slot called by the context menu to show the difference of a
589 the repository side-by-side allowing the selection of revisions to compare. 599 file to the repository side-by-side.
600
601 It allows the selection of revisions to compare.
590 """ 602 """
591 itm = self.browser.currentItem() 603 itm = self.browser.currentItem()
592 fn = itm.fileName() 604 fn = itm.fileName()
593 self.vcs.hgSbsDiff(fn, extended=True) 605 self.vcs.hgSbsDiff(fn, extended=True)
594 606
595 def __HgAnnotate(self): 607 def __HgAnnotate(self):
596 """ 608 """
597 Private slot called by the context menu to show the annotations of a file. 609 Private slot called by the context menu to show the annotations of a
610 file.
598 """ 611 """
599 itm = self.browser.currentItem() 612 itm = self.browser.currentItem()
600 fn = itm.fileName() 613 fn = itm.fileName()
601 self.vcs.hgAnnotate(fn) 614 self.vcs.hgAnnotate(fn)
602 615
603 def __HgLogBrowser(self): 616 def __HgLogBrowser(self):
604 """ 617 """
605 Private slot called by the context menu to show the log browser for a file. 618 Private slot called by the context menu to show the log browser for a
619 file.
606 """ 620 """
607 itm = self.browser.currentItem() 621 itm = self.browser.currentItem()
608 try: 622 try:
609 fn = itm.fileName() 623 fn = itm.fileName()
610 isFile = True 624 isFile = True
625 names.append(itm.dirName()) 639 names.append(itm.dirName())
626 self.vcs.hgResolve(names) 640 self.vcs.hgResolve(names)
627 641
628 def __HgForget(self): 642 def __HgForget(self):
629 """ 643 """
630 Private slot called by the context menu to remove the selected file from the 644 Private slot called by the context menu to remove the selected file
631 Mercurial repository leaving a copy in the project directory. 645 from the Mercurial repository leaving a copy in the project directory.
632 """ 646 """
633 from UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog 647 from UI.DeleteFilesConfirmationDialog import \
648 DeleteFilesConfirmationDialog
634 if self.isTranslationsBrowser: 649 if self.isTranslationsBrowser:
635 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) 650 items = self.browser.getSelectedItems([ProjectBrowserFileItem])
636 names = [itm.fileName() for itm in items] 651 names = [itm.fileName() for itm in items]
637 652
638 dlg = DeleteFilesConfirmationDialog(self.parent(), 653 dlg = DeleteFilesConfirmationDialog(self.parent(),
639 self.trUtf8("Remove from repository only"), 654 self.trUtf8("Remove from repository only"),
640 self.trUtf8("Do you really want to remove these translation files from" 655 self.trUtf8("Do you really want to remove these files"
641 " the repository?"), 656 " from the repository?"),
642 names) 657 names)
643 else: 658 else:
644 items = self.browser.getSelectedItems() 659 items = self.browser.getSelectedItems()
645 names = [itm.fileName() for itm in items] 660 names = [itm.fileName() for itm in items]
646 files = [self.browser.project.getRelativePath(name) \ 661 files = [self.browser.project.getRelativePath(name) \

eric ide

mercurial