[evolution/wip/mcrha/webkit-jsc-api] Cut/Copy/Paste actions not updated when selection changed
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/wip/mcrha/webkit-jsc-api] Cut/Copy/Paste actions not updated when selection changed
- Date: Tue, 10 Mar 2020 11:51:31 +0000 (UTC)
commit 731cb70259dd3041879f45172f39289e5a255478
Author: Milan Crha <mcrha redhat com>
Date: Tue Mar 10 12:53:28 2020 +0100
Cut/Copy/Paste actions not updated when selection changed
data/webkit/e-editor.js | 2 +
src/modules/webkit-editor/e-webkit-editor.c | 127 +++++++++++++---------------
2 files changed, 63 insertions(+), 66 deletions(-)
---
diff --git a/data/webkit/e-editor.js b/data/webkit/e-editor.js
index 1b2416e0e1..029261466b 100644
--- a/data/webkit/e-editor.js
+++ b/data/webkit/e-editor.js
@@ -4509,6 +4509,8 @@ document.onselectionchange = function() {
EvoEditor.maybeUpdateFormattingState(EvoEditor.forceFormatStateUpdate ? EvoEditor.FORCE_YES :
EvoEditor.FORCE_MAYBE);
EvoEditor.forceFormatStateUpdate = false;
+
+ window.webkit.messageHandlers.selectionChanged.postMessage(null);
};
EvoEditor.initializeContent();
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 7b25e1fa84..7721d57fc5 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -638,21 +638,6 @@ webkit_editor_get_last_error (EWebKitEditor *wk_editor)
return wk_editor->priv->last_error;
}
-static void
-webkit_editor_can_paste_cb (WebKitWebView *view,
- GAsyncResult *result,
- EWebKitEditor *wk_editor)
-{
- gboolean value;
-
- value = webkit_web_view_can_execute_editing_command_finish (view, result, NULL);
-
- if (wk_editor->priv->can_paste != value) {
- wk_editor->priv->can_paste = value;
- g_object_notify (G_OBJECT (wk_editor), "can-paste");
- }
-}
-
static gboolean
webkit_editor_can_paste (EWebKitEditor *wk_editor)
{
@@ -661,21 +646,6 @@ webkit_editor_can_paste (EWebKitEditor *wk_editor)
return wk_editor->priv->can_paste;
}
-static void
-webkit_editor_can_cut_cb (WebKitWebView *view,
- GAsyncResult *result,
- EWebKitEditor *wk_editor)
-{
- gboolean value;
-
- value = webkit_web_view_can_execute_editing_command_finish (view, result, NULL);
-
- if (wk_editor->priv->can_cut != value) {
- wk_editor->priv->can_cut = value;
- g_object_notify (G_OBJECT (wk_editor), "can-cut");
- }
-}
-
static gboolean
webkit_editor_can_cut (EWebKitEditor *wk_editor)
{
@@ -684,21 +654,6 @@ webkit_editor_can_cut (EWebKitEditor *wk_editor)
return wk_editor->priv->can_cut;
}
-static void
-webkit_editor_can_copy_cb (WebKitWebView *view,
- GAsyncResult *result,
- EWebKitEditor *wk_editor)
-{
- gboolean value;
-
- value = webkit_web_view_can_execute_editing_command_finish (view, result, NULL);
-
- if (wk_editor->priv->can_copy != value) {
- wk_editor->priv->can_copy = value;
- g_object_notify (G_OBJECT (wk_editor), "can-copy");
- }
-}
-
static gboolean
webkit_editor_is_malfunction (EWebKitEditor *wk_editor)
{
@@ -861,27 +816,6 @@ formatting_changed_cb (WebKitUserContentManager *manager,
jsc_params = webkit_javascript_result_get_js_value (js_result);
g_return_if_fail (jsc_value_is_object (jsc_params));
- webkit_web_view_can_execute_editing_command (
- WEBKIT_WEB_VIEW (wk_editor),
- WEBKIT_EDITING_COMMAND_COPY,
- NULL, /* cancellable */
- (GAsyncReadyCallback) webkit_editor_can_copy_cb,
- wk_editor);
-
- webkit_web_view_can_execute_editing_command (
- WEBKIT_WEB_VIEW (wk_editor),
- WEBKIT_EDITING_COMMAND_CUT,
- NULL, /* cancellable */
- (GAsyncReadyCallback) webkit_editor_can_cut_cb,
- wk_editor);
-
- webkit_web_view_can_execute_editing_command (
- WEBKIT_WEB_VIEW (wk_editor),
- WEBKIT_EDITING_COMMAND_PASTE,
- NULL, /* cancellable */
- (GAsyncReadyCallback) webkit_editor_can_paste_cb,
- wk_editor);
-
object = G_OBJECT (wk_editor);
g_object_freeze_notify (object);
@@ -1094,6 +1028,41 @@ formatting_changed_cb (WebKitUserContentManager *manager,
g_object_thaw_notify (object);
}
+static void
+selection_changed_cb (WebKitUserContentManager *manager,
+ WebKitJavascriptResult *js_result,
+ gpointer user_data)
+{
+ EWebKitEditor *wk_editor = user_data;
+ WebKitEditorState *editor_state;
+
+ g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
+
+ editor_state = webkit_web_view_get_editor_state (WEBKIT_WEB_VIEW (wk_editor));
+
+ if (editor_state) {
+ GObject *object = G_OBJECT (wk_editor);
+ gboolean value;
+
+ #define check_and_set_prop(_prop_var, _prop_name, _val_func) \
+ value = _val_func (editor_state); \
+ if (_prop_var != value) { \
+ _prop_var = value; \
+ g_object_notify (object, _prop_name); \
+ }
+
+ g_object_freeze_notify (object);
+
+ check_and_set_prop (wk_editor->priv->can_copy, "can-copy",
webkit_editor_state_is_copy_available);
+ check_and_set_prop (wk_editor->priv->can_cut, "can-cut",
webkit_editor_state_is_cut_available);
+ check_and_set_prop (wk_editor->priv->can_paste, "can-paste",
webkit_editor_state_is_paste_available);
+
+ g_object_thaw_notify (object);
+
+ #undef set_prop
+ }
+}
+
static void
undu_redo_state_changed_cb (WebKitUserContentManager *manager,
WebKitJavascriptResult *js_result,
@@ -4033,12 +4002,15 @@ webkit_editor_constructed (GObject *object)
G_CALLBACK (context_menu_requested_cb), wk_editor, 0);
g_signal_connect_object (manager, "script-message-received::formattingChanged",
G_CALLBACK (formatting_changed_cb), wk_editor, 0);
+ g_signal_connect_object (manager, "script-message-received::selectionChanged",
+ G_CALLBACK (selection_changed_cb), wk_editor, 0);
g_signal_connect_object (manager, "script-message-received::undoRedoStateChanged",
G_CALLBACK (undu_redo_state_changed_cb), wk_editor, 0);
webkit_user_content_manager_register_script_message_handler (manager, "contentChanged");
webkit_user_content_manager_register_script_message_handler (manager, "contextMenuRequested");
webkit_user_content_manager_register_script_message_handler (manager, "formattingChanged");
+ webkit_user_content_manager_register_script_message_handler (manager, "selectionChanged");
webkit_user_content_manager_register_script_message_handler (manager, "undoRedoStateChanged");
/* Give spell check languages to WebKit */
@@ -4695,6 +4667,26 @@ webkit_editor_style_settings_changed_cb (GSettings *settings,
}
}
+static void
+webkit_editor_can_paste_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EWebKitEditor *wk_editor;
+ gboolean can;
+
+ g_return_if_fail (E_IS_WEBKIT_EDITOR (source_object));
+
+ wk_editor = E_WEBKIT_EDITOR (source_object);
+
+ can = webkit_web_view_can_execute_editing_command_finish (WEBKIT_WEB_VIEW (wk_editor), result, NULL);
+
+ if (wk_editor->priv->can_paste != can) {
+ wk_editor->priv->can_paste = can;
+ g_object_notify (G_OBJECT (wk_editor), "can-paste");
+ }
+}
+
static void
webkit_editor_load_changed_cb (EWebKitEditor *wk_editor,
WebKitLoadEvent load_event)
@@ -4744,6 +4736,9 @@ webkit_editor_load_changed_cb (EWebKitEditor *wk_editor,
initialized_callback (E_CONTENT_EDITOR (wk_editor), initialized_user_data);
}
+ webkit_web_view_can_execute_editing_command (WEBKIT_WEB_VIEW (wk_editor),
+ WEBKIT_EDITING_COMMAND_PASTE, NULL, webkit_editor_can_paste_cb, NULL);
+
e_content_editor_emit_load_finished (E_CONTENT_EDITOR (wk_editor));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]