Skip to content
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

Add "Delete Tag" menu option to tags in the Tag Database and tag box #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Darxoon
Copy link

@Darxoon Darxoon commented Apr 30, 2024

I added this menu option to the tag database and tag boxes. It will prompt the user and if they say yes, delete the tags and remove all references to it

grafik

One thing I added is that when you hold shift while clicking Delete Tag, the prompt and popup after it was deleted will be skipped. I figured this would be useful when deleting a lot of tags at the same time.

Copy link
Collaborator

@Loran425 Loran425 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall but there are some guardrails for system tags that I think should be implemented to prevent errors.

Also Highlights some other refactoring that should probably happen in the tag_database.py file and further supports the use use of a constants file recommended in #88

@@ -92,8 +92,9 @@ def update_tags(self, query:str):
l = QHBoxLayout(c)
l.setContentsMargins(0,0,0,0)
l.setSpacing(3)
tw = TagWidget(self.lib, self.lib.get_tag(tag_id), True, False)
tw = TagWidget(self.lib, self.lib.get_tag(tag_id), True, False, True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably remove the ability to delete "System Tags" (archived & favorite) since TagStudio recreates those tags on system shutdown if they are missing.

Suggested change
tw = TagWidget(self.lib, self.lib.get_tag(tag_id), True, False, True)
if tag_id in [0, 1]: # [0, 1] should probably be extracted as a constant during refactor
tag_deletable = False
else:
tag_deletable = True
tw = TagWidget(self.lib, self.lib.get_tag(tag_id), True, False, tag_deletable )

@@ -106,8 +107,9 @@ def update_tags(self, query:str):
l = QHBoxLayout(c)
l.setContentsMargins(0,0,0,0)
l.setSpacing(3)
tw = TagWidget(self.lib, tag, True, False)
tw = TagWidget(self.lib, tag, True, False, True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably remove the ability to delete "System Tags" (archived & favorite) since TagStudio recreates those tags on system shutdown if they are missing.

Suggested change
tw = TagWidget(self.lib, tag, True, False, True)
if tag.id in [0, 1]: # [0, 1] should probably be extracted as a constant during refactor
tag_deletable = False
else:
tag_deletable = True
tw = TagWidget(self.lib, self.lib.get_tag(tag_id), True, False, tag_deletable )

Comment on lines +131 to +147
def delete_tag(self, tag_id:int):
def show_delete_prompt() -> bool:
result = QMessageBox.question(self, "Delete Tag", f"Are you sure you want to delete Tag {tag.name}?",
QMessageBox.Yes | QMessageBox.No)

return result == QMessageBox.Yes

tag = self.lib.get_tag(tag_id)
shift_held = Qt.KeyboardModifier.ShiftModifier in QApplication.keyboardModifiers()

if shift_held or show_delete_prompt():
self.lib.remove_tag(tag_id)
self.update_tags()

if not shift_held:
QMessageBox.information(self, "Delete Tag", "Tag deleted.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having to replicate this here and in tag_database makes me think there should be a more reusable way to implement these dialogs but I think that will be a whole codebase sweep that needs to happen so I don't think that's an issue for this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered putting this function in a place where I could reuse it without repeating myself. the other event listeners don't do this either though so I chose to be consistent with them

tw.on_click.connect(lambda checked=False, q=f'tag_id: {tag}': (self.driver.main_window.searchField.setText(q), self.driver.filter_items(q)))
tw.on_remove.connect(lambda checked=False, t=tag: (self.remove_tag(t)))
tw.on_edit.connect(lambda checked=False, t=tag: (self.edit_tag(t)))
tw = TagWidget(self.lib, self.lib.get_tag(tag_id), True, True, True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably remove the ability to delete "System Tags" (archived & favorite) since TagStudio recreates those tags on system shutdown if they are missing.

Suggested change
tw = TagWidget(self.lib, self.lib.get_tag(tag_id), True, True, True)
if tag_id in [0, 1]: # [0, 1] should probably be extracted as a constant during refactor
tag_deletable = False
else:
tag_deletable = True
tw = TagWidget(self.lib, self.lib.get_tag(tag_id), True, False, tag_deletable )

@Loran425 Loran425 added the enhancement New feature or request label May 1, 2024
@Archina
Copy link

Archina commented May 1, 2024

Would it be possible to add something like a reactive store to handle updates of the tags and similar structures instead of pushing signals back and forth.

This would relax the coupling between the TagDatabase and the TagWidget. It would also make it easier to listen to such changes in other places, like under the image preview in the main tag browser.

However, I am more of a Frontend Dev than a python dev.

@Darxoon
Copy link
Author

Darxoon commented May 2, 2024

I implemented your suggestions that system tags can't be deleted now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

None yet

4 participants