7 Module implementing a dialog to show the output of the svn diff command |
7 Module implementing a dialog to show the output of the svn diff command |
8 process. |
8 process. |
9 """ |
9 """ |
10 |
10 |
11 import os |
11 import os |
|
12 import pathlib |
12 |
13 |
13 import pysvn |
14 import pysvn |
14 |
15 |
15 from PyQt6.QtCore import QFileInfo, QDateTime, Qt, pyqtSlot |
16 from PyQt6.QtCore import QDateTime, Qt, pyqtSlot |
16 from PyQt6.QtGui import QTextCursor |
17 from PyQt6.QtGui import QTextCursor |
17 from PyQt6.QtWidgets import QWidget, QDialogButtonBox |
18 from PyQt6.QtWidgets import QWidget, QDialogButtonBox |
18 |
19 |
19 from EricWidgets.EricApplication import ericApp |
20 from EricWidgets.EricApplication import ericApp |
20 from EricWidgets import EricMessageBox, EricFileDialog |
21 from EricWidgets import EricMessageBox, EricFileDialog |
429 EricFileDialog.DontConfirmOverwrite) |
430 EricFileDialog.DontConfirmOverwrite) |
430 |
431 |
431 if not fname: |
432 if not fname: |
432 return # user aborted |
433 return # user aborted |
433 |
434 |
434 ext = QFileInfo(fname).suffix() |
435 fpath = pathlib.Path(fname) |
435 if not ext: |
436 if not fpath.suffix: |
436 ex = selectedFilter.split("(*")[1].split(")")[0] |
437 ex = selectedFilter.split("(*")[1].split(")")[0] |
437 if ex: |
438 if ex: |
438 fname += ex |
439 fpath = fpath.with_suffix(ex) |
439 if QFileInfo(fname).exists(): |
440 if fpath.exists(): |
440 res = EricMessageBox.yesNo( |
441 res = EricMessageBox.yesNo( |
441 self, |
442 self, |
442 self.tr("Save Diff"), |
443 self.tr("Save Diff"), |
443 self.tr("<p>The patch file <b>{0}</b> already exists." |
444 self.tr("<p>The patch file <b>{0}</b> already exists." |
444 " Overwrite it?</p>").format(fname), |
445 " Overwrite it?</p>").format(str(fpath)), |
445 icon=EricMessageBox.Warning) |
446 icon=EricMessageBox.Warning) |
446 if not res: |
447 if not res: |
447 return |
448 return |
448 fname = Utilities.toNativeSeparators(fname) |
|
449 |
449 |
450 eol = ericApp().getObject("Project").getEolString() |
450 eol = ericApp().getObject("Project").getEolString() |
451 try: |
451 try: |
452 with open(fname, "w", encoding="utf-8", newline="") as f: |
452 with fpath.open("w", encoding="utf-8", newline="") as f: |
453 f.write(eol.join(self.contents.toPlainText().splitlines())) |
453 f.write(eol.join(self.contents.toPlainText().splitlines())) |
454 except OSError as why: |
454 except OSError as why: |
455 EricMessageBox.critical( |
455 EricMessageBox.critical( |
456 self, self.tr('Save Diff'), |
456 self, self.tr('Save Diff'), |
457 self.tr( |
457 self.tr( |
458 '<p>The patch file <b>{0}</b> could not be saved.' |
458 '<p>The patch file <b>{0}</b> could not be saved.' |
459 '<br>Reason: {1}</p>') |
459 '<br>Reason: {1}</p>') |
460 .format(fname, str(why))) |
460 .format(str(fpath), str(why))) |
461 |
461 |
462 @pyqtSlot() |
462 @pyqtSlot() |
463 def on_refreshButton_clicked(self): |
463 def on_refreshButton_clicked(self): |
464 """ |
464 """ |
465 Private slot to refresh the display. |
465 Private slot to refresh the display. |