claude refactorings, flutter best practices, platform dependent changes, general cleanup
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user