mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
Simplify code by using pathSpec
This commit is contained in:
@ -94,29 +94,27 @@ class GitNoteRepository {
|
||||
return NoteRepoResult(noteFilePath: newFullPath, error: false);
|
||||
}
|
||||
|
||||
Future<NoteRepoResult> removeNote(String noteFilePath) async {
|
||||
var pathSpec = noteFilePath.replaceFirst(gitDirPath, "").substring(1);
|
||||
|
||||
Future<NoteRepoResult> removeNote(Note note) async {
|
||||
// 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(
|
||||
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 {
|
||||
var pathSpec = folderPath.replaceFirst(gitDirPath, "").substring(1);
|
||||
|
||||
await _gitRepo.rm(pathSpec);
|
||||
Future<NoteRepoResult> removeFolder(NotesFolderFS folder) async {
|
||||
var spec = folder.pathSpec();
|
||||
await _gitRepo.rm(spec);
|
||||
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 {
|
||||
|
@ -259,4 +259,11 @@ class Note with NotesNotifier {
|
||||
notifyModifiedListeners(this);
|
||||
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);
|
||||
|
||||
folder.parentFS.removeFolder(folder);
|
||||
_gitRepo.removeFolder(folder.folderPath).then((NoteRepoResult _) {
|
||||
_gitRepo.removeFolder(folder).then((NoteRepoResult _) {
|
||||
_syncNotes();
|
||||
});
|
||||
});
|
||||
@ -199,7 +199,7 @@ class StateContainer with ChangeNotifier {
|
||||
return _opLock.synchronized(() async {
|
||||
// FIXME: What if the Note hasn't yet been saved?
|
||||
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?
|
||||
// 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
|
||||
|
Reference in New Issue
Block a user