mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
Rename Note: Ensure markdown files end with .md
This broke when supporting txt files
This commit is contained in:
@ -306,24 +306,26 @@ class Note with NotesNotifier {
|
|||||||
void rename(String newName) {
|
void rename(String newName) {
|
||||||
// Do not let the user rename it to a non-markdown file
|
// Do not let the user rename it to a non-markdown file
|
||||||
switch (_fileFormat) {
|
switch (_fileFormat) {
|
||||||
case NoteFileFormat.Markdown:
|
|
||||||
if (!newName.toLowerCase().endsWith('.md')) {
|
|
||||||
newName += '.md';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NoteFileFormat.Txt:
|
case NoteFileFormat.Txt:
|
||||||
if (!newName.toLowerCase().endsWith('.txt')) {
|
if (!newName.toLowerCase().endsWith('.txt')) {
|
||||||
newName += '.txt';
|
newName += '.txt';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case NoteFileFormat.Markdown:
|
||||||
|
default:
|
||||||
|
if (!newName.toLowerCase().endsWith('.md')) {
|
||||||
|
newName += '.md';
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldFilePath = filePath;
|
var oldFilePath = filePath;
|
||||||
var parentDirName = p.dirname(filePath);
|
var parentDirName = p.dirname(filePath);
|
||||||
var newFilePath = p.join(parentDirName, newName);
|
var newFilePath = p.join(parentDirName, newName);
|
||||||
if (_loadState != NoteLoadState.None) {
|
|
||||||
// for new notes
|
// The file will not exist for new notes
|
||||||
|
if (File(oldFilePath).existsSync()) {
|
||||||
File(filePath).renameSync(newFilePath);
|
File(filePath).renameSync(newFilePath);
|
||||||
}
|
}
|
||||||
_filePath = newFilePath;
|
_filePath = newFilePath;
|
||||||
|
@ -229,6 +229,7 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
note = _note;
|
note = _note;
|
||||||
note.rename(fileName);
|
note.rename(fileName);
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
var container = Provider.of<StateContainer>(context, listen: false);
|
var container = Provider.of<StateContainer>(context, listen: false);
|
||||||
container.renameNote(note, fileName);
|
container.renameNote(note, fileName);
|
||||||
|
Reference in New Issue
Block a user