From 7c6cd71639137ed1d869681d407ec0e14f26d4d3 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Thu, 24 Sep 2020 13:20:36 -0700 Subject: [PATCH 1/2] hasStrings linux --- shell/platform/linux/fl_platform_plugin.cc | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_platform_plugin.cc b/shell/platform/linux/fl_platform_plugin.cc index 55aa6b002547d..5ff90281c6d7a 100644 --- a/shell/platform/linux/fl_platform_plugin.cc +++ b/shell/platform/linux/fl_platform_plugin.cc @@ -17,8 +17,10 @@ static constexpr char kUnknownClipboardFormatError[] = static constexpr char kFailedError[] = "Failed"; static constexpr char kGetClipboardDataMethod[] = "Clipboard.getData"; static constexpr char kSetClipboardDataMethod[] = "Clipboard.setData"; +static constexpr char kClipboardHasStringsMethod[] = "Clipboard.hasStrings"; static constexpr char kSystemNavigatorPopMethod[] = "SystemNavigator.pop"; static constexpr char kTextKey[] = "text"; +static constexpr char kValueKey[] = "value"; static constexpr char kTextPlainFormat[] = "text/plain"; @@ -56,6 +58,21 @@ static void clipboard_text_cb(GtkClipboard* clipboard, send_response(method_call, response); } +// Called when clipboard text received during has_strings. +static void clipboard_text_has_strings_cb(GtkClipboard* clipboard, + const gchar* text, + gpointer user_data) { + g_autoptr(FlMethodCall) method_call = FL_METHOD_CALL(user_data); + + g_autoptr(FlValue) result = fl_value_new_map(); + fl_value_set_string_take(result, kValueKey, + fl_value_new_bool(text != nullptr && strlen(text) > 0)); + + g_autoptr(FlMethodResponse) response = + FL_METHOD_RESPONSE(fl_method_success_response_new(result)); + send_response(method_call, response); +} + // Called when Flutter wants to copy to the clipboard. static FlMethodResponse* clipboard_set_data(FlPlatformPlugin* self, FlValue* args) { @@ -100,7 +117,20 @@ static FlMethodResponse* clipboard_get_data_async(FlPlatformPlugin* self, gtk_clipboard_request_text(clipboard, clipboard_text_cb, g_object_ref(method_call)); - // Will response later. + // Will respond later. + return nullptr; +} + +// Called when Flutter wants to know if the content of the clipboard is able to +// be pasted, without actually accessing the clipboard content itself. +static FlMethodResponse* clipboard_has_strings_async(FlPlatformPlugin* self, + FlMethodCall* method_call) { + GtkClipboard* clipboard = + gtk_clipboard_get_default(gdk_display_get_default()); + gtk_clipboard_request_text(clipboard, clipboard_text_has_strings_cb, + g_object_ref(method_call)); + + // Will respond later. return nullptr; } @@ -131,6 +161,8 @@ static void method_call_cb(FlMethodChannel* channel, response = clipboard_set_data(self, args); } else if (strcmp(method, kGetClipboardDataMethod) == 0) { response = clipboard_get_data_async(self, method_call); + } else if (strcmp(method, kClipboardHasStringsMethod) == 0) { + response = clipboard_has_strings_async(self, method_call); } else if (strcmp(method, kSystemNavigatorPopMethod) == 0) { response = system_navigator_pop(self); } else { From 9c88b9dff0486a7cc9f20c3d7ffc6c139fdf3c18 Mon Sep 17 00:00:00 2001 From: Justin McCandless Date: Fri, 25 Sep 2020 08:39:01 -0700 Subject: [PATCH 2/2] Formatting --- shell/platform/linux/fl_platform_plugin.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/shell/platform/linux/fl_platform_plugin.cc b/shell/platform/linux/fl_platform_plugin.cc index 5ff90281c6d7a..314b32939e6c8 100644 --- a/shell/platform/linux/fl_platform_plugin.cc +++ b/shell/platform/linux/fl_platform_plugin.cc @@ -60,13 +60,14 @@ static void clipboard_text_cb(GtkClipboard* clipboard, // Called when clipboard text received during has_strings. static void clipboard_text_has_strings_cb(GtkClipboard* clipboard, - const gchar* text, - gpointer user_data) { + const gchar* text, + gpointer user_data) { g_autoptr(FlMethodCall) method_call = FL_METHOD_CALL(user_data); g_autoptr(FlValue) result = fl_value_new_map(); - fl_value_set_string_take(result, kValueKey, - fl_value_new_bool(text != nullptr && strlen(text) > 0)); + fl_value_set_string_take( + result, kValueKey, + fl_value_new_bool(text != nullptr && strlen(text) > 0)); g_autoptr(FlMethodResponse) response = FL_METHOD_RESPONSE(fl_method_success_response_new(result)); @@ -123,8 +124,9 @@ static FlMethodResponse* clipboard_get_data_async(FlPlatformPlugin* self, // Called when Flutter wants to know if the content of the clipboard is able to // be pasted, without actually accessing the clipboard content itself. -static FlMethodResponse* clipboard_has_strings_async(FlPlatformPlugin* self, - FlMethodCall* method_call) { +static FlMethodResponse* clipboard_has_strings_async( + FlPlatformPlugin* self, + FlMethodCall* method_call) { GtkClipboard* clipboard = gtk_clipboard_get_default(gdk_display_get_default()); gtk_clipboard_request_text(clipboard, clipboard_text_has_strings_cb,