45 lines
1.3 KiB
Dart
45 lines
1.3 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
import '../api/marianumcloud/webdav/queries/list_files/cacheable_file.dart';
|
|
|
|
enum FileClipboardOperation { cut, copy }
|
|
|
|
/// In-memory clipboard for file operations within the app. Mirrors the
|
|
/// cut/copy/paste pattern of native file managers (iOS Files, Android Files,
|
|
/// Finder). Contents are not persisted across app restarts.
|
|
///
|
|
/// Listen via [ChangeNotifier] (e.g. `ListenableBuilder`) to render a paste
|
|
/// banner when [isEmpty] is false.
|
|
class FileClipboard extends ChangeNotifier {
|
|
FileClipboard._();
|
|
static final FileClipboard instance = FileClipboard._();
|
|
|
|
FileClipboardOperation? _operation;
|
|
List<CacheableFile> _files = const [];
|
|
|
|
FileClipboardOperation? get operation => _operation;
|
|
List<CacheableFile> get files => List.unmodifiable(_files);
|
|
bool get isEmpty => _files.isEmpty;
|
|
|
|
void cut(List<CacheableFile> files) {
|
|
if (files.isEmpty) return;
|
|
_operation = FileClipboardOperation.cut;
|
|
_files = List.of(files);
|
|
notifyListeners();
|
|
}
|
|
|
|
void copy(List<CacheableFile> files) {
|
|
if (files.isEmpty) return;
|
|
_operation = FileClipboardOperation.copy;
|
|
_files = List.of(files);
|
|
notifyListeners();
|
|
}
|
|
|
|
void clear() {
|
|
if (_operation == null && _files.isEmpty) return;
|
|
_operation = null;
|
|
_files = const [];
|
|
notifyListeners();
|
|
}
|
|
}
|