17 |
17 |
18 class ShellHistoryDialog(QDialog, Ui_ShellHistoryDialog): |
18 class ShellHistoryDialog(QDialog, Ui_ShellHistoryDialog): |
19 """ |
19 """ |
20 Class implementing the shell history dialog. |
20 Class implementing the shell history dialog. |
21 """ |
21 """ |
|
22 |
22 def __init__(self, history, vm, shell): |
23 def __init__(self, history, vm, shell): |
23 """ |
24 """ |
24 Constructor |
25 Constructor |
25 |
26 |
26 @param history reference to the current shell history |
27 @param history reference to the current shell history |
27 @type list of str |
28 @type list of str |
28 @param vm reference to the viewmanager object |
29 @param vm reference to the viewmanager object |
29 @type ViewManager |
30 @type ViewManager |
30 @param shell reference to the shell object |
31 @param shell reference to the shell object |
31 @type Shell |
32 @type Shell |
32 """ |
33 """ |
33 super().__init__(shell) |
34 super().__init__(shell) |
34 self.setupUi(self) |
35 self.setupUi(self) |
35 |
36 |
36 self.__vm = vm |
37 self.__vm = vm |
37 self.__shell = shell |
38 self.__shell = shell |
38 |
39 |
39 self.historyList.addItems(history) |
40 self.historyList.addItems(history) |
40 index = shell.getHistoryIndex() |
41 index = shell.getHistoryIndex() |
41 if index < 0 or index >= len(history): |
42 if index < 0 or index >= len(history): |
42 self.historyList.setCurrentRow( |
43 self.historyList.setCurrentRow( |
43 self.historyList.count() - 1, |
44 self.historyList.count() - 1, QItemSelectionModel.SelectionFlag.Select |
44 QItemSelectionModel.SelectionFlag.Select) |
45 ) |
45 else: |
46 else: |
46 self.historyList.setCurrentRow( |
47 self.historyList.setCurrentRow( |
47 index, QItemSelectionModel.SelectionFlag.Select) |
48 index, QItemSelectionModel.SelectionFlag.Select |
|
49 ) |
48 self.historyList.scrollToItem(self.historyList.currentItem()) |
50 self.historyList.scrollToItem(self.historyList.currentItem()) |
49 |
51 |
50 @pyqtSlot() |
52 @pyqtSlot() |
51 def on_historyList_itemSelectionChanged(self): |
53 def on_historyList_itemSelectionChanged(self): |
52 """ |
54 """ |
53 Private slot to handle a change of the selection. |
55 Private slot to handle a change of the selection. |
54 """ |
56 """ |
55 selected = len(self.historyList.selectedItems()) > 0 |
57 selected = len(self.historyList.selectedItems()) > 0 |
56 self.copyButton.setEnabled(selected and |
58 self.copyButton.setEnabled(selected and self.__vm.activeWindow() is not None) |
57 self.__vm.activeWindow() is not None) |
|
58 self.deleteButton.setEnabled(selected) |
59 self.deleteButton.setEnabled(selected) |
59 self.executeButton.setEnabled(selected) |
60 self.executeButton.setEnabled(selected) |
60 |
61 |
61 @pyqtSlot(QListWidgetItem) |
62 @pyqtSlot(QListWidgetItem) |
62 def on_historyList_itemDoubleClicked(self, item): |
63 def on_historyList_itemDoubleClicked(self, item): |
63 """ |
64 """ |
64 Private slot to handle a double click of an item. |
65 Private slot to handle a double click of an item. |
65 |
66 |
66 @param item reference to the item that was double clicked |
67 @param item reference to the item that was double clicked |
67 (QListWidgetItem) |
68 (QListWidgetItem) |
68 """ |
69 """ |
69 self.on_executeButton_clicked() |
70 self.on_executeButton_clicked() |
70 |
71 |
71 @pyqtSlot() |
72 @pyqtSlot() |
72 def on_deleteButton_clicked(self): |
73 def on_deleteButton_clicked(self): |
73 """ |
74 """ |
74 Private slot to delete the selected entries from the history. |
75 Private slot to delete the selected entries from the history. |
75 """ |
76 """ |
76 for itm in self.historyList.selectedItems(): |
77 for itm in self.historyList.selectedItems(): |
77 ditm = self.historyList.takeItem(self.historyList.row(itm)) |
78 ditm = self.historyList.takeItem(self.historyList.row(itm)) |
78 del ditm |
79 del ditm |
79 self.historyList.scrollToItem(self.historyList.currentItem()) |
80 self.historyList.scrollToItem(self.historyList.currentItem()) |
80 self.historyList.setFocus() |
81 self.historyList.setFocus() |
81 |
82 |
82 @pyqtSlot() |
83 @pyqtSlot() |
83 def on_copyButton_clicked(self): |
84 def on_copyButton_clicked(self): |
84 """ |
85 """ |
85 Private slot to copy the selected entries to the current editor. |
86 Private slot to copy the selected entries to the current editor. |
86 """ |
87 """ |
107 # selectedItems() doesn't seem to preserve the order |
108 # selectedItems() doesn't seem to preserve the order |
108 itm = self.historyList.item(index) |
109 itm = self.historyList.item(index) |
109 if itm.isSelected(): |
110 if itm.isSelected(): |
110 lines.append(itm.text()) |
111 lines.append(itm.text()) |
111 cmds = os.linesep.join(lines) + os.linesep |
112 cmds = os.linesep.join(lines) + os.linesep |
112 self.__shell.executeLines( |
113 self.__shell.executeLines(cmds, historyIndex=self.historyList.currentRow()) |
113 cmds, |
114 |
114 historyIndex=self.historyList.currentRow()) |
|
115 |
|
116 # reload the list because shell modified it |
115 # reload the list because shell modified it |
117 self.on_reloadButton_clicked() |
116 self.on_reloadButton_clicked() |
118 |
117 |
119 @pyqtSlot() |
118 @pyqtSlot() |
120 def on_reloadButton_clicked(self): |
119 def on_reloadButton_clicked(self): |
121 """ |
120 """ |
122 Private slot to reload the history. |
121 Private slot to reload the history. |
123 """ |
122 """ |
124 history = self.__shell.getHistory(None) |
123 history = self.__shell.getHistory(None) |
125 index = self.__shell.getHistoryIndex() |
124 index = self.__shell.getHistoryIndex() |
126 |
125 |
127 self.historyList.clear() |
126 self.historyList.clear() |
128 self.historyList.addItems(history) |
127 self.historyList.addItems(history) |
129 if index < 0 or index >= len(history): |
128 if index < 0 or index >= len(history): |
130 self.historyList.setCurrentRow( |
129 self.historyList.setCurrentRow( |
131 self.historyList.count() - 1, |
130 self.historyList.count() - 1, QItemSelectionModel.SelectionFlag.Select |
132 QItemSelectionModel.SelectionFlag.Select) |
131 ) |
133 else: |
132 else: |
134 self.historyList.setCurrentRow( |
133 self.historyList.setCurrentRow( |
135 index, QItemSelectionModel.SelectionFlag.Select) |
134 index, QItemSelectionModel.SelectionFlag.Select |
|
135 ) |
136 self.historyList.scrollToItem(self.historyList.currentItem()) |
136 self.historyList.scrollToItem(self.historyList.currentItem()) |
137 |
137 |
138 self.historyList.setFocus(Qt.FocusReason.OtherFocusReason) |
138 self.historyList.setFocus(Qt.FocusReason.OtherFocusReason) |
139 |
139 |
140 def getHistory(self): |
140 def getHistory(self): |
141 """ |
141 """ |
142 Public method to retrieve the history from the dialog. |
142 Public method to retrieve the history from the dialog. |
143 |
143 |
144 @return tuple containing the list of history entries and the |
144 @return tuple containing the list of history entries and the |
145 current row |
145 current row |
146 @rtype tuple of (list of str, int) |
146 @rtype tuple of (list of str, int) |
147 """ |
147 """ |
148 history = [] |
148 history = [] |