QScintilla/ShellHistoryDialog.py

changeset 5799
e87f52c0374a
parent 5798
e4f9552f7f93
child 6048
82ad8ec9548c
equal deleted inserted replaced
5798:e4f9552f7f93 5799:e87f52c0374a
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import os 12 import os
13 13
14 from PyQt5.QtCore import pyqtSlot, QItemSelectionModel 14 from PyQt5.QtCore import pyqtSlot, Qt, QItemSelectionModel
15 from PyQt5.QtWidgets import QListWidgetItem, QDialog 15 from PyQt5.QtWidgets import QListWidgetItem, QDialog
16 16
17 from .Ui_ShellHistoryDialog import Ui_ShellHistoryDialog 17 from .Ui_ShellHistoryDialog import Ui_ShellHistoryDialog
18 18
19 19
23 """ 23 """
24 def __init__(self, history, vm, shell): 24 def __init__(self, history, vm, shell):
25 """ 25 """
26 Constructor 26 Constructor
27 27
28 @param history reference to the current shell history (list of strings) 28 @param history reference to the current shell history
29 @type list of str
29 @param vm reference to the viewmanager object 30 @param vm reference to the viewmanager object
31 @type ViewManager
30 @param shell reference to the shell object 32 @param shell reference to the shell object
33 @type Shell
31 """ 34 """
32 super(ShellHistoryDialog, self).__init__(shell) 35 super(ShellHistoryDialog, self).__init__(shell)
33 self.setupUi(self) 36 self.setupUi(self)
34 37
38 self.__vm = vm
39 self.__shell = shell
40
35 self.historyList.addItems(history) 41 self.historyList.addItems(history)
36 self.historyList.setCurrentRow( 42 index = shell.getHistoryIndex()
37 self.historyList.count() - 1, QItemSelectionModel.Clear) 43 if index < 0 or index >= len(history):
44 self.historyList.setCurrentRow(
45 self.historyList.count() - 1, QItemSelectionModel.Select)
46 else:
47 self.historyList.setCurrentRow(index, QItemSelectionModel.Select)
38 self.historyList.scrollToItem(self.historyList.currentItem()) 48 self.historyList.scrollToItem(self.historyList.currentItem())
39
40 self.vm = vm
41 self.shell = shell
42 49
43 @pyqtSlot() 50 @pyqtSlot()
44 def on_historyList_itemSelectionChanged(self): 51 def on_historyList_itemSelectionChanged(self):
45 """ 52 """
46 Private slot to handle a change of the selection. 53 Private slot to handle a change of the selection.
47 """ 54 """
48 selected = len(self.historyList.selectedItems()) > 0 55 selected = len(self.historyList.selectedItems()) > 0
49 self.copyButton.setEnabled(selected and 56 self.copyButton.setEnabled(selected and
50 self.vm.activeWindow() is not None) 57 self.__vm.activeWindow() is not None)
51 self.deleteButton.setEnabled(selected) 58 self.deleteButton.setEnabled(selected)
52 self.executeButton.setEnabled(selected) 59 self.executeButton.setEnabled(selected)
53 60
54 @pyqtSlot(QListWidgetItem) 61 @pyqtSlot(QListWidgetItem)
55 def on_historyList_itemDoubleClicked(self, item): 62 def on_historyList_itemDoubleClicked(self, item):
75 @pyqtSlot() 82 @pyqtSlot()
76 def on_copyButton_clicked(self): 83 def on_copyButton_clicked(self):
77 """ 84 """
78 Private slot to copy the selected entries to the current editor. 85 Private slot to copy the selected entries to the current editor.
79 """ 86 """
80 aw = self.vm.activeWindow() 87 aw = self.__vm.activeWindow()
81 if aw is not None: 88 if aw is not None:
82 lines = [] 89 lines = []
83 for index in range(self.historyList.count()): 90 for index in range(self.historyList.count()):
84 # selectedItems() doesn't seem to preserve the order 91 # selectedItems() doesn't seem to preserve the order
85 itm = self.historyList.item(index) 92 itm = self.historyList.item(index)
100 # selectedItems() doesn't seem to preserve the order 107 # selectedItems() doesn't seem to preserve the order
101 itm = self.historyList.item(index) 108 itm = self.historyList.item(index)
102 if itm.isSelected(): 109 if itm.isSelected():
103 lines.append(itm.text()) 110 lines.append(itm.text())
104 cmds = os.linesep.join(lines) + os.linesep 111 cmds = os.linesep.join(lines) + os.linesep
105 self.shell.executeLines(cmds) 112 self.__shell.executeLines(
113 cmds,
114 historyIndex=self.historyList.currentRow())
106 115
107 # reload the list because shell modified it 116 # reload the list because shell modified it
108 self.on_reloadButton_clicked() 117 self.on_reloadButton_clicked()
109 118
110 @pyqtSlot() 119 @pyqtSlot()
111 def on_reloadButton_clicked(self): 120 def on_reloadButton_clicked(self):
112 """ 121 """
113 Private slot to reload the history. 122 Private slot to reload the history.
114 """ 123 """
115 history = self.shell.getHistory(None) 124 history = self.__shell.getHistory(None)
125 index = self.__shell.getHistoryIndex()
126
116 self.historyList.clear() 127 self.historyList.clear()
117 self.historyList.addItems(history) 128 self.historyList.addItems(history)
118 self.historyList.setCurrentRow( 129 if index < 0 or index >= len(history):
119 self.historyList.count() - 1, QItemSelectionModel.Clear) 130 self.historyList.setCurrentRow(
131 self.historyList.count() - 1, QItemSelectionModel.Select)
132 else:
133 self.historyList.setCurrentRow(index, QItemSelectionModel.Select)
120 self.historyList.scrollToItem(self.historyList.currentItem()) 134 self.historyList.scrollToItem(self.historyList.currentItem())
135
136 self.historyList.setFocus(Qt.OtherFocusReason)
121 137
122 def getHistory(self): 138 def getHistory(self):
123 """ 139 """
124 Public method to retrieve the history from the dialog. 140 Public method to retrieve the history from the dialog.
125 141

eric ide

mercurial