mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 19:36:25 +08:00
Move Note Delete dialog to its own file
+ translate
This commit is contained in:
@ -222,7 +222,10 @@ widgets:
|
|||||||
sortingOptions: Sorting Options
|
sortingOptions: Sorting Options
|
||||||
viewOptions: View Options
|
viewOptions: View Options
|
||||||
searchFailed: No Search Results Found
|
searchFailed: No Search Results Found
|
||||||
|
NoteDeleteDialog:
|
||||||
|
title: Do you want to delete this note?
|
||||||
|
yes: Delete
|
||||||
|
no: No
|
||||||
|
|
||||||
rootFolder: Root Folder
|
rootFolder: Root Folder
|
||||||
ignoredFiles:
|
ignoredFiles:
|
||||||
|
@ -20,6 +20,7 @@ import 'package:gitjournal/state_container.dart';
|
|||||||
import 'package:gitjournal/utils.dart';
|
import 'package:gitjournal/utils.dart';
|
||||||
import 'package:gitjournal/utils/logger.dart';
|
import 'package:gitjournal/utils/logger.dart';
|
||||||
import 'package:gitjournal/widgets/folder_selection_dialog.dart';
|
import 'package:gitjournal/widgets/folder_selection_dialog.dart';
|
||||||
|
import 'package:gitjournal/widgets/note_delete_dialog.dart';
|
||||||
import 'package:gitjournal/widgets/note_editor_selector.dart';
|
import 'package:gitjournal/widgets/note_editor_selector.dart';
|
||||||
import 'package:gitjournal/widgets/note_tag_editor.dart';
|
import 'package:gitjournal/widgets/note_tag_editor.dart';
|
||||||
import 'package:gitjournal/widgets/rename_dialog.dart';
|
import 'package:gitjournal/widgets/rename_dialog.dart';
|
||||||
@ -256,13 +257,25 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _noteDeletionSelected(Note note) {
|
void _noteDeletionSelected(Note note) async {
|
||||||
if (_isNewNote && !_noteModified(note)) {
|
if (_isNewNote && !_noteModified(note)) {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
showDialog(context: context, builder: _buildAlertDialog);
|
var shouldDelete = await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => NoteDeleteDialog(),
|
||||||
|
);
|
||||||
|
if (shouldDelete == true) {
|
||||||
|
_deleteNote(note);
|
||||||
|
|
||||||
|
if (_isNewNote) {
|
||||||
|
Navigator.pop(context); // Note Editor
|
||||||
|
} else {
|
||||||
|
Navigator.pop(context, ShowUndoSnackbar()); // Note Editor
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _deleteNote(Note note) {
|
void _deleteNote(Note note) {
|
||||||
@ -274,32 +287,6 @@ class NoteEditorState extends State<NoteEditor> {
|
|||||||
stateContainer.removeNote(note);
|
stateContainer.removeNote(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildAlertDialog(BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('Do you want to delete this note?'),
|
|
||||||
actions: <Widget>[
|
|
||||||
FlatButton(
|
|
||||||
onPressed: () => Navigator.of(context).pop(false),
|
|
||||||
child: const Text('Keep Writing'),
|
|
||||||
),
|
|
||||||
FlatButton(
|
|
||||||
onPressed: () {
|
|
||||||
_deleteNote(note);
|
|
||||||
|
|
||||||
Navigator.pop(context); // Alert box
|
|
||||||
|
|
||||||
if (_isNewNote) {
|
|
||||||
Navigator.pop(context); // Note Editor
|
|
||||||
} else {
|
|
||||||
Navigator.pop(context, ShowUndoSnackbar()); // Note Editor
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: const Text('Delete'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _noteModified(Note note) {
|
bool _noteModified(Note note) {
|
||||||
if (_isNewNote) {
|
if (_isNewNote) {
|
||||||
return note.title.isNotEmpty || note.body.isNotEmpty;
|
return note.title.isNotEmpty || note.body.isNotEmpty;
|
||||||
|
22
lib/widgets/note_delete_dialog.dart
Normal file
22
lib/widgets/note_delete_dialog.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
|
class NoteDeleteDialog extends StatelessWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(tr('widgets.NoteDeleteDialog.title')),
|
||||||
|
actions: <Widget>[
|
||||||
|
FlatButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(false),
|
||||||
|
child: Text(tr('widgets.NoteDeleteDialog.no')),
|
||||||
|
),
|
||||||
|
FlatButton(
|
||||||
|
onPressed: () => Navigator.of(context).pop(true),
|
||||||
|
child: Text(tr('widgets.NoteDeleteDialog.yes')),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user