QScintilla/Shell.py

changeset 5798
e4f9552f7f93
parent 5736
000ea446ff4b
child 5799
e87f52c0374a
equal deleted inserted replaced
5797:8bc870b7a8a6 5798:e4f9552f7f93
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import sys 12 import sys
13 import re 13 import re
14
15 try:
16 from enum import Enum
17 except ImportError:
18 from ThirdParty.enum import Enum
14 19
15 from PyQt5.QtCore import pyqtSignal, QFileInfo, Qt, QEvent 20 from PyQt5.QtCore import pyqtSignal, QFileInfo, Qt, QEvent
16 from PyQt5.QtGui import QClipboard, QPalette, QFont 21 from PyQt5.QtGui import QClipboard, QPalette, QFont
17 from PyQt5.QtWidgets import QDialog, QInputDialog, QApplication, QMenu, \ 22 from PyQt5.QtWidgets import QDialog, QInputDialog, QApplication, QMenu, \
18 QWidget, QHBoxLayout, QVBoxLayout, QShortcut 23 QWidget, QHBoxLayout, QVBoxLayout, QShortcut
81 @return reference to the shell widget (Shell) 86 @return reference to the shell widget (Shell)
82 """ 87 """
83 return self.__shell 88 return self.__shell
84 89
85 90
91 class ShellHistoryStyle(Enum):
92 """
93 Class defining the shell history styles.
94 """
95 Disabled = 0
96 LinuxStyle = 1
97 WindowsStyle = 2
98
99
86 class Shell(QsciScintillaCompat): 100 class Shell(QsciScintillaCompat):
87 """ 101 """
88 Class implementing a graphical Python shell. 102 Class implementing a graphical Python shell.
89 103
90 A user can enter commands that are executed in the remote 104 A user can enter commands that are executed in the remote
91 Python interpreter. 105 Python interpreter.
92 106
93 @signal searchStringFound(found) emitted to indicate the search 107 @signal searchStringFound(bool) emitted to indicate the search
94 result (boolean) 108 result
109 @signal historyStyleChanged(int) emitted to indicate a change of
110 the history style
95 """ 111 """
96 searchStringFound = pyqtSignal(bool) 112 searchStringFound = pyqtSignal(bool)
113 historyStyleChanged = pyqtSignal(int)
97 114
98 def __init__(self, dbs, vm, windowedVariant, parent=None): 115 def __init__(self, dbs, vm, windowedVariant, parent=None):
99 """ 116 """
100 Constructor 117 Constructor
101 118
125 if self.__windowed: 142 if self.__windowed:
126 self.setWhatsThis(self.tr( 143 self.setWhatsThis(self.tr(
127 """<b>The Shell Window</b>""" 144 """<b>The Shell Window</b>"""
128 """<p>You can use the cursor keys while entering commands.""" 145 """<p>You can use the cursor keys while entering commands."""
129 """ There is also a history of commands that can be recalled""" 146 """ There is also a history of commands that can be recalled"""
130 """ using the up and down cursor keys. Pressing the up or""" 147 """ using the up and down cursor keys while holding down the"""
131 """ down key after some text has been entered will start an""" 148 """ Ctrl-key. Pressing these keys after some text has been"""
132 """ incremental search.</p>""" 149 """ entered will start an incremental search.</p>"""
133 """<p>The shell has some special commands. 'reset' kills the""" 150 """<p>The shell has some special commands. 'reset' kills the"""
134 """ shell and starts a new one. 'clear' clears the display""" 151 """ shell and starts a new one. 'clear' clears the display"""
135 """ of the shell window. 'start' is used to switch the shell""" 152 """ of the shell window. 'start' is used to switch the shell"""
136 """ language and must be followed by a supported language.""" 153 """ language and must be followed by a supported language."""
137 """ Supported languages are listed by the 'languages'""" 154 """ Supported languages are listed by the 'languages'"""
150 """ interpreter is the one that is used to run the program""" 167 """ interpreter is the one that is used to run the program"""
151 """ being debugged. This means that you can execute any""" 168 """ being debugged. This means that you can execute any"""
152 """ command while the program being debugged is running.</p>""" 169 """ command while the program being debugged is running.</p>"""
153 """<p>You can use the cursor keys while entering commands.""" 170 """<p>You can use the cursor keys while entering commands."""
154 """ There is also a history of commands that can be recalled""" 171 """ There is also a history of commands that can be recalled"""
155 """ using the up and down cursor keys. Pressing the up or""" 172 """ using the up and down cursor keys while holding down the"""
156 """ down key after some text has been entered will start an""" 173 """ Ctrl-key. Pressing these keys after some text has been"""
157 """ incremental search.</p>""" 174 """ entered will start an incremental search.</p>"""
158 """<p>The shell has some special commands. 'reset' kills the""" 175 """<p>The shell has some special commands. 'reset' kills the"""
159 """ shell and starts a new one. 'clear' clears the display""" 176 """ shell and starts a new one. 'clear' clears the display"""
160 """ of the shell window. 'start' is used to switch the shell""" 177 """ of the shell window. 'start' is used to switch the shell"""
161 """ language and must be followed by a supported language.""" 178 """ language and must be followed by a supported language."""
162 """ Supported languages are listed by the 'languages'""" 179 """ Supported languages are listed by the 'languages'"""
202 self.inDragDrop = False 219 self.inDragDrop = False
203 self.lexer_ = None 220 self.lexer_ = None
204 self.completionText = "" 221 self.completionText = ""
205 222
206 # Initialize history 223 # Initialize history
207 self.historyLists = {} 224 self.__historyLists = {}
208 self.maxHistoryEntries = Preferences.getShell("MaxHistoryEntries") 225 self.__maxHistoryEntries = Preferences.getShell("MaxHistoryEntries")
209 self.history = [] 226 self.__historyStyle = Preferences.getShell("HistoryStyle")
210 self.histidx = -1 227 self.__history = []
228 self.__setHistoryIndex()
211 # remove obsolete shell histories (Python and Ruby) 229 # remove obsolete shell histories (Python and Ruby)
212 for clientType in ["Python", "Ruby"]: 230 for clientType in ["Python", "Ruby"]:
213 Preferences.Prefs.settings.remove("Shell/Histories/" + clientType) 231 Preferences.Prefs.settings.remove("Shell/Histories/" + clientType)
214 232
215 self.clientType = '' 233 self.clientType = ''
251 # Create a little context menu 269 # Create a little context menu
252 self.menu = QMenu(self) 270 self.menu = QMenu(self)
253 self.menu.addAction(self.tr('Cut'), self.cut) 271 self.menu.addAction(self.tr('Cut'), self.cut)
254 self.menu.addAction(self.tr('Copy'), self.copy) 272 self.menu.addAction(self.tr('Copy'), self.copy)
255 self.menu.addAction(self.tr('Paste'), self.paste) 273 self.menu.addAction(self.tr('Paste'), self.paste)
256 self.menu.addMenu(self.hmenu) 274 self.menu.addMenu(self.hmenu).setEnabled(self.isHistoryEnabled())
275
257 self.menu.addSeparator() 276 self.menu.addSeparator()
258 self.menu.addAction(self.tr('Find'), self.__find) 277 self.menu.addAction(self.tr('Find'), self.__find)
259 self.menu.addSeparator() 278 self.menu.addSeparator()
260 self.menu.addAction(self.tr('Clear'), self.clear) 279 self.menu.addAction(self.tr('Clear'), self.clear)
261 self.menu.addAction(self.tr('Reset'), self.__reset) 280 self.menu.addAction(self.tr('Reset'), self.__reset)
310 QsciScintilla.SCI_CHARRIGHTEXTEND: self.extendSelectionRight, 329 QsciScintilla.SCI_CHARRIGHTEXTEND: self.extendSelectionRight,
311 QsciScintilla.SCI_WORDLEFTEXTEND: self.__QScintillaWordLeftExtend, 330 QsciScintilla.SCI_WORDLEFTEXTEND: self.__QScintillaWordLeftExtend,
312 QsciScintilla.SCI_WORDRIGHTEXTEND: self.extendSelectionWordRight, 331 QsciScintilla.SCI_WORDRIGHTEXTEND: self.extendSelectionWordRight,
313 QsciScintilla.SCI_VCHOMEEXTEND: self.__QScintillaVCHomeExtend, 332 QsciScintilla.SCI_VCHOMEEXTEND: self.__QScintillaVCHomeExtend,
314 QsciScintilla.SCI_LINEENDEXTEND: self.extendSelectionToEOL, 333 QsciScintilla.SCI_LINEENDEXTEND: self.extendSelectionToEOL,
334
335 QsciScintilla.SCI_CANCEL: self.__QScintillaCancel,
315 } 336 }
316 337
317 self.grabGesture(Qt.PinchGesture) 338 self.grabGesture(Qt.PinchGesture)
318 339
319 def __showLanguageMenu(self): 340 def __showLanguageMenu(self):
336 357
337 def closeShell(self): 358 def closeShell(self):
338 """ 359 """
339 Public method to shutdown the shell. 360 Public method to shutdown the shell.
340 """ 361 """
341 for clientType in self.historyLists: 362 for clientType in self.__historyLists:
342 self.saveHistory(clientType) 363 self.saveHistory(clientType)
343 364
344 def __bindLexer(self, language='Python3'): 365 def __bindLexer(self, language='Python3'):
345 """ 366 """
346 Private slot to set the lexer. 367 Private slot to set the lexer.
547 @param clType type of the debug client (string) 568 @param clType type of the debug client (string)
548 """ 569 """
549 self.clientCapabilities = cap 570 self.clientCapabilities = cap
550 if clType != self.clientType: 571 if clType != self.clientType:
551 self.clientType = clType 572 self.clientType = clType
552 self.__bindLexer(clType) 573 self.__bindLexer(self.clientType)
553 self.__setTextDisplay() 574 self.__setTextDisplay()
554 self.__setMargin0() 575 self.__setMargin0()
555 self.__setAutoCompletion(clType) 576 self.__setAutoCompletion(self.clientType)
556 self.__setCallTips(clType) 577 self.__setCallTips(self.clientType)
557 self.racEnabled = \ 578 self.racEnabled = \
558 Preferences.getShell("AutoCompletionEnabled") and \ 579 Preferences.getShell("AutoCompletionEnabled") and \
559 (cap & HasCompleter) > 0 580 (cap & HasCompleter) > 0
560 581
561 if clType not in self.historyLists: 582 if self.clientType not in self.__historyLists:
562 # load history list 583 # load history list
563 self.loadHistory(clType) 584 self.loadHistory(self.clientType)
564 self.history = self.historyLists[clType] 585 self.__history = self.__historyLists[self.clientType]
565 self.histidx = -1 586 self.__setHistoryIndex()
566 587
588 def __setHistoryIndex(self, index=None):
589 """
590 Private method to set the initial history index.
591
592 @param index index value to be set
593 @type int or None
594 """
595 if index is None:
596 # determine based on history style
597 if self.__historyStyle == ShellHistoryStyle.WindowsStyle:
598 idx = int(Preferences.Prefs.settings.value(
599 "Shell/HistoryIndexes/" + self.clientType, -1))
600 self.__histidx = idx
601 else:
602 self.__histidx = -1
603 else:
604 self.__histidx = index
605 if self.__histidx >= len(self.__history):
606 self.__histidx = -1
607 if self.clientType and \
608 self.__historyStyle == ShellHistoryStyle.WindowsStyle:
609 Preferences.Prefs.settings.setValue(
610 "Shell/HistoryIndexes/" + self.clientType, self.__histidx)
611
612 def __isHistoryIndexValid(self):
613 """
614 Private method to test, if the history index is valid.
615
616 @return flag indicating validity
617 @rtype bool
618 """
619 return (0 <= self.__histidx < len(self.__history))
620
567 def loadHistory(self, clientType): 621 def loadHistory(self, clientType):
568 """ 622 """
569 Public method to load the history for the given client type. 623 Public method to load the history for the given client type.
570 624
571 @param clientType type of the debug client (string) 625 @param clientType type of the debug client (string)
572 """ 626 """
573 hl = Preferences.Prefs.settings.value("Shell/Histories/" + clientType) 627 hl = Preferences.Prefs.settings.value("Shell/Histories/" + clientType)
574 if hl is not None: 628 if hl is not None:
575 self.historyLists[clientType] = hl[-self.maxHistoryEntries:] 629 self.__historyLists[clientType] = hl[-self.__maxHistoryEntries:]
576 else: 630 else:
577 self.historyLists[clientType] = [] 631 self.__historyLists[clientType] = []
578 632
579 def reloadHistory(self): 633 def reloadHistory(self):
580 """ 634 """
581 Public method to reload the history of the currently selected client 635 Public method to reload the history of the currently selected client
582 type. 636 type.
583 """ 637 """
584 self.loadHistory(self.clientType) 638 self.loadHistory(self.clientType)
585 self.history = self.historyLists[self.clientType] 639 self.__history = self.__historyLists[self.clientType]
586 self.histidx = -1 640 self.__setHistoryIndex()
587 641
588 def saveHistory(self, clientType): 642 def saveHistory(self, clientType):
589 """ 643 """
590 Public method to save the history for the given client type. 644 Public method to save the history for the given client type.
591 645
592 @param clientType type of the debug client (string) 646 @param clientType type of the debug client (string)
593 """ 647 """
594 if clientType in self.historyLists: 648 if clientType in self.__historyLists:
595 Preferences.Prefs.settings.setValue( 649 Preferences.Prefs.settings.setValue(
596 "Shell/Histories/" + clientType, self.historyLists[clientType]) 650 "Shell/Histories/" + clientType,
651 self.__historyLists[clientType])
597 652
598 def getHistory(self, clientType): 653 def getHistory(self, clientType):
599 """ 654 """
600 Public method to get the history for the given client type. 655 Public method to get the history for the given client type.
601 656
602 @param clientType type of the debug client (string). 657 @param clientType type of the debug client (string).
603 If it is None, the current history is returned. 658 If it is None, the current history is returned.
604 @return reference to the history list (list of strings) 659 @return reference to the history list (list of strings)
605 """ 660 """
606 if clientType is None: 661 if clientType is None:
607 return self.history 662 return self.__history
608 elif clientType in self.historyLists: 663 elif clientType in self.__historyLists:
609 return self.historyLists[clientType] 664 return self.__historyLists[clientType]
610 else: 665 else:
611 return [] 666 return []
612 667
613 def clearHistory(self): 668 def clearHistory(self):
614 """ 669 """
615 Public slot to clear the current history. 670 Public slot to clear the current history.
616 """ 671 """
617 if self.clientType: 672 if self.clientType:
618 self.historyLists[self.clientType] = [] 673 self.__historyLists[self.clientType] = []
619 self.history = self.historyLists[self.clientType] 674 self.__history = self.__historyLists[self.clientType]
620 else: 675 else:
621 self.history = [] 676 self.__history = []
622 self.histidx = -1 677 self.__setHistoryIndex(index=-1)
623 678
624 def selectHistory(self): 679 def selectHistory(self):
625 """ 680 """
626 Public slot to select a history entry to execute. 681 Public slot to select a history entry to execute.
627 """ 682 """
683 current = self.__histidx
684 if current == -1:
685 current = len(self.__history) - 1
628 cmd, ok = QInputDialog.getItem( 686 cmd, ok = QInputDialog.getItem(
629 self, 687 self,
630 self.tr("Select History"), 688 self.tr("Select History"),
631 self.tr("Select the history entry to execute" 689 self.tr("Select the history entry to execute"
632 " (most recent shown last)."), 690 " (most recent shown last)."),
633 self.history, 691 self.__history,
634 0, False) 692 current, False)
635 if ok: 693 if ok:
636 self.__insertHistory(cmd) 694 self.__insertHistory(cmd)
637 695
638 def showHistory(self): 696 def showHistory(self):
639 """ 697 """
640 Public slot to show the shell history dialog. 698 Public slot to show the shell history dialog.
641 """ 699 """
642 from .ShellHistoryDialog import ShellHistoryDialog 700 from .ShellHistoryDialog import ShellHistoryDialog
643 dlg = ShellHistoryDialog(self.history, self.vm, self) 701 dlg = ShellHistoryDialog(self.__history, self.vm, self)
644 if dlg.exec_() == QDialog.Accepted: 702 if dlg.exec_() == QDialog.Accepted:
645 self.historyLists[self.clientType] = dlg.getHistory() 703 self.__historyLists[self.clientType], idx = dlg.getHistory()
646 self.history = self.historyLists[self.clientType] 704 self.__history = self.__historyLists[self.clientType]
647 self.histidx = -1 705 self.__setHistoryIndex(index=idx)
648 706
649 def clearAllHistories(self): 707 def clearAllHistories(self):
650 """ 708 """
651 Public method to clear all available histories and sync them. 709 Public method to clear all available histories and sync them.
652 """ 710 """
653 Preferences.Prefs.settings.beginGroup("Shell/Histories") 711 Preferences.Prefs.settings.beginGroup("Shell/Histories")
654 for clientType in Preferences.Prefs.settings.childKeys(): 712 for clientType in Preferences.Prefs.settings.childKeys():
655 self.historyLists[clientType] = [] 713 self.__historyLists[clientType] = []
656 self.saveHistory(clientType) 714 self.saveHistory(clientType)
657 Preferences.Prefs.settings.endGroup() 715 Preferences.Prefs.settings.endGroup()
658 716
659 self.clearHistory() 717 self.clearHistory()
660 718
1341 """ 1399 """
1342 Private method to handle the Ctrl+Up key. 1400 Private method to handle the Ctrl+Up key.
1343 1401
1344 @param cmd QScintilla command 1402 @param cmd QScintilla command
1345 """ 1403 """
1346 line, col = self.__getEndPos() 1404 if self.isHistoryEnabled():
1347 buf = self.text(line) 1405 line, col = self.__getEndPos()
1348 if buf.startswith(sys.ps1): 1406 buf = self.text(line)
1349 buf = buf.replace(sys.ps1, "") 1407 if buf.startswith(sys.ps1):
1350 if buf.startswith(sys.ps2): 1408 buf = buf.replace(sys.ps1, "")
1351 buf = buf.replace(sys.ps2, "") 1409 if buf.startswith(sys.ps2):
1352 if buf and self.incrementalSearchActive: 1410 buf = buf.replace(sys.ps2, "")
1353 if self.incrementalSearchString: 1411 if buf and self.incrementalSearchActive:
1354 idx = self.__rsearchHistory(self.incrementalSearchString, 1412 if self.incrementalSearchString and \
1355 self.histidx) 1413 buf.startswith(self.incrementalSearchString):
1356 if idx >= 0: 1414 idx, found = self.__rsearchHistory(
1357 self.histidx = idx 1415 self.incrementalSearchString, self.__histidx)
1358 self.__useHistory() 1416 if found and idx >= 0:
1417 self.__setHistoryIndex(index=idx)
1418 self.__useHistory()
1419 else:
1420 idx, found = self.__rsearchHistory(buf)
1421 if found and idx >= 0:
1422 self.__setHistoryIndex(index=idx)
1423 self.incrementalSearchString = buf
1424 self.__useHistory()
1359 else: 1425 else:
1360 idx = self.__rsearchHistory(buf) 1426 if self.__histidx < 0:
1361 if idx >= 0: 1427 # wrap around
1362 self.histidx = idx 1428 self.__setHistoryIndex(index=len(self.__history) - 1)
1363 self.incrementalSearchString = buf 1429 else:
1364 self.__useHistory() 1430 self.__setHistoryIndex(index=self.__histidx - 1)
1365 else:
1366 if self.histidx < 0:
1367 self.histidx = len(self.history)
1368 if self.histidx > 0:
1369 self.histidx = self.histidx - 1
1370 self.__useHistory() 1431 self.__useHistory()
1371 1432
1372 def __QScintillaHistoryDown(self, cmd): 1433 def __QScintillaHistoryDown(self, cmd):
1373 """ 1434 """
1374 Private method to handle the Ctrl+Down key. 1435 Private method to handle the Ctrl+Down key.
1375 1436
1376 @param cmd QScintilla command 1437 @param cmd QScintilla command
1377 """ 1438 """
1378 line, col = self.__getEndPos() 1439 if self.isHistoryEnabled():
1379 buf = self.text(line) 1440 line, col = self.__getEndPos()
1380 if buf.startswith(sys.ps1): 1441 buf = self.text(line)
1381 buf = buf.replace(sys.ps1, "") 1442 if buf.startswith(sys.ps1):
1382 if buf.startswith(sys.ps2): 1443 buf = buf.replace(sys.ps1, "")
1383 buf = buf.replace(sys.ps2, "") 1444 if buf.startswith(sys.ps2):
1384 if buf and self.incrementalSearchActive: 1445 buf = buf.replace(sys.ps2, "")
1385 if self.incrementalSearchString: 1446 if buf and self.incrementalSearchActive:
1386 idx = self.__searchHistory( 1447 if self.incrementalSearchString and \
1387 self.incrementalSearchString, self.histidx) 1448 buf.startswith(self.incrementalSearchString):
1388 if idx >= 0: 1449 idx, found = self.__searchHistory(
1389 self.histidx = idx 1450 self.incrementalSearchString, self.__histidx)
1390 self.__useHistory() 1451 if found and idx >= 0:
1452 self.__setHistoryIndex(index=idx)
1453 self.__useHistory()
1454 else:
1455 idx, found = self.__searchHistory(buf)
1456 if found and idx >= 0:
1457 self.__setHistoryIndex(index=idx)
1458 self.incrementalSearchString = buf
1459 self.__useHistory()
1391 else: 1460 else:
1392 idx = self.__searchHistory(buf) 1461 if self.__histidx >= len(self.__history) - 1:
1393 if idx >= 0: 1462 # wrap around
1394 self.histidx = idx 1463 self.__setHistoryIndex(index=0)
1395 self.incrementalSearchString = buf 1464 else:
1396 self.__useHistory() 1465 self.__setHistoryIndex(index=self.__histidx + 1)
1397 else:
1398 if self.histidx >= 0 and self.histidx < len(self.history):
1399 self.histidx += 1
1400 self.__useHistory() 1466 self.__useHistory()
1401 1467
1468 def __QScintillaCancel(self):
1469 """
1470 Private method to handle the ESC command.
1471 """
1472 if self.incrementalSearchActive:
1473 self.__resetIncrementalHistorySearch()
1474 self.__insertHistory("")
1475
1402 def __QScintillaCharLeftExtend(self): 1476 def __QScintillaCharLeftExtend(self):
1403 """ 1477 """
1404 Private method to handle the Extend Selection Left command. 1478 Private method to handle the Extend Selection Left command.
1405 """ 1479 """
1406 self.__QScintillaLeftCommand(self.extendSelectionLeft, True) 1480 self.__QScintillaLeftCommand(self.extendSelectionLeft, True)
1445 """ 1519 """
1446 if not self.inRawMode: 1520 if not self.inRawMode:
1447 self.inCommandExecution = True 1521 self.inCommandExecution = True
1448 self.interruptCommandExecution = False 1522 self.interruptCommandExecution = False
1449 if not cmd: 1523 if not cmd:
1524 # make sure cmd is a string
1450 cmd = '' 1525 cmd = ''
1451 if len(self.history) == 0 or self.history[-1] != cmd: 1526 # TODO: change according to history style
1452 if len(self.history) == self.maxHistoryEntries: 1527 # Linux - append (i.e. keep as is)
1453 del self.history[0] 1528 # Windows - modify current entry if index not at end, add otherwise
1454 self.history.append(cmd) 1529 if self.isHistoryEnabled():
1455 self.histidx = -1 1530 if cmd != "" and (
1531 len(self.__history) == 0 or self.__history[-1] != cmd):
1532 if len(self.__history) == self.__maxHistoryEntries:
1533 del self.__history[0]
1534 self.__history.append(cmd)
1535 self.__histidx = -1
1456 if cmd.startswith('start '): 1536 if cmd.startswith('start '):
1457 if not self.passive: 1537 if not self.passive:
1458 cmdList = cmd.split(None, 1) 1538 cmdList = cmd.split(None, 1)
1459 if len(cmdList) < 2: 1539 if len(cmdList) < 2:
1460 self.dbs.startClient(False) # same as reset 1540 self.dbs.startClient(False) # same as reset
1520 1600
1521 def __useHistory(self): 1601 def __useHistory(self):
1522 """ 1602 """
1523 Private method to display a command from the history. 1603 Private method to display a command from the history.
1524 """ 1604 """
1525 if self.histidx < len(self.history): 1605 if self.__isHistoryIndexValid():
1526 cmd = self.history[self.histidx] 1606 cmd = self.__history[self.__histidx]
1527 else: 1607 else:
1528 cmd = "" 1608 cmd = ""
1529 self.incrementalSearchString = "" 1609 self.__resetIncrementalHistorySearch()
1530 self.incrementalSearchActive = False
1531 1610
1532 self.__insertHistory(cmd) 1611 self.__insertHistory(cmd)
1533 1612
1534 def __insertHistory(self, cmd): 1613 def __insertHistory(self, cmd):
1535 """ 1614 """
1540 self.setCursorPosition(self.prline, self.prcol) 1619 self.setCursorPosition(self.prline, self.prcol)
1541 self.setSelection(self.prline, self.prcol, 1620 self.setSelection(self.prline, self.prcol,
1542 self.prline, self.lineLength(self.prline)) 1621 self.prline, self.lineLength(self.prline))
1543 self.removeSelectedText() 1622 self.removeSelectedText()
1544 self.__insertText(cmd) 1623 self.__insertText(cmd)
1545 1624
1625 def __resetIncrementalHistorySearch(self):
1626 """
1627 Private method to reset the incremental history search.
1628 """
1629 self.incrementalSearchString = ""
1630 self.incrementalSearchActive = False
1631
1546 def __searchHistory(self, txt, startIdx=-1): 1632 def __searchHistory(self, txt, startIdx=-1):
1547 """ 1633 """
1548 Private method used to search the history. 1634 Private method used to search the history.
1549 1635
1550 @param txt text to match at the beginning (string) 1636 @param txt text to match at the beginning
1551 @param startIdx index to start search from (integer) 1637 @type str
1552 @return index of found entry (integer) 1638 @param startIdx index to start search from
1639 @type int
1640 @return tuple containing the index of found entry and a flag indicating
1641 that something was found
1642 @rtype tuple of (int, bool)
1553 """ 1643 """
1554 if startIdx == -1: 1644 if startIdx == -1:
1555 idx = 0 1645 idx = 0
1556 else: 1646 else:
1557 idx = startIdx + 1 1647 idx = startIdx + 1
1558 while idx < len(self.history) and \ 1648 while idx < len(self.__history) and \
1559 not self.history[idx].startswith(txt): 1649 not self.__history[idx].startswith(txt):
1560 idx += 1 1650 idx += 1
1561 return idx 1651 found = (idx < len(self.__history) and
1652 self.__history[idx].startswith(txt))
1653 return idx, found
1562 1654
1563 def __rsearchHistory(self, txt, startIdx=-1): 1655 def __rsearchHistory(self, txt, startIdx=-1):
1564 """ 1656 """
1565 Private method used to reverse search the history. 1657 Private method used to reverse search the history.
1566 1658
1567 @param txt text to match at the beginning (string) 1659 @param txt text to match at the beginning
1568 @param startIdx index to start search from (integer) 1660 @type str
1569 @return index of found entry (integer) 1661 @param startIdx index to start search from
1662 @type int
1663 @return tuple containing the index of found entry and a flag indicating
1664 that something was found
1665 @rtype tuple of (int, bool)
1570 """ 1666 """
1571 if startIdx == -1: 1667 if startIdx == -1:
1572 idx = len(self.history) - 1 1668 idx = len(self.__history) - 1
1573 else: 1669 else:
1574 idx = startIdx - 1 1670 idx = startIdx - 1
1575 while idx >= 0 and \ 1671 while idx >= 0 and \
1576 not self.history[idx].startswith(txt): 1672 not self.__history[idx].startswith(txt):
1577 idx -= 1 1673 idx -= 1
1578 return idx 1674 found = idx >= 0 and self.__history[idx].startswith(txt)
1675 return idx, found
1579 1676
1580 def focusNextPrevChild(self, nextChild): 1677 def focusNextPrevChild(self, nextChild):
1581 """ 1678 """
1582 Public method to stop Tab moving to the next window. 1679 Public method to stop Tab moving to the next window.
1583 1680
1647 # set the autocompletion and calltips function 1744 # set the autocompletion and calltips function
1648 self.__setAutoCompletion() 1745 self.__setAutoCompletion()
1649 self.__setCallTips() 1746 self.__setCallTips()
1650 1747
1651 # do the history related stuff 1748 # do the history related stuff
1652 self.maxHistoryEntries = Preferences.getShell("MaxHistoryEntries") 1749 self.__maxHistoryEntries = Preferences.getShell("MaxHistoryEntries")
1653 for key in list(self.historyLists.keys()): 1750 for key in list(self.__historyLists.keys()):
1654 self.historyLists[key] = \ 1751 self.__historyLists[key] = \
1655 self.historyLists[key][-self.maxHistoryEntries:] 1752 self.__historyLists[key][-self.__maxHistoryEntries:]
1753 self.__historyStyle = Preferences.getShell("HistoryStyle")
1754 self.__setHistoryIndex()
1755 self.historyStyleChanged.emit(self.__historyStyle)
1756 if not self.__windowed:
1757 self.hmenu.menuAction().setEnabled(self.isHistoryEnabled())
1656 1758
1657 # do stdout /stderr stuff 1759 # do stdout /stderr stuff
1658 showStdOutErr = Preferences.getShell("ShowStdOutErr") 1760 showStdOutErr = Preferences.getShell("ShowStdOutErr")
1659 if self.__showStdOutErr != showStdOutErr: 1761 if self.__showStdOutErr != showStdOutErr:
1660 if showStdOutErr: 1762 if showStdOutErr:
1896 line, index = -1, -1 1998 line, index = -1, -1
1897 ok = self.findFirst( 1999 ok = self.findFirst(
1898 txt, False, caseSensitive, wholeWord, False, 2000 txt, False, caseSensitive, wholeWord, False,
1899 forward=False, line=line, index=index) 2001 forward=False, line=line, index=index)
1900 self.searchStringFound.emit(ok) 2002 self.searchStringFound.emit(ok)
2003
2004 def historyStyle(self):
2005 """
2006 Public method to get the shell history style.
2007
2008 @return shell history style
2009 @rtype ShellHistoryStyle
2010 """
2011 return self.__historyStyle
2012
2013 def isHistoryEnabled(self):
2014 """
2015 Public method to check, if the history is enabled.
2016
2017 @return flag indicating if history is enabled
2018 @rtype bool
2019 """
2020 return self.__historyStyle != ShellHistoryStyle.Disabled

eric ide

mercurial