QScintilla/ShellHistoryDialog.py

changeset 5799
e87f52c0374a
parent 5798
e4f9552f7f93
child 6048
82ad8ec9548c
--- a/QScintilla/ShellHistoryDialog.py	Sun Jul 09 19:44:33 2017 +0200
+++ b/QScintilla/ShellHistoryDialog.py	Mon Jul 10 18:24:35 2017 +0200
@@ -11,7 +11,7 @@
 
 import os
 
-from PyQt5.QtCore import pyqtSlot, QItemSelectionModel
+from PyQt5.QtCore import pyqtSlot, Qt, QItemSelectionModel
 from PyQt5.QtWidgets import QListWidgetItem, QDialog
 
 from .Ui_ShellHistoryDialog import Ui_ShellHistoryDialog
@@ -25,20 +25,27 @@
         """
         Constructor
         
-        @param history reference to the current shell history (list of strings)
+        @param history reference to the current shell history
+        @type list of str
         @param vm reference to the viewmanager object
+        @type ViewManager
         @param shell reference to the shell object
+        @type Shell
         """
         super(ShellHistoryDialog, self).__init__(shell)
         self.setupUi(self)
         
+        self.__vm = vm
+        self.__shell = shell
+        
         self.historyList.addItems(history)
-        self.historyList.setCurrentRow(
-            self.historyList.count() - 1, QItemSelectionModel.Clear)
+        index = shell.getHistoryIndex()
+        if index < 0 or index >= len(history):
+            self.historyList.setCurrentRow(
+                self.historyList.count() - 1, QItemSelectionModel.Select)
+        else:
+            self.historyList.setCurrentRow(index, QItemSelectionModel.Select)
         self.historyList.scrollToItem(self.historyList.currentItem())
-        
-        self.vm = vm
-        self.shell = shell
     
     @pyqtSlot()
     def on_historyList_itemSelectionChanged(self):
@@ -47,7 +54,7 @@
         """
         selected = len(self.historyList.selectedItems()) > 0
         self.copyButton.setEnabled(selected and
-                                   self.vm.activeWindow() is not None)
+                                   self.__vm.activeWindow() is not None)
         self.deleteButton.setEnabled(selected)
         self.executeButton.setEnabled(selected)
     
@@ -77,7 +84,7 @@
         """
         Private slot to copy the selected entries to the current editor.
         """
-        aw = self.vm.activeWindow()
+        aw = self.__vm.activeWindow()
         if aw is not None:
             lines = []
             for index in range(self.historyList.count()):
@@ -102,7 +109,9 @@
             if itm.isSelected():
                 lines.append(itm.text())
         cmds = os.linesep.join(lines) + os.linesep
-        self.shell.executeLines(cmds)
+        self.__shell.executeLines(
+            cmds,
+            historyIndex=self.historyList.currentRow())
         
         # reload the list because shell modified it
         self.on_reloadButton_clicked()
@@ -112,13 +121,20 @@
         """
         Private slot to reload the history.
         """
-        history = self.shell.getHistory(None)
+        history = self.__shell.getHistory(None)
+        index = self.__shell.getHistoryIndex()
+        
         self.historyList.clear()
         self.historyList.addItems(history)
-        self.historyList.setCurrentRow(
-            self.historyList.count() - 1, QItemSelectionModel.Clear)
+        if index < 0 or index >= len(history):
+            self.historyList.setCurrentRow(
+                self.historyList.count() - 1, QItemSelectionModel.Select)
+        else:
+            self.historyList.setCurrentRow(index, QItemSelectionModel.Select)
         self.historyList.scrollToItem(self.historyList.currentItem())
         
+        self.historyList.setFocus(Qt.OtherFocusReason)
+        
     def getHistory(self):
         """
         Public method to retrieve the history from the dialog.

eric ide

mercurial