eric7/Plugins/VcsPlugins/vcsMercurial/HgDiffDialog.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8322
b422b4e77d19
child 8358
144a6b854f70
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
9 9
10 from PyQt6.QtCore import pyqtSlot, QFileInfo, Qt 10 from PyQt6.QtCore import pyqtSlot, QFileInfo, Qt
11 from PyQt6.QtGui import QTextCursor 11 from PyQt6.QtGui import QTextCursor
12 from PyQt6.QtWidgets import QWidget, QDialogButtonBox 12 from PyQt6.QtWidgets import QWidget, QDialogButtonBox
13 13
14 from E5Gui import E5MessageBox, E5FileDialog 14 from E5Gui import EricMessageBox, EricFileDialog
15 from E5Gui.E5Application import e5App 15 from E5Gui.EricApplication import ericApp
16 16
17 from .Ui_HgDiffDialog import Ui_HgDiffDialog 17 from .Ui_HgDiffDialog import Ui_HgDiffDialog
18 from .HgDiffHighlighter import HgDiffHighlighter 18 from .HgDiffHighlighter import HgDiffHighlighter
19 from .HgDiffGenerator import HgDiffGenerator 19 from .HgDiffGenerator import HgDiffGenerator
20 20
96 self.activateWindow() 96 self.activateWindow()
97 97
98 procStarted = self.__diffGenerator.start( 98 procStarted = self.__diffGenerator.start(
99 fn, versions=versions, bundle=bundle, qdiff=qdiff) 99 fn, versions=versions, bundle=bundle, qdiff=qdiff)
100 if not procStarted: 100 if not procStarted:
101 E5MessageBox.critical( 101 EricMessageBox.critical(
102 self, 102 self,
103 self.tr('Process Generation Error'), 103 self.tr('Process Generation Error'),
104 self.tr( 104 self.tr(
105 'The process {0} could not be started. ' 105 'The process {0} could not be started. '
106 'Ensure, that it is in the search path.' 106 'Ensure, that it is in the search path.'
217 else: 217 else:
218 fname = dname 218 fname = dname
219 else: 219 else:
220 fname = self.vcs.splitPath(self.filename)[0] 220 fname = self.vcs.splitPath(self.filename)[0]
221 221
222 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 222 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter(
223 self, 223 self,
224 self.tr("Save Diff"), 224 self.tr("Save Diff"),
225 fname, 225 fname,
226 self.tr("Patch Files (*.diff)"), 226 self.tr("Patch Files (*.diff)"),
227 None, 227 None,
228 E5FileDialog.DontConfirmOverwrite) 228 EricFileDialog.DontConfirmOverwrite)
229 229
230 if not fname: 230 if not fname:
231 return # user aborted 231 return # user aborted
232 232
233 ext = QFileInfo(fname).suffix() 233 ext = QFileInfo(fname).suffix()
234 if not ext: 234 if not ext:
235 ex = selectedFilter.split("(*")[1].split(")")[0] 235 ex = selectedFilter.split("(*")[1].split(")")[0]
236 if ex: 236 if ex:
237 fname += ex 237 fname += ex
238 if QFileInfo(fname).exists(): 238 if QFileInfo(fname).exists():
239 res = E5MessageBox.yesNo( 239 res = EricMessageBox.yesNo(
240 self, 240 self,
241 self.tr("Save Diff"), 241 self.tr("Save Diff"),
242 self.tr("<p>The patch file <b>{0}</b> already exists." 242 self.tr("<p>The patch file <b>{0}</b> already exists."
243 " Overwrite it?</p>").format(fname), 243 " Overwrite it?</p>").format(fname),
244 icon=E5MessageBox.Warning) 244 icon=EricMessageBox.Warning)
245 if not res: 245 if not res:
246 return 246 return
247 fname = Utilities.toNativeSeparators(fname) 247 fname = Utilities.toNativeSeparators(fname)
248 248
249 eol = e5App().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 open(fname, "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 E5MessageBox.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(fname, str(why)))

eric ide

mercurial