From a2e57460d729fe4accadb5e1e6fea3e72af10a5f Mon Sep 17 00:00:00 2001 From: lifegpc Date: Mon, 4 Sep 2023 22:37:02 +0800 Subject: [PATCH] Add context menu for image --- lib/components/image.dart | 26 ++++++ lib/components/thumbnail.dart | 5 +- lib/l10n/app_en.arb | 3 +- lib/l10n/app_zh.arb | 3 +- linux/flutter/generated_plugin_registrant.cc | 8 ++ linux/flutter/generated_plugins.cmake | 2 + macos/Flutter/GeneratedPluginRegistrant.swift | 6 ++ pubspec.lock | 80 +++++++++++++++++++ pubspec.yaml | 2 + .../flutter/generated_plugin_registrant.cc | 6 ++ windows/flutter/generated_plugins.cmake | 2 + 11 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 lib/components/image.dart diff --git a/lib/components/image.dart b/lib/components/image.dart new file mode 100644 index 0000000..4e21c48 --- /dev/null +++ b/lib/components/image.dart @@ -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)); + } +} diff --git a/lib/components/thumbnail.dart b/lib/components/thumbnail.dart index d00457c..8dd2c91 100644 --- a/lib/components/thumbnail.dart +++ b/lib/components/thumbnail.dart @@ -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 { 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 { )) ], ) - : Image.memory(_data!) + : ImageWithContextMenu(_data!) : Text("Error $_error")); } } diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 174c860..5d7239c 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -26,5 +26,6 @@ "showNsfw": "Show NSFW image by default", "read": "Read", "download": "Download", - "colon": ":" + "colon": ":", + "copyImage": "Copy image to clipboard" } diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 085bbab..a49cbc1 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -26,5 +26,6 @@ "showNsfw": "默认显示NSFW图片", "read": "阅读", "download": "下载", - "colon": ":" + "colon": ":", + "copyImage": "复制图片到剪贴板" } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index b7a6d08..e6c274d 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,13 +6,21 @@ #include "generated_plugin_registrant.h" +#include #include +#include #include 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); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 913ac71..47f2675 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,7 +3,9 @@ # list(APPEND FLUTTER_PLUGIN_LIST + irondash_engine_context screen_retriever + super_native_extensions window_manager ) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 4efc9f2..6a5d0a8 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -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")) } diff --git a/pubspec.lock b/pubspec.lock index bdc03df..d7c5cd6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 2f6d731..8a3fd27 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index d6b86fa..af70343 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,12 +6,18 @@ #include "generated_plugin_registrant.h" +#include #include +#include #include void RegisterPlugins(flutter::PluginRegistry* registry) { + IrondashEngineContextPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("IrondashEngineContextPluginCApi")); ScreenRetrieverPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("ScreenRetrieverPlugin")); + SuperNativeExtensionsPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("SuperNativeExtensionsPluginCApi")); WindowManagerPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("WindowManagerPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index bfa52f4..3a49777 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,7 +3,9 @@ # list(APPEND FLUTTER_PLUGIN_LIST + irondash_engine_context screen_retriever + super_native_extensions window_manager )