mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-18 09:22:47 +08:00
Allow Folders to be deleted
For safety we're only allowing non-empty folders to be deleted. Ideally, we should have some kind of undo button. Or some kind of history - since we do have that with git. Related to #18
This commit is contained in:
@ -48,6 +48,23 @@ class NotesFolder with ChangeNotifier {
|
||||
return _entities.firstWhere((e) => e.isNote, orElse: () => null) != null;
|
||||
}
|
||||
|
||||
bool get hasNotesRecursive {
|
||||
bool has = hasNotes;
|
||||
if (has) return true;
|
||||
|
||||
for (var i = 0; i < _entities.length; i++) {
|
||||
var e = _entities[i];
|
||||
if (e.isNote) continue;
|
||||
|
||||
has = has || e.folder.hasNotes;
|
||||
if (has) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return has;
|
||||
}
|
||||
|
||||
int get numberOfNotes {
|
||||
int i = 0;
|
||||
_entities.forEach((e) {
|
||||
@ -231,6 +248,21 @@ class NotesFolder with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void removeFolder(NotesFolder folder) {
|
||||
folder.removeListener(_entityChanged);
|
||||
|
||||
var i = _entities.indexWhere((e) {
|
||||
if (e.isNote) return false;
|
||||
return e.folder.folderPath == folder.folderPath;
|
||||
});
|
||||
assert(i != -1);
|
||||
|
||||
_entities.removeAt(i);
|
||||
_entityMap.remove(folder.folderPath);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void rename(String newName) {
|
||||
var dir = Directory(folderPath);
|
||||
var parentDirName = dirname(folderPath);
|
||||
|
Reference in New Issue
Block a user