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 |
12 import pathlib |
13 from PyQt6.QtCore import QTimer, QFileInfo, QProcess, pyqtSlot, Qt |
13 |
|
14 from PyQt6.QtCore import QTimer, QProcess, pyqtSlot, Qt |
14 from PyQt6.QtGui import QTextCursor |
15 from PyQt6.QtGui import QTextCursor |
15 from PyQt6.QtWidgets import QWidget, QLineEdit, QDialogButtonBox |
16 from PyQt6.QtWidgets import QWidget, QLineEdit, QDialogButtonBox |
16 |
17 |
17 from EricWidgets.EricApplication import ericApp |
18 from EricWidgets.EricApplication import ericApp |
18 from EricWidgets import EricMessageBox, EricFileDialog |
19 from EricWidgets import EricMessageBox, EricFileDialog |
19 |
20 |
20 from .Ui_SvnDiffDialog import Ui_SvnDiffDialog |
21 from .Ui_SvnDiffDialog import Ui_SvnDiffDialog |
21 from .SvnDiffHighlighter import SvnDiffHighlighter |
22 from .SvnDiffHighlighter import SvnDiffHighlighter |
22 |
23 |
23 import Utilities |
|
24 import Preferences |
24 import Preferences |
25 from Globals import strToQByteArray |
25 from Globals import strToQByteArray |
26 |
26 |
27 |
27 |
28 class SvnDiffDialog(QWidget, Ui_SvnDiffDialog): |
28 class SvnDiffDialog(QWidget, Ui_SvnDiffDialog): |
383 EricFileDialog.DontConfirmOverwrite) |
383 EricFileDialog.DontConfirmOverwrite) |
384 |
384 |
385 if not fname: |
385 if not fname: |
386 return # user aborted |
386 return # user aborted |
387 |
387 |
388 ext = QFileInfo(fname).suffix() |
388 fpath = pathlib.Path(fname) |
389 if not ext: |
389 if not fpath.suffix: |
390 ex = selectedFilter.split("(*")[1].split(")")[0] |
390 ex = selectedFilter.split("(*")[1].split(")")[0] |
391 if ex: |
391 if ex: |
392 fname += ex |
392 fpath = fpath.with_suffix(ex) |
393 if QFileInfo(fname).exists(): |
393 if fpath.exists(): |
394 res = EricMessageBox.yesNo( |
394 res = EricMessageBox.yesNo( |
395 self, |
395 self, |
396 self.tr("Save Diff"), |
396 self.tr("Save Diff"), |
397 self.tr("<p>The patch file <b>{0}</b> already exists." |
397 self.tr("<p>The patch file <b>{0}</b> already exists." |
398 " Overwrite it?</p>").format(fname), |
398 " Overwrite it?</p>").format(str(fpath)), |
399 icon=EricMessageBox.Warning) |
399 icon=EricMessageBox.Warning) |
400 if not res: |
400 if not res: |
401 return |
401 return |
402 fname = Utilities.toNativeSeparators(fname) |
|
403 |
402 |
404 eol = ericApp().getObject("Project").getEolString() |
403 eol = ericApp().getObject("Project").getEolString() |
405 try: |
404 try: |
406 with open(fname, "w", encoding="utf-8", newline="") as f: |
405 with fpath.open("w", encoding="utf-8", newline="") as f: |
407 f.write(eol.join(self.contents.toPlainText().splitlines())) |
406 f.write(eol.join(self.contents.toPlainText().splitlines())) |
408 except OSError as why: |
407 except OSError as why: |
409 EricMessageBox.critical( |
408 EricMessageBox.critical( |
410 self, self.tr('Save Diff'), |
409 self, self.tr('Save Diff'), |
411 self.tr( |
410 self.tr( |
412 '<p>The patch file <b>{0}</b> could not be saved.' |
411 '<p>The patch file <b>{0}</b> could not be saved.' |
413 '<br>Reason: {1}</p>') |
412 '<br>Reason: {1}</p>') |
414 .format(fname, str(why))) |
413 .format(str(fpath), str(why))) |
415 |
414 |
416 @pyqtSlot() |
415 @pyqtSlot() |
417 def on_refreshButton_clicked(self): |
416 def on_refreshButton_clicked(self): |
418 """ |
417 """ |
419 Private slot to refresh the display. |
418 Private slot to refresh the display. |