300 if not ext: |
300 if not ext: |
301 ex = selectedFilter.split("(*")[1].split(")")[0] |
301 ex = selectedFilter.split("(*")[1].split(")")[0] |
302 if ex: |
302 if ex: |
303 fname += ex |
303 fname += ex |
304 if QFileInfo(fname).exists(): |
304 if QFileInfo(fname).exists(): |
305 res = E5MessageBox.yesNo(self, |
305 res = E5MessageBox.yesNo( |
|
306 self, |
306 self.trUtf8("Save Diff"), |
307 self.trUtf8("Save Diff"), |
307 self.trUtf8("<p>The patch file <b>{0}</b> already exists." |
308 self.trUtf8("<p>The patch file <b>{0}</b> already exists." |
308 " Overwrite it?</p>").format(fname), |
309 " Overwrite it?</p>").format(fname), |
309 icon=E5MessageBox.Warning) |
310 icon=E5MessageBox.Warning) |
310 if not res: |
311 if not res: |
339 try: |
340 try: |
340 f1 = open(self.filename1, "r", encoding="utf-8") |
341 f1 = open(self.filename1, "r", encoding="utf-8") |
341 lines1 = f1.readlines() |
342 lines1 = f1.readlines() |
342 f1.close() |
343 f1.close() |
343 except IOError: |
344 except IOError: |
344 E5MessageBox.critical(self, |
345 E5MessageBox.critical( |
|
346 self, |
345 self.trUtf8("Compare Files"), |
347 self.trUtf8("Compare Files"), |
346 self.trUtf8( |
348 self.trUtf8( |
347 """<p>The file <b>{0}</b> could not be read.</p>""") |
349 """<p>The file <b>{0}</b> could not be read.</p>""") |
348 .format(self.filename1)) |
350 .format(self.filename1)) |
349 return |
351 return |
356 try: |
358 try: |
357 f2 = open(self.filename2, "r", encoding="utf-8") |
359 f2 = open(self.filename2, "r", encoding="utf-8") |
358 lines2 = f2.readlines() |
360 lines2 = f2.readlines() |
359 f2.close() |
361 f2.close() |
360 except IOError: |
362 except IOError: |
361 E5MessageBox.critical(self, |
363 E5MessageBox.critical( |
|
364 self, |
362 self.trUtf8("Compare Files"), |
365 self.trUtf8("Compare Files"), |
363 self.trUtf8( |
366 self.trUtf8( |
364 """<p>The file <b>{0}</b> could not be read.</p>""") |
367 """<p>The file <b>{0}</b> could not be read.</p>""") |
365 .format(self.filename2)) |
368 .format(self.filename2)) |
366 return |
369 return |
396 self.contents.setTextCursor(tc) |
399 self.contents.setTextCursor(tc) |
397 self.contents.setCurrentCharFormat(format) |
400 self.contents.setCurrentCharFormat(format) |
398 self.contents.insertPlainText(txt) |
401 self.contents.insertPlainText(txt) |
399 |
402 |
400 def __generateUnifiedDiff(self, a, b, fromfile, tofile, |
403 def __generateUnifiedDiff(self, a, b, fromfile, tofile, |
401 fromfiledate, tofiledate): |
404 fromfiledate, tofiledate): |
402 """ |
405 """ |
403 Private slot to generate a unified diff output. |
406 Private slot to generate a unified diff output. |
404 |
407 |
405 @param a first sequence of lines (list of strings) |
408 @param a first sequence of lines (list of strings) |
406 @param b second sequence of lines (list of strings) |
409 @param b second sequence of lines (list of strings) |
409 @param fromfiledate modification time of the first file (string) |
412 @param fromfiledate modification time of the first file (string) |
410 @param tofiledate modification time of the second file (string) |
413 @param tofiledate modification time of the second file (string) |
411 """ |
414 """ |
412 paras = 0 |
415 paras = 0 |
413 for line in unified_diff(a, b, fromfile, tofile, |
416 for line in unified_diff(a, b, fromfile, tofile, |
414 fromfiledate, tofiledate): |
417 fromfiledate, tofiledate): |
415 if line.startswith('+') or line.startswith('>'): |
418 if line.startswith('+') or line.startswith('>'): |
416 format = self.cAddedFormat |
419 format = self.cAddedFormat |
417 elif line.startswith('-') or line.startswith('<'): |
420 elif line.startswith('-') or line.startswith('<'): |
418 format = self.cRemovedFormat |
421 format = self.cRemovedFormat |
419 elif line.startswith('@@'): |
422 elif line.startswith('@@'): |
428 if paras == 0: |
431 if paras == 0: |
429 self.__appendText( |
432 self.__appendText( |
430 self.trUtf8('There is no difference.'), self.cNormalFormat) |
433 self.trUtf8('There is no difference.'), self.cNormalFormat) |
431 |
434 |
432 def __generateContextDiff(self, a, b, fromfile, tofile, |
435 def __generateContextDiff(self, a, b, fromfile, tofile, |
433 fromfiledate, tofiledate): |
436 fromfiledate, tofiledate): |
434 """ |
437 """ |
435 Private slot to generate a context diff output. |
438 Private slot to generate a context diff output. |
436 |
439 |
437 @param a first sequence of lines (list of strings) |
440 @param a first sequence of lines (list of strings) |
438 @param b second sequence of lines (list of strings) |
441 @param b second sequence of lines (list of strings) |
441 @param fromfiledate modification time of the first file (string) |
444 @param fromfiledate modification time of the first file (string) |
442 @param tofiledate modification time of the second file (string) |
445 @param tofiledate modification time of the second file (string) |
443 """ |
446 """ |
444 paras = 0 |
447 paras = 0 |
445 for line in context_diff(a, b, fromfile, tofile, |
448 for line in context_diff(a, b, fromfile, tofile, |
446 fromfiledate, tofiledate): |
449 fromfiledate, tofiledate): |
447 if line.startswith('+ '): |
450 if line.startswith('+ '): |
448 format = self.cAddedFormat |
451 format = self.cAddedFormat |
449 elif line.startswith('- '): |
452 elif line.startswith('- '): |
450 format = self.cRemovedFormat |
453 format = self.cRemovedFormat |
451 elif line.startswith('! '): |
454 elif line.startswith('! '): |