NoteFileFormat: Refactor

Get all the allowed extensions in one place. Currently the code is
scattered all over the place.
This commit is contained in:
Vishesh Handa
2020-09-26 19:19:26 +02:00
parent 4b3f1669f5
commit 82db15128b
3 changed files with 33 additions and 6 deletions

View File

@ -268,7 +268,7 @@ widgets:
rootFolder: Root Folder
ignoredFiles:
dot: Starts with a .
ext: Doesn't end with .md or .txt
ext: Doesn't end with one of the following -
drawer:
setup: Setup Git Host
pro: Unlock Pro Version

View File

@ -36,6 +36,34 @@ enum NoteType {
Journal,
}
class NoteFileFormatInfo {
static List<String> allowedExtensions() {
return [
'.md',
'.txt',
];
}
static String defaultExtension(NoteFileFormat format) {
switch (format) {
case NoteFileFormat.Markdown:
return ".md";
case NoteFileFormat.Txt:
return ".txt";
default:
return ".md";
}
}
static bool isAllowedFileName(String filePath) {
var noteFilePath = filePath.toLowerCase();
var isMarkdownFile = noteFilePath.endsWith('.md');
var isTxtFile = noteFilePath.endsWith('.txt');
return isMarkdownFile || isTxtFile;
}
}
enum NoteFileFormat {
Markdown,
Txt,

View File

@ -250,13 +250,12 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
});
continue;
}
var noteFilePath = note.filePath.toLowerCase();
var isMarkdownFile = noteFilePath.endsWith('.md');
var isTxtFile = noteFilePath.endsWith('.txt');
if (!isMarkdownFile && !isTxtFile) {
if (!NoteFileFormatInfo.isAllowedFileName(note.filePath)) {
var ignoredFile = IgnoredFile(
filePath: fsEntity.path,
reason: tr("ignoredFiles.ext"),
reason: tr("ignoredFiles.ext") +
" " +
NoteFileFormatInfo.allowedExtensions().join(' '),
);
_ignoredFiles.add(ignoredFile);