7 Module implementing a dialog to show the output of the git diff command |
7 Module implementing a dialog to show the output of the git diff command |
8 process. |
8 process. |
9 """ |
9 """ |
10 |
10 |
11 import contextlib |
11 import contextlib |
12 |
12 import pathlib |
13 from PyQt6.QtCore import pyqtSlot, QFileInfo, Qt |
13 |
|
14 from PyQt6.QtCore import pyqtSlot, Qt |
14 from PyQt6.QtGui import QTextCursor |
15 from PyQt6.QtGui import QTextCursor |
15 from PyQt6.QtWidgets import QWidget, QDialogButtonBox |
16 from PyQt6.QtWidgets import QWidget, QDialogButtonBox |
16 |
17 |
17 from EricWidgets import EricMessageBox, EricFileDialog |
18 from EricWidgets import EricMessageBox, EricFileDialog |
18 from EricWidgets.EricApplication import ericApp |
19 from EricWidgets.EricApplication import ericApp |
329 EricFileDialog.DontConfirmOverwrite) |
329 EricFileDialog.DontConfirmOverwrite) |
330 |
330 |
331 if not fname: |
331 if not fname: |
332 return # user aborted |
332 return # user aborted |
333 |
333 |
334 ext = QFileInfo(fname).suffix() |
334 fpath = pathlib.Path(fname) |
335 if not ext: |
335 if not fpath.suffix: |
336 ex = selectedFilter.split("(*")[1].split(")")[0] |
336 ex = selectedFilter.split("(*")[1].split(")")[0] |
337 if ex: |
337 if ex: |
338 fname += ex |
338 fpath = fpath.with_suffix(ex) |
339 if QFileInfo(fname).exists(): |
339 if fpath.exists(): |
340 res = EricMessageBox.yesNo( |
340 res = EricMessageBox.yesNo( |
341 self, |
341 self, |
342 self.tr("Save Diff"), |
342 self.tr("Save Diff"), |
343 self.tr("<p>The patch file <b>{0}</b> already exists." |
343 self.tr("<p>The patch file <b>{0}</b> already exists." |
344 " Overwrite it?</p>").format(fname), |
344 " Overwrite it?</p>").format(fpath), |
345 icon=EricMessageBox.Warning) |
345 icon=EricMessageBox.Warning) |
346 if not res: |
346 if not res: |
347 return |
347 return |
348 fname = Utilities.toNativeSeparators(fname) |
|
349 |
348 |
350 eol = ericApp().getObject("Project").getEolString() |
349 eol = ericApp().getObject("Project").getEolString() |
351 try: |
350 try: |
352 with open(fname, "w", encoding="utf-8", newline="") as f: |
351 with fpath.open("w", encoding="utf-8", newline="") as f: |
353 f.write(eol.join(self.contents2.toPlainText().splitlines())) |
352 f.write(eol.join(self.contents2.toPlainText().splitlines())) |
354 f.write(eol) |
353 f.write(eol) |
355 except OSError as why: |
354 except OSError as why: |
356 EricMessageBox.critical( |
355 EricMessageBox.critical( |
357 self, self.tr('Save Diff'), |
356 self, self.tr('Save Diff'), |
358 self.tr( |
357 self.tr( |
359 '<p>The patch file <b>{0}</b> could not be saved.' |
358 '<p>The patch file <b>{0}</b> could not be saved.' |
360 '<br>Reason: {1}</p>') |
359 '<br>Reason: {1}</p>') |
361 .format(fname, str(why))) |
360 .format(fpath, str(why))) |
362 |
361 |
363 @pyqtSlot() |
362 @pyqtSlot() |
364 def on_refreshButton_clicked(self): |
363 def on_refreshButton_clicked(self): |
365 """ |
364 """ |
366 Private slot to refresh the display. |
365 Private slot to refresh the display. |