diff -r 8c5296fe3056 -r 8a68afaf1ba2 eric7/UI/DiffDialog.py --- a/eric7/UI/DiffDialog.py Wed Jun 15 09:44:07 2022 +0200 +++ b/eric7/UI/DiffDialog.py Thu Jun 16 18:28:59 2022 +0200 @@ -8,11 +8,12 @@ """ import os +import pathlib import time import contextlib from difflib import unified_diff, context_diff -from PyQt6.QtCore import QFileInfo, QEvent, pyqtSlot +from PyQt6.QtCore import QEvent, pyqtSlot from PyQt6.QtGui import QTextCursor from PyQt6.QtWidgets import QWidget, QApplication, QDialogButtonBox @@ -114,25 +115,24 @@ if not fname: return - ext = QFileInfo(fname).suffix() - if not ext: + fpath = pathlib.Path(fname) + if not fpath.suffix: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: - fname += ex - if QFileInfo(fname).exists(): + fpath = fpath.with_suffix(ex) + if fpath.exists(): res = EricMessageBox.yesNo( self, self.tr("Save Diff"), self.tr("<p>The patch file <b>{0}</b> already exists." - " Overwrite it?</p>").format(fname), + " Overwrite it?</p>").format(str(fpath)), icon=EricMessageBox.Warning) if not res: return - fname = Utilities.toNativeSeparators(fname) txt = self.contents.toPlainText() try: - with open(fname, "w", encoding="utf-8") as f, \ + with fpath.open("w", encoding="utf-8") as f, \ contextlib.suppress(UnicodeError): f.write(txt) except OSError as why: @@ -140,7 +140,7 @@ self, self.tr('Save Diff'), self.tr( '<p>The patch file <b>{0}</b> could not be saved.<br />' - 'Reason: {1}</p>').format(fname, str(why))) + 'Reason: {1}</p>').format(str(fpath), str(why))) @pyqtSlot() def on_diffButton_clicked(self):