From ade58079a0a3e6b9d1a0793ab4c084d0f9431f4d Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Fri, 24 Oct 2025 08:21:26 -0700 Subject: Update FilterEdit and FilterTarget to preserve existing selections The down and enter keys now preserve an existing selection in the associated list or table views, rather than unconditionally selecting or activating the first item. --- python/examples/triage/exports.py | 13 ++++++++----- python/examples/triage/imports.py | 13 ++++++++----- python/examples/typelibexplorer.py | 30 ++++++++++++++++-------------- 3 files changed, 32 insertions(+), 24 deletions(-) (limited to 'python') diff --git a/python/examples/triage/exports.py b/python/examples/triage/exports.py index 730b37df..fb831401 100644 --- a/python/examples/triage/exports.py +++ b/python/examples/triage/exports.py @@ -154,11 +154,14 @@ class ExportsTreeView(QTreeView, FilterTarget): def scrollToCurrentItem(self): self.scrollTo(self.currentIndex()) - def selectFirstItem(self): - self.setCurrentIndex(self.model.index(0, 0, QModelIndex())) - - def activateFirstItem(self): - self.exportDoubleClicked(self.model.index(0, 0, QModelIndex())) + def ensureSelection(self): + if not self.currentIndex().isValid(): + self.setCurrentIndex(self.model.index(0, 0, QModelIndex())) + + def activateSelection(self): + self.ensureSelection() + if self.currentIndex().isValid(): + self.exportDoubleClicked(self.currentIndex()) def closeFilter(self): self.setFocus(Qt.OtherFocusReason) diff --git a/python/examples/triage/imports.py b/python/examples/triage/imports.py index dbe8ed47..b4163cbe 100644 --- a/python/examples/triage/imports.py +++ b/python/examples/triage/imports.py @@ -336,11 +336,14 @@ class ImportsTreeView(QTreeView, FilterTarget): def scrollToCurrentItem(self): self.scrollTo(self.currentIndex()) - def selectFirstItem(self): - self.setCurrentIndex(self.model.index(0, 0, QModelIndex())) - - def activateFirstItem(self): - self.importDoubleClicked(self.model.index(0, 0, QModelIndex())) + def ensureSelection(self): + if not self.currentIndex().isValid(): + self.setCurrentIndex(self.model.index(0, 0, QModelIndex())) + + def activateSelection(self): + self.ensureSelection() + if self.currentIndex().isValid(): + self.importDoubleClicked(self.currentIndex()) def closeFilter(self): self.setFocus(Qt.OtherFocusReason) diff --git a/python/examples/typelibexplorer.py b/python/examples/typelibexplorer.py index f8e889e4..a963c039 100644 --- a/python/examples/typelibexplorer.py +++ b/python/examples/typelibexplorer.py @@ -51,11 +51,12 @@ class TypelibTypeTableWidget(QTableWidget, FilterTarget): def scrollToCurrentItem(self): self.scrollTo(self.currentIndex()) - def selectFirstItem(self): - self.setCurrentIndex(self.model().index(0, 0, QModelIndex())) + def ensureSelection(self): + if not self.currentIndex().isValid(): + self.setCurrentIndex(self.model().index(0, 0, QModelIndex())) - def activateFirstItem(self): - self.setCurrentIndex(self.model().index(0, 0, QModelIndex())) + def activateSelection(self): + self.ensureSelection() def closeFilter(self): self.setFocus(Qt.OtherFocusReason) @@ -109,11 +110,12 @@ class TypelibObjectTableWidget(QTableWidget, FilterTarget): def scrollToCurrentItem(self): self.scrollTo(self.currentIndex()) - def selectFirstItem(self): - self.setCurrentIndex(self.model().index(0, 0, QModelIndex())) + def ensureSelection(self): + if not self.currentIndex().isValid(): + self.setCurrentIndex(self.model().index(0, 0, QModelIndex())) - def activateFirstItem(self): - self.setCurrentIndex(self.model().index(0, 0, QModelIndex())) + def activateSelection(self): + self.ensureSelection() def closeFilter(self): self.setFocus(Qt.OtherFocusReason) @@ -335,17 +337,17 @@ class TypelibExplorerWidget(SidebarWidget, FilterTarget): else: self.type_table.scrollToCurrentItem() - def selectFirstItem(self): + def ensureSelection(self): if self.horizontal_tabs.currentIndex() == 0: - self.object_table.selectFirstItem() + self.object_table.ensureSelection() else: - self.type_table.selectFirstItem() + self.type_table.ensureSelection() - def activateFirstItem(self): + def activateSelection(self): if self.horizontal_tabs.currentIndex() == 0: - self.object_table.activateFirstItem() + self.object_table.activateSelection() else: - self.type_table.activateFirstItem() + self.type_table.activateSelection() def closeFilter(self): if self.horizontal_tabs.currentIndex() == 0: -- cgit v1.3.1