| 290 | |
| 291 | |
| 292 | class ImportsTreeView(QTreeView, FilterTarget): |
| 293 | def __init__(self, parent, view, data): |
| 294 | QTreeView.__init__(self, parent) |
| 295 | FilterTarget.__init__(self) |
| 296 | self.data = data |
| 297 | self.parent = parent |
| 298 | self.view = view |
| 299 | |
| 300 | # Allow view-specific shortcuts when imports are focused |
| 301 | self.actionHandler = UIActionHandler() |
| 302 | self.actionHandler.setupActionHandler(self) |
| 303 | self.actionHandler.setActionContext(lambda: self.view.actionContext()) |
| 304 | |
| 305 | self.model = GenericImportsModel(self.data) |
| 306 | self.setModel(self.model) |
| 307 | self.setRootIsDecorated(False) |
| 308 | self.setUniformRowHeights(True) |
| 309 | self.setSortingEnabled(True) |
| 310 | self.sortByColumn(0, Qt.AscendingOrder) |
| 311 | if self.model.ordinal_col is not None: |
| 312 | self.setColumnWidth(self.model.ordinal_col, 55) |
| 313 | |
| 314 | self.setFont(binaryninjaui.getMonospaceFont(self)) |
| 315 | |
| 316 | self.selectionModel().currentChanged.connect(self.importSelected) |
| 317 | self.doubleClicked.connect(self.importDoubleClicked) |
| 318 | |
| 319 | def importSelected(self, cur, prev): |
| 320 | sym = self.model.getSymbol(cur) |
| 321 | if sym is not None: |
| 322 | self.view.setCurrentOffset(sym.address) |
| 323 | |
| 324 | def importDoubleClicked(self, cur): |
| 325 | sym = self.model.getSymbol(cur) |
| 326 | if sym is not None: |
| 327 | viewFrame = ViewFrame.viewFrameForWidget(self) |
| 328 | viewFrame.navigate("Linear:" + viewFrame.getCurrentDataType(), sym.address) |
| 329 | |
| 330 | def setFilter(self, filterText): |
| 331 | self.model.setFilter(filterText) |
| 332 | |
| 333 | def scrollToFirstItem(self): |
| 334 | self.scrollToTop() |
| 335 | |
| 336 | def scrollToCurrentItem(self): |
| 337 | self.scrollTo(self.currentIndex()) |
| 338 | |
| 339 | def selectFirstItem(self): |
| 340 | self.setCurrentIndex(self.model.index(0, 0, QModelIndex())) |
| 341 | |
| 342 | def activateFirstItem(self): |
| 343 | self.importDoubleClicked(self.model.index(0, 0, QModelIndex())) |
| 344 | |
| 345 | def closeFilter(self): |
| 346 | self.setFocus(Qt.OtherFocusReason) |
| 347 | |
| 348 | def keyPressEvent(self, event): |
| 349 | if (len(event.text()) == 1) and (ord(event.text()[0:1]) > 32) and (ord(event.text()[0:1]) < 127): |