fix(shell): select a newly added library folder in the tree

Adding a root left it in the tree but unselected -- the user had to
go find and click it themselves. addRoot now selects it right away
(onFolderSelected then jumps to Photos and filters to it, same as a
manual click), and replaceRoot carries that selection over to the
rebuilt row once the folder's scan finishes, the same way it already
carries over the expanded state.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-19 13:15:04 -04:00
co-authored by Claude Sonnet 5
parent ed464ae73b
commit e27e1aacdd
@@ -215,6 +215,10 @@ public class LibraryFolderTree extends StackPane implements Disposable {
tree.getRoot().getChildren().add(item);
tree.getRoot().getChildren().sort(BY_DISPLAY_NAME);
updateEmptyState();
// A root the user just picked should read as "here it is, already showing" rather than leaving
// them to go find and click it themselves — onFolderSelected then does the rest (jumps to Photos,
// filters the gallery to it) exactly as a manual click would.
tree.getSelectionModel().select(item);
}
/**
@@ -245,8 +249,11 @@ public class LibraryFolderTree extends StackPane implements Disposable {
}
/**
* Swaps in a freshly built root item, carrying over whether the stale one was expanded. A no-op if the
* root is gone by the time the scan finishes — added and removed again before its walk completed.
* Swaps in a freshly built root item, carrying over whether the stale one was expanded — and, since a
* just-added root ({@link #addRoot}) is selected before its scan ever finishes, whether it was selected
* too, or that selection would otherwise vanish under it the moment the scan's own rebuild lands. A
* no-op if the root is gone by the time the scan finishes — added and removed again before its walk
* completed.
*/
@FxThread
private void replaceRoot(Path path, FolderTreeItem refreshed) {
@@ -254,7 +261,11 @@ public class LibraryFolderTree extends StackPane implements Disposable {
for (int i = 0; i < roots.size(); i++) {
if (roots.get(i).getValue().equals(path)) {
refreshed.setExpanded(roots.get(i).isExpanded());
boolean wasSelected = roots.get(i).equals(tree.getSelectionModel().getSelectedItem());
roots.set(i, refreshed);
if (wasSelected) {
tree.getSelectionModel().select(refreshed);
}
return;
}
}