Add context menu for image

This commit is contained in:
2023-09-04 22:37:02 +08:00
parent c3e46170d4
commit a2e57460d7
11 changed files with 139 additions and 4 deletions

26
lib/components/image.dart Normal file
View File

@@ -0,0 +1,26 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:super_clipboard/super_clipboard.dart';
import 'package:super_context_menu/super_context_menu.dart';
class ImageWithContextMenu extends StatelessWidget {
const ImageWithContextMenu(this.data, {Key? key}) : super(key: key);
final Uint8List data;
@override
Widget build(BuildContext context) {
return ContextMenuWidget(
menuProvider: (_) {
return Menu(children: [
MenuAction(
title: AppLocalizations.of(context)!.copyImage,
callback: () {
final item = DataWriterItem();
item.add(Formats.jpeg(data));
ClipboardWriter.instance.write([item]);
}),
]);
},
child: Image.memory(data));
}
}

View File

@@ -6,6 +6,7 @@ import 'package:logging/logging.dart';
import '../api/client.dart';
import '../api/gallery.dart';
import '../globals.dart';
import 'image.dart';
final _log = Logger("Thumbnail");
@@ -110,7 +111,7 @@ class _Thumbnail extends State<Thumbnail> {
sigmaX: 10,
sigmaY: 10,
tileMode: TileMode.decal),
child: Image.memory(_data!))),
child: ImageWithContextMenu(_data!))),
SizedBox(
width: widget.width.toDouble(),
height: widget.height.toDouble(),
@@ -126,7 +127,7 @@ class _Thumbnail extends State<Thumbnail> {
))
],
)
: Image.memory(_data!)
: ImageWithContextMenu(_data!)
: Text("Error $_error"));
}
}

View File

@@ -26,5 +26,6 @@
"showNsfw": "Show NSFW image by default",
"read": "Read",
"download": "Download",
"colon": ":"
"colon": ":",
"copyImage": "Copy image to clipboard"
}

View File

@@ -26,5 +26,6 @@
"showNsfw": "默认显示NSFW图片",
"read": "阅读",
"download": "下载",
"colon": ":"
"colon": ":",
"copyImage": "复制图片到剪贴板"
}

View File

@@ -6,13 +6,21 @@
#include "generated_plugin_registrant.h"
#include <irondash_engine_context/irondash_engine_context_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <super_native_extensions/super_native_extensions_plugin.h>
#include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) irondash_engine_context_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "IrondashEngineContextPlugin");
irondash_engine_context_plugin_register_with_registrar(irondash_engine_context_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) super_native_extensions_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "SuperNativeExtensionsPlugin");
super_native_extensions_plugin_register_with_registrar(super_native_extensions_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);

View File

@@ -3,7 +3,9 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
irondash_engine_context
screen_retriever
super_native_extensions
window_manager
)

View File

@@ -6,15 +6,21 @@ import FlutterMacOS
import Foundation
import cryptography_flutter
import device_info_plus
import irondash_engine_context
import path_provider_foundation
import screen_retriever
import shared_preferences_foundation
import super_native_extensions
import window_manager
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
CryptographyFlutterPlugin.register(with: registry.registrar(forPlugin: "CryptographyFlutterPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
IrondashEngineContextPlugin.register(with: registry.registrar(forPlugin: "IrondashEngineContextPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SuperNativeExtensionsPlugin.register(with: registry.registrar(forPlugin: "SuperNativeExtensionsPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}

View File

@@ -202,6 +202,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.2"
device_info_plus:
dependency: transitive
description:
name: device_info_plus
sha256: "86add5ef97215562d2e090535b0a16f197902b10c369c558a100e74ea06e8659"
url: "https://pub.dev"
source: hosted
version: "9.0.3"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64
url: "https://pub.dev"
source: hosted
version: "7.0.0"
dio:
dependency: "direct main"
description:
@@ -390,6 +406,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
irondash_engine_context:
dependency: transitive
description:
name: irondash_engine_context
sha256: fea21bff36d44a5955beba90619f54b9169884014128ae75f50eba2db03c24a0
url: "https://pub.dev"
source: hosted
version: "0.3.1"
irondash_message_channel:
dependency: transitive
description:
name: irondash_message_channel
sha256: "500daa1fbe679f7d28a5258df3ff47dab6de352e680dc93c1ca9eae1555d8db5"
url: "https://pub.dev"
source: hosted
version: "0.3.1"
js:
dependency: transitive
description:
@@ -526,6 +558,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.1"
pixel_snap:
dependency: transitive
description:
name: pixel_snap
sha256: "5de3662b926c9bc189578cf90f9d5b350ee61bc8e20e8a91fa1dfdd26c9f5ece"
url: "https://pub.dev"
source: hosted
version: "0.1.2"
platform:
dependency: transitive
description:
@@ -731,6 +771,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
super_clipboard:
dependency: "direct main"
description:
name: super_clipboard
sha256: "548642d62d691d2ba00850efe0f7a11ce5696e59111658abd4c6cb76b49aa61d"
url: "https://pub.dev"
source: hosted
version: "0.6.4"
super_context_menu:
dependency: "direct main"
description:
name: super_context_menu
sha256: "18736520541aee293720597b399ecfd18e7be16cc2dba72e7dee0edfa5925857"
url: "https://pub.dev"
source: hosted
version: "0.6.4"
super_native_extensions:
dependency: transitive
description:
name: super_native_extensions
sha256: "3bbb95899f848617b819eec1fa00c80a617f1bd469a480b1f0c4dd383da4c5ec"
url: "https://pub.dev"
source: hosted
version: "0.6.4"
term_glyph:
dependency: transitive
description:
@@ -779,6 +843,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.2"
uuid:
dependency: transitive
description:
name: uuid
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
url: "https://pub.dev"
source: hosted
version: "3.0.7"
vector_math:
dependency: transitive
description:
@@ -819,6 +891,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.0.7"
win32_registry:
dependency: transitive
description:
name: win32_registry
sha256: e4506d60b7244251bc59df15656a3093501c37fb5af02105a944d73eb95be4c9
url: "https://pub.dev"
source: hosted
version: "1.1.1"
window_manager:
dependency: "direct main"
description:

View File

@@ -31,6 +31,8 @@ dependencies:
path_provider: ^2.1.0
retrofit: ^4.0.1
shared_preferences: ^2.2.0
super_clipboard: ^0.6.4
super_context_menu: ^0.6.4
window_manager: ^0.3.6
dependency_overrides:

View File

@@ -6,12 +6,18 @@
#include "generated_plugin_registrant.h"
#include <irondash_engine_context/irondash_engine_context_plugin_c_api.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <super_native_extensions/super_native_extensions_plugin_c_api.h>
#include <window_manager/window_manager_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
IrondashEngineContextPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("IrondashEngineContextPluginCApi"));
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
SuperNativeExtensionsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SuperNativeExtensionsPluginCApi"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}

View File

@@ -3,7 +3,9 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
irondash_engine_context
screen_retriever
super_native_extensions
window_manager
)