From 7ae2bc24d6ab82586806f2dde271668723c0fc9d Mon Sep 17 00:00:00 2001 From: Coolio Date: Tue, 19 Nov 2024 16:14:34 -0600 Subject: [PATCH] feat(ui): pre-select default tag name in `BuildTagPanel` (#592) This changes the behavior of the tag name inside `BuildTagPanel` for newly created tags: * The default "New Tag" name is now automatically highlighted * Blank tag names (including spaces) are no longer allowed to be created * NOTE: This does not change the tag name column rules in the db, nor does it necessarily need to *** * [Feature Request]: Make the create tag panel have empty tag name field * [Feature Request]: Make the create tag panel have empty tag name field * Revert "[Feature Request]: Make the create tag panel have empty tag name field" This reverts commit f9c7f5d8892fb70a1618f05554234851a27c7eaa. * [Feature Request]: Make the create tag panel have empty tag name field * Revert "[Feature Request]: Make the create tag panel have empty tag name field" This reverts commit e5df3e0f15a1b97c49390ee6190b906958eddbb1. * Update .gitignore * Updated as per disscussion in issue #591 (DRAFT * Updated as per disscussion in issue #591 (DRAFT * Added formatting * Updated code as per discussion is #592 * Updated code as per discussion is #592 (again) * Fixed spacing * Add placeholder text to name field. Co-authored-by: Travis Abendshien <46939827+CyanVoxel@users.noreply.github.com> * Use universal red color for red border. Co-authored-by: Travis Abendshien <46939827+CyanVoxel@users.noreply.github.com> * fix: add `src.core.palette` imports --------- Co-authored-by: Travis Abendshien <46939827+CyanVoxel@users.noreply.github.com> --- tagstudio/src/qt/modals/build_tag.py | 19 ++++++++++++++++++- tagstudio/src/qt/widgets/panel.py | 6 ++++++ tagstudio/src/qt/widgets/tag_box.py | 0 3 files changed, 24 insertions(+), 1 deletion(-) mode change 100644 => 100755 tagstudio/src/qt/modals/build_tag.py mode change 100644 => 100755 tagstudio/src/qt/widgets/panel.py mode change 100644 => 100755 tagstudio/src/qt/widgets/tag_box.py diff --git a/tagstudio/src/qt/modals/build_tag.py b/tagstudio/src/qt/modals/build_tag.py old mode 100644 new mode 100755 index dc45563c..af779819 --- a/tagstudio/src/qt/modals/build_tag.py +++ b/tagstudio/src/qt/modals/build_tag.py @@ -18,7 +18,7 @@ from PySide6.QtWidgets import ( ) from src.core.library import Library, Tag from src.core.library.alchemy.enums import TagColor -from src.core.palette import ColorType, get_tag_color +from src.core.palette import ColorType, UiColor, get_tag_color, get_ui_color from src.qt.modals.tag_search import TagSearchPanel from src.qt.widgets.panel import PanelModal, PanelWidget from src.qt.widgets.tag import TagWidget @@ -51,6 +51,9 @@ class BuildTagPanel(PanelWidget): self.name_title.setText("Name") self.name_layout.addWidget(self.name_title) self.name_field = QLineEdit() + self.name_field.setFixedHeight(24) + self.name_field.textChanged.connect(self.on_name_changed) + self.name_field.setPlaceholderText("Tag Name (Required)") self.name_layout.addWidget(self.name_field) # Shorthand ------------------------------------------------------------ @@ -162,6 +165,8 @@ class BuildTagPanel(PanelWidget): # TODO - fill subtags self.subtags: set[int] = set() self.set_tag(tag or Tag(name="New Tag")) + if tag is None: + self.name_field.selectAll() def add_subtag_callback(self, tag_id: int): logger.info("add_subtag_callback", tag_id=tag_id) @@ -204,6 +209,18 @@ class BuildTagPanel(PanelWidget): self.tag = tag + def on_name_changed(self): + is_empty = not self.name_field.text().strip() + + self.name_field.setStyleSheet( + f"border: 1px solid {get_ui_color(ColorType.PRIMARY, UiColor.RED)}; border-radius: 2px" + if is_empty + else "" + ) + + if self.panel_save_button is not None: + self.panel_save_button.setDisabled(is_empty) + def build_tag(self) -> Tag: color = self.color_field.currentData() or TagColor.DEFAULT diff --git a/tagstudio/src/qt/widgets/panel.py b/tagstudio/src/qt/widgets/panel.py old mode 100644 new mode 100755 index 8c403a66..d16803c7 --- a/tagstudio/src/qt/widgets/panel.py +++ b/tagstudio/src/qt/widgets/panel.py @@ -54,6 +54,7 @@ class PanelModal(QWidget): self.done_button.clicked.connect(self.hide) if done_callback: self.done_button.clicked.connect(done_callback) + self.widget.panel_done_button = self.done_button self.button_layout.addWidget(self.done_button) if save_callback or has_save: @@ -62,6 +63,7 @@ class PanelModal(QWidget): self.cancel_button.clicked.connect(self.hide) self.cancel_button.clicked.connect(widget.reset) # self.cancel_button.clicked.connect(cancel_callback) + self.widget.panel_cancel_button = self.cancel_button self.button_layout.addWidget(self.cancel_button) self.save_button = QPushButton() @@ -69,6 +71,7 @@ class PanelModal(QWidget): self.save_button.setAutoDefault(True) self.save_button.clicked.connect(self.hide) self.save_button.clicked.connect(self.saved.emit) + self.widget.panel_save_button = self.save_button if done_callback: self.save_button.clicked.connect(done_callback) @@ -93,6 +96,9 @@ class PanelWidget(QWidget): """Used for widgets that go in a modal panel, ex. for editing or searching.""" done = Signal() + panel_save_button: QPushButton | None = None + panel_cancel_button: QPushButton | None = None + panel_done_button: QPushButton | None = None def __init__(self): super().__init__() diff --git a/tagstudio/src/qt/widgets/tag_box.py b/tagstudio/src/qt/widgets/tag_box.py old mode 100644 new mode 100755