mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-08-06 15:21:21 +08:00
Add Note.apply
Avoid calling each setter as each results in the entire tree being rebuilt.
This commit is contained in:
@ -102,10 +102,11 @@ class Checklist {
|
||||
for (var item in items) {
|
||||
_lines[item.lineNo] = item.toString();
|
||||
}
|
||||
_note.body = _lines.join('\n');
|
||||
var body = _lines.join('\n');
|
||||
if (endsWithNewLine) {
|
||||
_note.body += '\n';
|
||||
body += '\n';
|
||||
}
|
||||
_note.apply(body: body);
|
||||
return _note;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ class Note {
|
||||
Map<String, dynamic> extraProps = const {},
|
||||
String fileName = "",
|
||||
}) : fileLastModified = DateTime.fromMillisecondsSinceEpoch(0) {
|
||||
created = DateTime.now();
|
||||
_created = DateTime.now();
|
||||
_loadState = NoteLoadState.Loaded;
|
||||
_fileFormat = NoteFileFormat.Markdown;
|
||||
var settings = NoteSerializationSettings.fromConfig(parent.config);
|
||||
@ -158,10 +158,73 @@ class Note {
|
||||
return _filePath as String;
|
||||
}
|
||||
|
||||
set filePath(String newpath) {
|
||||
_filePath = newpath;
|
||||
void apply({
|
||||
String? filePath,
|
||||
DateTime? created,
|
||||
DateTime? modified,
|
||||
String? body,
|
||||
String? title,
|
||||
NoteType? type,
|
||||
Map<String, dynamic>? extraProps,
|
||||
Set<String>? tags,
|
||||
NoteFileFormat? fileFormat,
|
||||
NoteLoadState? loadState,
|
||||
}) {
|
||||
var changed = false;
|
||||
if (filePath != null) {
|
||||
_filePath = filePath;
|
||||
changed = true;
|
||||
}
|
||||
if (canHaveMetadata) {
|
||||
if (created != null && created != _created) {
|
||||
_created = created;
|
||||
changed = true;
|
||||
}
|
||||
if (modified != null && modified != _modified) {
|
||||
_modified = modified;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (type != null && type != _type) {
|
||||
_type = type;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (extraProps != null) {
|
||||
_extraProps = extraProps;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (tags != null) {
|
||||
_tags = tags;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (body != null && body != _body) {
|
||||
_body = body;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (title != null && title != _title) {
|
||||
_title = title;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (fileFormat != null && _fileFormat != fileFormat) {
|
||||
_fileFormat = fileFormat;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (loadState != null && _loadState != loadState) {
|
||||
_loadState = loadState;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
_notifyModified();
|
||||
}
|
||||
}
|
||||
|
||||
String get fileName {
|
||||
return p.basename(filePath);
|
||||
@ -171,88 +234,35 @@ class Note {
|
||||
return _created;
|
||||
}
|
||||
|
||||
set created(DateTime? dt) {
|
||||
if (!canHaveMetadata) return;
|
||||
|
||||
_created = dt;
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
DateTime? get modified {
|
||||
return _modified;
|
||||
}
|
||||
|
||||
set modified(DateTime? dt) {
|
||||
if (!canHaveMetadata) return;
|
||||
|
||||
_modified = dt;
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
void updateModified() {
|
||||
modified = DateTime.now();
|
||||
_modified = DateTime.now();
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
String get body {
|
||||
return _body;
|
||||
}
|
||||
|
||||
set body(String newBody) {
|
||||
if (newBody == _body) {
|
||||
return;
|
||||
}
|
||||
|
||||
_body = newBody;
|
||||
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
String get title {
|
||||
return _title;
|
||||
}
|
||||
|
||||
set title(String title) {
|
||||
if (title != _title) {
|
||||
_title = title;
|
||||
_notifyModified();
|
||||
}
|
||||
}
|
||||
|
||||
NoteType get type {
|
||||
return _type;
|
||||
}
|
||||
|
||||
set type(NoteType type) {
|
||||
if (!canHaveMetadata) return;
|
||||
|
||||
if (type != _type) {
|
||||
_type = type;
|
||||
_notifyModified();
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> get tags {
|
||||
return _tags;
|
||||
}
|
||||
|
||||
set tags(Set<String> tags) {
|
||||
if (!canHaveMetadata) return;
|
||||
|
||||
_tags = tags;
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
Map<String, dynamic> get extraProps {
|
||||
return _extraProps;
|
||||
}
|
||||
|
||||
set extraProps(Map<String, dynamic> props) {
|
||||
if (!canHaveMetadata) return;
|
||||
|
||||
_extraProps = props;
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
bool get canHaveMetadata {
|
||||
if (_fileFormat == NoteFileFormat.Txt ||
|
||||
_fileFormat == NoteFileFormat.OrgMode) {
|
||||
@ -277,11 +287,6 @@ class Note {
|
||||
return _loadState;
|
||||
}
|
||||
|
||||
set loadState(NoteLoadState state) {
|
||||
_loadState = state;
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => _filePath.hashCode;
|
||||
|
||||
@ -341,11 +346,6 @@ class Note {
|
||||
NoteFileFormat? get fileFormat {
|
||||
return _fileFormat;
|
||||
}
|
||||
|
||||
set fileFormat(NoteFileFormat? format) {
|
||||
_fileFormat = format;
|
||||
_notifyModified();
|
||||
}
|
||||
}
|
||||
|
||||
String ensureFileNameUnique(String parentDir, String name, String ext) {
|
||||
|
@ -141,6 +141,7 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
void decode(MdYamlDoc data, Note note) {
|
||||
var propsUsed = <String>{};
|
||||
|
||||
DateTime? modified;
|
||||
var modifiedKeyOptions = [
|
||||
"modified",
|
||||
"mod",
|
||||
@ -154,10 +155,10 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
var val = data.props[possibleKey];
|
||||
if (val != null) {
|
||||
if (val is int) {
|
||||
note.modified = parseUnixTimeStamp(val);
|
||||
modified = parseUnixTimeStamp(val);
|
||||
settings.modifiedFormat = DateFormat.UnixTimeStamp;
|
||||
} else {
|
||||
note.modified = parseDateTime(val.toString());
|
||||
modified = parseDateTime(val.toString());
|
||||
settings.modifiedFormat = DateFormat.Iso8601;
|
||||
}
|
||||
settings.modifiedKey = possibleKey;
|
||||
@ -167,8 +168,9 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
}
|
||||
}
|
||||
|
||||
note.body = settings.emojify ? emojiParser.emojify(data.body) : data.body;
|
||||
var body = settings.emojify ? emojiParser.emojify(data.body) : data.body;
|
||||
|
||||
DateTime? created;
|
||||
var createdKeyOptions = [
|
||||
"created",
|
||||
"date",
|
||||
@ -177,10 +179,10 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
var val = data.props[possibleKey];
|
||||
if (val != null) {
|
||||
if (val is int) {
|
||||
note.created = parseUnixTimeStamp(val);
|
||||
created = parseUnixTimeStamp(val);
|
||||
settings.createdFormat = DateFormat.UnixTimeStamp;
|
||||
} else {
|
||||
note.created = parseDateTime(val.toString());
|
||||
created = parseDateTime(val.toString());
|
||||
settings.createdFormat = DateFormat.Iso8601;
|
||||
}
|
||||
settings.createdKey = possibleKey;
|
||||
@ -193,15 +195,16 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
//
|
||||
// Title parsing
|
||||
//
|
||||
String? title;
|
||||
if (data.props.containsKey(settings.titleKey)) {
|
||||
var title = data.props[settings.titleKey]?.toString() ?? "";
|
||||
note.title = settings.emojify ? emojiParser.emojify(title) : title;
|
||||
title = data.props[settings.titleKey]?.toString() ?? "";
|
||||
title = settings.emojify ? emojiParser.emojify(title) : title;
|
||||
|
||||
propsUsed.add(settings.titleKey);
|
||||
settings.titleSettings = SettingsTitle.InYaml;
|
||||
} else {
|
||||
var startsWithH1 = false;
|
||||
for (var line in LineSplitter.split(note.body)) {
|
||||
for (var line in LineSplitter.split(body)) {
|
||||
if (line.trim().isEmpty) {
|
||||
continue;
|
||||
}
|
||||
@ -210,35 +213,36 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
}
|
||||
|
||||
if (startsWithH1) {
|
||||
var titleStartIndex = note.body.indexOf('#');
|
||||
var titleEndIndex = note.body.indexOf('\n', titleStartIndex);
|
||||
if (titleEndIndex == -1 || titleEndIndex == note.body.length) {
|
||||
note.title = note.body.substring(titleStartIndex + 1).trim();
|
||||
note.body = "";
|
||||
var titleStartIndex = body.indexOf('#');
|
||||
var titleEndIndex = body.indexOf('\n', titleStartIndex);
|
||||
if (titleEndIndex == -1 || titleEndIndex == body.length) {
|
||||
title = body.substring(titleStartIndex + 1).trim();
|
||||
body = "";
|
||||
} else {
|
||||
note.title =
|
||||
note.body.substring(titleStartIndex + 1, titleEndIndex).trim();
|
||||
note.body = note.body.substring(titleEndIndex + 1).trim();
|
||||
title = body.substring(titleStartIndex + 1, titleEndIndex).trim();
|
||||
body = body.substring(titleEndIndex + 1).trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var type = data.props[settings.typeKey];
|
||||
switch (type) {
|
||||
NoteType? type;
|
||||
var typeStr = data.props[settings.typeKey];
|
||||
switch (typeStr) {
|
||||
case "Checklist":
|
||||
note.type = NoteType.Checklist;
|
||||
type = NoteType.Checklist;
|
||||
break;
|
||||
case "Journal":
|
||||
note.type = NoteType.Journal;
|
||||
type = NoteType.Journal;
|
||||
break;
|
||||
default:
|
||||
note.type = NoteType.Unknown;
|
||||
type = NoteType.Unknown;
|
||||
break;
|
||||
}
|
||||
if (type != null) {
|
||||
if (typeStr != null) {
|
||||
propsUsed.add(settings.typeKey);
|
||||
}
|
||||
|
||||
Set<String>? _tags;
|
||||
try {
|
||||
var tagKeyOptions = [
|
||||
"tags",
|
||||
@ -249,9 +253,9 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
var tags = data.props[possibleKey];
|
||||
if (tags != null) {
|
||||
if (tags is YamlList) {
|
||||
note.tags = tags.map((t) => t.toString()).toSet();
|
||||
_tags = tags.map((t) => t.toString()).toSet();
|
||||
} else if (tags is List) {
|
||||
note.tags = tags.map((t) => t.toString()).toSet();
|
||||
_tags = tags.map((t) => t.toString()).toSet();
|
||||
} else if (tags is String) {
|
||||
settings.tagsInString = true;
|
||||
var allTags = tags.split(' ');
|
||||
@ -261,7 +265,7 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
allTags = allTags.map((e) => e.substring(1)).toList();
|
||||
}
|
||||
|
||||
note.tags = allTags.toSet();
|
||||
_tags = allTags.toSet();
|
||||
} else {
|
||||
Log.e("Note Tags Decoding Failed: $tags");
|
||||
}
|
||||
@ -276,13 +280,23 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
}
|
||||
|
||||
// Extra Props
|
||||
note.extraProps = {};
|
||||
var extraProps = <String, dynamic>{};
|
||||
data.props.forEach((key, val) {
|
||||
if (propsUsed.contains(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
note.extraProps[key] = val;
|
||||
extraProps[key] = val;
|
||||
});
|
||||
|
||||
note.apply(
|
||||
created: created,
|
||||
modified: modified,
|
||||
body: body,
|
||||
title: title,
|
||||
type: type,
|
||||
extraProps: extraProps,
|
||||
tags: _tags,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -56,14 +56,12 @@ class NoteStorage {
|
||||
} catch (e, stackTrace) {
|
||||
if (e is FileSystemException &&
|
||||
e.osError!.errorCode == 2 /* File Not Found */) {
|
||||
note.loadState = NoteLoadState.NotExists;
|
||||
note.parent.noteModified(note);
|
||||
note.apply(loadState: NoteLoadState.NotExists);
|
||||
return Result(note.loadState);
|
||||
}
|
||||
|
||||
logExceptionWarning(e, stackTrace);
|
||||
note.loadState = NoteLoadState.Error;
|
||||
note.parent.noteModified(note);
|
||||
note.apply(loadState: NoteLoadState.Error);
|
||||
return Result(note.loadState);
|
||||
}
|
||||
Log.d("Note modified: $note.filePath");
|
||||
@ -78,49 +76,48 @@ class NoteStorage {
|
||||
var dataResult = await mdYamlDocLoader.loadDoc(note.filePath);
|
||||
if (dataResult.isSuccess) {
|
||||
note.data = dataResult.getOrThrow();
|
||||
note.fileFormat = NoteFileFormat.Markdown;
|
||||
note.apply(fileFormat: NoteFileFormat.Markdown);
|
||||
} else {
|
||||
if (dataResult.error is MdYamlDocNotFoundException) {
|
||||
note.loadState = NoteLoadState.NotExists;
|
||||
note.parent.noteModified(note);
|
||||
note.apply(loadState: NoteLoadState.NotExists);
|
||||
return Result(note.loadState);
|
||||
}
|
||||
if (dataResult.error is MdYamlParsingException) {
|
||||
note.loadState = NoteLoadState.Error;
|
||||
note.parent.noteModified(note);
|
||||
note.apply(loadState: NoteLoadState.Error);
|
||||
return Result(note.loadState);
|
||||
}
|
||||
}
|
||||
} else if (isTxt) {
|
||||
try {
|
||||
note.body = await File(note.filePath).readAsString();
|
||||
note.fileFormat = NoteFileFormat.Txt;
|
||||
note.apply(
|
||||
body: await File(note.filePath).readAsString(),
|
||||
fileFormat: NoteFileFormat.Txt,
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
logExceptionWarning(e, stackTrace);
|
||||
|
||||
note.loadState = NoteLoadState.Error;
|
||||
note.parent.noteModified(note);
|
||||
note.apply(loadState: NoteLoadState.Error);
|
||||
return Result(note.loadState);
|
||||
}
|
||||
} else if (isOrg) {
|
||||
try {
|
||||
note.body = await File(note.filePath).readAsString();
|
||||
note.fileFormat = NoteFileFormat.OrgMode;
|
||||
note.apply(
|
||||
body: await File(note.filePath).readAsString(),
|
||||
fileFormat: NoteFileFormat.OrgMode,
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
logExceptionWarning(e, stackTrace);
|
||||
|
||||
note.loadState = NoteLoadState.Error;
|
||||
note.parent.noteModified(note);
|
||||
note.apply(loadState: NoteLoadState.Error);
|
||||
return Result(note.loadState);
|
||||
}
|
||||
} else {
|
||||
note.loadState = NoteLoadState.Error;
|
||||
note.parent.noteModified(note);
|
||||
note.apply(loadState: NoteLoadState.Error);
|
||||
return Result(note.loadState);
|
||||
}
|
||||
|
||||
note.fileLastModified = file.lastModifiedSync();
|
||||
note.loadState = NoteLoadState.Loaded;
|
||||
note.apply(loadState: NoteLoadState.Loaded);
|
||||
|
||||
note.parent.noteModified(note);
|
||||
return Result(note.loadState);
|
||||
|
@ -557,7 +557,7 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
|
||||
if (File(oldFilePath).existsSync()) {
|
||||
File(note.filePath).renameSync(newFilePath);
|
||||
}
|
||||
note.filePath = newFilePath;
|
||||
note.apply(filePath: newFilePath);
|
||||
|
||||
_noteRenamed(note, oldFilePath);
|
||||
}
|
||||
|
@ -13,15 +13,19 @@ class EmojiTransformer implements NoteReadTransformer, NoteWriteTransformer {
|
||||
|
||||
@override
|
||||
Future<Note> onRead(Note note) async {
|
||||
note.title = _emojiParser.emojify(note.title);
|
||||
note.body = _emojiParser.emojify(note.body);
|
||||
note.apply(
|
||||
body: _emojiParser.emojify(note.body),
|
||||
title: _emojiParser.emojify(note.title),
|
||||
);
|
||||
return note;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Note> onWrite(Note note) async {
|
||||
note.body = _emojiParser.unemojify(note.body);
|
||||
note.title = _emojiParser.unemojify(note.title);
|
||||
note.apply(
|
||||
body: _emojiParser.unemojify(note.body),
|
||||
title: _emojiParser.unemojify(note.title),
|
||||
);
|
||||
return note;
|
||||
}
|
||||
}
|
||||
|
@ -226,8 +226,10 @@ class ChecklistEditorState extends State<ChecklistEditor>
|
||||
}
|
||||
|
||||
var note = checklist.note;
|
||||
note.title = _titleTextController.text.trim();
|
||||
note.type = NoteType.Checklist;
|
||||
note.apply(
|
||||
title: _titleTextController.text.trim(),
|
||||
type: NoteType.Checklist,
|
||||
);
|
||||
return note;
|
||||
}
|
||||
|
||||
@ -313,7 +315,7 @@ class ChecklistEditorState extends State<ChecklistEditor>
|
||||
Future<void> addImage(String filePath) async {
|
||||
var note = getNote();
|
||||
var image = await core.Image.copyIntoFs(note.parent, filePath);
|
||||
note.body += image.toMarkup(note.fileFormat);
|
||||
note.apply(body: note.body + image.toMarkup(note.fileFormat));
|
||||
|
||||
setState(() {
|
||||
checklist = Checklist(note);
|
||||
|
@ -134,8 +134,10 @@ class JournalEditorState extends State<JournalEditor>
|
||||
|
||||
@override
|
||||
Note getNote() {
|
||||
note.body = _textController.text.trim();
|
||||
note.type = NoteType.Journal;
|
||||
note.apply(
|
||||
body: _textController.text.trim(),
|
||||
type: NoteType.Journal,
|
||||
);
|
||||
return note;
|
||||
}
|
||||
|
||||
@ -174,7 +176,7 @@ class JournalEditorState extends State<JournalEditor>
|
||||
Future<void> addImage(String filePath) async {
|
||||
var note = getNote();
|
||||
var image = await core.Image.copyIntoFs(note.parent, filePath);
|
||||
note.body += image.toMarkup(note.fileFormat);
|
||||
note.apply(body: note.body + image.toMarkup(note.fileFormat));
|
||||
|
||||
setState(() {
|
||||
_textController.text = note.body;
|
||||
|
@ -162,9 +162,11 @@ class MarkdownEditorState extends State<MarkdownEditor>
|
||||
}
|
||||
|
||||
void _updateNote() {
|
||||
note.title = _titleTextController.text.trim();
|
||||
note.body = _textController.text;
|
||||
note.type = NoteType.Unknown;
|
||||
note.apply(
|
||||
body: _textController.text.trim(),
|
||||
title: _titleTextController.text.trim(),
|
||||
type: NoteType.Unknown,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -218,7 +220,7 @@ class MarkdownEditorState extends State<MarkdownEditor>
|
||||
Future<void> addImage(String filePath) async {
|
||||
var note = getNote();
|
||||
var image = await core.Image.copyIntoFs(note.parent, filePath);
|
||||
note.body += image.toMarkup(note.fileFormat);
|
||||
note.apply(body: note.body + image.toMarkup(note.fileFormat));
|
||||
|
||||
setState(() {
|
||||
_textController.text = note.body;
|
||||
|
@ -154,7 +154,7 @@ class OrgEditorState extends State<OrgEditor>
|
||||
Future<void> addImage(String filePath) async {
|
||||
var note = getNote();
|
||||
var image = await core.Image.copyIntoFs(note.parent, filePath);
|
||||
note.body += image.toMarkup(note.fileFormat);
|
||||
note.apply(body: note.body + image.toMarkup(note.fileFormat));
|
||||
|
||||
setState(() {
|
||||
_textController.text = note.body;
|
||||
|
@ -162,7 +162,7 @@ class RawEditorState extends State<RawEditor>
|
||||
Future<void> addImage(String filePath) async {
|
||||
var note = getNote();
|
||||
var image = await core.Image.copyIntoFs(note.parent, filePath);
|
||||
note.body += image.toMarkup(note.fileFormat);
|
||||
note.apply(body: note.body + image.toMarkup(note.fileFormat));
|
||||
|
||||
setState(() {
|
||||
_textController.text = note.body;
|
||||
|
@ -117,7 +117,7 @@ class NoteEditorState extends State<NoteEditor> with WidgetsBindingObserver {
|
||||
) {
|
||||
note = Note.newNote(folder, extraProps: extraProps, fileName: fileName);
|
||||
if (existingText.isNotEmpty) {
|
||||
note!.body = existingText;
|
||||
note!.apply(body: existingText);
|
||||
}
|
||||
|
||||
if (existingImages.isNotEmpty) {
|
||||
@ -125,7 +125,7 @@ class NoteEditorState extends State<NoteEditor> with WidgetsBindingObserver {
|
||||
() async {
|
||||
try {
|
||||
var image = await core.Image.copyIntoFs(note!.parent, imagePath);
|
||||
note!.body += image.toMarkup(note!.fileFormat);
|
||||
note!.apply(body: note!.body + image.toMarkup(note!.fileFormat));
|
||||
} catch (e, st) {
|
||||
Log.e("New Note Existing Image", ex: e, stacktrace: st);
|
||||
}
|
||||
@ -489,7 +489,7 @@ class NoteEditorState extends State<NoteEditor> with WidgetsBindingObserver {
|
||||
if (!eq(note!.tags, newTags)) {
|
||||
setState(() {
|
||||
Log.i("Settings tags to: $newTags");
|
||||
note!.tags = newTags;
|
||||
note!.apply(tags: newTags);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -51,23 +51,28 @@ class _NoteMetadataSettingsScreenState
|
||||
|
||||
var parent = NotesFolderFS(null, '', folderConfig);
|
||||
var note = Note(parent, "fileName.md", DateTime.now());
|
||||
note.title = tr("settings.noteMetaData.exampleTitle");
|
||||
note.body = tr("settings.noteMetaData.exampleBody");
|
||||
note.created = created;
|
||||
note.modified = modified;
|
||||
note.tags = {
|
||||
tr("settings.noteMetaData.exampleTag1"),
|
||||
tr("settings.noteMetaData.exampleTag2"),
|
||||
};
|
||||
|
||||
Map<String, dynamic>? extraProps;
|
||||
if (settings.customMetaData != "") {
|
||||
var customMetaDataMap =
|
||||
MarkdownYAMLCodec.parseYamlText(settings.customMetaData);
|
||||
if (customMetaDataMap.isNotEmpty) {
|
||||
note.extraProps = customMetaDataMap;
|
||||
extraProps = customMetaDataMap;
|
||||
}
|
||||
}
|
||||
|
||||
note.apply(
|
||||
title: tr("settings.noteMetaData.exampleTitle"),
|
||||
body: tr("settings.noteMetaData.exampleBody"),
|
||||
created: created,
|
||||
modified: modified,
|
||||
extraProps: extraProps,
|
||||
tags: {
|
||||
tr("settings.noteMetaData.exampleTag1"),
|
||||
tr("settings.noteMetaData.exampleTag2"),
|
||||
},
|
||||
);
|
||||
|
||||
var body = Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
|
@ -47,8 +47,10 @@ void main() {
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var note = Note(rootFolder, _getRandomFilePath(rootFolder.folderPath),
|
||||
DateTime.now());
|
||||
note.modified = DateTime(2020, 1, 10 + (i * 2));
|
||||
note.body = "$i\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 10 + (i * 2)),
|
||||
body: "$i\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
|
||||
@ -61,8 +63,10 @@ void main() {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var note = Note(sub1Folder, _getRandomFilePath(sub1Folder.folderPath),
|
||||
DateTime.now());
|
||||
note.modified = DateTime(2020, 1, 10 + (i * 2));
|
||||
note.body = "sub1-$i\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 10 + (i * 2)),
|
||||
body: "sub1-$i\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
|
||||
@ -71,8 +75,10 @@ void main() {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var note = Note(sub2Folder, _getRandomFilePath(sub2Folder.folderPath),
|
||||
DateTime.now());
|
||||
note.modified = DateTime(2020, 1, 10 + (i * 2));
|
||||
note.body = "sub2-$i\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 10 + (i * 2)),
|
||||
body: "sub2-$i\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
|
||||
@ -81,8 +87,10 @@ void main() {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var note = Note(
|
||||
p1Folder, _getRandomFilePath(p1Folder.folderPath), DateTime.now());
|
||||
note.modified = DateTime(2020, 1, 10 + (i * 2));
|
||||
note.body = "p1-$i\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 10 + (i * 2)),
|
||||
body: "p1-$i\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
|
||||
|
@ -69,8 +69,9 @@ Future<void> _writeRandomNote(
|
||||
}
|
||||
|
||||
var note = Note(NotesFolderFS(null, dirPath, config), path, DateTime.now());
|
||||
note.modified = DateTime(2014, 1, 1 + (random.nextInt(2000)));
|
||||
note.body = "p1";
|
||||
|
||||
note.apply(
|
||||
modified: DateTime(2014, 1, 1 + (random.nextInt(2000))),
|
||||
body: "p1",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
|
@ -47,8 +47,10 @@ void main() {
|
||||
for (var i = 0; i < 3; i++) {
|
||||
var note = Note(rootFolder, _getRandomFilePath(rootFolder.folderPath),
|
||||
DateTime.now());
|
||||
note.modified = DateTime(2020, 1, 10 + (i * 2));
|
||||
note.body = "$i\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 10 + (i * 2)),
|
||||
body: "$i\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
|
||||
@ -61,8 +63,10 @@ void main() {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var note = Note(sub1Folder, _getRandomFilePath(sub1Folder.folderPath),
|
||||
DateTime.now());
|
||||
note.modified = DateTime(2020, 1, 10 + (i * 2));
|
||||
note.body = "sub1-$i\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 10 + (i * 2)),
|
||||
body: "sub1-$i\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
|
||||
@ -71,8 +75,10 @@ void main() {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var note = Note(sub2Folder, _getRandomFilePath(sub2Folder.folderPath),
|
||||
DateTime.now());
|
||||
note.modified = DateTime(2020, 1, 10 + (i * 2));
|
||||
note.body = "sub2-$i\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 10 + (i * 2)),
|
||||
body: "sub2-$i\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
|
||||
@ -81,8 +87,10 @@ void main() {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
var note = Note(
|
||||
p1Folder, _getRandomFilePath(p1Folder.folderPath), DateTime.now());
|
||||
note.modified = DateTime(2020, 1, 10 + (i * 2));
|
||||
note.body = "p1-$i\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 10 + (i * 2)),
|
||||
body: "p1-$i\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
|
||||
@ -120,8 +128,10 @@ void main() {
|
||||
|
||||
var p1 = (f.fsFolder as NotesFolderFS).getFolderWithSpec("sub1/p1")!;
|
||||
var note = Note(p1, p.join(p1.folderPath, "new.md"), DateTime.now());
|
||||
note.modified = DateTime(2020, 2, 1);
|
||||
note.body = "new\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 2, 1),
|
||||
body: "new\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
|
||||
p1.add(note);
|
||||
|
@ -42,8 +42,7 @@ void main() {
|
||||
expect(note.body, "I ❤️ you");
|
||||
expect(note.title, "Why not ☕?");
|
||||
|
||||
note.body = "Why not ☕?";
|
||||
note.title = "I ❤️ you";
|
||||
note.apply(body: "Why not ☕?", title: "I ❤️ you");
|
||||
|
||||
serializer.encode(note, doc);
|
||||
expect(doc.body, "Why not :coffee:?");
|
||||
@ -64,8 +63,7 @@ void main() {
|
||||
expect(note.body, "I heart you");
|
||||
expect(note.title, "Why not coffee?");
|
||||
|
||||
note.body = "Why not coffee?";
|
||||
note.title = "I heart you";
|
||||
note.apply(body: "Why not coffee?", title: "I heart you");
|
||||
|
||||
serializer.encode(note, doc);
|
||||
expect(doc.body, "# I heart you\n\nWhy not coffee?");
|
||||
|
@ -42,8 +42,7 @@ void main() {
|
||||
|
||||
var parent = NotesFolderFS(null, tempDir.path, config);
|
||||
var n1 = Note(parent, n1Path, DateTime.now());
|
||||
n1.body = "test\n";
|
||||
n1.created = dt;
|
||||
n1.apply(created: dt, body: "test\n");
|
||||
|
||||
var n2 = Note(parent, n2Path, DateTime.now());
|
||||
n2.data = MdYamlDoc(body: "test2\n", props: props);
|
||||
|
@ -48,7 +48,7 @@ Hello
|
||||
var note = Note(parentFolder, notePath, DateTime.now());
|
||||
await storage.load(note);
|
||||
|
||||
note.modified = DateTime.utc(2019, 12, 02, 4, 0, 0);
|
||||
note.apply(modified: DateTime.utc(2019, 12, 02, 4, 0, 0));
|
||||
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
|
||||
@ -80,7 +80,7 @@ Hello
|
||||
var note = Note(parentFolder, notePath, DateTime.now());
|
||||
await storage.load(note);
|
||||
|
||||
note.modified = DateTime.utc(2019, 12, 02, 4, 0, 0);
|
||||
note.apply(modified: DateTime.utc(2019, 12, 02, 4, 0, 0));
|
||||
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
|
||||
@ -116,10 +116,7 @@ Hello
|
||||
expect(note.tags.contains('B'), true);
|
||||
expect(note.tags.length, 2);
|
||||
|
||||
note.tags = {...note.tags}..add('C');
|
||||
note.tags.add('D');
|
||||
note.tags.remove('B');
|
||||
|
||||
note.apply(tags: {'A', 'C', 'D'});
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
|
||||
var expectedContent = """---
|
||||
@ -260,8 +257,10 @@ Hello
|
||||
expect(note.modified, DateTime.parse('2021-07-14T10:14:49Z'));
|
||||
expect(note.created, DateTime.parse('2021-07-14T10:14:49Z'));
|
||||
|
||||
note.modified = DateTime.parse('2020-07-14T10:14:49Z');
|
||||
note.created = DateTime.parse('2020-06-13T10:14:49Z');
|
||||
note.apply(
|
||||
created: DateTime.parse('2020-06-13T10:14:49Z'),
|
||||
modified: DateTime.parse('2020-07-14T10:14:49Z'),
|
||||
);
|
||||
|
||||
var expectedContent = """---
|
||||
bar: Foo
|
||||
|
@ -38,8 +38,10 @@ void main() {
|
||||
folder,
|
||||
p.join(folder.folderPath, "${random.nextInt(1000)}.md"),
|
||||
DateTime.now());
|
||||
note.modified = DateTime(2020, 1, 10 + (i * 2));
|
||||
note.body = "$i\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 10 + (i * 2)),
|
||||
body: "$i\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
}
|
||||
await folder.loadRecursively();
|
||||
@ -76,7 +78,7 @@ void main() {
|
||||
);
|
||||
|
||||
var i = sf.notes.indexWhere((n) => n.body == "1\n");
|
||||
sf.notes[i].modified = DateTime(2020, 2, 1);
|
||||
sf.notes[i].apply(modified: DateTime(2020, 2, 1));
|
||||
|
||||
expect(sf.notes[0].body, "1\n");
|
||||
expect(sf.notes[1].body, "4\n");
|
||||
@ -96,8 +98,10 @@ void main() {
|
||||
Note(folder, p.join(folder.folderPath, "new.md"), DateTime.now());
|
||||
folder.add(note);
|
||||
|
||||
note.modified = DateTime(2020, 2, 1);
|
||||
note.body = "new\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 2, 1),
|
||||
body: "new\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
|
||||
expect(sf.notes.length, 6);
|
||||
@ -121,8 +125,10 @@ void main() {
|
||||
Note(folder, p.join(folder.folderPath, "new.md"), DateTime.now());
|
||||
folder.add(note);
|
||||
|
||||
note.modified = DateTime(2020, 1, 1);
|
||||
note.body = "new\n";
|
||||
note.apply(
|
||||
modified: DateTime(2020, 1, 1),
|
||||
body: "new\n",
|
||||
);
|
||||
await NoteStorage().save(note).throwOnError();
|
||||
|
||||
expect(sf.notes.length, 6);
|
||||
|
@ -24,16 +24,13 @@ void main() {
|
||||
test('Created', () async {
|
||||
var folder = NotesFolderFS(null, '/tmp/', config);
|
||||
var n1 = Note(folder, '/tmp/1.md', DateTime.now());
|
||||
n1.created = DateTime(2020, 10, 01);
|
||||
n1.apply(created: DateTime(2020, 10, 01));
|
||||
|
||||
var n2 = Note(folder, '/tmp/2.md', DateTime.now());
|
||||
n2.created = DateTime(2020, 10, 02);
|
||||
n2.apply(created: DateTime(2020, 10, 02));
|
||||
|
||||
var n3 = Note(folder, '/tmp/3.md', DateTime.now());
|
||||
n3.created = null;
|
||||
|
||||
var n4 = Note(folder, '/tmp/4.md', DateTime.now());
|
||||
n4.created = null;
|
||||
|
||||
var notes = [n1, n2, n3, n4];
|
||||
var sortFn = SortingMode(SortingField.Created, SortingOrder.Descending)
|
||||
@ -49,16 +46,13 @@ void main() {
|
||||
test('Modified', () async {
|
||||
var folder = NotesFolderFS(null, '/tmp/', config);
|
||||
var n1 = Note(folder, '/tmp/1.md', DateTime.now());
|
||||
n1.modified = DateTime(2020, 10, 01);
|
||||
n1.apply(modified: DateTime(2020, 10, 01));
|
||||
|
||||
var n2 = Note(folder, '/tmp/2.md', DateTime.now());
|
||||
n2.modified = DateTime(2020, 10, 02);
|
||||
n2.apply(modified: DateTime(2020, 10, 02));
|
||||
|
||||
var n3 = Note(folder, '/tmp/3.md', DateTime.now());
|
||||
n3.modified = null;
|
||||
|
||||
var n4 = Note(folder, '/tmp/4.md', DateTime.now());
|
||||
n4.modified = null;
|
||||
|
||||
var notes = [n1, n2, n3, n4];
|
||||
var sortFn = SortingMode(SortingField.Modified, SortingOrder.Descending)
|
||||
|
Reference in New Issue
Block a user