Allow Delete dialogs to be configured

Fixes #330
This commit is contained in:
Vishesh Handa
2020-11-18 13:01:33 +01:00
parent a9f3001798
commit e87a096c7d
5 changed files with 31 additions and 8 deletions

View File

@ -110,6 +110,7 @@ settings:
title: Misc Settings
swipe: Swipe to Delete Note
listView: List View
confirmDelete: Show a Popup to Confirm Deletes
NoteFileNameFormat:
iso8601WithTimeZone: ISO8601 With TimeZone
iso8601: ISO8601

View File

@ -485,10 +485,14 @@ class _FolderViewState extends State<FolderView> {
void _deleteNote() async {
var note = selectedNote;
var shouldDelete = await showDialog(
context: context,
builder: (context) => NoteDeleteDialog(),
);
var settings = Provider.of<Settings>(context, listen: false);
var shouldDelete = true;
if (settings.confirmDelete) {
shouldDelete = await showDialog(
context: context,
builder: (context) => NoteDeleteDialog(),
);
}
if (shouldDelete == true) {
var stateContainer = Provider.of<Repository>(context, listen: false);
stateContainer.removeNote(note);

View File

@ -17,6 +17,7 @@ import 'package:gitjournal/editors/markdown_editor.dart';
import 'package:gitjournal/editors/raw_editor.dart';
import 'package:gitjournal/error_reporting.dart';
import 'package:gitjournal/repository.dart';
import 'package:gitjournal/settings.dart';
import 'package:gitjournal/utils.dart';
import 'package:gitjournal/utils/logger.dart';
import 'package:gitjournal/widgets/folder_selection_dialog.dart';
@ -293,10 +294,14 @@ class NoteEditorState extends State<NoteEditor> with WidgetsBindingObserver {
return;
}
var shouldDelete = await showDialog(
context: context,
builder: (context) => NoteDeleteDialog(),
);
var settings = Provider.of<Settings>(context, listen: false);
var shouldDelete = true;
if (settings.confirmDelete) {
shouldDelete = await showDialog(
context: context,
builder: (context) => NoteDeleteDialog(),
);
}
if (shouldDelete == true) {
_deleteNote(note);

View File

@ -27,6 +27,14 @@ class _SettingsMiscState extends State<SettingsMisc> {
settings.save();
},
),
SwitchListTile(
title: Text(tr('settings.misc.confirmDelete')),
value: settings.confirmDelete,
onChanged: (bool newVal) {
settings.confirmDelete = newVal;
settings.save();
},
),
],
crossAxisAlignment: CrossAxisAlignment.start,
);

View File

@ -65,6 +65,7 @@ class Settings extends ChangeNotifier {
Set<String> inlineTagPrefixes = {'#'};
bool bottomMenuBar = true;
bool confirmDelete = true;
bool storeInternally = true;
String storageLocation = "";
@ -145,6 +146,7 @@ class Settings extends ChangeNotifier {
sshPassword = _getString(pref, "sshPassword") ?? sshPassword;
bottomMenuBar = _getBool(pref, "bottomMenuBar") ?? bottomMenuBar;
confirmDelete = _getBool(pref, "confirmDelete") ?? confirmDelete;
storeInternally = _getBool(pref, "storeInternally") ?? storeInternally;
storageLocation = _getString(pref, "storageLocation") ?? "";
}
@ -241,6 +243,8 @@ class Settings extends ChangeNotifier {
defaultSet.inlineTagPrefixes);
await _setBool(
pref, "bottomMenuBar", bottomMenuBar, defaultSet.bottomMenuBar);
await _setBool(
pref, "confirmDelete", confirmDelete, defaultSet.confirmDelete);
await _setBool(
pref, "storeInternally", storeInternally, defaultSet.storeInternally);
await _setString(
@ -353,6 +357,7 @@ class Settings extends ChangeNotifier {
'emojiParser': emojiParser.toString(),
'folderName': folderName.toString(),
'bottomMenuBar': bottomMenuBar.toString(),
'confirmDelete': confirmDelete.toString(),
'storeInternally': storeInternally.toString(),
'storageLocation': storageLocation,
'sshPublicKey': sshPublicKey.isNotEmpty.toString(),