mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 02:59:02 +08:00
TagsFolder: Auto add relevant tag to new notes
This commit is contained in:
@ -68,10 +68,17 @@ class Note with NotesNotifier {
|
|||||||
|
|
||||||
Note(this.parent, this._filePath);
|
Note(this.parent, this._filePath);
|
||||||
|
|
||||||
Note.newNote(this.parent) {
|
Note.newNote(this.parent, {Map<String, dynamic> extraProps = const {}}) {
|
||||||
created = DateTime.now();
|
created = DateTime.now();
|
||||||
_loadState = NoteLoadState.Loaded;
|
_loadState = NoteLoadState.Loaded;
|
||||||
_fileFormat = NoteFileFormat.Markdown;
|
_fileFormat = NoteFileFormat.Markdown;
|
||||||
|
|
||||||
|
if (extraProps.isNotEmpty) {
|
||||||
|
extraProps.forEach((key, value) {
|
||||||
|
_data.props[key] = value;
|
||||||
|
});
|
||||||
|
noteSerializer.decode(_data, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String get filePath {
|
String get filePath {
|
||||||
|
@ -106,9 +106,15 @@ class NoteSerializer implements NoteSerializerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var tags = data.props[settings.tagsKey] as YamlList;
|
var tags = data.props[settings.tagsKey];
|
||||||
if (tags != null) {
|
if (tags != null) {
|
||||||
note.tags = tags.map((t) => t.toString()).toSet();
|
if (tags is YamlList) {
|
||||||
|
note.tags = tags.map((t) => t.toString()).toSet();
|
||||||
|
} else if (tags is List) {
|
||||||
|
note.tags = tags.map((t) => t.toString()).toSet();
|
||||||
|
} else {
|
||||||
|
Log.e("Note Tags Decoding Failed: $tags");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log.e("Note Decoding Failed: $e");
|
Log.e("Note Decoding Failed: $e");
|
||||||
|
@ -28,8 +28,12 @@ enum DropDownChoices {
|
|||||||
|
|
||||||
class FolderView extends StatefulWidget {
|
class FolderView extends StatefulWidget {
|
||||||
final NotesFolder notesFolder;
|
final NotesFolder notesFolder;
|
||||||
|
final Map<String, dynamic> newNoteExtraProps;
|
||||||
|
|
||||||
FolderView({@required this.notesFolder});
|
FolderView({
|
||||||
|
@required this.notesFolder,
|
||||||
|
this.newNoteExtraProps = const {},
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_FolderViewState createState() => _FolderViewState();
|
_FolderViewState createState() => _FolderViewState();
|
||||||
@ -211,7 +215,11 @@ class _FolderViewState extends State<FolderView> {
|
|||||||
var routeType =
|
var routeType =
|
||||||
SettingsEditorType.fromEditorType(editorType).toInternalString();
|
SettingsEditorType.fromEditorType(editorType).toInternalString();
|
||||||
var route = MaterialPageRoute(
|
var route = MaterialPageRoute(
|
||||||
builder: (context) => NoteEditor.newNote(fsFolder, editorType),
|
builder: (context) => NoteEditor.newNote(
|
||||||
|
fsFolder,
|
||||||
|
editorType,
|
||||||
|
newNoteExtraProps: widget.newNoteExtraProps,
|
||||||
|
),
|
||||||
settings: RouteSettings(name: '/newNote/$routeType'),
|
settings: RouteSettings(name: '/newNote/$routeType'),
|
||||||
);
|
);
|
||||||
await Navigator.of(context).push(route);
|
await Navigator.of(context).push(route);
|
||||||
|
@ -29,23 +29,32 @@ class NoteEditor extends StatefulWidget {
|
|||||||
final String existingText;
|
final String existingText;
|
||||||
final List<String> existingImages;
|
final List<String> existingImages;
|
||||||
|
|
||||||
|
final Map<String, dynamic> newNoteExtraProps;
|
||||||
|
|
||||||
NoteEditor.fromNote(this.note)
|
NoteEditor.fromNote(this.note)
|
||||||
: notesFolder = note.parent,
|
: notesFolder = note.parent,
|
||||||
defaultEditorType = null,
|
defaultEditorType = null,
|
||||||
existingText = null,
|
existingText = null,
|
||||||
existingImages = null;
|
existingImages = null,
|
||||||
|
newNoteExtraProps = null;
|
||||||
|
|
||||||
NoteEditor.newNote(
|
NoteEditor.newNote(
|
||||||
this.notesFolder,
|
this.notesFolder,
|
||||||
this.defaultEditorType, {
|
this.defaultEditorType, {
|
||||||
this.existingText,
|
this.existingText,
|
||||||
this.existingImages,
|
this.existingImages,
|
||||||
|
this.newNoteExtraProps = const {},
|
||||||
}) : note = null;
|
}) : note = null;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
NoteEditorState createState() {
|
NoteEditorState createState() {
|
||||||
if (note == null) {
|
if (note == null) {
|
||||||
return NoteEditorState.newNote(notesFolder, existingText, existingImages);
|
return NoteEditorState.newNote(
|
||||||
|
notesFolder,
|
||||||
|
existingText,
|
||||||
|
existingImages,
|
||||||
|
newNoteExtraProps,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return NoteEditorState.fromNote(note);
|
return NoteEditorState.fromNote(note);
|
||||||
}
|
}
|
||||||
@ -72,8 +81,9 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
NotesFolderFS folder,
|
NotesFolderFS folder,
|
||||||
String existingText,
|
String existingText,
|
||||||
List<String> existingImages,
|
List<String> existingImages,
|
||||||
|
Map<String, dynamic> extraProps,
|
||||||
) {
|
) {
|
||||||
note = Note.newNote(folder);
|
note = Note.newNote(folder, extraProps: extraProps);
|
||||||
if (existingText != null) {
|
if (existingText != null) {
|
||||||
note.body = existingText;
|
note.body = existingText;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:gitjournal/core/flattened_notes_folder.dart';
|
import 'package:gitjournal/core/flattened_notes_folder.dart';
|
||||||
import 'package:gitjournal/core/note.dart';
|
import 'package:gitjournal/core/note.dart';
|
||||||
|
import 'package:gitjournal/core/note_serializer.dart';
|
||||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||||
import 'package:gitjournal/screens/folder_view.dart';
|
import 'package:gitjournal/screens/folder_view.dart';
|
||||||
import 'package:gitjournal/widgets/app_bar_menu_button.dart';
|
import 'package:gitjournal/widgets/app_bar_menu_button.dart';
|
||||||
@ -52,7 +53,13 @@ class TagListingScreen extends StatelessWidget {
|
|||||||
title: tag,
|
title: tag,
|
||||||
);
|
);
|
||||||
|
|
||||||
return FolderView(notesFolder: folder);
|
final propNames = NoteSerializationSettings();
|
||||||
|
return FolderView(
|
||||||
|
notesFolder: folder,
|
||||||
|
newNoteExtraProps: {
|
||||||
|
propNames.tagsKey: [tag],
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
settings: const RouteSettings(name: '/tags/'),
|
settings: const RouteSettings(name: '/tags/'),
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user