mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Simplify code by using pathSpec
This commit is contained in:
@ -94,29 +94,27 @@ class GitNoteRepository {
|
|||||||
return NoteRepoResult(noteFilePath: newFullPath, error: false);
|
return NoteRepoResult(noteFilePath: newFullPath, error: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<NoteRepoResult> removeNote(String noteFilePath) async {
|
Future<NoteRepoResult> removeNote(Note note) async {
|
||||||
var pathSpec = noteFilePath.replaceFirst(gitDirPath, "").substring(1);
|
|
||||||
|
|
||||||
// We are not calling note.remove() as gitRm will also remove the file
|
// We are not calling note.remove() as gitRm will also remove the file
|
||||||
await _gitRepo.rm(pathSpec);
|
var spec = note.pathSpec();
|
||||||
|
await _gitRepo.rm(spec);
|
||||||
await _gitRepo.commit(
|
await _gitRepo.commit(
|
||||||
message: "Removed Note " + pathSpec,
|
message: "Removed Note " + spec,
|
||||||
);
|
);
|
||||||
|
|
||||||
return NoteRepoResult(noteFilePath: noteFilePath, error: false);
|
return NoteRepoResult(noteFilePath: note.filePath, error: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<NoteRepoResult> removeFolder(String folderPath) async {
|
Future<NoteRepoResult> removeFolder(NotesFolderFS folder) async {
|
||||||
var pathSpec = folderPath.replaceFirst(gitDirPath, "").substring(1);
|
var spec = folder.pathSpec();
|
||||||
|
await _gitRepo.rm(spec);
|
||||||
await _gitRepo.rm(pathSpec);
|
|
||||||
await _gitRepo.commit(
|
await _gitRepo.commit(
|
||||||
message: "Removed Folder " + pathSpec,
|
message: "Removed Folder " + spec,
|
||||||
);
|
);
|
||||||
|
|
||||||
await Directory(folderPath).delete(recursive: true);
|
await Directory(folder.folderPath).delete(recursive: true);
|
||||||
|
|
||||||
return NoteRepoResult(noteFilePath: folderPath, error: false);
|
return NoteRepoResult(noteFilePath: folder.folderPath, error: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<NoteRepoResult> resetLastCommit() async {
|
Future<NoteRepoResult> resetLastCommit() async {
|
||||||
|
@ -259,4 +259,11 @@ class Note with NotesNotifier {
|
|||||||
notifyModifiedListeners(this);
|
notifyModifiedListeners(this);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String pathSpec() {
|
||||||
|
if (parent == null) {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
return p.join(parent.pathSpec(), fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ class StateContainer with ChangeNotifier {
|
|||||||
Fimber.d("Removing Folder: " + folder.folderPath);
|
Fimber.d("Removing Folder: " + folder.folderPath);
|
||||||
|
|
||||||
folder.parentFS.removeFolder(folder);
|
folder.parentFS.removeFolder(folder);
|
||||||
_gitRepo.removeFolder(folder.folderPath).then((NoteRepoResult _) {
|
_gitRepo.removeFolder(folder).then((NoteRepoResult _) {
|
||||||
_syncNotes();
|
_syncNotes();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -199,7 +199,7 @@ class StateContainer with ChangeNotifier {
|
|||||||
return _opLock.synchronized(() async {
|
return _opLock.synchronized(() async {
|
||||||
// FIXME: What if the Note hasn't yet been saved?
|
// FIXME: What if the Note hasn't yet been saved?
|
||||||
note.parent.remove(note);
|
note.parent.remove(note);
|
||||||
_gitRepo.removeNote(note.filePath).then((NoteRepoResult _) async {
|
_gitRepo.removeNote(note).then((NoteRepoResult _) async {
|
||||||
// FIXME: Is there a way of figuring this amount dynamically?
|
// FIXME: Is there a way of figuring this amount dynamically?
|
||||||
// The '4 seconds' is taken from snack_bar.dart -> _kSnackBarDisplayDuration
|
// The '4 seconds' is taken from snack_bar.dart -> _kSnackBarDisplayDuration
|
||||||
// We wait an aritfical amount of time, so that the user has a change to undo
|
// We wait an aritfical amount of time, so that the user has a change to undo
|
||||||
|
Reference in New Issue
Block a user