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) |
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 |