mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
NoteFileFormat: Refactor
Get all the allowed extensions in one place. Currently the code is scattered all over the place.
This commit is contained in:
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user