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