Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] bug where preview panel ui would not update when fields where removed from an entry #560

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions tagstudio/src/qt/widgets/preview_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@
logger = structlog.get_logger(__name__)


def update_selected_entry(driver: "QtDriver"):
for grid_idx in driver.selected:
entry = driver.frame_content[grid_idx]
# reload entry
results = driver.lib.search_library(FilterState(id=entry.id))
logger.info("found item", entries=len(results), grid_idx=grid_idx, lookup_id=entry.id)
assert results, f"Entry not found: {entry.id}"
driver.frame_content[grid_idx] = next(results)


class PreviewPanel(QWidget):
"""The Preview Panel Widget."""

Expand Down Expand Up @@ -291,6 +281,18 @@ def __init__(self, library: Library, driver: "QtDriver"):
root_layout.setContentsMargins(0, 0, 0, 0)
root_layout.addWidget(splitter)

def update_selected_entry(self, driver: "QtDriver"):
for grid_idx in driver.selected:
entry = driver.frame_content[grid_idx]
results = self.lib.search_library(FilterState(id=entry.id))
logger.info(
"found item",
entries=len(results.items),
grid_idx=grid_idx,
lookup_id=entry.id,
)
self.driver.frame_content[grid_idx] = results[0]

def remove_field_prompt(self, name: str) -> str:
return f'Are you sure you want to remove field "{name}"?'

Expand Down Expand Up @@ -891,7 +893,7 @@ def write_container(self, index: int, field: BaseField, is_mixed: bool = False):
prompt=self.remove_field_prompt(field.type.name),
callback=lambda: (
self.remove_field(field),
update_selected_entry(self.driver),
self.update_selected_entry(self.driver),
# reload entry and its fields
self.update_widgets(),
),
Expand Down