5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to show the output of the hg diff command process. |
7 Module implementing a dialog to show the output of the hg diff command process. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtCore import pyqtSlot, QFileInfo, Qt |
10 import pathlib |
|
11 |
|
12 from PyQt6.QtCore import pyqtSlot, Qt |
11 from PyQt6.QtGui import QTextCursor |
13 from PyQt6.QtGui import QTextCursor |
12 from PyQt6.QtWidgets import QWidget, QDialogButtonBox |
14 from PyQt6.QtWidgets import QWidget, QDialogButtonBox |
13 |
15 |
14 from EricWidgets import EricMessageBox, EricFileDialog |
16 from EricWidgets import EricMessageBox, EricFileDialog |
15 from EricWidgets.EricApplication import ericApp |
17 from EricWidgets.EricApplication import ericApp |
16 |
18 |
17 from .Ui_HgDiffDialog import Ui_HgDiffDialog |
19 from .Ui_HgDiffDialog import Ui_HgDiffDialog |
18 from .HgDiffHighlighter import HgDiffHighlighter |
20 from .HgDiffHighlighter import HgDiffHighlighter |
19 from .HgDiffGenerator import HgDiffGenerator |
21 from .HgDiffGenerator import HgDiffGenerator |
20 |
22 |
21 import Utilities |
|
22 import Preferences |
23 import Preferences |
23 |
24 |
24 |
25 |
25 class HgDiffDialog(QWidget, Ui_HgDiffDialog): |
26 class HgDiffDialog(QWidget, Ui_HgDiffDialog): |
26 """ |
27 """ |
228 EricFileDialog.DontConfirmOverwrite) |
229 EricFileDialog.DontConfirmOverwrite) |
229 |
230 |
230 if not fname: |
231 if not fname: |
231 return # user aborted |
232 return # user aborted |
232 |
233 |
233 ext = QFileInfo(fname).suffix() |
234 fpath = pathlib.Path(fname) |
234 if not ext: |
235 if not fpath.suffix: |
235 ex = selectedFilter.split("(*")[1].split(")")[0] |
236 ex = selectedFilter.split("(*")[1].split(")")[0] |
236 if ex: |
237 if ex: |
237 fname += ex |
238 fpath = fpath.with_suffix(ex) |
238 if QFileInfo(fname).exists(): |
239 if fpath.exists(): |
239 res = EricMessageBox.yesNo( |
240 res = EricMessageBox.yesNo( |
240 self, |
241 self, |
241 self.tr("Save Diff"), |
242 self.tr("Save Diff"), |
242 self.tr("<p>The patch file <b>{0}</b> already exists." |
243 self.tr("<p>The patch file <b>{0}</b> already exists." |
243 " Overwrite it?</p>").format(fname), |
244 " Overwrite it?</p>").format(str(fpath)), |
244 icon=EricMessageBox.Warning) |
245 icon=EricMessageBox.Warning) |
245 if not res: |
246 if not res: |
246 return |
247 return |
247 fname = Utilities.toNativeSeparators(fname) |
|
248 |
248 |
249 eol = ericApp().getObject("Project").getEolString() |
249 eol = ericApp().getObject("Project").getEolString() |
250 try: |
250 try: |
251 with open(fname, "w", encoding="utf-8", newline="") as f: |
251 with fpath.open("w", encoding="utf-8", newline="") as f: |
252 f.write(eol.join(self.contents.toPlainText().splitlines())) |
252 f.write(eol.join(self.contents.toPlainText().splitlines())) |
253 except OSError as why: |
253 except OSError as why: |
254 EricMessageBox.critical( |
254 EricMessageBox.critical( |
255 self, self.tr('Save Diff'), |
255 self, self.tr('Save Diff'), |
256 self.tr( |
256 self.tr( |
257 '<p>The patch file <b>{0}</b> could not be saved.' |
257 '<p>The patch file <b>{0}</b> could not be saved.' |
258 '<br>Reason: {1}</p>') |
258 '<br>Reason: {1}</p>') |
259 .format(fname, str(why))) |
259 .format(str(fpath), str(why))) |
260 |
260 |
261 @pyqtSlot() |
261 @pyqtSlot() |
262 def on_refreshButton_clicked(self): |
262 def on_refreshButton_clicked(self): |
263 """ |
263 """ |
264 Private slot to refresh the display. |
264 Private slot to refresh the display. |