Skip to content

feat: click tags in tag library to edit #987

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions src/tagstudio/qt/modals/tag_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
class TagSearchPanel(PanelWidget):
tag_chosen = Signal(int)
lib: Library
driver: "QtDriver"
driver: "QtDriver | None" = None
is_initialized: bool = False
first_tag_id: int | None = None
is_tag_chooser: bool
Expand All @@ -56,12 +56,11 @@ class TagSearchPanel(PanelWidget):
def __init__(
self,
library: Library,
exclude: list[int] = None,
exclude: list[int] | None = None,
is_tag_chooser: bool = True,
):
super().__init__()
self.lib = library
self.driver = None
self.exclude = exclude or []

self.is_tag_chooser = is_tag_chooser
Expand Down Expand Up @@ -194,7 +193,8 @@ def update_tags(self, query: str | None = None):
create_button: QPushButton | None = None
if self.create_button_in_layout and self.scroll_layout.count():
create_button = self.scroll_layout.takeAt(self.scroll_layout.count() - 1).widget() # type: ignore
create_button.deleteLater()
if create_button:
create_button.deleteLater()
self.create_button_in_layout = False

# Get results for the search query
Expand Down Expand Up @@ -264,7 +264,7 @@ def set_tag_widget(self, tag: Tag | None, index: int):
self.scroll_layout.addWidget(new_tw)

# Assign the tag to the widget at the given index.
tag_widget: TagWidget = self.scroll_layout.itemAt(index).widget()
assert isinstance(tag_widget := self.scroll_layout.itemAt(index).widget(), TagWidget)
tag_widget.set_tag(tag)

# Set tag widget viability and potentially return early
Expand All @@ -279,21 +279,22 @@ def set_tag_widget(self, tag: Tag | None, index: int):
tag_widget.has_remove = has_remove_button

with catch_warnings(record=True):
tag_widget.on_click.disconnect()
tag_widget.on_edit.disconnect()
tag_widget.on_remove.disconnect()
tag_widget.bg_button.clicked.disconnect()

tag_id = tag.id
tag_widget.on_click.connect(lambda t=tag: self.edit_tag(t))
tag_widget.on_edit.connect(lambda t=tag: self.edit_tag(t))
tag_widget.on_remove.connect(lambda t=tag: self.delete_tag(t))
tag_widget.bg_button.clicked.connect(lambda: self.tag_chosen.emit(tag_id))

if self.driver:
tag_widget.search_for_tag_action.triggered.connect(
lambda checked=False, tag_id=tag.id: (
self.driver.main_window.search_field.setText(f"tag_id:{tag_id}"),
self.driver.update_browsing_state(BrowsingState.from_tag_id(tag_id)),
)
if self.driver
else None
)
tag_widget.search_for_tag_action.setEnabled(True)
else:
Expand Down