-
Notifications
You must be signed in to change notification settings - Fork 848
优化工具栏“全选”功能 #5867
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
base: main
Are you sure you want to change the base?
优化工具栏“全选”功能 #5867
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| import javafx.beans.property.BooleanProperty; | ||
| import javafx.beans.property.ObjectProperty; | ||
| import javafx.beans.property.SimpleBooleanProperty; | ||
| import javafx.collections.ListChangeListener; | ||
| import javafx.collections.transformation.FilteredList; | ||
| import javafx.geometry.Insets; | ||
| import javafx.geometry.Pos; | ||
|
|
@@ -123,12 +124,20 @@ final class DataPackListPageSkin extends SkinBase<DataPackListPage> { | |
| enableButton.disableProperty().bind(getSkinnable().readOnly); | ||
| disableButton.disableProperty().bind(getSkinnable().readOnly); | ||
|
|
||
| // reason for not using selectAll() is that selectAll() first clears all selected then selects all, causing the toolbar to flicker | ||
| var selectAllButton = createToolbarButton2(i18n("button.select_all"), SVG.SELECT_ALL, () -> listView.getSelectionModel().selectRange(0, listView.getItems().size())); | ||
|
|
||
| listView.getSelectionModel().getSelectedItems().addListener( | ||
| (ListChangeListener<Object>) change -> { | ||
| selectAllButton.setDisable(!listView.getItems().isEmpty() | ||
| && listView.getSelectionModel().getSelectedItems().size() == listView.getItems().size()); | ||
| } | ||
| ); | ||
|
Comment on lines
+127
to
+135
|
||
| selectingToolbar.getChildren().addAll( | ||
| removeButton, | ||
| enableButton, | ||
| disableButton, | ||
| createToolbarButton2(i18n("button.select_all"), SVG.SELECT_ALL, () -> | ||
| listView.getSelectionModel().selectRange(0, listView.getItems().size())),//reason for not using selectAll() is that selectAll() first clears all selected then selects all, causing the toolbar to flicker | ||
| selectAllButton, | ||
| createToolbarButton2(i18n("button.cancel"), SVG.CANCEL, () -> | ||
| listView.getSelectionModel().clearSelection()) | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,7 +54,10 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.ui.animation.ContainerAnimations; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.ui.animation.TransitionPane; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.ui.construct.*; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.util.*; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.util.FXThread; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.util.Lazy; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.util.Pair; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.util.StringUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.util.i18n.I18n; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.util.io.CompressingUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jackhuang.hmcl.util.io.FileUtils; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -154,6 +157,17 @@ final class ModListPageSkin extends SkinBase<ModListPage> { | |||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Toolbar Selecting | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // reason for not using selectAll() is that selectAll() first clears all selected then selects all, causing the toolbar to flicker | ||||||||||||||||||||||||||||||||||||||||||||||||
| var selectAll = createToolbarButton2(i18n("button.select_all"), SVG.SELECT_ALL, () -> listView.getSelectionModel().selectRange(0, listView.getItems().size())); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| listView.getSelectionModel().getSelectedItems().addListener( | ||||||||||||||||||||||||||||||||||||||||||||||||
| (ListChangeListener<Object>) change -> { | ||||||||||||||||||||||||||||||||||||||||||||||||
| selectAll.setDisable(!listView.getItems().isEmpty() | ||||||||||||||||||||||||||||||||||||||||||||||||
| && listView.getSelectionModel().getSelectedItems().size() == listView.getItems().size()); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+164
to
+169
|
||||||||||||||||||||||||||||||||||||||||||||||||
| listView.getSelectionModel().getSelectedItems().addListener( | |
| (ListChangeListener<Object>) change -> { | |
| selectAll.setDisable(!listView.getItems().isEmpty() | |
| && listView.getSelectionModel().getSelectedItems().size() == listView.getItems().size()); | |
| } | |
| ); | |
| selectAll.disableProperty().bind(Bindings.createBooleanBinding( | |
| () -> !listView.getItems().isEmpty() | |
| && listView.getSelectionModel().getSelectedItems().size() == listView.getItems().size(), | |
| listView.getItems(), | |
| listView.getSelectionModel().getSelectedItems() | |
| )); |
Copilot
AI
Mar 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ListChangeListener<Object>) is an unchecked/overly-broad cast here. It would be better to disambiguate the overloaded addListener call using the correct generic type (e.g., ListChangeListener or a named listener variable) so warnings aren’t suppressed and the intent stays type-safe.
| listView.getSelectionModel().getSelectedItems().addListener( | |
| (ListChangeListener<Object>) change -> { | |
| selectAll.setDisable(!listView.getItems().isEmpty() | |
| && listView.getSelectionModel().getSelectedItems().size() == listView.getItems().size()); | |
| } | |
| ); | |
| ListChangeListener<ModInfoObject> selectionListener = change -> { | |
| selectAll.setDisable(!listView.getItems().isEmpty() | |
| && listView.getSelectionModel().getSelectedItems().size() == listView.getItems().size()); | |
| }; | |
| listView.getSelectionModel().getSelectedItems().addListener(selectionListener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ListChangeListener<Object>)is an unchecked/overly-broad cast and loses type safety. Use the correct generic type for the selectedItems list (e.g., ListChangeListener) or a named listener variable to disambiguate the overload without casting to Object.