src/eric7/Plugins/VcsPlugins/vcsMercurial/HisteditExtension/HgHisteditCommitEditor.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
19 19
20 class HgHisteditCommitEditor(QDialog, Ui_HgHisteditCommitEditor): 20 class HgHisteditCommitEditor(QDialog, Ui_HgHisteditCommitEditor):
21 """ 21 """
22 Class implementing a dialog to edit the commit message of a revision. 22 Class implementing a dialog to edit the commit message of a revision.
23 """ 23 """
24
24 def __init__(self, fileName, parent=None): 25 def __init__(self, fileName, parent=None):
25 """ 26 """
26 Constructor 27 Constructor
27 28
28 @param fileName name of the file containing the commit message 29 @param fileName name of the file containing the commit message
29 to be edited 30 to be edited
30 @type str 31 @type str
31 @param parent reference to the parent widget 32 @param parent reference to the parent widget
32 @type QWidget 33 @type QWidget
33 """ 34 """
34 super().__init__(parent) 35 super().__init__(parent)
35 self.setupUi(self) 36 self.setupUi(self)
36 37
37 self.__fileName = fileName 38 self.__fileName = fileName
38 self.__readFile() 39 self.__readFile()
39 40
40 self.recentCommitMessages = Preferences.toList( 41 self.recentCommitMessages = Preferences.toList(
41 Preferences.getSettings().value('Mercurial/Commits')) 42 Preferences.getSettings().value("Mercurial/Commits")
43 )
42 self.recentComboBox.clear() 44 self.recentComboBox.clear()
43 self.recentComboBox.addItem("") 45 self.recentComboBox.addItem("")
44 self.recentComboBox.addItems(self.recentCommitMessages) 46 self.recentComboBox.addItems(self.recentCommitMessages)
45 47
46 def __readFile(self): 48 def __readFile(self):
47 """ 49 """
48 Private method to read the file containing the commit message and 50 Private method to read the file containing the commit message and
49 populate the dialog. 51 populate the dialog.
50 """ 52 """
53 txt = f.read() 55 txt = f.read()
54 except OSError as err: 56 except OSError as err:
55 EricMessageBox.critical( 57 EricMessageBox.critical(
56 self, 58 self,
57 self.tr("Edit Commit Message"), 59 self.tr("Edit Commit Message"),
58 self.tr("""<p>The file <b>{0}</b> could not be read.</p>""" 60 self.tr(
59 """<p>Reason: {1}</p>""").format( 61 """<p>The file <b>{0}</b> could not be read.</p>"""
60 self.__fileName, str(err))) 62 """<p>Reason: {1}</p>"""
63 ).format(self.__fileName, str(err)),
64 )
61 self.on_buttonBox_rejected() 65 self.on_buttonBox_rejected()
62 return 66 return
63 67
64 msgLines = [] 68 msgLines = []
65 infoLines = [] 69 infoLines = []
66 for line in txt.splitlines(): 70 for line in txt.splitlines():
67 if line.startswith("#"): 71 if line.startswith("#"):
68 infoLines.append(line[1:].lstrip()) 72 infoLines.append(line[1:].lstrip())
69 elif line.startswith("HG:"): 73 elif line.startswith("HG:"):
70 infoLines.append(line[3:].lstrip()) 74 infoLines.append(line[3:].lstrip())
71 else: 75 else:
72 msgLines.append(line) 76 msgLines.append(line)
73 77
74 # remove empty lines at end of message 78 # remove empty lines at end of message
75 for row in range(len(msgLines) - 1, -1, -1): 79 for row in range(len(msgLines) - 1, -1, -1):
76 if msgLines[row] == "": 80 if msgLines[row] == "":
77 del msgLines[row] 81 del msgLines[row]
78 else: 82 else:
79 break 83 break
80 84
81 self.messageEdit.setPlainText("\n".join(msgLines)) 85 self.messageEdit.setPlainText("\n".join(msgLines))
82 self.infoEdit.setPlainText("\n".join(infoLines)) 86 self.infoEdit.setPlainText("\n".join(infoLines))
83 87
84 @pyqtSlot() 88 @pyqtSlot()
85 def on_buttonBox_accepted(self): 89 def on_buttonBox_accepted(self):
86 """ 90 """
87 Private slot called by the buttonBox accepted signal. 91 Private slot called by the buttonBox accepted signal.
88 """ 92 """
92 f.write(msg) 96 f.write(msg)
93 except OSError as err: 97 except OSError as err:
94 EricMessageBox.critical( 98 EricMessageBox.critical(
95 self, 99 self,
96 self.tr("Edit Commit Message"), 100 self.tr("Edit Commit Message"),
97 self.tr("""<p>The file <b>{0}</b> could not be read.</p>""" 101 self.tr(
98 """<p>Reason: {1}</p>""").format( 102 """<p>The file <b>{0}</b> could not be read.</p>"""
99 self.__fileName, str(err))) 103 """<p>Reason: {1}</p>"""
104 ).format(self.__fileName, str(err)),
105 )
100 self.on_buttonBox_rejected() 106 self.on_buttonBox_rejected()
101 return 107 return
102 108
103 self.close() 109 self.close()
104 QCoreApplication.exit(0) 110 QCoreApplication.exit(0)
105 111
106 @pyqtSlot() 112 @pyqtSlot()
107 def on_buttonBox_rejected(self): 113 def on_buttonBox_rejected(self):
108 """ 114 """
109 Private slot called by the buttonBox rejected signal. 115 Private slot called by the buttonBox rejected signal.
110 """ 116 """
111 self.close() 117 self.close()
112 QCoreApplication.exit(1) 118 QCoreApplication.exit(1)
113 119
114 @pyqtSlot(int) 120 @pyqtSlot(int)
115 def on_recentComboBox_activated(self, index): 121 def on_recentComboBox_activated(self, index):
116 """ 122 """
117 Private slot to select a commit message from recent ones. 123 Private slot to select a commit message from recent ones.
118 124
119 @param index index of the selected entry 125 @param index index of the selected entry
120 @type int 126 @type int
121 """ 127 """
122 txt = self.recentComboBox.itemText(index) 128 txt = self.recentComboBox.itemText(index)
123 if txt: 129 if txt:

eric ide

mercurial