Merge pull request #1035 from BlueGreenMagick/sidebar-on-click-index

change _on_click_current to _on_click_index
This commit is contained in:
Damien Elmes 2021-02-21 10:36:03 +10:00 committed by GitHub
commit 83c8d53da2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View file

@ -35,7 +35,7 @@ zjosua <zjosua@hotmail.com>
Arthur Milchior <arthur@milchior.fr> Arthur Milchior <arthur@milchior.fr>
Yngve Hoiseth <yngve@hoiseth.net> Yngve Hoiseth <yngve@hoiseth.net>
Ijgnd Ijgnd
Yoonchae Lee Yoonchae Lee <bluegreenmagick@gmail.com>
Evandro Coan <github.com/evandrocoan> Evandro Coan <github.com/evandrocoan>
Alan Du <alanhdu@gmail.com> Alan Du <alanhdu@gmail.com>
Yuchen Lei <lyc@xuming.studio> Yuchen Lei <lyc@xuming.studio>

View file

@ -442,11 +442,13 @@ class SidebarTreeView(QTreeView):
def mouseReleaseEvent(self, event: QMouseEvent) -> None: def mouseReleaseEvent(self, event: QMouseEvent) -> None:
super().mouseReleaseEvent(event) super().mouseReleaseEvent(event)
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
self._on_click_current() idx = self.indexAt(event.pos())
self._on_click_index(idx)
def keyPressEvent(self, event: QKeyEvent) -> None: def keyPressEvent(self, event: QKeyEvent) -> None:
if event.key() in (Qt.Key_Return, Qt.Key_Enter): if event.key() in (Qt.Key_Return, Qt.Key_Enter):
self._on_click_current() idx = self.currentIndex()
self._on_click_index(idx)
else: else:
super().keyPressEvent(event) super().keyPressEvent(event)
@ -516,8 +518,7 @@ class SidebarTreeView(QTreeView):
self.browser.editor.saveNow(on_save) self.browser.editor.saveNow(on_save)
return True return True
def _on_click_current(self) -> None: def _on_click_index(self, idx: QModelIndex) -> None:
idx = self.currentIndex()
if item := self.model().item_for_index(idx): if item := self.model().item_for_index(idx):
if item.on_click: if item.on_click:
item.on_click() item.on_click()