mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-01 12:23:44 +08:00
Add a 'type' to each Note
This way we can load the appropirate editor according to the types available.
This commit is contained in:
@ -20,6 +20,12 @@ enum NoteLoadState {
|
||||
NotExists,
|
||||
}
|
||||
|
||||
enum NoteType {
|
||||
Unknown,
|
||||
Checklist,
|
||||
Journal,
|
||||
}
|
||||
|
||||
class Note with NotesNotifier {
|
||||
NotesFolderFS parent;
|
||||
String _filePath;
|
||||
@ -28,6 +34,8 @@ class Note with NotesNotifier {
|
||||
DateTime _created;
|
||||
DateTime _modified;
|
||||
String _body = "";
|
||||
NoteType _type = NoteType.Unknown;
|
||||
|
||||
MdYamlDoc _data = MdYamlDoc();
|
||||
NoteSerializer noteSerializer = NoteSerializer();
|
||||
|
||||
@ -104,6 +112,17 @@ class Note with NotesNotifier {
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
NoteType get type {
|
||||
return _type;
|
||||
}
|
||||
|
||||
set type(NoteType type) {
|
||||
if (!canHaveMetadata) return;
|
||||
|
||||
_type = type;
|
||||
_notifyModified();
|
||||
}
|
||||
|
||||
bool get canHaveMetadata {
|
||||
return Settings.instance.yamlHeaderEnabled;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ class NoteSerializationSettings {
|
||||
String modifiedKey = Settings.instance.yamlModifiedKey;
|
||||
String createdKey = "created";
|
||||
String titleKey = "title";
|
||||
String typeKey = "type";
|
||||
}
|
||||
|
||||
class NoteSerializer implements NoteSerializerInterface {
|
||||
@ -46,6 +47,13 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
data.props.remove(settings.titleKey);
|
||||
}
|
||||
|
||||
if (note.type != NoteType.Unknown) {
|
||||
var type = note.type.toString().substring(9); // Remove "NoteType."
|
||||
data.props[settings.typeKey] = type;
|
||||
} else {
|
||||
data.props.remove(settings.typeKey);
|
||||
}
|
||||
|
||||
data.body = emojiParser.unemojify(note.body);
|
||||
}
|
||||
|
||||
@ -74,5 +82,18 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
|
||||
var title = data.props[settings.titleKey]?.toString() ?? "";
|
||||
note.title = emojiParser.emojify(title);
|
||||
|
||||
var type = data.props[settings.typeKey];
|
||||
switch (type) {
|
||||
case "Checklist":
|
||||
note.type = NoteType.Checklist;
|
||||
break;
|
||||
case "Journal":
|
||||
note.type = NoteType.Journal;
|
||||
break;
|
||||
default:
|
||||
note.type = NoteType.Unknown;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,6 +134,7 @@ class ChecklistEditorState extends State<ChecklistEditor>
|
||||
Note getNote() {
|
||||
var note = checklist.note;
|
||||
note.title = _titleTextController.text.trim();
|
||||
note.type = NoteType.Checklist;
|
||||
return note;
|
||||
}
|
||||
|
||||
|
@ -77,13 +77,10 @@ class JournalEditorState extends State<JournalEditor> implements EditorState {
|
||||
);
|
||||
}
|
||||
|
||||
void _updateNote() {
|
||||
note.body = _textController.text.trim();
|
||||
}
|
||||
|
||||
@override
|
||||
Note getNote() {
|
||||
_updateNote();
|
||||
note.body = _textController.text.trim();
|
||||
note.type = NoteType.Journal;
|
||||
return note;
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ class MarkdownEditorState extends State<MarkdownEditor> implements EditorState {
|
||||
void _updateNote() {
|
||||
note.title = _titleTextController.text.trim();
|
||||
note.body = _textController.text.trim();
|
||||
note.type = NoteType.Unknown;
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -5,7 +5,6 @@ import 'package:gitjournal/core/notes_folder.dart';
|
||||
import 'package:gitjournal/folder_views/card_view.dart';
|
||||
import 'package:gitjournal/folder_views/journal_view.dart';
|
||||
import 'package:gitjournal/screens/note_editor.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
import 'package:gitjournal/utils.dart';
|
||||
|
||||
import 'standard_view.dart';
|
||||
@ -26,10 +25,7 @@ Widget buildFolderView(
|
||||
) {
|
||||
var noteSelectionFn = (Note note) async {
|
||||
var route = MaterialPageRoute(
|
||||
builder: (context) => NoteEditor.fromNote(
|
||||
note,
|
||||
Settings.instance.defaultEditor.toEditorType(),
|
||||
),
|
||||
builder: (context) => NoteEditor.fromNote(note),
|
||||
);
|
||||
var showUndoSnackBar = await Navigator.of(context).push(route);
|
||||
if (showUndoSnackBar != null) {
|
||||
|
@ -7,6 +7,7 @@ import 'package:gitjournal/editors/journal_editor.dart';
|
||||
import 'package:gitjournal/editors/markdown_editor.dart';
|
||||
import 'package:gitjournal/editors/raw_editor.dart';
|
||||
import 'package:gitjournal/editors/checklist_editor.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
import 'package:gitjournal/state_container.dart';
|
||||
import 'package:gitjournal/widgets/folder_selection_dialog.dart';
|
||||
import 'package:gitjournal/widgets/rename_dialog.dart';
|
||||
@ -19,7 +20,9 @@ class NoteEditor extends StatefulWidget {
|
||||
final NotesFolder notesFolder;
|
||||
final EditorType defaultEditorType;
|
||||
|
||||
NoteEditor.fromNote(this.note, this.defaultEditorType) : notesFolder = null;
|
||||
NoteEditor.fromNote(this.note)
|
||||
: notesFolder = null,
|
||||
defaultEditorType = null;
|
||||
NoteEditor.newNote(this.notesFolder, this.defaultEditorType) : note = null;
|
||||
|
||||
@override
|
||||
@ -59,7 +62,21 @@ class NoteEditorState extends State<NoteEditor> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
editorType = widget.defaultEditorType;
|
||||
if (widget.defaultEditorType != null) {
|
||||
editorType = widget.defaultEditorType;
|
||||
} else {
|
||||
switch (note.type) {
|
||||
case NoteType.Journal:
|
||||
editorType = EditorType.Journal;
|
||||
break;
|
||||
case NoteType.Checklist:
|
||||
editorType = EditorType.Checklist;
|
||||
break;
|
||||
case NoteType.Unknown:
|
||||
editorType = Settings.instance.defaultEditor.toEditorType();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
Reference in New Issue
Block a user