Skip to content

Commit 7ae2bc2

Browse files
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 f9c7f5d. * [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 e5df3e0. * 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>
1 parent 2977e07 commit 7ae2bc2

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

tagstudio/src/qt/modals/build_tag.py

100644100755
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
)
1919
from src.core.library import Library, Tag
2020
from src.core.library.alchemy.enums import TagColor
21-
from src.core.palette import ColorType, get_tag_color
21+
from src.core.palette import ColorType, UiColor, get_tag_color, get_ui_color
2222
from src.qt.modals.tag_search import TagSearchPanel
2323
from src.qt.widgets.panel import PanelModal, PanelWidget
2424
from src.qt.widgets.tag import TagWidget
@@ -51,6 +51,9 @@ def __init__(self, library: Library, tag: Tag | None = None):
5151
self.name_title.setText("Name")
5252
self.name_layout.addWidget(self.name_title)
5353
self.name_field = QLineEdit()
54+
self.name_field.setFixedHeight(24)
55+
self.name_field.textChanged.connect(self.on_name_changed)
56+
self.name_field.setPlaceholderText("Tag Name (Required)")
5457
self.name_layout.addWidget(self.name_field)
5558

5659
# Shorthand ------------------------------------------------------------
@@ -162,6 +165,8 @@ def __init__(self, library: Library, tag: Tag | None = None):
162165
# TODO - fill subtags
163166
self.subtags: set[int] = set()
164167
self.set_tag(tag or Tag(name="New Tag"))
168+
if tag is None:
169+
self.name_field.selectAll()
165170

166171
def add_subtag_callback(self, tag_id: int):
167172
logger.info("add_subtag_callback", tag_id=tag_id)
@@ -204,6 +209,18 @@ def set_tag(self, tag: Tag):
204209

205210
self.tag = tag
206211

212+
def on_name_changed(self):
213+
is_empty = not self.name_field.text().strip()
214+
215+
self.name_field.setStyleSheet(
216+
f"border: 1px solid {get_ui_color(ColorType.PRIMARY, UiColor.RED)}; border-radius: 2px"
217+
if is_empty
218+
else ""
219+
)
220+
221+
if self.panel_save_button is not None:
222+
self.panel_save_button.setDisabled(is_empty)
223+
207224
def build_tag(self) -> Tag:
208225
color = self.color_field.currentData() or TagColor.DEFAULT
209226

tagstudio/src/qt/widgets/panel.py

100644100755
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(
5454
self.done_button.clicked.connect(self.hide)
5555
if done_callback:
5656
self.done_button.clicked.connect(done_callback)
57+
self.widget.panel_done_button = self.done_button
5758
self.button_layout.addWidget(self.done_button)
5859

5960
if save_callback or has_save:
@@ -62,13 +63,15 @@ def __init__(
6263
self.cancel_button.clicked.connect(self.hide)
6364
self.cancel_button.clicked.connect(widget.reset)
6465
# self.cancel_button.clicked.connect(cancel_callback)
66+
self.widget.panel_cancel_button = self.cancel_button
6567
self.button_layout.addWidget(self.cancel_button)
6668

6769
self.save_button = QPushButton()
6870
self.save_button.setText("Save")
6971
self.save_button.setAutoDefault(True)
7072
self.save_button.clicked.connect(self.hide)
7173
self.save_button.clicked.connect(self.saved.emit)
74+
self.widget.panel_save_button = self.save_button
7275

7376
if done_callback:
7477
self.save_button.clicked.connect(done_callback)
@@ -93,6 +96,9 @@ class PanelWidget(QWidget):
9396
"""Used for widgets that go in a modal panel, ex. for editing or searching."""
9497

9598
done = Signal()
99+
panel_save_button: QPushButton | None = None
100+
panel_cancel_button: QPushButton | None = None
101+
panel_done_button: QPushButton | None = None
96102

97103
def __init__(self):
98104
super().__init__()

tagstudio/src/qt/widgets/tag_box.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)