未验证 提交 9a7b556f 编写于 作者: J Justin McCandless 提交者: GitHub

hasStrings Linux (#21388)

hasStrings method for clipboard status, Linux
上级 6c0ca5e7
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册