QScintilla/ShellHistoryDialog.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2008 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the shell history dialog.
8 """
9
10 import os
11
12 from PyQt4.QtCore import *
13 from PyQt4.QtGui import *
14
15 from Ui_ShellHistoryDialog import Ui_ShellHistoryDialog
16
17 class ShellHistoryDialog(QDialog, Ui_ShellHistoryDialog):
18 """
19 Class implementing the shell history dialog.
20 """
21 def __init__(self, history, vm, shell):
22 """
23 Constructor
24
25 @param history reference to the current shell history (list of strings)
26 @param vm reference to the viewmanager object
27 @param shell reference to the shell object
28 """
29 QDialog.__init__(self, shell)
30 self.setupUi(self)
31
32 self.historyList.addItems(history)
33 self.historyList.setCurrentRow(self.historyList.count() - 1,
34 QItemSelectionModel.Clear)
35 self.historyList.scrollToItem(self.historyList.currentItem())
36
37 self.vm = vm
38 self.shell = shell
39
40 @pyqtSlot()
41 def on_historyList_itemSelectionChanged(self):
42 """
43 Private slot to handle a change of the selection.
44 """
45 selected = len(self.historyList.selectedItems()) > 0
46 self.copyButton.setEnabled(selected and \
47 self.vm.activeWindow() is not None)
48 self.deleteButton.setEnabled(selected)
49 self.executeButton.setEnabled(selected)
50
51 @pyqtSlot(QListWidgetItem)
52 def on_historyList_itemDoubleClicked(self, item):
53 """
54 Private slot to handle a double click of an item.
55
56 @param item reference to the item that was double clicked (QListWidgetItem)
57 """
58 self.on_executeButton_clicked()
59
60 @pyqtSlot()
61 def on_deleteButton_clicked(self):
62 """
63 Private slot to delete the selected entries from the history.
64 """
65 for itm in self.historyList.selectedItems():
66 ditm = self.historyList.takeItem(self.historyList.row(itm))
67 del ditm
68 self.historyList.scrollToItem(self.historyList.currentItem())
69 self.historyList.setFocus()
70
71 @pyqtSlot()
72 def on_copyButton_clicked(self):
73 """
74 Private slot to copy the selected entries to the current editor.
75 """
76 aw = self.vm.activeWindow()
77 if aw is not None:
78 lines = []
79 for index in range(self.historyList.count()):
80 # selectedItems() doesn't seem to preserve the order
81 itm = self.historyList.item(index)
82 if itm.isSelected():
83 lines.append(itm.text())
84 eol = aw.getLineSeparator()
85 txt = eol.join(lines) + eol
86 aw.insert(txt)
87 self.historyList.setFocus()
88
89 @pyqtSlot()
90 def on_executeButton_clicked(self):
91 """
92 Private slot to execute the selected entries in the shell.
93 """
94 lines = []
95 for index in range(self.historyList.count()):
96 # selectedItems() doesn't seem to preserve the order
97 itm = self.historyList.item(index)
98 if itm.isSelected():
99 lines.append(itm.text())
100 cmds = os.linesep.join(lines) + os.linesep
101 self.shell.executeLines(cmds)
102
103 # reload the list because shell modified it
104 self.on_reloadButton_clicked()
105
106 @pyqtSlot()
107 def on_reloadButton_clicked(self):
108 """
109 Private slot to reload the history.
110 """
111 history = self.shell.getHistory(None)
112 self.historyList.clear()
113 self.historyList.addItems(history)
114 self.historyList.setCurrentRow(self.historyList.count() - 1,
115 QItemSelectionModel.Clear)
116 self.historyList.scrollToItem(self.historyList.currentItem())
117
118 def getHistory(self):
119 """
120 Public method to retrieve the history from the dialog.
121
122 @return list of history entries (list of strings)
123 """
124 history = []
125 for index in range(self.historyList.count()):
126 history.append(self.historyList.item(index).text())
127 return history

eric ide

mercurial