-
-
Notifications
You must be signed in to change notification settings - Fork 394
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
Conversation
"copypaste.copy_fields": "Copy Fields", | ||
"copypaste.paste_fields": "Paste Fields", |
There was a problem hiding this comment.
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
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 |
good catch! seems to be a pre-existing bug in add_tags_to_entry |
There was a problem hiding this 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!
tagstudio/src/qt/ts_qt.py
Outdated
self.preview_panel.update_widgets() | ||
|
||
def set_macro_menu_viability(self): | ||
self.autofill_action.setDisabled(not self.selected) | ||
|
||
def set_copypaste_menu_viability(self): |
There was a problem hiding this comment.
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
tagstudio/src/qt/ts_qt.py
Outdated
for field in self.copy_buffer["fields"]: | ||
self.lib.add_field_to_entry(id, field_id=field.type_key, value=field.value) |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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!
There was a problem hiding this 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!
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.