|
@@ -79,8 +79,10 @@ class _ChangeCoverPopoverState extends State<ChangeCoverPopover> {
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider(
|
|
return BlocProvider(
|
|
- create: (context) => ChangeCoverPopoverBloc()
|
|
|
|
- ..add(const ChangeCoverPopoverEvent.fetchPickedImagePaths()),
|
|
|
|
|
|
+ create: (context) => ChangeCoverPopoverBloc(
|
|
|
|
+ editorState: widget.editorState,
|
|
|
|
+ node: widget.node,
|
|
|
|
+ )..add(const ChangeCoverPopoverEvent.fetchPickedImagePaths()),
|
|
child: BlocBuilder<ChangeCoverPopoverBloc, ChangeCoverPopoverState>(
|
|
child: BlocBuilder<ChangeCoverPopoverBloc, ChangeCoverPopoverState>(
|
|
builder: (context, state) {
|
|
builder: (context, state) {
|
|
return Padding(
|
|
return Padding(
|
|
@@ -149,10 +151,31 @@ class _ChangeCoverPopoverState extends State<ChangeCoverPopover> {
|
|
hoverColor: Theme.of(context).colorScheme.secondaryContainer,
|
|
hoverColor: Theme.of(context).colorScheme.secondaryContainer,
|
|
LocaleKeys.document_plugins_cover_clearAll.tr(),
|
|
LocaleKeys.document_plugins_cover_clearAll.tr(),
|
|
fontColor: Theme.of(context).colorScheme.tertiary,
|
|
fontColor: Theme.of(context).colorScheme.tertiary,
|
|
- onPressed: () {
|
|
|
|
- context
|
|
|
|
- .read<ChangeCoverPopoverBloc>()
|
|
|
|
- .add(const ChangeCoverPopoverEvent.clearAllImages());
|
|
|
|
|
|
+ onPressed: () async {
|
|
|
|
+ final hasFileImageCover = CoverSelectionType.fromString(
|
|
|
|
+ widget.node.attributes[kCoverSelectionTypeAttribute],
|
|
|
|
+ ) ==
|
|
|
|
+ CoverSelectionType.file;
|
|
|
|
+ final changeCoverBloc = context.read<ChangeCoverPopoverBloc>();
|
|
|
|
+ if (hasFileImageCover) {
|
|
|
|
+ await showDialog(
|
|
|
|
+ context: context,
|
|
|
|
+ builder: (context) {
|
|
|
|
+ return DeleteImageAlertDialog(
|
|
|
|
+ onSubmit: () {
|
|
|
|
+ changeCoverBloc.add(
|
|
|
|
+ const ChangeCoverPopoverEvent.clearAllImages(),
|
|
|
|
+ );
|
|
|
|
+ Navigator.pop(context);
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ context
|
|
|
|
+ .read<ChangeCoverPopoverBloc>()
|
|
|
|
+ .add(const ChangeCoverPopoverEvent.clearAllImages());
|
|
|
|
+ }
|
|
},
|
|
},
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
),
|
|
),
|
|
@@ -263,6 +286,32 @@ class _ChangeCoverPopoverState extends State<ChangeCoverPopover> {
|
|
images[index - 1],
|
|
images[index - 1],
|
|
);
|
|
);
|
|
},
|
|
},
|
|
|
|
+ onImageDelete: () async {
|
|
|
|
+ final changeCoverBloc =
|
|
|
|
+ context.read<ChangeCoverPopoverBloc>();
|
|
|
|
+ final deletingCurrentCover =
|
|
|
|
+ widget.node.attributes[kCoverSelectionAttribute] ==
|
|
|
|
+ images[index - 1];
|
|
|
|
+ if (deletingCurrentCover) {
|
|
|
|
+ await showDialog(
|
|
|
|
+ context: context,
|
|
|
|
+ builder: (context) {
|
|
|
|
+ return DeleteImageAlertDialog(
|
|
|
|
+ onSubmit: () {
|
|
|
|
+ changeCoverBloc.add(
|
|
|
|
+ ChangeCoverPopoverEvent.deleteImage(
|
|
|
|
+ images[index - 1],
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ Navigator.pop(context);
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ },
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ changeCoverBloc.add(DeleteImage(images[index - 1]));
|
|
|
|
+ }
|
|
|
|
+ },
|
|
imagePath: images[index - 1],
|
|
imagePath: images[index - 1],
|
|
);
|
|
);
|
|
},
|
|
},
|
|
@@ -285,14 +334,68 @@ class _ChangeCoverPopoverState extends State<ChangeCoverPopover> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+class DeleteImageAlertDialog extends StatelessWidget {
|
|
|
|
+ const DeleteImageAlertDialog({
|
|
|
|
+ Key? key,
|
|
|
|
+ required this.onSubmit,
|
|
|
|
+ }) : super(key: key);
|
|
|
|
+
|
|
|
|
+ final Function() onSubmit;
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ Widget build(BuildContext context) {
|
|
|
|
+ return AlertDialog(
|
|
|
|
+ title: FlowyText.semibold(
|
|
|
|
+ "Image is used in cover",
|
|
|
|
+ fontSize: 20,
|
|
|
|
+ color: Theme.of(context).colorScheme.tertiary,
|
|
|
|
+ ),
|
|
|
|
+ content: Container(
|
|
|
|
+ constraints: const BoxConstraints(minHeight: 100),
|
|
|
|
+ padding: const EdgeInsets.symmetric(
|
|
|
|
+ vertical: 20,
|
|
|
|
+ ),
|
|
|
|
+ child: Column(
|
|
|
|
+ mainAxisSize: MainAxisSize.min,
|
|
|
|
+ children: [
|
|
|
|
+ const Text(LocaleKeys.document_plugins_cover_coverRemoveAlert).tr(),
|
|
|
|
+ const SizedBox(
|
|
|
|
+ height: 4,
|
|
|
|
+ ),
|
|
|
|
+ const Text(
|
|
|
|
+ LocaleKeys.document_plugins_cover_alertDialogConfirmation,
|
|
|
|
+ ).tr(),
|
|
|
|
+ ],
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ contentPadding: const EdgeInsets.symmetric(
|
|
|
|
+ vertical: 10.0,
|
|
|
|
+ horizontal: 20.0,
|
|
|
|
+ ),
|
|
|
|
+ actions: [
|
|
|
|
+ TextButton(
|
|
|
|
+ onPressed: () => Navigator.pop(context),
|
|
|
|
+ child: const Text(LocaleKeys.button_Cancel).tr(),
|
|
|
|
+ ),
|
|
|
|
+ TextButton(
|
|
|
|
+ onPressed: onSubmit,
|
|
|
|
+ child: const Text(LocaleKeys.button_OK).tr(),
|
|
|
|
+ ),
|
|
|
|
+ ],
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
class ImageGridItem extends StatefulWidget {
|
|
class ImageGridItem extends StatefulWidget {
|
|
const ImageGridItem({
|
|
const ImageGridItem({
|
|
Key? key,
|
|
Key? key,
|
|
required this.onImageSelect,
|
|
required this.onImageSelect,
|
|
|
|
+ required this.onImageDelete,
|
|
required this.imagePath,
|
|
required this.imagePath,
|
|
}) : super(key: key);
|
|
}) : super(key: key);
|
|
|
|
|
|
final Function() onImageSelect;
|
|
final Function() onImageSelect;
|
|
|
|
+ final Function() onImageDelete;
|
|
final String imagePath;
|
|
final String imagePath;
|
|
|
|
|
|
@override
|
|
@override
|
|
@@ -343,11 +446,7 @@ class _ImageGridItemState extends State<ImageGridItem> {
|
|
'editor/delete',
|
|
'editor/delete',
|
|
color: Theme.of(context).colorScheme.tertiary,
|
|
color: Theme.of(context).colorScheme.tertiary,
|
|
),
|
|
),
|
|
- onPressed: () {
|
|
|
|
- context.read<ChangeCoverPopoverBloc>().add(
|
|
|
|
- ChangeCoverPopoverEvent.deleteImage(widget.imagePath),
|
|
|
|
- );
|
|
|
|
- },
|
|
|
|
|
|
+ onPressed: widget.onImageDelete,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|