mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-07-28 16:25:09 +02:00
feat(ui/ux): replace "Add Tag/Field" modals with search+create bar(s) with autocomplete (#1451)
* feat(ui): replace add tag modal with autocomplete search/create bar
* fix(ui): restore esc to deselect entries behavior
* refactor: code cleanup and fixes
* refactor: RADICAL mvc refactor...
* feat: add setting to open edit window when creating tags
* feat(ui): add edit tag setting to context menu, tweak translations
* chore: remove unused TYPE_CHECKING imports
* chore: remove unused local import
* refactor(ui): refactor preview panel into new MVC pattern
* refactor: remove controller suffix from preview_panel.py
* refactor: remove unnecessary methods and properties
* Revert "refactor: remove controller suffix from preview_panel.py"
This reverts commit c8ba9b15c2.
* chore: cleanup comments
* feat(ui): add autocomplete search for field templates
* feat(ui): add shortcut for opening field template search bar
* fix(ui): update tag search bar when entry tags are updated
* fix(ui): fix issues with tag and field widget appearances
* refactor(ui): use Qt's .layout() method instead of _layout references
* feat(ui): add underline indicator for search bar items
* ui: misc UI fixes and tweaks
* refactor: remove view parameters
* docs: update docstrings
This commit is contained in:
committed by
GitHub
parent
2fdd1e4cb3
commit
5557fe4f7c
@@ -1,16 +1,16 @@
|
||||
# SPDX-FileCopyrightText: (c) TagStudio Contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# pyright: reportPrivateUsage=false
|
||||
|
||||
from tagstudio.core.library.alchemy.library import Library
|
||||
from tagstudio.core.library.alchemy.models import Entry, Tag
|
||||
from tagstudio.core.utils.types import unwrap
|
||||
from tagstudio.qt.controllers.preview_panel_controller import PreviewPanel
|
||||
from tagstudio.qt.ts_qt import QtDriver
|
||||
|
||||
|
||||
def test_update_selection_empty(qt_driver: QtDriver, library: Library):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
def test_update_selection_empty(qt_driver: QtDriver):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
# Clear the library selection (selecting 1 then unselecting 1)
|
||||
qt_driver.toggle_item_selection(1, append=False, bridge=False)
|
||||
@@ -18,26 +18,26 @@ def test_update_selection_empty(qt_driver: QtDriver, library: Library):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
for container in panel.field_containers_widget.containers:
|
||||
for container in panel.containers._containers:
|
||||
assert container.isHidden()
|
||||
|
||||
|
||||
def test_update_selection_single(qt_driver: QtDriver, library: Library, entry_full: Entry):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
def test_update_selection_single(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should show all applicable tags and field containers
|
||||
for container in panel.field_containers_widget.containers:
|
||||
for container in panel.containers._containers:
|
||||
assert not container.isHidden()
|
||||
|
||||
|
||||
def test_update_selection_multiple(qt_driver: QtDriver, library: Library):
|
||||
def test_update_selection_multiple(qt_driver: QtDriver):
|
||||
# TODO: Implement mixed field editing. Currently these containers will be hidden,
|
||||
# same as the empty selection behavior.
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
# Select the multiple entries
|
||||
qt_driver.toggle_item_selection(1, append=False, bridge=False)
|
||||
@@ -45,12 +45,12 @@ def test_update_selection_multiple(qt_driver: QtDriver, library: Library):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should show mixed field editing
|
||||
for container in panel.field_containers_widget.containers:
|
||||
for container in panel.containers._containers:
|
||||
assert container.isHidden()
|
||||
|
||||
|
||||
def test_add_tag_to_selection_single(qt_driver: QtDriver, library: Library, entry_full: Entry):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
def test_add_tag_to_selection_single(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
assert {t.id for t in entry_full.tags} == {1000}
|
||||
|
||||
@@ -59,15 +59,15 @@ def test_add_tag_to_selection_single(qt_driver: QtDriver, library: Library, entr
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Add new tag
|
||||
panel.field_containers_widget.add_tags_to_selected(2000)
|
||||
panel.containers.add_tags_to_selected(2000)
|
||||
|
||||
# Then reload entry
|
||||
refreshed_entry: Entry = next(library.all_entries(with_joins=True))
|
||||
refreshed_entry: Entry = next(qt_driver.lib.all_entries(with_joins=True))
|
||||
assert {t.id for t in refreshed_entry.tags} == {1000, 2000}
|
||||
|
||||
|
||||
def test_add_same_tag_to_selection_single(qt_driver: QtDriver, library: Library, entry_full: Entry):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
def test_add_same_tag_to_selection_single(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
assert {t.id for t in entry_full.tags} == {1000}
|
||||
|
||||
@@ -76,16 +76,16 @@ def test_add_same_tag_to_selection_single(qt_driver: QtDriver, library: Library,
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Add an existing tag
|
||||
panel.field_containers_widget.add_tags_to_selected(1000)
|
||||
panel.containers.add_tags_to_selected(1000)
|
||||
|
||||
# Then reload entry
|
||||
refreshed_entry = next(library.all_entries(with_joins=True))
|
||||
refreshed_entry = next(qt_driver.lib.all_entries(with_joins=True))
|
||||
assert {t.id for t in refreshed_entry.tags} == {1000}
|
||||
|
||||
|
||||
def test_add_tag_to_selection_multiple(qt_driver: QtDriver, library: Library):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
all_entries = library.all_entries(with_joins=True)
|
||||
def test_add_tag_to_selection_multiple(qt_driver: QtDriver):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
all_entries = qt_driver.lib.all_entries(with_joins=True)
|
||||
|
||||
# We want to verify that tag 1000 is on some, but not all entries already.
|
||||
tag_present_on_some: bool = False
|
||||
@@ -101,15 +101,15 @@ def test_add_tag_to_selection_multiple(qt_driver: QtDriver, library: Library):
|
||||
assert tag_absent_on_some
|
||||
|
||||
# Select the multiple entries
|
||||
for i, e in enumerate(library.all_entries(with_joins=True), start=0):
|
||||
for i, e in enumerate(qt_driver.lib.all_entries(with_joins=True), start=0):
|
||||
qt_driver.toggle_item_selection(e.id, append=(True if i == 0 else False), bridge=False) # noqa: SIM210
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Add new tag
|
||||
panel.field_containers_widget.add_tags_to_selected(1000)
|
||||
panel.containers.add_tags_to_selected(1000)
|
||||
|
||||
# Then reload all entries and recheck the presence of tag 1000
|
||||
refreshed_entries = library.all_entries(with_joins=True)
|
||||
refreshed_entries = qt_driver.lib.all_entries(with_joins=True)
|
||||
tag_present_on_some = False
|
||||
tag_absent_on_some = False
|
||||
|
||||
@@ -123,23 +123,23 @@ def test_add_tag_to_selection_multiple(qt_driver: QtDriver, library: Library):
|
||||
assert not tag_absent_on_some
|
||||
|
||||
|
||||
def test_meta_tag_category(qt_driver: QtDriver, library: Library, entry_full: Entry):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
def test_meta_tag_category(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
# Ensure the Favorite tag is on entry_full
|
||||
library.add_tags_to_entries(1, entry_full.id)
|
||||
qt_driver.lib.add_tags_to_entries(1, entry_full.id)
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
assert len(panel.field_containers_widget.containers) == 3
|
||||
for i, container in enumerate(panel.field_containers_widget.containers):
|
||||
assert len(panel.containers._containers) == 3
|
||||
for i, container in enumerate(panel.containers._containers):
|
||||
match i:
|
||||
case 0:
|
||||
# Check if the container is the Meta Tags category
|
||||
tag: Tag = unwrap(library.get_tag(2))
|
||||
tag: Tag = unwrap(qt_driver.lib.get_tag(2))
|
||||
assert container.title == f"<h4>{tag.name}</h4>"
|
||||
case 1:
|
||||
# Check if the container is the Tags category
|
||||
@@ -151,30 +151,28 @@ def test_meta_tag_category(qt_driver: QtDriver, library: Library, entry_full: En
|
||||
pass
|
||||
|
||||
|
||||
def test_custom_tag_category(qt_driver: QtDriver, library: Library, entry_full: Entry):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
def test_custom_tag_category(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
# Set tag 1000 (foo) as a category
|
||||
tag: Tag = unwrap(library.get_tag(1000))
|
||||
tag: Tag = unwrap(qt_driver.lib.get_tag(1000))
|
||||
tag.is_category = True
|
||||
library.update_tag(
|
||||
tag,
|
||||
)
|
||||
qt_driver.lib.update_tag(tag)
|
||||
|
||||
# Ensure the Favorite tag is on entry_full
|
||||
library.add_tags_to_entries(1, entry_full.id)
|
||||
qt_driver.lib.add_tags_to_entries(1, entry_full.id)
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# FieldContainer should hide all containers
|
||||
assert len(panel.field_containers_widget.containers) == 3
|
||||
for i, container in enumerate(panel.field_containers_widget.containers):
|
||||
assert len(panel.containers._containers) == 3
|
||||
for i, container in enumerate(panel.containers._containers):
|
||||
match i:
|
||||
case 0:
|
||||
# Check if the container is the Meta Tags category
|
||||
tag_2: Tag = unwrap(library.get_tag(2))
|
||||
tag_2: Tag = unwrap(qt_driver.lib.get_tag(2))
|
||||
assert container.title == f"<h4>{tag_2.name}</h4>"
|
||||
case 1:
|
||||
# Check if the container is the custom "foo" category
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# SPDX-FileCopyrightText: (c) TagStudio Contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# pyright: reportPrivateUsage=false, reportAttributeAccessIssue=false
|
||||
|
||||
import os
|
||||
from collections.abc import Callable
|
||||
@@ -8,9 +9,7 @@ from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from PySide6.QtGui import (
|
||||
QAction,
|
||||
)
|
||||
from PySide6.QtGui import QAction
|
||||
from PySide6.QtWidgets import QMenu, QMenuBar
|
||||
from pytestqt.qtbot import QtBot
|
||||
|
||||
@@ -60,11 +59,10 @@ def test_filepath_setting(qtbot: QtBot, qt_driver: QtDriver, filepath_option: Sh
|
||||
)
|
||||
def test_file_path_display(
|
||||
qt_driver: QtDriver,
|
||||
library: Library,
|
||||
filepath_option: ShowFilepathOption,
|
||||
expected_path: Callable[[Library], Path],
|
||||
):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
# Select 2
|
||||
qt_driver.toggle_item_selection(2, append=False, bridge=False)
|
||||
@@ -73,15 +71,15 @@ def test_file_path_display(
|
||||
qt_driver.settings.show_filepath = filepath_option
|
||||
|
||||
# Apply the mock value
|
||||
entry = library.get_entry(2)
|
||||
entry = qt_driver.lib.get_entry(2)
|
||||
assert isinstance(entry, Entry)
|
||||
filename = entry.path
|
||||
panel._file_attributes_widget.update_stats(filepath=unwrap(library.library_dir) / filename) # pyright: ignore[reportPrivateUsage]
|
||||
panel.layout().file_attrs.update_stats(filepath=unwrap(qt_driver.lib.library_dir) / filename)
|
||||
|
||||
# Generate the expected file string.
|
||||
# This is copied directly from the file_attributes.py file
|
||||
# can be imported as a function in the future
|
||||
display_path: Path = expected_path(library)
|
||||
display_path: Path = expected_path(qt_driver.lib)
|
||||
file_str: str = ""
|
||||
separator: str = f"<a style='color: #777777'><b>{os.path.sep}</a>" # Gray
|
||||
for i, part in enumerate(display_path.parts):
|
||||
@@ -94,7 +92,7 @@ def test_file_path_display(
|
||||
file_str += f"<b>{'\u200b'.join(part_)}</b>"
|
||||
|
||||
# Assert the file path is displayed correctly
|
||||
assert panel._file_attributes_widget.file_label.text() == file_str # pyright: ignore[reportPrivateUsage]
|
||||
assert panel.layout().file_attrs.file_label.text() == file_str
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -146,7 +144,7 @@ def test_title_update(
|
||||
qt_driver.main_window.menu_bar.folders_to_tags_action = QAction(menu_bar)
|
||||
|
||||
# Trigger the update
|
||||
qt_driver._init_library(library_dir, open_status) # pyright: ignore[reportPrivateUsage]
|
||||
qt_driver._init_library(library_dir, open_status)
|
||||
|
||||
# Assert the title is updated correctly
|
||||
qt_driver.main_window.setWindowTitle.assert_called_with(expected_title(library_dir, base_title)) # pyright: ignore[reportAttributeAccessIssue]
|
||||
qt_driver.main_window.setWindowTitle.assert_called_with(expected_title(library_dir, base_title))
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
# SPDX-FileCopyrightText: (c) TagStudio Contributors
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
# pyright: reportPrivateUsage=false
|
||||
|
||||
from tagstudio.core.library.alchemy.library import Library
|
||||
from tagstudio.core.library.alchemy.models import Entry
|
||||
from tagstudio.qt.controllers.preview_panel_controller import PreviewPanel
|
||||
from tagstudio.qt.ts_qt import QtDriver
|
||||
|
||||
|
||||
def test_update_selection_empty(qt_driver: QtDriver, library: Library):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
def test_update_selection_empty(qt_driver: QtDriver):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
# Clear the library selection (selecting 1 then unselecting 1)
|
||||
qt_driver.toggle_item_selection(1, append=False, bridge=False)
|
||||
@@ -17,22 +17,27 @@ def test_update_selection_empty(qt_driver: QtDriver, library: Library):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Panel should disable UI that allows for entry modification
|
||||
assert not panel.add_buttons_enabled
|
||||
assert panel.layout().add_tag_button.isEnabled() == panel.layout().add_field_button.isEnabled()
|
||||
assert (
|
||||
not panel.layout().add_tag_button.isEnabled()
|
||||
and not panel.layout().add_field_button.isEnabled()
|
||||
)
|
||||
|
||||
|
||||
def test_update_selection_single(qt_driver: QtDriver, library: Library, entry_full: Entry):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
def test_update_selection_single(qt_driver: QtDriver, entry_full: Entry):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
# Select the single entry
|
||||
qt_driver.toggle_item_selection(entry_full.id, append=False, bridge=False)
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Panel should enable UI that allows for entry modification
|
||||
assert panel.add_buttons_enabled
|
||||
assert panel.layout().add_tag_button.isEnabled() == panel.layout().add_field_button.isEnabled()
|
||||
assert panel.layout().add_tag_button.isEnabled() and panel.layout().add_field_button.isEnabled()
|
||||
|
||||
|
||||
def test_update_selection_multiple(qt_driver: QtDriver, library: Library):
|
||||
panel = PreviewPanel(library, qt_driver)
|
||||
def test_update_selection_multiple(qt_driver: QtDriver):
|
||||
panel = PreviewPanel(qt_driver)
|
||||
|
||||
# Select the multiple entries
|
||||
qt_driver.toggle_item_selection(1, append=False, bridge=False)
|
||||
@@ -40,4 +45,5 @@ def test_update_selection_multiple(qt_driver: QtDriver, library: Library):
|
||||
panel.set_selection(qt_driver.selected)
|
||||
|
||||
# Panel should enable UI that allows for entry modification
|
||||
assert panel.add_buttons_enabled
|
||||
assert panel.layout().add_tag_button.isEnabled() == panel.layout().add_field_button.isEnabled()
|
||||
assert panel.layout().add_tag_button.isEnabled() and panel.layout().add_field_button.isEnabled()
|
||||
|
||||
Reference in New Issue
Block a user