eric7/QScintilla/Shell.py

branch
eric7
changeset 8521
4794215f9a3c
parent 8481
02865597d820
child 8525
23d37fb05a21
equal deleted inserted replaced
8520:48e1237aaef7 8521:4794215f9a3c
19 QVBoxLayout, QSizePolicy 19 QVBoxLayout, QSizePolicy
20 ) 20 )
21 from PyQt6.Qsci import QsciScintilla 21 from PyQt6.Qsci import QsciScintilla
22 22
23 from EricWidgets.EricApplication import ericApp 23 from EricWidgets.EricApplication import ericApp
24 from EricWidgets import EricMessageBox 24 from EricWidgets import EricMessageBox, EricFileDialog
25 25
26 from .QsciScintillaCompat import QsciScintillaCompat 26 from .QsciScintillaCompat import QsciScintillaCompat
27 27
28 import Preferences 28 import Preferences
29 import Utilities 29 import Utilities
315 self.menu.addAction( 315 self.menu.addAction(
316 self.tr('Restart and Clear'), self.doClearRestart) 316 self.tr('Restart and Clear'), self.doClearRestart)
317 self.menu.addSeparator() 317 self.menu.addSeparator()
318 self.menu.addMenu(self.lmenu) 318 self.menu.addMenu(self.lmenu)
319 self.menu.addAction(self.tr('Active Name'), self.__showVenvName) 319 self.menu.addAction(self.tr('Active Name'), self.__showVenvName)
320 self.menu.addSeparator()
321 self.menu.addAction(self.tr("Save Contents..."), self.saveContents)
320 self.menu.addSeparator() 322 self.menu.addSeparator()
321 self.menu.addAction(self.tr("Configure..."), self.__configure) 323 self.menu.addAction(self.tr("Configure..."), self.__configure)
322 324
323 self.__bindLexer() 325 self.__bindLexer()
324 self.__setTextDisplay() 326 self.__setTextDisplay()
2376 @return flag indicating if history is enabled 2378 @return flag indicating if history is enabled
2377 @rtype bool 2379 @rtype bool
2378 """ 2380 """
2379 return self.__historyStyle != ShellHistoryStyle.DISABLED 2381 return self.__historyStyle != ShellHistoryStyle.DISABLED
2380 2382
2383 def saveContents(self):
2384 """
2385 Public method to save the current contents to a file.
2386 """
2387 # TODO: not yet implemented
2388 txt = self.text()
2389 if txt:
2390 fn, selectedFilter = EricFileDialog.getSaveFileNameAndFilter(
2391 self,
2392 self.tr("Save Shell Contents"),
2393 Preferences.getMultiProject("Workspace"),
2394 self.tr("Text Files (*.txt);;All Files (*)"),
2395 None,
2396 EricFileDialog.DontConfirmOverwrite
2397 )
2398
2399 if fn:
2400 if fn.endswith("."):
2401 fn = fn[:-1]
2402
2403 ext = QFileInfo(fn).suffix()
2404 if not ext:
2405 ex = selectedFilter.split("(*")[1].split(")")[0]
2406 if ex:
2407 fn += ex
2408 if QFileInfo(fn).exists():
2409 res = EricMessageBox.yesNo(
2410 self,
2411 self.tr("Save Shell Contents"),
2412 self.tr("<p>The file <b>{0}</b> already exists."
2413 " Overwrite it?</p>").format(fn),
2414 icon=EricMessageBox.Warning)
2415 if not res:
2416 return
2417 fn = Utilities.toNativeSeparators(fn)
2418 try:
2419 with open(fn, "w", encoding="utf-8") as f:
2420 f.write(txt)
2421 except (OSError, UnicodeError) as why:
2422 EricMessageBox.critical(
2423 self,
2424 self.tr("Save Shell Contents"),
2425 self.tr('<p>The file <b>{0}</b> could not be saved.<br/>'
2426 'Reason: {1}</p>')
2427 .format(fn, str(why)))
2428
2381 ################################################################# 2429 #################################################################
2382 ## Project Support 2430 ## Project Support
2383 ################################################################# 2431 #################################################################
2384 2432
2385 def __projectOpened(self): 2433 def __projectOpened(self):

eric ide

mercurial