Skip to content

Commit

Permalink
Shortcuts: Highlight entire row in ShortcutsTable
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Jul 24, 2023
1 parent 77ff71b commit 5dba927
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
25 changes: 13 additions & 12 deletions spyder/plugins/shortcuts/widgets/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@
from qtpy.QtWidgets import (QAbstractItemView, QApplication, QDialog,
QGridLayout, QHBoxLayout, QKeySequenceEdit,
QLabel, QLineEdit, QMessageBox, QPushButton,
QSpacerItem, QTableView, QVBoxLayout)
QSpacerItem, QVBoxLayout)

# Local imports
from spyder.api.translations import _
from spyder.config.manager import CONF
from spyder.utils.icon_manager import ima
from spyder.utils.qthelpers import create_toolbutton
from spyder.utils.stringmatching import get_search_regex, get_search_scores
from spyder.widgets.helperwidgets import (VALID_FINDER_CHARS,
CustomSortFilterProxy,
HelperToolButton,
HTMLDelegate)
from spyder.widgets.helperwidgets import (
HelperToolButton, HTMLDelegate, HoverRowsTableView, VALID_FINDER_CHARS)


# Valid shortcut keys
Expand Down Expand Up @@ -653,10 +651,10 @@ def reset(self):
self.endResetModel()


class ShortcutsTable(QTableView):
def __init__(self,
parent=None, text_color=None, text_color_highlight=None):
QTableView.__init__(self, parent)
class ShortcutsTable(HoverRowsTableView):
def __init__(self, parent=None, text_color=None,
text_color_highlight=None):
HoverRowsTableView.__init__(self, parent)
self._parent = parent
self.finder = None
self.shortcut_data = None
Expand All @@ -675,8 +673,7 @@ def __init__(self,
self.setModel(self.proxy_model)

self.hideColumn(SEARCH_SCORE)
self.setItemDelegateForColumn(NAME, HTMLDelegate(self, margin=9))
self.setItemDelegateForColumn(CONTEXT, HTMLDelegate(self, margin=9))
self.setItemDelegate(HTMLDelegate(self, margin=9))
self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setSelectionMode(QAbstractItemView.SingleSelection)
self.setSortingEnabled(True)
Expand All @@ -685,6 +682,10 @@ def __init__(self,

self.verticalHeader().hide()

self.sig_hover_index_changed.connect(
self.itemDelegate().on_hover_index_changed
)

def set_shortcut_data(self, shortcut_data):
"""
Shortcut data comes from the registration of actions on the main
Expand Down Expand Up @@ -783,7 +784,7 @@ def save_shortcuts(self):
def show_editor(self):
"""Create, setup and display the shortcut editor dialog."""
index = self.proxy_model.mapToSource(self.currentIndex())
row, column = index.row(), index.column()
row = index.row()
shortcuts = self.source_model.shortcuts
context = shortcuts[row].context
name = shortcuts[row].name
Expand Down
3 changes: 3 additions & 0 deletions spyder/widgets/helperwidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ def paint(self, painter, option, index):
else options.widget.style())
options.text = ""

# This paints the entire row associated to the delegate when it's
# hovered and the table that holds it informs it what's the current
# row (see HoverRowsTableView for an example).
if index.row() == self._hovered_row:
painter.fillRect(
options.rect, QColor(QStylePalette.COLOR_BACKGROUND_3)
Expand Down

0 comments on commit 5dba927

Please sign in to comment.