HexEdit/HexEditMainWindow.py

changeset 4659
2863d05e83c6
parent 4658
d760763dcc4a
child 4665
30d4972ab403
equal deleted inserted replaced
4658:d760763dcc4a 4659:2863d05e83c6
51 @keyparam project reference to the project object (Project) 51 @keyparam project reference to the project object (Project)
52 """ 52 """
53 super(HexEditMainWindow, self).__init__(parent) 53 super(HexEditMainWindow, self).__init__(parent)
54 self.setObjectName("eric6_hex_editor") 54 self.setObjectName("eric6_hex_editor")
55 55
56 self.__srHistory = {
57 "search": [],
58 # list of recent searches (tuple of format type index and
59 # search term)
60 "replace": [],
61 # list of recent replaces (tuple of format type index and
62 # replace term
63 }
64
56 self.__fromEric = fromEric 65 self.__fromEric = fromEric
57 self.setWindowIcon(UI.PixmapCache.getIcon("hexEditor.png")) 66 self.setWindowIcon(UI.PixmapCache.getIcon("hexEditor.png"))
58 67
59 if not self.__fromEric: 68 if not self.__fromEric:
60 self.setStyle(Preferences.getUI("Style"), 69 self.setStyle(Preferences.getUI("Style"),
61 Preferences.getUI("StyleSheet")) 70 Preferences.getUI("StyleSheet"))
62 71
63 self.__editor = HexEditWidget() 72 self.__editor = HexEditWidget()
64 self.__searchWidget = HexEditSearchReplaceWidget(self.__editor, False) 73 self.__searchWidget = HexEditSearchReplaceWidget(
65 self.__replaceWidget = HexEditSearchReplaceWidget(self.__editor, True) 74 self.__editor, self, False)
75 self.__replaceWidget = HexEditSearchReplaceWidget(
76 self.__editor, self, True)
66 cw = QWidget() 77 cw = QWidget()
67 layout = QVBoxLayout(cw) 78 layout = QVBoxLayout(cw)
68 layout.setContentsMargins(1, 1, 1, 1) 79 layout.setContentsMargins(1, 1, 1, 1)
69 layout.setSpacing(1) 80 layout.setSpacing(1)
70 layout.addWidget(self.__editor) 81 layout.addWidget(self.__editor)
1190 def __search(self): 1201 def __search(self):
1191 """ 1202 """
1192 Private method to handle the search action. 1203 Private method to handle the search action.
1193 """ 1204 """
1194 self.__replaceWidget.hide() 1205 self.__replaceWidget.hide()
1195 self.__searchWidget.show() 1206 if self.__editor.hasSelection():
1207 txt = self.__editor.selectionToHexString()
1208 else:
1209 txt = ""
1210 self.__searchWidget.show(txt)
1196 1211
1197 def __replace(self): 1212 def __replace(self):
1198 """ 1213 """
1199 Private method to handle the replace action. 1214 Private method to handle the replace action.
1200 """ 1215 """
1201 self.__searchWidget.hide() 1216 self.__searchWidget.hide()
1202 self.__replaceWidget.show() 1217 if self.__editor.hasSelection():
1218 txt = self.__editor.selectionToHexString()
1219 else:
1220 txt = ""
1221 self.__replaceWidget.show(txt)
1203 1222
1204 def preferencesChanged(self): 1223 def preferencesChanged(self):
1205 """ 1224 """
1206 Public method to (re-)read the various settings. 1225 Public method to (re-)read the various settings.
1207 """ 1226 """
1250 """ 1269 """
1251 Private slot to handle preferences changes by our local dialog. 1270 Private slot to handle preferences changes by our local dialog.
1252 """ 1271 """
1253 for hexEditor in HexEditMainWindow.windows: 1272 for hexEditor in HexEditMainWindow.windows:
1254 hexEditor.preferencesChanged() 1273 hexEditor.preferencesChanged()
1274
1275 def getSRHistory(self, key):
1276 """
1277 Public method to get the search or replace history list.
1278
1279 @param key name of list to return
1280 @type str (must be 'search' or 'replace')
1281 @return the requested history list
1282 @type list of tuples of (int, str)
1283 """
1284 assert key in ['search', 'replace']
1285
1286 return self.__srHistory[key]

eric ide

mercurial