|
29 | 29 | import java.util.Collection; |
30 | 30 | import java.util.Collections; |
31 | 31 | import java.util.IdentityHashMap; |
| 32 | +import java.util.List; |
32 | 33 | import java.util.Map; |
33 | 34 | import java.util.Set; |
34 | 35 | import java.util.WeakHashMap; |
@@ -409,18 +410,47 @@ public CommitMessageI getCommitPanel() { |
409 | 410 | return commitPanel; |
410 | 411 | } |
411 | 412 |
|
| 413 | + /** |
| 414 | + * Snapshots the panel selection into immutable collections. Must be called on the EDT |
| 415 | + * because reading the panel's inclusion model is EDT-only; the returned snapshot is |
| 416 | + * safe to read from background threads. |
| 417 | + */ |
| 418 | + @NotNull |
| 419 | + public SelectionSnapshot captureSelection() { |
| 420 | + if (checkinProjectPanel == null) { |
| 421 | + return new SelectionSnapshot(Collections.emptyList(), Collections.emptyList()); |
| 422 | + } |
| 423 | + return new SelectionSnapshot( |
| 424 | + List.copyOf(checkinProjectPanel.getSelectedChanges()), |
| 425 | + List.copyOf(checkinProjectPanel.getFiles())); |
| 426 | + } |
| 427 | + } |
| 428 | + |
| 429 | + /** |
| 430 | + * Immutable snapshot of the commit panel selection captured on the EDT, safe to read |
| 431 | + * from background threads. |
| 432 | + */ |
| 433 | + public static final class SelectionSnapshot { |
| 434 | + private final Collection<Change> selectedChanges; |
| 435 | + private final Collection<File> selectedFiles; |
| 436 | + |
| 437 | + private SelectionSnapshot(@NotNull Collection<Change> selectedChanges, @NotNull Collection<File> selectedFiles) { |
| 438 | + this.selectedChanges = selectedChanges; |
| 439 | + this.selectedFiles = selectedFiles; |
| 440 | + } |
| 441 | + |
412 | 442 | @NotNull |
413 | 443 | public Collection<Change> getSelectedChanges() { |
414 | | - return checkinProjectPanel != null ? checkinProjectPanel.getSelectedChanges() : Collections.emptyList(); |
| 444 | + return selectedChanges; |
415 | 445 | } |
416 | 446 |
|
417 | 447 | @NotNull |
418 | 448 | public Collection<File> getSelectedFiles() { |
419 | | - return checkinProjectPanel != null ? checkinProjectPanel.getFiles() : Collections.emptyList(); |
| 449 | + return selectedFiles; |
420 | 450 | } |
421 | 451 |
|
422 | 452 | public boolean hasSelection() { |
423 | | - return !getSelectedChanges().isEmpty() || !getSelectedFiles().isEmpty(); |
| 453 | + return !selectedChanges.isEmpty() || !selectedFiles.isEmpty(); |
424 | 454 | } |
425 | 455 | } |
426 | 456 | } |
0 commit comments