Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py

changeset 3279
8df9706ef7f4
parent 3273
075758282fdb
child 3283
2079b76a738b
equal deleted inserted replaced
3278:243e6075af82 3279:8df9706ef7f4
9 9
10 import os 10 import os
11 11
12 from PyQt4.QtCore import pyqtSlot, Qt, QDate, QProcess, QTimer, QRegExp, \ 12 from PyQt4.QtCore import pyqtSlot, Qt, QDate, QProcess, QTimer, QRegExp, \
13 QSize, QPoint 13 QSize, QPoint
14 from PyQt4.QtGui import QDialog, QDialogButtonBox, QHeaderView, \ 14 from PyQt4.QtGui import QWidget, QDialogButtonBox, QHeaderView, \
15 QTreeWidgetItem, QApplication, QCursor, QLineEdit, QColor, \ 15 QTreeWidgetItem, QApplication, QCursor, QLineEdit, QColor, \
16 QPixmap, QPainter, QPen, QBrush, QIcon, QMenu 16 QPixmap, QPainter, QPen, QBrush, QIcon, QMenu
17 17
18 from E5Gui.E5Application import e5App 18 from E5Gui.E5Application import e5App
19 from E5Gui import E5MessageBox 19 from E5Gui import E5MessageBox
27 "cyan", "olive", "magenta", "darkred", "darkmagenta", 27 "cyan", "olive", "magenta", "darkred", "darkmagenta",
28 "darkcyan", "gray", "yellow"] 28 "darkcyan", "gray", "yellow"]
29 COLORS = [str(QColor(x).name()) for x in COLORNAMES] 29 COLORS = [str(QColor(x).name()) for x in COLORNAMES]
30 30
31 31
32 class HgLogBrowserDialog(QDialog, Ui_HgLogBrowserDialog): 32 class HgLogBrowserDialog(QWidget, Ui_HgLogBrowserDialog):
33 """ 33 """
34 Class implementing a dialog to browse the log history. 34 Class implementing a dialog to browse the log history.
35 """ 35 """
36 IconColumn = 0 36 IconColumn = 0
37 BranchColumn = 1 37 BranchColumn = 1
53 @param isFile flag indicating log for a file is to be shown (boolean) 53 @param isFile flag indicating log for a file is to be shown (boolean)
54 @param parent parent widget (QWidget) 54 @param parent parent widget (QWidget)
55 """ 55 """
56 super().__init__(parent) 56 super().__init__(parent)
57 self.setupUi(self) 57 self.setupUi(self)
58 self.setWindowFlags(self.windowFlags() | Qt.WindowMinMaxButtonsHint)
59 58
60 if mode == "log": 59 if mode == "log":
61 self.setWindowTitle(self.tr("Mercurial Log")) 60 self.setWindowTitle(self.tr("Mercurial Log"))
62 elif mode == "incoming": 61 elif mode == "incoming":
63 self.setWindowTitle(self.tr("Mercurial Log (Incoming)")) 62 self.setWindowTitle(self.tr("Mercurial Log (Incoming)"))
143 self.tr("Copy Changesets"), self.__graftActTriggered) 142 self.tr("Copy Changesets"), self.__graftActTriggered)
144 self.__graftAct.setToolTip(self.tr( 143 self.__graftAct.setToolTip(self.tr(
145 "Copy the selected changesets to the current branch")) 144 "Copy the selected changesets to the current branch"))
146 else: 145 else:
147 self.__graftAct = None 146 self.__graftAct = None
147
148 if self.vcs.version >= (2, 1): 148 if self.vcs.version >= (2, 1):
149 self.__phaseAct = self.__actionsMenu.addAction( 149 self.__phaseAct = self.__actionsMenu.addAction(
150 self.tr("Change Phase"), self.__phaseActTriggered) 150 self.tr("Change Phase"), self.__phaseActTriggered)
151 self.__phaseAct.setToolTip(self.tr( 151 self.__phaseAct.setToolTip(self.tr(
152 "Change the phase of the selected revisions")) 152 "Change the phase of the selected revisions"))
154 """<b>Change Phase</b>\n<p>This changes the phase of the""" 154 """<b>Change Phase</b>\n<p>This changes the phase of the"""
155 """ selected revisions. The selected revisions have to have""" 155 """ selected revisions. The selected revisions have to have"""
156 """ the same current phase.</p>""")) 156 """ the same current phase.</p>"""))
157 else: 157 else:
158 self.__phaseAct = None 158 self.__phaseAct = None
159
159 self.__tagAct = self.__actionsMenu.addAction( 160 self.__tagAct = self.__actionsMenu.addAction(
160 self.tr("Tag"), self.__tagActTriggered) 161 self.tr("Tag"), self.__tagActTriggered)
161 self.__tagAct.setToolTip(self.tr("Tag the selected revision")) 162 self.__tagAct.setToolTip(self.tr("Tag the selected revision"))
163
164 self.__switchAct = self.__actionsMenu.addAction(
165 self.tr("Switch"), self.__switchActTriggered)
166 self.__switchAct.setToolTip(self.tr(
167 "Switch the working directory to the selected revision"))
168
162 self.actionsButton.setIcon( 169 self.actionsButton.setIcon(
163 UI.PixmapCache.getIcon("actionsToolButton.png")) 170 UI.PixmapCache.getIcon("actionsToolButton.png"))
164 self.actionsButton.setMenu(self.__actionsMenu) 171 self.actionsButton.setMenu(self.__actionsMenu)
165 172
166 def __initData(self): 173 def __initData(self):
969 976
970 self.__filterLogsEnabled = True 977 self.__filterLogsEnabled = True
971 self.__filterLogs() 978 self.__filterLogs()
972 979
973 self.__updateDiffButtons() 980 self.__updateDiffButtons()
974 self.__updatePhaseAction() 981 self.__updateToolMenuActions()
975 self.__updateGraftAction()
976 self.__updateTagAction()
977 982
978 def __readStdout(self): 983 def __readStdout(self):
979 """ 984 """
980 Private slot to handle the readyReadStandardOutput signal. 985 Private slot to handle the readyReadStandardOutput signal.
981 986
1071 self.diffP1Button.setEnabled(False) 1076 self.diffP1Button.setEnabled(False)
1072 self.diffP2Button.setEnabled(False) 1077 self.diffP2Button.setEnabled(False)
1073 1078
1074 self.diffRevisionsButton.setEnabled(False) 1079 self.diffRevisionsButton.setEnabled(False)
1075 1080
1076 def __updatePhaseAction(self): 1081 def __updateToolMenuActions(self):
1077 """ 1082 """
1078 Private slot to update the status of the phase action. 1083 Private slot to update the status of the tool menu actions and
1079 """ 1084 the tool menu button.
1080 if self.initialCommandMode == "log": 1085 """
1081 # step 1: count entries with changeable phases 1086 if self.initialCommandMode == "log" and self.projectMode:
1082 secret = 0 1087 if self.__phaseAct is not None:
1083 draft = 0 1088 # step 1: count entries with changeable phases
1084 public = 0 1089 secret = 0
1085 for itm in self.logTree.selectedItems(): 1090 draft = 0
1086 phase = itm.text(self.PhaseColumn) 1091 public = 0
1087 if phase == "draft": 1092 for itm in self.logTree.selectedItems():
1088 draft += 1 1093 phase = itm.text(self.PhaseColumn)
1089 elif phase == "secret": 1094 if phase == "draft":
1090 secret += 1 1095 draft += 1
1096 elif phase == "secret":
1097 secret += 1
1098 else:
1099 public += 1
1100
1101 # step 2: set the status of the phase button
1102 if public == 0 and \
1103 ((secret > 0 and draft == 0) or
1104 (secret == 0 and draft > 0)):
1105 self.__phaseAct.setEnabled(True)
1091 else: 1106 else:
1092 public += 1 1107 self.__phaseAct.setEnabled(False)
1093 1108
1094 # step 2: set the status of the phase button 1109 if self.__graftAct is not None:
1095 if public == 0 and \
1096 ((secret > 0 and draft == 0) or
1097 (secret == 0 and draft > 0)):
1098 self.__phaseAct.setEnabled(True)
1099 else:
1100 self.__phaseAct.setEnabled(False)
1101 else:
1102 self.__phaseAct.setEnabled(False)
1103
1104 def __updateGraftAction(self):
1105 """
1106 Private slot to update the status of the graft action.
1107 """
1108 if self.__graftAct is not None:
1109 if self.initialCommandMode == "log":
1110 # step 1: count selected entries not belonging to the 1110 # step 1: count selected entries not belonging to the
1111 # current branch 1111 # current branch
1112 otherBranches = 0 1112 otherBranches = 0
1113 for itm in self.logTree.selectedItems(): 1113 for itm in self.logTree.selectedItems():
1114 branch = itm.text(self.BranchColumn) 1114 branch = itm.text(self.BranchColumn)
1115 if branch != self.__projectBranch: 1115 if branch != self.__projectBranch:
1116 otherBranches += 1 1116 otherBranches += 1
1117 1117
1118 # step 2: set the status of the graft action 1118 # step 2: set the status of the graft action
1119 self.__graftAct.setEnabled(otherBranches > 0) 1119 self.__graftAct.setEnabled(otherBranches > 0)
1120 else: 1120
1121 self.__graftAct.setEnabled(False)
1122
1123 def __updateTagAction(self):
1124 """
1125 Private slot to update the status of the graft action.
1126 """
1127 if self.initialCommandMode == "log":
1128 self.__tagAct.setEnabled(len(self.logTree.selectedItems()) == 1) 1121 self.__tagAct.setEnabled(len(self.logTree.selectedItems()) == 1)
1129 else: 1122 self.__switchAct.setEnabled(len(self.logTree.selectedItems()) == 1)
1130 self.__tagAct.setEnabled(False) 1123
1124 self.actionsButton.setEnabled(True)
1125 else:
1126 self.actionsButton.setEnabled(False)
1131 1127
1132 def __updateGui(self, itm): 1128 def __updateGui(self, itm):
1133 """ 1129 """
1134 Private slot to update GUI elements except the diff and phase buttons. 1130 Private slot to update GUI elements except tool menu actions.
1135 1131
1136 @param itm reference to the item the update should be based on 1132 @param itm reference to the item the update should be based on
1137 (QTreeWidgetItem) 1133 (QTreeWidgetItem)
1138 """ 1134 """
1139 self.messageEdit.clear() 1135 self.messageEdit.clear()
1159 @param current reference to the new current item (QTreeWidgetItem) 1155 @param current reference to the new current item (QTreeWidgetItem)
1160 @param previous reference to the old current item (QTreeWidgetItem) 1156 @param previous reference to the old current item (QTreeWidgetItem)
1161 """ 1157 """
1162 self.__updateGui(current) 1158 self.__updateGui(current)
1163 self.__updateDiffButtons() 1159 self.__updateDiffButtons()
1164 self.__updatePhaseAction() 1160 self.__updateToolMenuActions()
1165 self.__updateGraftAction()
1166 self.__updateTagAction()
1167 1161
1168 @pyqtSlot() 1162 @pyqtSlot()
1169 def on_logTree_itemSelectionChanged(self): 1163 def on_logTree_itemSelectionChanged(self):
1170 """ 1164 """
1171 Private slot called, when the selection has changed. 1165 Private slot called, when the selection has changed.
1172 """ 1166 """
1173 if len(self.logTree.selectedItems()) == 1: 1167 if len(self.logTree.selectedItems()) == 1:
1174 self.__updateGui(self.logTree.selectedItems()[0]) 1168 self.__updateGui(self.logTree.selectedItems()[0])
1175 1169
1176 self.__updateDiffButtons() 1170 self.__updateDiffButtons()
1177 self.__updatePhaseAction() 1171 self.__updateToolMenuActions()
1178 self.__updateGraftAction()
1179 self.__updateTagAction()
1180 1172
1181 @pyqtSlot() 1173 @pyqtSlot()
1182 def on_nextButton_clicked(self): 1174 def on_nextButton_clicked(self):
1183 """ 1175 """
1184 Private slot to handle the Next button. 1176 Private slot to handle the Next button.
1459 self.tr( 1451 self.tr(
1460 """The project should be reread. Do this now?"""), 1452 """The project should be reread. Do this now?"""),
1461 yesDefault=True) 1453 yesDefault=True)
1462 if res: 1454 if res:
1463 e5App().getObject("Project").reopenProject() 1455 e5App().getObject("Project").reopenProject()
1464 else: 1456 return
1465 self.on_refreshButton_clicked() 1457
1458 self.on_refreshButton_clicked()
1466 1459
1467 @pyqtSlot() 1460 @pyqtSlot()
1468 def __tagActTriggered(self): 1461 def __tagActTriggered(self):
1469 """ 1462 """
1470 Private slot to tag the selected revision. 1463 Private slot to tag the selected revision.
1471 """ 1464 """
1472 if len(self.logTree.selectedItems()): 1465 if len(self.logTree.selectedItems()) == 1:
1473 itm = self.logTree.selectedItems()[0] 1466 itm = self.logTree.selectedItems()[0]
1474 rev = itm.text(self.RevisionColumn).strip().split(":", 1)[0] 1467 rev = itm.text(self.RevisionColumn).strip().split(":", 1)[0]
1475 tag = itm.text(self.TagsColumn).strip().split(", ", 1)[0] 1468 tag = itm.text(self.TagsColumn).strip().split(", ", 1)[0]
1476 res = self.vcs.vcsTag(self.repodir, revision=rev, tagName=tag) 1469 res = self.vcs.vcsTag(self.repodir, revision=rev, tagName=tag)
1477 if res: 1470 if res:
1478 self.on_refreshButton_clicked() 1471 self.on_refreshButton_clicked()
1472
1473 @pyqtSlot()
1474 def __switchActTriggered(self):
1475 """
1476 Private slot to switch the working directory to the
1477 selected revision.
1478 """
1479 if len(self.logTree.selectedItems()) == 1:
1480 itm = self.logTree.selectedItems()[0]
1481 rev = itm.text(self.RevisionColumn).strip().split(":", 1)[0]
1482 if rev:
1483 shouldReopen = self.vcs.vcsUpdate(self.repodir, revision=rev)
1484 if shouldReopen:
1485 res = E5MessageBox.yesNo(
1486 None,
1487 self.tr("Switch"),
1488 self.tr(
1489 """The project should be reread. Do this now?"""),
1490 yesDefault=True)
1491 if res:
1492 e5App().getObject("Project").reopenProject()
1493 return
1494
1495 self.on_refreshButton_clicked()

eric ide

mercurial