@@ -17,8 +17,10 @@ static constexpr char kUnknownClipboardFormatError[] =
17
17
static constexpr char kFailedError [] = " Failed" ;
18
18
static constexpr char kGetClipboardDataMethod [] = " Clipboard.getData" ;
19
19
static constexpr char kSetClipboardDataMethod [] = " Clipboard.setData" ;
20
+ static constexpr char kClipboardHasStringsMethod [] = " Clipboard.hasStrings" ;
20
21
static constexpr char kSystemNavigatorPopMethod [] = " SystemNavigator.pop" ;
21
22
static constexpr char kTextKey [] = " text" ;
23
+ static constexpr char kValueKey [] = " value" ;
22
24
23
25
static constexpr char kTextPlainFormat [] = " text/plain" ;
24
26
@@ -56,6 +58,22 @@ static void clipboard_text_cb(GtkClipboard* clipboard,
56
58
send_response (method_call, response);
57
59
}
58
60
61
+ // Called when clipboard text received during has_strings.
62
+ static void clipboard_text_has_strings_cb (GtkClipboard* clipboard,
63
+ const gchar* text,
64
+ gpointer user_data) {
65
+ g_autoptr (FlMethodCall) method_call = FL_METHOD_CALL (user_data);
66
+
67
+ g_autoptr (FlValue) result = fl_value_new_map ();
68
+ fl_value_set_string_take (
69
+ result, kValueKey ,
70
+ fl_value_new_bool (text != nullptr && strlen (text) > 0 ));
71
+
72
+ g_autoptr (FlMethodResponse) response =
73
+ FL_METHOD_RESPONSE (fl_method_success_response_new (result));
74
+ send_response (method_call, response);
75
+ }
76
+
59
77
// Called when Flutter wants to copy to the clipboard.
60
78
static FlMethodResponse* clipboard_set_data (FlPlatformPlugin* self,
61
79
FlValue* args) {
@@ -100,7 +118,21 @@ static FlMethodResponse* clipboard_get_data_async(FlPlatformPlugin* self,
100
118
gtk_clipboard_request_text (clipboard, clipboard_text_cb,
101
119
g_object_ref (method_call));
102
120
103
- // Will response later.
121
+ // Will respond later.
122
+ return nullptr ;
123
+ }
124
+
125
+ // Called when Flutter wants to know if the content of the clipboard is able to
126
+ // be pasted, without actually accessing the clipboard content itself.
127
+ static FlMethodResponse* clipboard_has_strings_async (
128
+ FlPlatformPlugin* self,
129
+ FlMethodCall* method_call) {
130
+ GtkClipboard* clipboard =
131
+ gtk_clipboard_get_default (gdk_display_get_default ());
132
+ gtk_clipboard_request_text (clipboard, clipboard_text_has_strings_cb,
133
+ g_object_ref (method_call));
134
+
135
+ // Will respond later.
104
136
return nullptr ;
105
137
}
106
138
@@ -131,6 +163,8 @@ static void method_call_cb(FlMethodChannel* channel,
131
163
response = clipboard_set_data (self, args);
132
164
} else if (strcmp (method, kGetClipboardDataMethod ) == 0 ) {
133
165
response = clipboard_get_data_async (self, method_call);
166
+ } else if (strcmp (method, kClipboardHasStringsMethod ) == 0 ) {
167
+ response = clipboard_has_strings_async (self, method_call);
134
168
} else if (strcmp (method, kSystemNavigatorPopMethod ) == 0 ) {
135
169
response = system_navigator_pop (self);
136
170
} else {
0 commit comments