Skip to content

fix(ui): (mostly) fix right-click search option on tags #756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions tagstudio/src/qt/modals/tag_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio


import typing

import src.qt.modals.build_tag as build_tag
import structlog
from PySide6.QtCore import QSize, Qt, Signal
Expand Down Expand Up @@ -32,6 +34,10 @@

logger = structlog.get_logger(__name__)

# Only import for type checking/autocompletion, will not be imported at runtime.
if typing.TYPE_CHECKING:
from src.qt.modals.build_tag import BuildTagPanel


class TagSearchPanel(PanelWidget):
tag_chosen = Signal(int)
Expand All @@ -41,7 +47,12 @@ class TagSearchPanel(PanelWidget):
is_tag_chooser: bool
exclude: list[int]

def __init__(self, library: Library, exclude: list[int] = None, is_tag_chooser: bool = True):
def __init__(
self,
library: Library,
exclude: list[int] = None,
is_tag_chooser: bool = True,
):
super().__init__()
self.lib = library
self.exclude = exclude or []
Expand Down Expand Up @@ -93,6 +104,17 @@ def __build_row_item_widget(self, tag: Tag):

tag_widget.on_edit.connect(lambda t=tag: self.edit_tag(t))
tag_widget.on_remove.connect(lambda t=tag: self.remove_tag(t))

# NOTE: A solution to this would be to pass the driver to TagSearchPanel, however that
# creates an exponential amount of work trying to fix the preexisting tests.

# tag_widget.search_for_tag_action.triggered.connect(
# lambda checked=False, tag_id=tag.id: (
# self.driver.main_window.searchField.setText(f"tag_id:{tag_id}"),
# self.driver.filter_items(FilterState.from_tag_id(tag_id)),
# )
# )

row.addWidget(tag_widget)

primary_color = get_primary_color(tag)
Expand Down Expand Up @@ -196,7 +218,7 @@ def on_tag_modal_saved():
self.search_field.setText("")
self.update_tags()

self.build_tag_modal: build_tag.BuildTagPanel = build_tag.BuildTagPanel(self.lib)
self.build_tag_modal: BuildTagPanel = build_tag.BuildTagPanel(self.lib)
self.add_tag_modal: PanelModal = PanelModal(self.build_tag_modal, has_save=True)
Translations.translate_with_setter(self.add_tag_modal.setTitle, "tag.new")
Translations.translate_with_setter(self.add_tag_modal.setWindowTitle, "tag.add")
Expand Down
7 changes: 3 additions & 4 deletions tagstudio/src/qt/widgets/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ def __init__(

# TODO: This currently doesn't work in "Add Tag" menus. Either fix this or
# disable it in that context.
search_for_tag_action = QAction(self)
search_for_tag_action.setText(Translations.translate_formatted("tag.search_for_tag"))
search_for_tag_action.triggered.connect(self.on_click.emit)
self.bg_button.addAction(search_for_tag_action)
self.search_for_tag_action = QAction(self)
self.search_for_tag_action.setText(Translations.translate_formatted("tag.search_for_tag"))
self.bg_button.addAction(self.search_for_tag_action)
# add_to_search_action = QAction(self)
# add_to_search_action.setText(Translations.translate_formatted("tag.add_to_search"))
# self.bg_button.addAction(add_to_search_action)
Expand Down
9 changes: 9 additions & 0 deletions tagstudio/src/qt/widgets/tag_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import structlog
from PySide6.QtCore import Signal
from src.core.library import Tag
from src.core.library.alchemy.enums import FilterState
from src.qt.flowlayout import FlowLayout
from src.qt.modals.build_tag import BuildTagPanel
from src.qt.widgets.fields import FieldWidget
Expand Down Expand Up @@ -61,6 +62,14 @@ def set_tags(self, tags: typing.Iterable[Tag]):
)
)
tag_widget.on_edit.connect(lambda t=tag: self.edit_tag(t))

tag_widget.search_for_tag_action.triggered.connect(
lambda checked=False, tag_id=tag.id: (
self.driver.main_window.searchField.setText(f"tag_id:{tag_id}"),
self.driver.filter_items(FilterState.from_tag_id(tag_id)),
)
)

self.base_layout.addWidget(tag_widget)

def edit_tag(self, tag: Tag):
Expand Down