[evolution-data-server/wip/mcrha/gtk4] Fix EBufferTagger
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/wip/mcrha/gtk4] Fix EBufferTagger
- Date: Tue, 19 Oct 2021 13:26:45 +0000 (UTC)
commit 38619bc5ebfedc65b111fcee469519f2853711d7
Author: Milan Crha <mcrha redhat com>
Date: Tue Oct 19 15:26:25 2021 +0200
Fix EBufferTagger
src/libedataserverui/e-buffer-tagger.c | 49 +++++++++++++++++++++-------------
1 file changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/src/libedataserverui/e-buffer-tagger.c b/src/libedataserverui/e-buffer-tagger.c
index 651e0b827..292cd8b67 100644
--- a/src/libedataserverui/e-buffer-tagger.c
+++ b/src/libedataserverui/e-buffer-tagger.c
@@ -538,12 +538,12 @@ update_mouse_cursor (GtkTextView *text_view,
if (url && *url && g_strcmp0 (url, g_object_get_data (G_OBJECT (text_view),
E_BUFFER_TAGGER_DATA_CURRENT_URI)) != 0) {
GActionGroup *action_group;
- GMenu *menu;
+ GMenu *menu, *section;
GMenuItem *item;
GVariant *variant;
const GActionEntry entries[] = {
- { "e-buffer-tagger.copy-uri", textview_copy_uri_cb, "s" },
- { "e-buffer-tagger.open-uri", textview_open_uri_cb, "s" }
+ { "copy-uri", textview_copy_uri_cb, "s" },
+ { "open-uri", textview_open_uri_cb, "s" }
};
action_group = G_ACTION_GROUP (g_simple_action_group_new ());
@@ -553,21 +553,24 @@ update_mouse_cursor (GtkTextView *text_view,
variant = g_variant_new_string (url);
- menu = g_menu_new ();
+ section = g_menu_new ();
item = g_menu_item_new (_("Copy _Link Location"), "e-buffer-tagger.copy-uri");
g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_TARGET, variant);
- g_menu_append_item (menu, item);
+ g_menu_append_item (section, item);
g_object_unref (item);
item = g_menu_item_new (_("O_pen Link in Browser"), "e-buffer-tagger.open-uri");
g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_TARGET, variant);
- g_menu_append_item (menu, item);
+ g_menu_append_item (section, item);
g_object_unref (item);
+ menu = g_menu_new ();
+ g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
+ g_object_unref (section);
+
gtk_text_view_set_extra_menu (text_view, G_MENU_MODEL (menu));
- g_variant_unref (variant);
g_object_unref (menu);
g_object_set_data_full (G_OBJECT (text_view), E_BUFFER_TAGGER_DATA_CURRENT_URI, url,
g_free);
@@ -575,9 +578,14 @@ update_mouse_cursor (GtkTextView *text_view,
} else if (!url || !*url) {
gtk_text_view_set_extra_menu (text_view, NULL);
gtk_widget_insert_action_group (GTK_WIDGET (text_view), "e-buffer-tagger", NULL);
+ g_object_set_data (G_OBJECT (text_view), E_BUFFER_TAGGER_DATA_CURRENT_URI, NULL);
}
g_free (url);
+ } else {
+ gtk_text_view_set_extra_menu (text_view, NULL);
+ gtk_widget_insert_action_group (GTK_WIDGET (text_view), "e-buffer-tagger", NULL);
+ g_object_set_data (G_OBJECT (text_view), E_BUFFER_TAGGER_DATA_CURRENT_URI, NULL);
}
#endif
@@ -591,14 +599,16 @@ update_mouse_cursor (GtkTextView *text_view,
if (hovering != hovering_over_link) {
update_state (buffer, E_BUFFER_TAGGER_STATE_IS_HOVERING, hovering);
-#if !GTK_CHECK_VERSION(4, 0, 0)
+#if GTK_CHECK_VERSION(4, 0, 0)
+ if (hovering && gtk_widget_has_focus (GTK_WIDGET (text_view)))
+ gtk_widget_set_cursor_from_name (GTK_WIDGET (text_view), "pointer");
+ else
+ gtk_widget_set_cursor_from_name (GTK_WIDGET (text_view), NULL);
+#else
if (hovering && gtk_widget_has_focus (GTK_WIDGET (text_view)))
gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT),
hand_cursor);
else
gdk_window_set_cursor (gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT),
regular_cursor);
-
- /* XXX Is this necessary? Appears to be a no-op. */
- get_pointer_position (text_view, NULL, NULL, NULL);
#endif
}
@@ -611,6 +621,7 @@ update_mouse_cursor (GtkTextView *text_view,
}
}
+#if !GTK_CHECK_VERSION(4, 0, 0)
static void
textview_style_updated_cb (GtkWidget *textview,
gpointer user_data)
@@ -655,6 +666,7 @@ textview_style_updated_cb (GtkWidget *textview,
g_object_set (G_OBJECT (tag), "foreground-rgba", &rgba, NULL);
}
+#endif
static gboolean
textview_query_tooltip (GtkTextView *text_view,
@@ -1015,9 +1027,6 @@ e_buffer_tagger_connect (GtkTextView *textview)
gtk_widget_set_has_tooltip (GTK_WIDGET (textview), TRUE);
- g_signal_connect (
- textview, "style-updated",
- G_CALLBACK (textview_style_updated_cb), NULL);
g_signal_connect (
textview, "query-tooltip",
G_CALLBACK (textview_query_tooltip), NULL);
@@ -1026,26 +1035,29 @@ e_buffer_tagger_connect (GtkTextView *textview)
controller = gtk_event_controller_key_new ();
g_object_set_data_full (G_OBJECT (textview), E_BUFFER_TAGGER_DATA_KEY_CONTROLLER,
- controller, g_object_unref);
+ g_object_ref (controller), g_object_unref);
gtk_widget_add_controller (widget, controller);
g_signal_connect_object (controller, "key-pressed",
G_CALLBACK (textview_key_press_event), textview, 0);
controller = gtk_event_controller_legacy_new ();
g_object_set_data_full (G_OBJECT (textview), E_BUFFER_TAGGER_DATA_LEGACY_CONTROLLER,
- controller, g_object_unref);
+ g_object_ref (controller), g_object_unref);
gtk_widget_add_controller (widget, controller);
g_signal_connect_object (controller, "event",
G_CALLBACK (textview_event_after), textview, G_CONNECT_SWAPPED);
controller = gtk_event_controller_motion_new ();
g_object_set_data_full (G_OBJECT (textview), E_BUFFER_TAGGER_DATA_MOTION_CONTROLLER,
- controller, g_object_unref);
+ g_object_ref (controller), g_object_unref);
gtk_widget_add_controller (widget, controller);
g_signal_connect_object (controller, "motion",
G_CALLBACK (textview_motion_notify_event), textview, G_CONNECT_SWAPPED);
#else
+ g_signal_connect (
+ textview, "style-updated",
+ G_CALLBACK (textview_style_updated_cb), NULL);
g_signal_connect (
textview, "key-press-event",
G_CALLBACK (textview_key_press_event), NULL);
@@ -1091,7 +1103,6 @@ e_buffer_tagger_disconnect (GtkTextView *textview)
gtk_widget_set_has_tooltip (GTK_WIDGET (textview), FALSE);
- g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_style_updated_cb), NULL);
g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_query_tooltip), NULL);
#if GTK_CHECK_VERSION(4, 0, 0)
widget = GTK_WIDGET (textview);
@@ -1110,11 +1121,11 @@ e_buffer_tagger_disconnect (GtkTextView *textview)
#undef drop_controller
g_object_set_data (G_OBJECT (textview), E_BUFFER_TAGGER_DATA_CURRENT_URI, NULL);
- g_object_set_data (G_OBJECT (textview), E_BUFFER_TAGGER_DATA_CURRENT_URI, NULL);
gtk_text_view_set_extra_menu (textview, NULL);
gtk_widget_insert_action_group (widget, "e-buffer-tagger", NULL);
#else
+ g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_style_updated_cb), NULL);
g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_key_press_event), NULL);
g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_event_after), NULL);
g_signal_handlers_disconnect_by_func (textview, G_CALLBACK (textview_motion_notify_event), NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]