mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 01:45:55 +08:00
Allow the Note FileName to be configured
This is super ugly, but it solves a real use case, and hopefully I'll eventually get around to improving the UI of the Settings page.
This commit is contained in:
@ -1,5 +1,9 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
String toIso8601(DateTime dt) {
|
||||
return DateFormat("yyyy-MM-ddTHH:mm:ss").format(dt);
|
||||
}
|
||||
|
||||
String toIso8601WithTimezone(DateTime dt) {
|
||||
var result = DateFormat("yyyy-MM-ddTHH:mm:ss").format(dt);
|
||||
|
||||
|
16
lib/note_fileName.dart
Normal file
16
lib/note_fileName.dart
Normal file
@ -0,0 +1,16 @@
|
||||
import 'package:journal/note.dart';
|
||||
import 'package:journal/datetime_utils.dart';
|
||||
import 'package:journal/settings.dart';
|
||||
|
||||
String getFileName(Note note) {
|
||||
switch (Settings.instance.noteFileNameFormat) {
|
||||
case NoteFileNameFormat.Iso8601:
|
||||
return toIso8601(note.created) + ".md";
|
||||
case NoteFileNameFormat.Iso8601WithTimeZone:
|
||||
return toIso8601WithTimezone(note.created) + ".md";
|
||||
case NoteFileNameFormat.Iso8601WithTimeZoneWithoutColon:
|
||||
return toIso8601WithTimezone(note.created).replaceAll(":", "_") + ".md";
|
||||
}
|
||||
|
||||
return note.created.toString();
|
||||
}
|
@ -183,6 +183,35 @@ class SettingsListState extends State<SettingsList> {
|
||||
ListTile(title: gitAuthorForm),
|
||||
ListTile(title: gitAuthorEmailForm),
|
||||
SizedBox(height: 16.0),
|
||||
PreferenceTitle("Storage"),
|
||||
DropdownPreference(
|
||||
'File Name',
|
||||
'file_name',
|
||||
defaultVal: "ISO8601 With TimeZone",
|
||||
values: [
|
||||
"ISO8601 With TimeZone",
|
||||
"ISO8601",
|
||||
"ISO8601 without Colons",
|
||||
],
|
||||
onChange: (newVal) {
|
||||
NoteFileNameFormat format;
|
||||
switch (newVal) {
|
||||
case "ISO8601 With TimeZone":
|
||||
format = NoteFileNameFormat.Iso8601WithTimeZone;
|
||||
break;
|
||||
case "ISO8601":
|
||||
format = NoteFileNameFormat.Iso8601;
|
||||
break;
|
||||
case "ISO8601 without Colons":
|
||||
format = NoteFileNameFormat.Iso8601WithTimeZoneWithoutColon;
|
||||
break;
|
||||
default:
|
||||
format = NoteFileNameFormat.Iso8601WithTimeZone;
|
||||
}
|
||||
Settings.instance.noteFileNameFormat = format;
|
||||
Settings.instance.save();
|
||||
},
|
||||
),
|
||||
VersionNumberTile(),
|
||||
]);
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:journal/analytics.dart';
|
||||
import 'package:journal/apis/git_migration.dart';
|
||||
import 'package:journal/appstate.dart';
|
||||
import 'package:journal/datetime_utils.dart';
|
||||
import 'package:journal/note.dart';
|
||||
import 'package:journal/note_fileName.dart';
|
||||
import 'package:journal/storage/git_storage.dart';
|
||||
import 'package:journal/storage/notes_repository.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
@ -217,7 +217,7 @@ class StateContainerState extends State<StateContainer> {
|
||||
Fimber.d("State Container insertNote");
|
||||
setState(() {
|
||||
if (note.filePath == null || note.filePath.isEmpty) {
|
||||
note.filePath = toIso8601WithTimezone(note.created) + '.md';
|
||||
note.filePath = getFileName(note);
|
||||
}
|
||||
appState.notes.insert(index, note);
|
||||
appState.hasJournalEntries = true;
|
||||
|
@ -8,8 +8,6 @@ import 'package:journal/storage/notes_repository.dart';
|
||||
import 'package:journal/storage/serializers.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
typedef String NoteFileNameGenerator(Note note);
|
||||
|
||||
/// Each Note is saved in a different file
|
||||
/// Each note must have a fileName which ends in a .md
|
||||
class FileStorage implements NoteRepository {
|
||||
|
Reference in New Issue
Block a user