src/eric7/QScintilla/Shell.py

branch
eric7
changeset 10157
0020603d754b
parent 10069
435cc5875135
child 10161
b0ccdb47acde
equal deleted inserted replaced
10156:e72868c86d84 10157:0020603d754b
2410 self.tr("Text Files (*.txt);;All Files (*)"), 2410 self.tr("Text Files (*.txt);;All Files (*)"),
2411 None, 2411 None,
2412 EricFileDialog.DontConfirmOverwrite, 2412 EricFileDialog.DontConfirmOverwrite,
2413 ) 2413 )
2414 2414
2415 if fn: 2415 if not fn:
2416 if fn.endswith("."): 2416 return
2417 fn = fn[:-1] 2417
2418 2418 if fn.endswith("."):
2419 fpath = pathlib.Path(fn) 2419 fn = fn[:-1]
2420 if not fpath.suffix: 2420
2421 ex = selectedFilter.split("(*")[1].split(")")[0] 2421 fpath = pathlib.Path(fn)
2422 if ex: 2422 if not fpath.suffix:
2423 fpath = fpath.with_suffix(ex) 2423 ex = selectedFilter.split("(*")[1].split(")")[0]
2424 if fpath.exists(): 2424 if ex:
2425 res = EricMessageBox.yesNo( 2425 fpath = fpath.with_suffix(ex)
2426 self, 2426 if fpath.exists():
2427 self.tr("Save Shell Contents"), 2427 res = EricMessageBox.yesNo(
2428 self.tr( 2428 self,
2429 "<p>The file <b>{0}</b> already exists." 2429 self.tr("Save Shell Contents"),
2430 " Overwrite it?</p>" 2430 self.tr(
2431 ).format(fpath), 2431 "<p>The file <b>{0}</b> already exists."
2432 icon=EricMessageBox.Warning, 2432 " Overwrite it?</p>"
2433 ) 2433 ).format(fpath),
2434 if not res: 2434 icon=EricMessageBox.Warning,
2435 return 2435 )
2436 if not res:
2437 return
2436 try: 2438 try:
2437 with fpath.open("w", encoding="utf-8") as f: 2439 with fpath.open("w", encoding="utf-8") as f:
2438 f.write(txt) 2440 f.write(txt)
2439 except (OSError, UnicodeError) as why: 2441 except (OSError, UnicodeError) as why:
2440 EricMessageBox.critical( 2442 EricMessageBox.critical(

eric ide

mercurial