eric7/QScintilla/Shell.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 8881
54e42bc2437a
child 9153
506e35e424d5
equal deleted inserted replaced
9151:8c5296fe3056 9152:8a68afaf1ba2
9 9
10 import sys 10 import sys
11 import re 11 import re
12 import contextlib 12 import contextlib
13 import enum 13 import enum
14 import pathlib
14 15
15 from PyQt6.QtCore import pyqtSignal, pyqtSlot, QFileInfo, Qt, QEvent 16 from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QEvent
16 from PyQt6.QtGui import QClipboard, QPalette, QFont, QShortcut 17 from PyQt6.QtGui import QClipboard, QPalette, QFont, QShortcut
17 from PyQt6.QtWidgets import ( 18 from PyQt6.QtWidgets import (
18 QDialog, QInputDialog, QApplication, QMenu, QWidget, QHBoxLayout, 19 QDialog, QInputDialog, QApplication, QMenu, QWidget, QHBoxLayout,
19 QVBoxLayout, QSizePolicy 20 QVBoxLayout, QSizePolicy
20 ) 21 )
2195 """ 2196 """
2196 if event.mimeData().hasUrls() and not self.__windowed: 2197 if event.mimeData().hasUrls() and not self.__windowed:
2197 for url in event.mimeData().urls(): 2198 for url in event.mimeData().urls():
2198 fname = url.toLocalFile() 2199 fname = url.toLocalFile()
2199 if fname: 2200 if fname:
2200 if not QFileInfo(fname).isDir(): 2201 if not pathlib.Path(fname).is_dir():
2201 self.vm.openSourceFile(fname) 2202 self.vm.openSourceFile(fname)
2202 else: 2203 else:
2203 EricMessageBox.information( 2204 EricMessageBox.information(
2204 self, 2205 self,
2205 self.tr("Drop Error"), 2206 self.tr("Drop Error"),
2397 2398
2398 if fn: 2399 if fn:
2399 if fn.endswith("."): 2400 if fn.endswith("."):
2400 fn = fn[:-1] 2401 fn = fn[:-1]
2401 2402
2402 ext = QFileInfo(fn).suffix() 2403 fpath = pathlib.Path(fn)
2403 if not ext: 2404 if not fpath.suffix:
2404 ex = selectedFilter.split("(*")[1].split(")")[0] 2405 ex = selectedFilter.split("(*")[1].split(")")[0]
2405 if ex: 2406 if ex:
2406 fn += ex 2407 fpath = fpath.with_suffix(ex)
2407 if QFileInfo(fn).exists(): 2408 if fpath.exists():
2408 res = EricMessageBox.yesNo( 2409 res = EricMessageBox.yesNo(
2409 self, 2410 self,
2410 self.tr("Save Shell Contents"), 2411 self.tr("Save Shell Contents"),
2411 self.tr("<p>The file <b>{0}</b> already exists." 2412 self.tr("<p>The file <b>{0}</b> already exists."
2412 " Overwrite it?</p>").format(fn), 2413 " Overwrite it?</p>").format(str(fpath)),
2413 icon=EricMessageBox.Warning) 2414 icon=EricMessageBox.Warning)
2414 if not res: 2415 if not res:
2415 return 2416 return
2416 fn = Utilities.toNativeSeparators(fn)
2417 try: 2417 try:
2418 with open(fn, "w", encoding="utf-8") as f: 2418 with fpath.open("w", encoding="utf-8") as f:
2419 f.write(txt) 2419 f.write(txt)
2420 except (OSError, UnicodeError) as why: 2420 except (OSError, UnicodeError) as why:
2421 EricMessageBox.critical( 2421 EricMessageBox.critical(
2422 self, 2422 self,
2423 self.tr("Save Shell Contents"), 2423 self.tr("Save Shell Contents"),
2424 self.tr('<p>The file <b>{0}</b> could not be saved.<br/>' 2424 self.tr('<p>The file <b>{0}</b> could not be saved.<br/>'
2425 'Reason: {1}</p>') 2425 'Reason: {1}</p>')
2426 .format(fn, str(why))) 2426 .format(str(fpath), str(why)))
2427 2427
2428 ################################################################# 2428 #################################################################
2429 ## Project Support 2429 ## Project Support
2430 ################################################################# 2430 #################################################################
2431 2431

eric ide

mercurial