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 f9c7f5d889.

* [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 e5df3e0f15.

* 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>
This commit is contained in:
Coolio
2024-11-19 16:14:34 -06:00
committed by GitHub
parent 2977e07223
commit 7ae2bc24d6
3 changed files with 24 additions and 1 deletions

19
tagstudio/src/qt/modals/build_tag.py Normal file → Executable file
View File

@@ -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

6
tagstudio/src/qt/widgets/panel.py Normal file → Executable file
View File

@@ -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__()

0
tagstudio/src/qt/widgets/tag_box.py Normal file → Executable file
View File