add desktop file selection and folder drop targets
This commit is contained in:
@@ -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: {});
|
||||
|
||||
Reference in New Issue
Block a user