diff --git a/CHANGELOG.md b/CHANGELOG.md index ec2474b..64e6ba6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 1.3.0 + +- Added feature to create a new note by sharing text with Noteless (#42) +- Adding an attachment to a note now automatically embeds it +- Improved blockquote styling (#44) +- Fixed some bugs + ## 1.2.1 - Added Android App Shortcut for creating a new note from the homescreen diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 816dca4..7ac434b 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -21,7 +21,7 @@ android:icon="@mipmap/ic_launcher"> - + diff --git a/lib/page/edit.dart b/lib/page/edit.dart index 59b3c36..069c641 100644 --- a/lib/page/edit.dart +++ b/lib/page/edit.dart @@ -48,6 +48,8 @@ class _EditPageState extends State { bool _previewEnabled = false; + TextSelection _textSelectionCache; + @override void initState() { note = widget.note; @@ -240,7 +242,12 @@ class _EditPageState extends State { }, )), PopupMenuButton( + onCanceled: () { + _rec.selection = _textSelectionCache; + }, onSelected: (String result) async { + _rec.selection = _textSelectionCache; + int divIndex = result.indexOf('.'); if (divIndex == -1) divIndex = result.length; @@ -279,9 +286,28 @@ class _EditPageState extends State { } await file.copy(newFile.path); - note.attachments.add(newFile.path.split('/').last); + final attachmentName = newFile.path.split('/').last; + + note.attachments.add(attachmentName); await file.delete(); + + int start = _rec.selection.start; + + final insert = '![](@attachment/$attachmentName)'; + + _rec.text = _rec.text.substring( + 0, + start, + ) + + insert + + _rec.text.substring( + start, + ); + + _rec.selection = TextSelection( + baseOffset: start, + extentOffset: start + insert.length); } break; @@ -388,100 +414,105 @@ class _EditPageState extends State { } PersistentStore.saveNote(note); }, - itemBuilder: (BuildContext context) => >[ - PopupMenuItem( - value: 'favorite', - child: Row( - children: [ - Icon( - note.favorited ? MdiIcons.starOff : MdiIcons.star, - color: Theme.of(context).colorScheme.onSurface, - ), - SizedBox( - width: 8, - ), - Text(note.favorited ? 'Unfavorite' : 'Favorite'), - ], - ), - ), - PopupMenuItem( - value: 'pin', - child: Row( - children: [ - Icon( - note.pinned ? MdiIcons.pinOff : MdiIcons.pin, - color: Theme.of(context).colorScheme.onSurface, - ), - SizedBox( - width: 8, - ), - Text(note.pinned ? 'Unpin' : 'Pin'), - ], + itemBuilder: (BuildContext context) { + _textSelectionCache = _rec.selection; + return >[ + PopupMenuItem( + value: 'favorite', + child: Row( + children: [ + Icon( + note.favorited ? MdiIcons.starOff : MdiIcons.star, + color: Theme.of(context).colorScheme.onSurface, + ), + SizedBox( + width: 8, + ), + Text(note.favorited ? 'Unfavorite' : 'Favorite'), + ], + ), ), - ), - for (String attachment in note.attachments) PopupMenuItem( - value: 'removeAttachment.$attachment', + value: 'pin', child: Row( children: [ Icon( - MdiIcons.paperclip, + note.pinned ? MdiIcons.pinOff : MdiIcons.pin, color: Theme.of(context).colorScheme.onSurface, ), SizedBox( width: 8, ), - Text(attachment), + Text(note.pinned ? 'Unpin' : 'Pin'), ], ), ), - PopupMenuItem( - value: 'addAttachment', - child: Row( - children: [ - Icon( - MdiIcons.filePlus, - color: Theme.of(context).colorScheme.onSurface, - ), - SizedBox( - width: 8, + for (String attachment in note.attachments) + PopupMenuItem( + value: 'removeAttachment.$attachment', + child: Row( + children: [ + Icon( + MdiIcons.paperclip, + color: Theme.of(context).colorScheme.onSurface, + ), + SizedBox( + width: 8, + ), + Flexible( + child: Text(attachment), + ), + ], ), - Text('Add Attachment'), - ], - ), - ), - for (String tag in note.tags) + ), PopupMenuItem( - value: 'removeTag.$tag', + value: 'addAttachment', child: Row( children: [ Icon( - MdiIcons.tag, + MdiIcons.filePlus, color: Theme.of(context).colorScheme.onSurface, ), SizedBox( width: 8, ), - Text(tag), + Text('Add Attachment'), ], ), ), - PopupMenuItem( - value: 'addTag', - child: Row( - children: [ - Icon( - MdiIcons.tagPlus, - color: Theme.of(context).colorScheme.onSurface, - ), - SizedBox( - width: 8, + for (String tag in note.tags) + PopupMenuItem( + value: 'removeTag.$tag', + child: Row( + children: [ + Icon( + MdiIcons.tag, + color: Theme.of(context).colorScheme.onSurface, + ), + SizedBox( + width: 8, + ), + Text(tag), + ], ), - Text('Add Tag'), - ], + ), + PopupMenuItem( + value: 'addTag', + child: Row( + children: [ + Icon( + MdiIcons.tagPlus, + color: Theme.of(context).colorScheme.onSurface, + ), + SizedBox( + width: 8, + ), + Text('Add Tag'), + ], + ), ), - ), - ], + ]; + }, ) ], ), diff --git a/lib/page/note_list.dart b/lib/page/note_list.dart index 612746a..57c6178 100644 --- a/lib/page/note_list.dart +++ b/lib/page/note_list.dart @@ -12,6 +12,7 @@ import 'package:package_info/package_info.dart'; import 'package:preferences/preferences.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:quick_actions/quick_actions.dart'; +import 'package:receive_sharing_intent/receive_sharing_intent.dart'; // import 'package:receive_sharing_intent/receive_sharing_intent.dart'; import 'about.dart'; @@ -33,7 +34,7 @@ class _NoteListPageState extends State { TextEditingController _searchFieldCtrl = TextEditingController(); bool searching = false; - // StreamSubscription _intentDataStreamSubscription; + StreamSubscription _intentDataStreamSubscription; @override void initState() { @@ -62,10 +63,10 @@ class _NoteListPageState extends State { icon: 'ic_shortcut_add'), ]); -/* // For sharing or opening urls/text coming from outside the app while the app is in the memory + // For sharing or opening urls/text coming from outside the app while the app is in the memory _intentDataStreamSubscription = ReceiveSharingIntent.getTextStream().listen((String value) { - print('SHARED $value'); + handleSharedText(value); ReceiveSharingIntent.reset(); }, onError: (err) { print("getLinkStream error: $err"); @@ -73,9 +74,9 @@ class _NoteListPageState extends State { // For sharing or opening urls/text coming from outside the app while the app is closed ReceiveSharingIntent.getInitialText().then((String value) { - print('SHARED $value'); + handleSharedText(value); ReceiveSharingIntent.reset(); - }); */ + }); } }); @@ -84,10 +85,36 @@ class _NoteListPageState extends State { @override void dispose() { - // _intentDataStreamSubscription.cancel(); + _intentDataStreamSubscription.cancel(); super.dispose(); } + handleSharedText(String value) { + if (value == null) return; + + showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text('Received text'), + content: + Scrollbar(child: SingleChildScrollView(child: Text(value))), + actions: [ + FlatButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text('Cancel')), + // FlatButton(onPressed: () {}, child: Text('Append to note')), + FlatButton( + onPressed: () { + Navigator.of(context).pop(); + createNewNote(value); + }, + child: Text('Create new note')), + ], + )); + } + Future _onWillPop() async { if (_selectedNotes.isNotEmpty) { setState(() { @@ -953,7 +980,7 @@ class _NoteListPageState extends State { ); } - Future createNewNote() async { + Future createNewNote([String content = '']) async { Note newNote = Note(); int i = 1; while (true) { @@ -986,7 +1013,7 @@ class _NoteListPageState extends State { _filterAndSortNotes(); - await PersistentStore.saveNote(newNote, '# ${newNote.title}\n\n'); + await PersistentStore.saveNote(newNote, '# ${newNote.title}\n\n$content'); await Navigator.of(context).push(MaterialPageRoute( builder: (context) => EditPage( diff --git a/lib/page/preview.dart b/lib/page/preview.dart index adb4723..e22eff1 100644 --- a/lib/page/preview.dart +++ b/lib/page/preview.dart @@ -185,6 +185,14 @@ pre { max-width: 100%; overflow-x: scroll; } + +blockquote{ + padding: 0em 0em 0em .6em; + margin-left: .1em; + border-left: 0.3em solid ${theme.brightness == Brightness.light ? 'lightgrey' : 'grey'}; +} + + diff --git a/pubspec.lock b/pubspec.lock index 26eb03c..2aa13b8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -384,6 +384,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.3" + receive_sharing_intent: + dependency: "direct main" + description: + name: receive_sharing_intent + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.1" rich_code_editor: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 8df1311..cc7ac97 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A markdown note-taking app for mobile devices. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.2.1+121 +version: 1.3.0+130 environment: sdk: ">=2.5.0 <3.0.0" @@ -47,7 +47,7 @@ dependencies: git: https://github.com/redsolver/rich_code_editor.git device_info: ">=0.4.2+4 <2.0.0" quick_actions: ^0.4.0+8 - # receive_sharing_intent: ^1.4.1 + receive_sharing_intent: ^1.4.1 dev_dependencies: flutter_launcher_icons: ^0.7.3