Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Yafc/Windows/MainScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ private void SetProject(Project project) {
project.AssureFirstPage();
}

summaryView.SetProject(project);

// Activate all page solvers for the summary view
foreach (var page in project.pages) {
_ = page.SolvePage();
Expand Down
45 changes: 38 additions & 7 deletions Yafc/Workspace/SummaryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private struct GoodDetails {
private readonly SummaryScrollArea scrollArea;
private readonly SummaryDataColumn goodsColumn;
private readonly DataGrid<ProjectPage> mainGrid;
private readonly HashSet<ProjectPage> subscribedPages = [];

private Dictionary<string, GoodDetails> allGoods = [];

Expand Down Expand Up @@ -210,20 +211,48 @@ public SummaryView(Project project) {

[MemberNotNull(nameof(project))]
public void SetProject(Project project) {
if (this.project != null) {
this.project.metaInfoChanged -= Recalculate;
if (ReferenceEquals(this.project, project)) {
SyncPageSubscriptions();
Recalculate();
return;
}

foreach (ProjectPage page in this.project.pages) {
page.contentChanged -= Recalculate;
}
if (this.project != null) {
this.project.metaInfoChanged -= ProjectMetaInfoChanged;
UnsubscribeFromAllPages();
}

this.project = project;
project.metaInfoChanged += Recalculate;
project.metaInfoChanged += ProjectMetaInfoChanged;
SyncPageSubscriptions();

Recalculate();
}

private void ProjectMetaInfoChanged() {
SyncPageSubscriptions();
Recalculate();
}

private void SyncPageSubscriptions() {
foreach (ProjectPage page in subscribedPages.Where(page => !project.pages.Contains(page)).ToList()) {
page.contentChanged -= Recalculate;
_ = subscribedPages.Remove(page);
}

foreach (ProjectPage page in project.pages) {
page.contentChanged += Recalculate;
if (subscribedPages.Add(page)) {
page.contentChanged += Recalculate;
}
}
}

private void UnsubscribeFromAllPages() {
foreach (ProjectPage page in subscribedPages) {
page.contentChanged -= Recalculate;
}

subscribedPages.Clear();
}

protected override void BuildPageTooltip(ImGui gui, Summary contents) {
Expand Down Expand Up @@ -281,6 +310,8 @@ protected override async void BuildContent(ImGui gui) {
scrollArea.Build(gui);
}

protected override void ModelContentsChanged(bool visualOnly) => Recalculate(visualOnly);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this override fix? Summary only has showOnlyIssues, and it's a plain auto-property with no RecordUndo() call, so changing it doesn't fire ContentChanged. The checkbox handler at line 265 already calls Recalculate() right after the toggle, and SetProject keeps
allGoods up to date anyway.

The only path I can find where this actually changes behavior is when SetModel calls ModelContentsChanged(false) as the user opens the Summary tab. Before, that was just a UI redraw; now it does a full recompute every time the tab is opened.

If you're adding it defensively to mirror ProductionSummaryView, could you add a short comment explaining what it's guarding against? Otherwise I think it can be dropped, which would keep this PR focused on the subscription fix.


private async Task AutoBalance() {
try {
// The things we've already updated, and the error each had before their previous update.
Expand Down
Loading