12 |
12 |
13 from PyQt6.QtCore import QTimer, QFileInfo, QProcess, pyqtSlot, Qt |
13 from PyQt6.QtCore import QTimer, QFileInfo, QProcess, pyqtSlot, Qt |
14 from PyQt6.QtGui import QTextCursor |
14 from PyQt6.QtGui import QTextCursor |
15 from PyQt6.QtWidgets import QWidget, QLineEdit, QDialogButtonBox |
15 from PyQt6.QtWidgets import QWidget, QLineEdit, QDialogButtonBox |
16 |
16 |
17 from E5Gui.E5Application import e5App |
17 from E5Gui.EricApplication import ericApp |
18 from E5Gui import E5MessageBox, E5FileDialog |
18 from E5Gui import EricMessageBox, EricFileDialog |
19 |
19 |
20 from .Ui_SvnDiffDialog import Ui_SvnDiffDialog |
20 from .Ui_SvnDiffDialog import Ui_SvnDiffDialog |
21 from .SvnDiffHighlighter import SvnDiffHighlighter |
21 from .SvnDiffHighlighter import SvnDiffHighlighter |
22 |
22 |
23 import Utilities |
23 import Utilities |
160 if isinstance(fn, list): |
160 if isinstance(fn, list): |
161 dname, fnames = self.vcs.splitPathList(fn) |
161 dname, fnames = self.vcs.splitPathList(fn) |
162 else: |
162 else: |
163 dname, fname = self.vcs.splitPath(fn) |
163 dname, fname = self.vcs.splitPath(fn) |
164 fnames = [fname] |
164 fnames = [fname] |
165 project = e5App().getObject('Project') |
165 project = ericApp().getObject('Project') |
166 if dname == project.getProjectPath(): |
166 if dname == project.getProjectPath(): |
167 path = "" |
167 path = "" |
168 else: |
168 else: |
169 path = project.getRelativePath(dname) |
169 path = project.getRelativePath(dname) |
170 if path: |
170 if path: |
184 self.process.start('svn', args) |
184 self.process.start('svn', args) |
185 procStarted = self.process.waitForStarted(5000) |
185 procStarted = self.process.waitForStarted(5000) |
186 if not procStarted: |
186 if not procStarted: |
187 self.inputGroup.setEnabled(False) |
187 self.inputGroup.setEnabled(False) |
188 self.inputGroup.hide() |
188 self.inputGroup.hide() |
189 E5MessageBox.critical( |
189 EricMessageBox.critical( |
190 self, |
190 self, |
191 self.tr('Process Generation Error'), |
191 self.tr('Process Generation Error'), |
192 self.tr( |
192 self.tr( |
193 'The process {0} could not be started. ' |
193 'The process {0} could not be started. ' |
194 'Ensure, that it is in the search path.' |
194 'Ensure, that it is in the search path.' |
372 else: |
372 else: |
373 fname = dname |
373 fname = dname |
374 else: |
374 else: |
375 fname = self.vcs.splitPath(self.filename)[0] |
375 fname = self.vcs.splitPath(self.filename)[0] |
376 |
376 |
377 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
377 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
378 self, |
378 self, |
379 self.tr("Save Diff"), |
379 self.tr("Save Diff"), |
380 fname, |
380 fname, |
381 self.tr("Patch Files (*.diff)"), |
381 self.tr("Patch Files (*.diff)"), |
382 None, |
382 None, |
383 E5FileDialog.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 ext = QFileInfo(fname).suffix() |
389 if not ext: |
389 if not ext: |
390 ex = selectedFilter.split("(*")[1].split(")")[0] |
390 ex = selectedFilter.split("(*")[1].split(")")[0] |
391 if ex: |
391 if ex: |
392 fname += ex |
392 fname += ex |
393 if QFileInfo(fname).exists(): |
393 if QFileInfo(fname).exists(): |
394 res = E5MessageBox.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(fname), |
399 icon=E5MessageBox.Warning) |
399 icon=EricMessageBox.Warning) |
400 if not res: |
400 if not res: |
401 return |
401 return |
402 fname = Utilities.toNativeSeparators(fname) |
402 fname = Utilities.toNativeSeparators(fname) |
403 |
403 |
404 eol = e5App().getObject("Project").getEolString() |
404 eol = ericApp().getObject("Project").getEolString() |
405 try: |
405 try: |
406 with open(fname, "w", encoding="utf-8", newline="") as f: |
406 with open(fname, "w", encoding="utf-8", newline="") as f: |
407 f.write(eol.join(self.contents.toPlainText().splitlines())) |
407 f.write(eol.join(self.contents.toPlainText().splitlines())) |
408 except OSError as why: |
408 except OSError as why: |
409 E5MessageBox.critical( |
409 EricMessageBox.critical( |
410 self, self.tr('Save Diff'), |
410 self, self.tr('Save Diff'), |
411 self.tr( |
411 self.tr( |
412 '<p>The patch file <b>{0}</b> could not be saved.' |
412 '<p>The patch file <b>{0}</b> could not be saved.' |
413 '<br>Reason: {1}</p>') |
413 '<br>Reason: {1}</p>') |
414 .format(fname, str(why))) |
414 .format(fname, str(why))) |