add desktop file selection and folder drop targets

This commit is contained in:
ngfchl
2026-07-18 18:52:04 +08:00
parent 43a07ac49b
commit a85083429b
2 changed files with 128 additions and 31 deletions
+39
View File
@@ -155,6 +155,7 @@ class FileState {
class FileNotifier extends StateNotifier<FileState> {
GuangyaAPI? _api;
var _detailGeneration = 0;
String? _selectionAnchorID;
FileNotifier() : super(const FileState());
@@ -491,6 +492,44 @@ class FileNotifier extends StateNotifier<FileState> {
state = state.copyWith(selectedIDs: newSelected);
}
void selectWithModifiers(
String id, {
required bool command,
required bool shift,
}) {
final index = state.files.indexWhere((file) => file.id == id);
if (index < 0) return;
final selected = Set<String>.from(state.selectedIDs);
if (shift && _selectionAnchorID != null) {
final anchor = state.files.indexWhere(
(file) => file.id == _selectionAnchorID,
);
if (anchor >= 0) {
final start = anchor < index ? anchor : index;
final end = anchor > index ? anchor : index;
final range = state.files
.sublist(start, end + 1)
.map((file) => file.id);
if (command) {
selected.addAll(range);
} else {
selected
..clear()
..addAll(range);
}
}
} else if (command) {
selected.contains(id) ? selected.remove(id) : selected.add(id);
_selectionAnchorID = id;
} else {
selected
..clear()
..add(id);
_selectionAnchorID = id;
}
state = state.copyWith(selectedIDs: selected);
}
void selectAll() {
if (state.selectedIDs.length == state.files.length) {
state = state.copyWith(selectedIDs: {});