Plugins/VcsPlugins/vcsMercurial/HgDiffDialog.py

changeset 945
8cd4d08fa9f6
parent 882
34b86be88bf0
child 1034
8a7fa049e9d3
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
17 17
18 from .Ui_HgDiffDialog import Ui_HgDiffDialog 18 from .Ui_HgDiffDialog import Ui_HgDiffDialog
19 19
20 import Utilities 20 import Utilities
21 import Preferences 21 import Preferences
22
22 23
23 class HgDiffDialog(QWidget, Ui_HgDiffDialog): 24 class HgDiffDialog(QWidget, Ui_HgDiffDialog):
24 """ 25 """
25 Class implementing a dialog to show the output of the hg diff command process. 26 Class implementing a dialog to show the output of the hg diff command process.
26 """ 27 """
27 def __init__(self, vcs, parent = None): 28 def __init__(self, vcs, parent=None):
28 """ 29 """
29 Constructor 30 Constructor
30 31
31 @param vcs reference to the vcs object 32 @param vcs reference to the vcs object
32 @param parent parent widget (QWidget) 33 @param parent parent widget (QWidget)
81 if version == "WORKING": 82 if version == "WORKING":
82 return None 83 return None
83 else: 84 else:
84 return str(version) 85 return str(version)
85 86
86 def start(self, fn, versions = None, bundle = None): 87 def start(self, fn, versions=None, bundle=None):
87 """ 88 """
88 Public slot to start the hg diff command. 89 Public slot to start the hg diff command.
89 90
90 @param fn filename to be diffed (string) 91 @param fn filename to be diffed (string)
91 @param versions list of versions to be diffed (list of up to 2 strings or None) 92 @param versions list of versions to be diffed (list of up to 2 strings or None)
195 self.contents.setCurrentCharFormat(format) 196 self.contents.setCurrentCharFormat(format)
196 self.contents.insertPlainText(txt) 197 self.contents.insertPlainText(txt)
197 198
198 def __readStdout(self): 199 def __readStdout(self):
199 """ 200 """
200 Private slot to handle the readyReadStandardOutput signal. 201 Private slot to handle the readyReadStandardOutput signal.
201 202
202 It reads the output of the process, formats it and inserts it into 203 It reads the output of the process, formats it and inserts it into
203 the contents pane. 204 the contents pane.
204 """ 205 """
205 self.process.setReadChannel(QProcess.StandardOutput) 206 self.process.setReadChannel(QProcess.StandardOutput)
206 207
207 while self.process.canReadLine(): 208 while self.process.canReadLine():
208 line = str(self.process.readLine(), 209 line = str(self.process.readLine(),
209 Preferences.getSystem("IOEncoding"), 210 Preferences.getSystem("IOEncoding"),
210 'replace') 211 'replace')
211 if line.startswith('+'): 212 if line.startswith('+'):
212 format = self.cAddedFormat 213 format = self.cAddedFormat
213 elif line.startswith('-'): 214 elif line.startswith('-'):
214 format = self.cRemovedFormat 215 format = self.cRemovedFormat
226 It reads the error output of the process and inserts it into the 227 It reads the error output of the process and inserts it into the
227 error pane. 228 error pane.
228 """ 229 """
229 if self.process is not None: 230 if self.process is not None:
230 self.errorGroup.show() 231 self.errorGroup.show()
231 s = str(self.process.readAllStandardError(), 232 s = str(self.process.readAllStandardError(),
232 Preferences.getSystem("IOEncoding"), 233 Preferences.getSystem("IOEncoding"),
233 'replace') 234 'replace')
234 self.errors.insertPlainText(s) 235 self.errors.insertPlainText(s)
235 self.errors.ensureCursorVisible() 236 self.errors.ensureCursorVisible()
236 237
237 def on_buttonBox_clicked(self, button): 238 def on_buttonBox_clicked(self, button):
282 if QFileInfo(fname).exists(): 283 if QFileInfo(fname).exists():
283 res = E5MessageBox.yesNo(self, 284 res = E5MessageBox.yesNo(self,
284 self.trUtf8("Save Diff"), 285 self.trUtf8("Save Diff"),
285 self.trUtf8("<p>The patch file <b>{0}</b> already exists." 286 self.trUtf8("<p>The patch file <b>{0}</b> already exists."
286 " Overwrite it?</p>").format(fname), 287 " Overwrite it?</p>").format(fname),
287 icon = E5MessageBox.Warning) 288 icon=E5MessageBox.Warning)
288 if not res: 289 if not res:
289 return 290 return
290 fname = Utilities.toNativeSeparators(fname) 291 fname = Utilities.toNativeSeparators(fname)
291 292
292 try: 293 try:
293 f = open(fname, "w", encoding = "utf-8") 294 f = open(fname, "w", encoding="utf-8")
294 f.write(self.contents.toPlainText()) 295 f.write(self.contents.toPlainText())
295 f.close() 296 f.close()
296 except IOError as why: 297 except IOError as why:
297 E5MessageBox.critical(self, self.trUtf8('Save Diff'), 298 E5MessageBox.critical(self, self.trUtf8('Save Diff'),
298 self.trUtf8('<p>The patch file <b>{0}</b> could not be saved.' 299 self.trUtf8('<p>The patch file <b>{0}</b> could not be saved.'

eric ide

mercurial