Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/common/actions/notes/delete.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '../../constants/constants.dart';
import '../../dialogs/confirmation_dialog.dart';
import '../../extensions/build_context_extension.dart';
import '../../ui/snack_bar_utils.dart';
import 'archive.dart';
import 'restore.dart';
import 'select.dart';

Expand Down Expand Up @@ -50,7 +49,7 @@ Future<bool> deleteNote(
context,
text: context.l.snack_bar_deleted(1),
onCancel: (globalRef) async => wasArchived
? await archiveNote(rootNavigatorKey.currentContext!, globalRef, note: note, cancel: false)
? await _restoreArchivedNotes(globalRef, [note])
: await restoreNote(rootNavigatorKey.currentContext!, globalRef, note: note, cancel: false),
);
}
Expand Down Expand Up @@ -86,14 +85,25 @@ Future<bool> deleteNotes(BuildContext context, WidgetRef ref, {required List<Not
context,
text: context.l.snack_bar_deleted(notes.length),
onCancel: (globalRef) async => wereArchived
? await archiveNotes(rootNavigatorKey.currentContext!, globalRef, notes: notes, cancel: false)
? await _restoreArchivedNotes(globalRef, notes)
: await restoreNotes(rootNavigatorKey.currentContext!, globalRef, notes: notes, cancel: false),
);
}

return succeeded;
}

/// Moves the deleted [notes] back to the archives, to cancel their deletion.
///
/// The notes are deleted, so they are first restored from the bin, then archived again, without confirmation.
Future<bool> _restoreArchivedNotes(WidgetRef ref, List<Note> notes) async {
if (!await ref.read(notesProvider(status: NoteStatus.deleted).notifier).setDeleted(notes, false)) {
return false;
}

return ref.read(notesProvider(status: NoteStatus.available).notifier).setArchived(notes, true);
}

/// Permanently deletes the [note].
///
/// Returns `true` if the [note] was permanently deleted, `false` otherwise.
Expand Down
3 changes: 3 additions & 0 deletions lib/common/navigation/app_bars/notes/editor_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class _BackAppBarState extends ConsumerState<EditorAppBar> {
await selectLabels(context, ref, note: note);
case EditorArchivedMenuOption.unarchive:
await unarchiveNote(context, ref, note: note, pop: true);
case EditorArchivedMenuOption.delete:
await deleteNote(context, ref, note: note, pop: true);
case EditorArchivedMenuOption.about:
await showAboutNote();
}
Expand Down Expand Up @@ -221,6 +223,7 @@ class _BackAppBarState extends ConsumerState<EditorAppBar> {
EditorArchivedMenuOption.share.popupMenuItem(context),
const PopupMenuDivider(),
EditorArchivedMenuOption.unarchive.popupMenuItem(context),
EditorArchivedMenuOption.delete.popupMenuItem(context),
const PopupMenuDivider(),
EditorArchivedMenuOption.about.popupMenuItem(context),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class NotesSelectionAppBar extends ConsumerWidget {
await shareNotes(context, notes: notes);
case SelectionArchivedMenuOption.unarchive:
await unarchiveNotes(context, ref, notes: notes);
case SelectionArchivedMenuOption.delete:
await deleteNotes(context, ref, notes: notes);
}
}

Expand Down Expand Up @@ -136,6 +138,7 @@ class NotesSelectionAppBar extends ConsumerWidget {
SelectionArchivedMenuOption.share.popupMenuItem(context),
const PopupMenuDivider(),
SelectionArchivedMenuOption.unarchive.popupMenuItem(context),
SelectionArchivedMenuOption.delete.popupMenuItem(context),
]),
onSelected: (menuOption) => onArchivedMenuOptionSelected(context, ref, selectedNotes, menuOption),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ enum EditorArchivedMenuOption {
/// Unarchive the note.
unarchive(Icons.unarchive),

/// Delete the note.
delete(Icons.delete),

/// Show information about the note.
about(Icons.info);

Expand All @@ -36,6 +39,8 @@ enum EditorArchivedMenuOption {
return context.l.menu_action_select_labels;
case unarchive:
return context.l.action_unarchive;
case delete:
return context.l.action_delete;
case about:
return context.l.action_about;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ enum SelectionArchivedMenuOption {
share(Icons.share),

/// Unarchive the note.
unarchive(Icons.unarchive);
unarchive(Icons.unarchive),

/// Delete the notes.
delete(Icons.delete);

/// Icon of the menu option.
final IconData icon;
Expand All @@ -30,6 +33,8 @@ enum SelectionArchivedMenuOption {
return context.fl.shareButtonLabel;
case unarchive:
return context.l.action_unarchive;
case delete:
return context.l.action_delete;
}
}

Expand Down
Loading