14 |
14 |
15 from PyQt6.QtCore import QFileInfo, QDateTime, Qt, pyqtSlot |
15 from PyQt6.QtCore import QFileInfo, QDateTime, Qt, pyqtSlot |
16 from PyQt6.QtGui import QTextCursor |
16 from PyQt6.QtGui import QTextCursor |
17 from PyQt6.QtWidgets import QWidget, QDialogButtonBox |
17 from PyQt6.QtWidgets import QWidget, QDialogButtonBox |
18 |
18 |
19 from E5Gui.E5Application import e5App |
19 from E5Gui.EricApplication import ericApp |
20 from E5Gui import E5MessageBox, E5FileDialog |
20 from E5Gui import EricMessageBox, EricFileDialog |
21 from E5Gui.E5OverrideCursor import E5OverrideCursor |
21 from E5Gui.EricOverrideCursor import EricOverrideCursor |
22 |
22 |
23 from EricUtilities.EricMutexLocker import EricMutexLocker |
23 from EricUtilities.EricMutexLocker import EricMutexLocker |
24 |
24 |
25 from .SvnDialogMixin import SvnDialogMixin |
25 from .SvnDialogMixin import SvnDialogMixin |
26 from .Ui_SvnDiffDialog import Ui_SvnDiffDialog |
26 from .Ui_SvnDiffDialog import Ui_SvnDiffDialog |
166 elif os.path.exists('/usr/tmp'): |
166 elif os.path.exists('/usr/tmp'): |
167 tmpdir = '/usr/tmp' |
167 tmpdir = '/usr/tmp' |
168 elif os.path.exists('/tmp'): # secok |
168 elif os.path.exists('/tmp'): # secok |
169 tmpdir = '/tmp' # secok |
169 tmpdir = '/tmp' # secok |
170 else: |
170 else: |
171 E5MessageBox.critical( |
171 EricMessageBox.critical( |
172 self, |
172 self, |
173 self.tr("Subversion Diff"), |
173 self.tr("Subversion Diff"), |
174 self.tr("""There is no temporary directory available.""")) |
174 self.tr("""There is no temporary directory available.""")) |
175 return |
175 return |
176 |
176 |
201 dname, fnames = self.vcs.splitPathList(fn) |
201 dname, fnames = self.vcs.splitPathList(fn) |
202 else: |
202 else: |
203 dname, fname = self.vcs.splitPath(fn) |
203 dname, fname = self.vcs.splitPath(fn) |
204 fnames = [fname] |
204 fnames = [fname] |
205 |
205 |
206 with E5OverrideCursor(): |
206 with EricOverrideCursor(): |
207 cwd = os.getcwd() |
207 cwd = os.getcwd() |
208 os.chdir(dname) |
208 os.chdir(dname) |
209 try: |
209 try: |
210 dname = e5App().getObject('Project').getRelativePath(dname) |
210 dname = ericApp().getObject('Project').getRelativePath(dname) |
211 if dname: |
211 if dname: |
212 dname += "/" |
212 dname += "/" |
213 with EricMutexLocker(self.vcs.vcsExecutionMutex): |
213 with EricMutexLocker(self.vcs.vcsExecutionMutex): |
214 for name in fnames: |
214 for name in fnames: |
215 self.__showError( |
215 self.__showError( |
418 else: |
418 else: |
419 fname = dname |
419 fname = dname |
420 else: |
420 else: |
421 fname = self.vcs.splitPath(self.filename)[0] |
421 fname = self.vcs.splitPath(self.filename)[0] |
422 |
422 |
423 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
423 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
424 self, |
424 self, |
425 self.tr("Save Diff"), |
425 self.tr("Save Diff"), |
426 fname, |
426 fname, |
427 self.tr("Patch Files (*.diff)"), |
427 self.tr("Patch Files (*.diff)"), |
428 None, |
428 None, |
429 E5FileDialog.DontConfirmOverwrite) |
429 EricFileDialog.DontConfirmOverwrite) |
430 |
430 |
431 if not fname: |
431 if not fname: |
432 return # user aborted |
432 return # user aborted |
433 |
433 |
434 ext = QFileInfo(fname).suffix() |
434 ext = QFileInfo(fname).suffix() |
435 if not ext: |
435 if not ext: |
436 ex = selectedFilter.split("(*")[1].split(")")[0] |
436 ex = selectedFilter.split("(*")[1].split(")")[0] |
437 if ex: |
437 if ex: |
438 fname += ex |
438 fname += ex |
439 if QFileInfo(fname).exists(): |
439 if QFileInfo(fname).exists(): |
440 res = E5MessageBox.yesNo( |
440 res = EricMessageBox.yesNo( |
441 self, |
441 self, |
442 self.tr("Save Diff"), |
442 self.tr("Save Diff"), |
443 self.tr("<p>The patch file <b>{0}</b> already exists." |
443 self.tr("<p>The patch file <b>{0}</b> already exists." |
444 " Overwrite it?</p>").format(fname), |
444 " Overwrite it?</p>").format(fname), |
445 icon=E5MessageBox.Warning) |
445 icon=EricMessageBox.Warning) |
446 if not res: |
446 if not res: |
447 return |
447 return |
448 fname = Utilities.toNativeSeparators(fname) |
448 fname = Utilities.toNativeSeparators(fname) |
449 |
449 |
450 eol = e5App().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 open(fname, "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 E5MessageBox.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(fname, str(why))) |