Ensure new notes always have a proper file ending

This commit is contained in:
Vishesh Handa
2020-06-06 12:31:24 +02:00
parent d736af3332
commit e6be9aa228

View File

@ -70,22 +70,24 @@ class Note with NotesNotifier {
Note.newNote(this.parent) { Note.newNote(this.parent) {
created = DateTime.now(); created = DateTime.now();
_loadState = NoteLoadState.Loaded; _loadState = NoteLoadState.Loaded;
_fileFormat = NoteFileFormat.Markdown;
} }
String get filePath { String get filePath {
if (_filePath == null) { if (_filePath == null) {
_filePath = p.join(parent.folderPath, _buildFileName()); _filePath = p.join(parent.folderPath, _buildFileName());
switch (_fileFormat) { switch (_fileFormat) {
case NoteFileFormat.Markdown:
if (!_filePath.toLowerCase().endsWith('.md')) {
_filePath += '.md';
}
break;
case NoteFileFormat.Txt: case NoteFileFormat.Txt:
if (!_filePath.toLowerCase().endsWith('.txt')) { if (!_filePath.toLowerCase().endsWith('.txt')) {
_filePath += '.txt'; _filePath += '.txt';
} }
break; break;
case NoteFileFormat.Markdown:
default:
if (!_filePath.toLowerCase().endsWith('.md')) {
_filePath += '.md';
}
break;
} }
} }