Skip to content

feat: copy/paste fields and tags #722

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 9 commits into from
Jan 31, 2025
Merged

Conversation

mashed5894
Copy link
Contributor

implementing #660 using stuff from #79. copying and pasting fields and tags with ctrl+c & ctrl+v from one or several entries (copying only works with a single entry). i got the preview to update properly, but im having some issues updating the badge when pasting to several entries at once. the system for doing so seems pretty convoluted and might need some refactoring to implement properly.

@CyanVoxel CyanVoxel added Type: Enhancement New feature or request Type: QoL A quality of life (QoL) enhancement or suggestion Type: UI/UX User interface and/or user experience TagStudio: Library Relating to the TagStudio library system Priority: High An important issue requiring attention TagStudio: Tags Relating to the TagStudio tag system labels Jan 23, 2025
@CyanVoxel CyanVoxel added this to the SQL Parity milestone Jan 23, 2025
Comment on lines 185 to 186
"copypaste.copy_fields": "Copy Fields",
"copypaste.paste_fields": "Paste Fields",
Copy link
Member

Choose a reason for hiding this comment

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

I know this is still a draft, I just wanted to drive-by nitpick and suggest renaming the termcopypaste to edit for clarity and consistency

@mashed5894 mashed5894 marked this pull request as ready for review January 23, 2025 22:34
@CyanVoxel CyanVoxel added the Status: Review Needed A review of this is needed label Jan 23, 2025
@CyanVoxel CyanVoxel linked an issue Jan 23, 2025 that may be closed by this pull request
3 tasks
@CyanVoxel
Copy link
Member

There seems to be an issue where pasting a group of tags to an entry which already contains one or more of the tags stops the rest of the tags from pasting

@mashed5894
Copy link
Contributor Author

good catch! seems to be a pre-existing bug in add_tags_to_entry

Copy link
Member

@CyanVoxel CyanVoxel left a comment

Choose a reason for hiding this comment

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

Approved once all comments are addressed, and the database insert fix discussed in the discord is implemented 👍

Thank you for your work on this!

self.preview_panel.update_widgets()

def set_macro_menu_viability(self):
self.autofill_action.setDisabled(not self.selected)

def set_copypaste_menu_viability(self):
Copy link
Member

Choose a reason for hiding this comment

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

Similar to the change in the translation keys, I suggest renaming copypaste here to something like clipboard

Comment on lines 1050 to 1051
for field in self.copy_buffer["fields"]:
self.lib.add_field_to_entry(id, field_id=field.type_key, value=field.value)
Copy link
Member

Choose a reason for hiding this comment

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

is it intended that mirror_entry_fields doesnt add a second field if the entry already has a field with the same key, and also doesnt mirror tags?

When answering you in the discord I missed one oversight about how the 9.4 version worked (if not the 9.0 version, which predates the initial commit on GitHub) - if a field has the same type key but a different value then it should be pasted. If the field has both the same type key and the same value, then I feel it's better for it to not be pasted, as duplicate fields with the same content most likely isn't ever the desired outcome.

@CyanVoxel CyanVoxel removed the Status: Review Needed A review of this is needed label Jan 24, 2025
Comment on lines 930 to 943
def add_tags_to_entry(self, entry_id: int, tag_ids: int | list[int] | set[int]) -> bool:
"""Add one or more tags to an entry."""
tag_ids_ = [tag_ids] if isinstance(tag_ids, int) else tag_ids
_tag_ids = [tag_ids] if isinstance(tag_ids, int) else tag_ids
tags = [{"tag_id": tag_id, "entry_id": entry_id} for tag_id in _tag_ids]
with Session(self.engine, expire_on_commit=False) as session:
stmt = insert(TagEntry).values(tags).on_conflict_do_nothing()
try:
# TODO: Optimize this by using a single query to update.
for tag_id in tag_ids_:
session.add(TagEntry(tag_id=tag_id, entry_id=entry_id))
session.flush()
session.execute(stmt)
session.commit()
return True
except IntegrityError as e:
logger.warning("[add_tags_to_entry]", warning=e)
session.rollback()
return False
return True
Copy link
Member

Choose a reason for hiding this comment

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

If these changes causing the failing migration tests are reverted, then I'd be happy to pull this!

@CyanVoxel CyanVoxel added the Status: Changes Requested Changes are quested to this label Jan 30, 2025
@CyanVoxel CyanVoxel removed the Status: Changes Requested Changes are quested to this label Jan 31, 2025
Copy link
Member

@CyanVoxel CyanVoxel left a comment

Choose a reason for hiding this comment

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

Thank you for all your work on this!

@CyanVoxel CyanVoxel merged commit 225fe98 into TagStudioDev:main Jan 31, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High An important issue requiring attention TagStudio: Library Relating to the TagStudio library system TagStudio: Tags Relating to the TagStudio tag system Type: Enhancement New feature or request Type: QoL A quality of life (QoL) enhancement or suggestion Type: UI/UX User interface and/or user experience
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[Parity]: Port Tag/Field Copy and Pasting from v9.4 to v9.5
2 participants