Skip to content

Commit

Permalink
Widgets: Show select row button icon for selected rows in Collections…
Browse files Browse the repository at this point in the history
…Editor
  • Loading branch information
ccordoba12 committed Jan 3, 2025
1 parent 367b985 commit 419b9a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions spyder/plugins/variableexplorer/widgets/collectionsdelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,11 @@ def paint(self, painter, option, index):
if (
# Do this only for the last column
index.column() == 3
# Do this when the row is hovered.
and index.row() == self.parent().hovered_row
# Do this when the row is hovered or if it's selected
and (
index.row() == self.parent().hovered_row
or index.row() in self.parent().selected_rows()
)
):
# Paint regular contents
super().paint(painter, option, index)
Expand Down Expand Up @@ -553,8 +556,14 @@ def editorEvent(self, event, model, option, index):

# Select/deselect row when clicking on the button
if click_x > x and (y < click_y < (y + SELECT_ROW_BUTTON_SIZE)):
current_selected_rows = self.parent().selected_rows()

# Clear cache of selected rows because either a selection or
# deselection is going to change it.
self.parent().selected_rows.cache_clear()

row = index.row()
if row in self.parent().selected_rows():
if row in current_selected_rows:
# Deselect row if selected
index_left = index.sibling(row, 0)
index_right = index.sibling(row, 3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# -----------------------------------------------------------------------------

# Standard library imports
from functools import lru_cache
import logging
from typing import Any, Callable, Optional

Expand Down Expand Up @@ -190,6 +191,7 @@ def resize_columns_to_contents(self):
"""Resize all the columns to its contents."""
self._horizontal_header().resizeSections(QHeaderView.ResizeToContents)

@lru_cache(maxsize=1)
def selected_rows(self):
"""Dummy method to be compatible with BaseTableView."""
return set()
Expand Down
2 changes: 2 additions & 0 deletions spyder/widgets/collectionseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# Standard library imports
import datetime
from functools import lru_cache
import io
import re
import sys
Expand Down Expand Up @@ -1504,6 +1505,7 @@ def paste(self):
QMessageBox.warning(self, _( "Empty clipboard"),
_("Nothing to be imported from clipboard."))

@lru_cache(maxsize=1)
def selected_rows(self):
"""Get the rows currently selected."""
return {
Expand Down

0 comments on commit 419b9a5

Please sign in to comment.