Plugins/VcsPlugins/vcsMercurial/HgStatusDialog.py

branch
Py2 comp.
changeset 2847
1843ef6e2656
parent 2791
a9577f248f04
parent 2840
10a133f3a5e8
child 3057
10516539f238
equal deleted inserted replaced
2846:b852fe4d153a 2847:1843ef6e2656
29 29
30 class HgStatusDialog(QWidget, Ui_HgStatusDialog): 30 class HgStatusDialog(QWidget, Ui_HgStatusDialog):
31 """ 31 """
32 Class implementing a dialog to show the output of the hg status command process. 32 Class implementing a dialog to show the output of the hg status command process.
33 """ 33 """
34 def __init__(self, vcs, parent=None): 34 def __init__(self, vcs, mq=False, parent=None):
35 """ 35 """
36 Constructor 36 Constructor
37 37
38 @param vcs reference to the vcs object 38 @param vcs reference to the vcs object
39 @param mq flag indicating to show a queue repo status (boolean)
39 @param parent parent widget (QWidget) 40 @param parent parent widget (QWidget)
40 """ 41 """
41 super(HgStatusDialog, self).__init__(parent) 42 super(HgStatusDialog, self).__init__(parent)
42 self.setupUi(self) 43 self.setupUi(self)
43 44
56 self.diff = None 57 self.diff = None
57 self.process = None 58 self.process = None
58 self.vcs = vcs 59 self.vcs = vcs
59 self.vcs.committed.connect(self.__committed) 60 self.vcs.committed.connect(self.__committed)
60 self.__hgClient = self.vcs.getClient() 61 self.__hgClient = self.vcs.getClient()
62 self.__mq = mq
61 63
62 self.statusList.headerItem().setText(self.__lastColumn, "") 64 self.statusList.headerItem().setText(self.__lastColumn, "")
63 self.statusList.header().setSortIndicator(self.__pathColumn, Qt.AscendingOrder) 65 self.statusList.header().setSortIndicator(self.__pathColumn, Qt.AscendingOrder)
64 66
67 if mq:
68 self.buttonsLine.setVisible(False)
69 self.addButton.setVisible(False)
70 self.diffButton.setVisible(False)
71 self.sbsDiffButton.setVisible(False)
72 self.revertButton.setVisible(False)
73 self.forgetButton.setVisible(False)
74 self.restoreButton.setVisible(False)
75
65 self.menuactions = [] 76 self.menuactions = []
66 self.menu = QMenu() 77 self.menu = QMenu()
67 self.menuactions.append(self.menu.addAction( 78 if not mq:
68 self.trUtf8("Commit changes to repository..."), self.__commit)) 79 self.menuactions.append(self.menu.addAction(
69 self.menuactions.append(self.menu.addAction( 80 self.trUtf8("Commit changes to repository..."), self.__commit))
70 self.trUtf8("Select all for commit"), self.__commitSelectAll)) 81 self.menuactions.append(self.menu.addAction(
71 self.menuactions.append(self.menu.addAction( 82 self.trUtf8("Select all for commit"), self.__commitSelectAll))
72 self.trUtf8("Deselect all from commit"), self.__commitDeselectAll)) 83 self.menuactions.append(self.menu.addAction(
73 self.menu.addSeparator() 84 self.trUtf8("Deselect all from commit"), self.__commitDeselectAll))
74 self.menuactions.append(self.menu.addAction( 85 self.menu.addSeparator()
75 self.trUtf8("Add to repository"), self.__add)) 86 self.menuactions.append(self.menu.addAction(
76 self.menuactions.append(self.menu.addAction( 87 self.trUtf8("Add to repository"), self.__add))
77 self.trUtf8("Show differences"), self.__diff)) 88 self.menuactions.append(self.menu.addAction(
78 self.menuactions.append(self.menu.addAction( 89 self.trUtf8("Show differences"), self.__diff))
79 self.trUtf8("Remove from repository"), self.__forget)) 90 self.menuactions.append(self.menu.addAction(
80 self.menuactions.append(self.menu.addAction( 91 self.trUtf8("Show differences side-by-side"), self.__sbsDiff))
81 self.trUtf8("Revert changes"), self.__revert)) 92 self.menuactions.append(self.menu.addAction(
82 self.menuactions.append(self.menu.addAction( 93 self.trUtf8("Remove from repository"), self.__forget))
83 self.trUtf8("Restore missing"), self.__restoreMissing)) 94 self.menuactions.append(self.menu.addAction(
84 self.menu.addSeparator() 95 self.trUtf8("Revert changes"), self.__revert))
85 self.menuactions.append(self.menu.addAction(self.trUtf8("Adjust column sizes"), 96 self.menuactions.append(self.menu.addAction(
86 self.__resizeColumns)) 97 self.trUtf8("Restore missing"), self.__restoreMissing))
87 for act in self.menuactions: 98 self.menu.addSeparator()
88 act.setEnabled(False) 99 self.menuactions.append(self.menu.addAction(
89 100 self.trUtf8("Adjust column sizes"), self.__resizeColumns))
90 self.statusList.setContextMenuPolicy(Qt.CustomContextMenu) 101 for act in self.menuactions:
91 self.statusList.customContextMenuRequested.connect(self.__showContextMenu) 102 act.setEnabled(False)
103
104 self.statusList.setContextMenuPolicy(Qt.CustomContextMenu)
105 self.statusList.customContextMenuRequested.connect(self.__showContextMenu)
92 106
93 self.modifiedIndicators = [ 107 self.modifiedIndicators = [
94 self.trUtf8('added'), 108 self.trUtf8('added'),
95 self.trUtf8('modified'), 109 self.trUtf8('modified'),
96 self.trUtf8('removed'), 110 self.trUtf8('removed'),
187 act.setEnabled(False) 201 act.setEnabled(False)
188 202
189 self.addButton.setEnabled(False) 203 self.addButton.setEnabled(False)
190 self.commitButton.setEnabled(False) 204 self.commitButton.setEnabled(False)
191 self.diffButton.setEnabled(False) 205 self.diffButton.setEnabled(False)
206 self.sbsDiffButton.setEnabled(False)
192 self.revertButton.setEnabled(False) 207 self.revertButton.setEnabled(False)
193 self.forgetButton.setEnabled(False) 208 self.forgetButton.setEnabled(False)
194 self.restoreButton.setEnabled(False) 209 self.restoreButton.setEnabled(False)
195 210
196 self.statusFilterCombo.clear() 211 self.statusFilterCombo.clear()
197 self.__statusFilters = [] 212 self.__statusFilters = []
198 213
199 self.setWindowTitle(self.trUtf8('Mercurial Status')) 214 if self.__mq:
215 self.setWindowTitle(self.trUtf8("Mercurial Queue Repository Status"))
216 else:
217 self.setWindowTitle(self.trUtf8('Mercurial Status'))
200 218
201 args = [] 219 args = []
202 args.append('status') 220 args.append('status')
203 self.vcs.addArguments(args, self.vcs.options['global']) 221 self.vcs.addArguments(args, self.vcs.options['global'])
204 self.vcs.addArguments(args, self.vcs.options['status']) 222 if self.__mq:
205 223 args.append('--mq')
206 if self.vcs.hasSubrepositories(): 224 if isinstance(fn, list):
207 args.append("--subrepos") 225 self.dname, fnames = self.vcs.splitPathList(fn)
208 226 else:
209 if isinstance(fn, list): 227 self.dname, fname = self.vcs.splitPath(fn)
210 self.dname, fnames = self.vcs.splitPathList(fn) 228 else:
211 self.vcs.addArguments(args, fn) 229 self.vcs.addArguments(args, self.vcs.options['status'])
212 else: 230
213 self.dname, fname = self.vcs.splitPath(fn) 231 if self.vcs.hasSubrepositories():
214 args.append(fn) 232 args.append("--subrepos")
233
234 if isinstance(fn, list):
235 self.dname, fnames = self.vcs.splitPathList(fn)
236 self.vcs.addArguments(args, fn)
237 else:
238 self.dname, fname = self.vcs.splitPath(fn)
239 args.append(fn)
215 240
216 # find the root of the repo 241 # find the root of the repo
217 repodir = self.dname 242 repodir = self.dname
218 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): 243 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)):
219 repodir = os.path.dirname(repodir) 244 repodir = os.path.dirname(repodir)
442 unversioned = len(self.__getUnversionedItems()) 467 unversioned = len(self.__getUnversionedItems())
443 missing = len(self.__getMissingItems()) 468 missing = len(self.__getMissingItems())
444 469
445 self.addButton.setEnabled(unversioned) 470 self.addButton.setEnabled(unversioned)
446 self.diffButton.setEnabled(modified) 471 self.diffButton.setEnabled(modified)
472 self.sbsDiffButton.setEnabled(modified == 1)
447 self.revertButton.setEnabled(modified) 473 self.revertButton.setEnabled(modified)
448 self.forgetButton.setEnabled(missing) 474 self.forgetButton.setEnabled(missing)
449 self.restoreButton.setEnabled(missing) 475 self.restoreButton.setEnabled(missing)
450 476
451 def __updateCommitButton(self): 477 def __updateCommitButton(self):
509 Private slot to handle the press of the Differences button. 535 Private slot to handle the press of the Differences button.
510 """ 536 """
511 self.__diff() 537 self.__diff()
512 538
513 @pyqtSlot() 539 @pyqtSlot()
540 def on_sbsDiffButton_clicked(self):
541 """
542 Private slot to handle the press of the Side-by-Side Diff button.
543 """
544 self.__sbsDiff()
545
546 @pyqtSlot()
514 def on_revertButton_clicked(self): 547 def on_revertButton_clicked(self):
515 """ 548 """
516 Private slot to handle the press of the Revert button. 549 Private slot to handle the press of the Revert button.
517 """ 550 """
518 self.__revert() 551 self.__revert()
545 578
546 def __commit(self): 579 def __commit(self):
547 """ 580 """
548 Private slot to handle the Commit context menu entry. 581 Private slot to handle the Commit context menu entry.
549 """ 582 """
550 names = [os.path.join(self.dname, itm.text(self.__pathColumn)) \ 583 if self.__mq:
551 for itm in self.__getCommitableItems()] 584 self.vcs.vcsCommit(self.dname, "", mq=True)
552 if not names: 585 else:
553 E5MessageBox.information(self, 586 names = [os.path.join(self.dname, itm.text(self.__pathColumn)) \
554 self.trUtf8("Commit"), 587 for itm in self.__getCommitableItems()]
555 self.trUtf8("""There are no entries selected to be""" 588 if not names:
556 """ committed.""")) 589 E5MessageBox.information(self,
557 return 590 self.trUtf8("Commit"),
558 591 self.trUtf8("""There are no entries selected to be"""
559 if Preferences.getVCS("AutoSaveFiles"): 592 """ committed."""))
560 vm = e5App().getObject("ViewManager") 593 return
561 for name in names: 594
562 vm.saveEditor(name) 595 if Preferences.getVCS("AutoSaveFiles"):
563 self.vcs.vcsCommit(names, '') 596 vm = e5App().getObject("ViewManager")
597 for name in names:
598 vm.saveEditor(name)
599 self.vcs.vcsCommit(names, '')
564 600
565 def __committed(self): 601 def __committed(self):
566 """ 602 """
567 Private slot called after the commit has finished. 603 Private slot called after the commit has finished.
568 """ 604 """
675 if self.diff is None: 711 if self.diff is None:
676 from .HgDiffDialog import HgDiffDialog 712 from .HgDiffDialog import HgDiffDialog
677 self.diff = HgDiffDialog(self.vcs) 713 self.diff = HgDiffDialog(self.vcs)
678 self.diff.show() 714 self.diff.show()
679 self.diff.start(names) 715 self.diff.start(names)
680 716
717 def __sbsDiff(self):
718 """
719 Private slot to handle the Diff context menu entry.
720 """
721 names = [os.path.join(self.dname, itm.text(self.__pathColumn))
722 for itm in self.__getModifiedItems()]
723 if not names:
724 E5MessageBox.information(self,
725 self.trUtf8("Side-by-Side Diff"),
726 self.trUtf8("""There are no uncommitted changes"""
727 """ available/selected."""))
728 return
729 elif len(names) > 1:
730 E5MessageBox.information(self,
731 self.trUtf8("Side-by-Side Diff"),
732 self.trUtf8("""Only one file with uncommitted changes"""
733 """ must be selected."""))
734 return
735
736 self.vcs.hgSbsDiff(names[0])
737
681 def __getCommitableItems(self): 738 def __getCommitableItems(self):
682 """ 739 """
683 Private method to retrieve all entries the user wants to commit. 740 Private method to retrieve all entries the user wants to commit.
684 741
685 @return list of all items, the user has checked 742 @return list of all items, the user has checked

eric ide

mercurial