From 9b61848a55e3202627d5fe0fcc2405f29d697687 Mon Sep 17 00:00:00 2001 From: Tom van Dijk <18gatenmaker6@gmail.com> Date: Fri, 28 Jun 2024 13:56:24 +0200 Subject: [PATCH 1/2] feat(qt): Add hotkey to add tags to selection This is used so that you don't have to go through the mouse-heavy nitty-gritty of: 1. Select one or more files 2. Add field 3. Tags 4. OK 5. Add Tag 6. Click on the plus sign 7. Done To get to a tag selection modal. This reduces a lot of friction in my opinion. I like the way that the fields can have multiple types, but in the majority of cases I just want to quickly tag one or more files in my selection and move on. The workflow after this change is as follows: 1. Select one or more files 2. Just press `Ctrl+Shift+T` 3. Click on the plus sign 4. Done This way the tagbox gets added automatically (through the powerful core library system) and you can immediately start tagging! --- tagstudio/src/qt/ts_qt.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index be7403683..6c947d35e 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -55,7 +55,7 @@ ) from humanfriendly import format_timespan -from src.core.enums import SettingItems, SearchMode +from src.core.enums import FieldID, SettingItems, SearchMode from src.core.library import ItemType from src.core.ts_core import TagStudioCore from src.core.constants import ( @@ -85,6 +85,7 @@ from src.qt.modals.fix_unlinked import FixUnlinkedEntriesModal from src.qt.modals.fix_dupes import FixDupeFilesModal from src.qt.modals.folders_to_tags import FoldersToTagsModal +from src.qt.modals.tag_search import TagSearchPanel # this import has side-effect of import PySide resources import src.qt.resources_rc # pylint: disable=unused-import @@ -384,6 +385,19 @@ def start(self) -> None: new_tag_action.setToolTip("Ctrl+T") edit_menu.addAction(new_tag_action) + add_tag_action = QAction("Add Tag To File", menu_bar) + add_tag_action.triggered.connect(lambda: self.attach_tag_action_callback()) + add_tag_action.setShortcut( + QtCore.QKeyCombination( + QtCore.Qt.KeyboardModifier( + QtCore.Qt.KeyboardModifier.ControlModifier + | QtCore.Qt.KeyboardModifier.ShiftModifier), + QtCore.Qt.Key.Key_T, + ) + ) + new_tag_action.setToolTip("Ctrl+Shift+T") + edit_menu.addAction(add_tag_action) + edit_menu.addSeparator() select_all_action = QAction("Select All", menu_bar) @@ -724,6 +738,24 @@ def add_tag_action_callback(self): # panel.tag_updated.connect(lambda tag: self.lib.update_tag(tag)) self.modal.show() + def attach_tag_action_callback(self): + selected_files = [x[1] for x in self.selected if x[0] == ItemType.ENTRY] + tsp = TagSearchPanel(self.lib) + tsp.tag_chosen.connect(lambda x: self.bulk_add_tags(x, selected_files)) + self.modal = PanelModal(tsp, "Bulk add tags (Tag Box)", "Add Tags") + tsp.update_tags() + self.modal.show() + + def bulk_add_tags(self, tag_id: int, files: list[int]): + for x in files: + # Hardcoded because the shortcut works for just the normal tags + self.lib.get_entry(x).add_tag(self.lib, tag_id, field_id=FieldID.TAGS) + + self.preview_panel.update_widgets() + + if tag_id in (TAG_FAVORITE, TAG_ARCHIVED): + self.update_badges() + def select_all_action_callback(self): for item in self.item_thumbs: if item.mode and (item.mode, item.item_id) not in self.selected: From 3809471502832eda69c6e0924f9390b5ac68582f Mon Sep 17 00:00:00 2001 From: Tom van Dijk <18gatenmaker6@gmail.com> Date: Mon, 1 Jul 2024 20:24:01 +0200 Subject: [PATCH 2/2] fixup! feat(qt): Add hotkey to add tags to selection --- tagstudio/src/qt/ts_qt.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 6c947d35e..445b2b30f 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -391,7 +391,8 @@ def start(self) -> None: QtCore.QKeyCombination( QtCore.Qt.KeyboardModifier( QtCore.Qt.KeyboardModifier.ControlModifier - | QtCore.Qt.KeyboardModifier.ShiftModifier), + | QtCore.Qt.KeyboardModifier.ShiftModifier + ), QtCore.Qt.Key.Key_T, ) )