mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
hasStrings Linux (flutter/engine#21388)
hasStrings method for clipboard status, Linux
This commit is contained in:
parent
035d66a75f
commit
30ff61de06
@ -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,22 @@ 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 +118,21 @@ 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 +163,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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user