eric7/Debugger/StartHistoryEditDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to edit a list of history entries.
8 """
9
10 from PyQt5.QtCore import pyqtSlot, Qt
11 from PyQt5.QtWidgets import QDialog, QInputDialog, QLineEdit
12
13 from E5Gui import E5MessageBox
14
15 from .Ui_StartHistoryEditDialog import Ui_StartHistoryEditDialog
16
17
18 class StartHistoryEditDialog(QDialog, Ui_StartHistoryEditDialog):
19 """
20 Class implementing a dialog to edit a list of history entries.
21 """
22 def __init__(self, history, parent=None):
23 """
24 Constructor
25
26 @param history list of history entries to be edited
27 @type list of str
28 @param parent reference to the parent widget
29 @type QWidget
30 """
31 super().__init__(parent)
32 self.setupUi(self)
33
34 self.historyList.addItems(history)
35 for row in range(self.historyList.count()):
36 itm = self.historyList.item(row)
37 flags = itm.flags() | Qt.ItemFlag.ItemIsEditable
38 itm.setFlags(flags)
39
40 self.__updateEditButtons()
41
42 def __updateEditButtons(self):
43 """
44 Private method to set the state of the edit buttons.
45 """
46 selectedCount = len(self.historyList.selectedItems())
47 self.editButton.setEnabled(selectedCount == 1)
48 self.deleteButton.setEnabled(selectedCount > 0)
49 self.deleteAllButton.setEnabled(self.historyList.count() > 0)
50
51 @pyqtSlot()
52 def on_historyList_itemSelectionChanged(self):
53 """
54 Private slot to handle the selection of entries.
55 """
56 self.__updateEditButtons()
57
58 @pyqtSlot()
59 def on_editButton_clicked(self):
60 """
61 Private slot to edit the selected entry.
62 """
63 itm = self.historyList.selectedItems()[0]
64 historyText, ok = QInputDialog.getText(
65 self,
66 self.tr("Edit History Entry"),
67 self.tr("Enter the new text:"),
68 QLineEdit.EchoMode.Normal,
69 itm.text())
70 if ok:
71 itm.setText(historyText)
72
73 @pyqtSlot()
74 def on_deleteButton_clicked(self):
75 """
76 Private slot to delete the selected entries.
77 """
78 yes = E5MessageBox.yesNo(
79 self,
80 self.tr("Delete Selected Entries"),
81 self.tr("""Do you really want to delete the selected"""
82 """ history entries?"""))
83 if yes:
84 for itm in self.historyList.selectedItems():
85 row = self.historyList.row(itm)
86 self.historyList.takeItem(row)
87 del itm
88
89 @pyqtSlot()
90 def on_deleteAllButton_clicked(self):
91 """
92 Private slot to delete all entries.
93 """
94 yes = E5MessageBox.yesNo(
95 self,
96 self.tr("Delete All Entries"),
97 self.tr("""Do you really want to delete the shown history?"""))
98 if yes:
99 self.historyList.clear()
100
101 def getHistory(self):
102 """
103 Public method to get the new list of history entries.
104
105 @return list of history entries
106 @rtype list of str
107 """
108 history = []
109 for row in range(self.historyList.count()):
110 entry = self.historyList.item(row).text()
111 history.append(entry)
112
113 return history

eric ide

mercurial