[gtk/wip/matthiasc/context-menu: 14/23] textview: Support toggle actions
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/context-menu: 14/23] textview: Support toggle actions
- Date: Tue, 11 Jun 2019 18:36:32 +0000 (UTC)
commit f4c48ec5ace94fb753884a52f7bbb42e103481a9
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jan 28 19:56:08 2019 -0500
textview: Support toggle actions
When creating a touch selection bubble, create toggle
buttons for toggle actions.
gtk/gtktextview.c | 41 +++++++++++++++++++++++++++++++++--------
1 file changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index ca730906b7..abfee66997 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -58,6 +58,8 @@
#include "gtkemojichooser.h"
#include "gtkpango.h"
#include "gtknative.h"
+#include "gtkwidgetprivate.h"
+#include "gtkactionmuxerprivate.h"
#include "a11y/gtktextviewaccessibleprivate.h"
@@ -8807,13 +8809,13 @@ append_bubble_item (GtkTextView *text_view,
GMenuModel *model,
int index)
{
- GtkTextViewPrivate *priv = text_view->priv;
GtkWidget *item, *image;
GVariant *att;
const char *icon_name;
const char *action_name;
- GAction *action;
GMenuModel *link;
+ char **split = NULL;
+ gboolean is_toggle_action = FALSE;
link = g_menu_model_get_item_link (model, index, "section");
if (link)
@@ -8838,14 +8840,37 @@ append_bubble_item (GtkTextView *text_view,
action_name = g_variant_get_string (att, NULL);
g_variant_unref (att);
- if (g_str_has_prefix (action_name, "context."))
- {
- action = g_action_map_lookup_action (priv->context_actions, action_name + strlen ("context."));
- if (action && !g_action_get_enabled (action))
- return;
+ split = g_strsplit (action_name, ".", 2);
+ if (split[0] && split[1])
+ {
+ GActionGroup *group = NULL;
+ gboolean enabled;
+ const GVariantType *param_type;
+ const GVariantType *state_type;
+ GtkActionMuxer *muxer;
+
+ muxer = _gtk_widget_get_action_muxer (GTK_WIDGET (text_view), FALSE);
+ if (muxer)
+ group = gtk_action_muxer_lookup (muxer, split[0]);
+ if (group)
+ {
+ g_action_group_query_action (group, split[1], &enabled, ¶m_type, &state_type, NULL, NULL);
+
+ if (!enabled)
+ return;
+
+ if (param_type == NULL &&
+ state_type != NULL &&
+ g_variant_type_equal (state_type, G_VARIANT_TYPE_BOOLEAN))
+ is_toggle_action = TRUE;
+ }
}
+ g_strfreev (split);
- item = gtk_button_new ();
+ if (is_toggle_action)
+ item = gtk_toggle_button_new ();
+ else
+ item = gtk_button_new ();
gtk_widget_set_focus_on_click (item, FALSE);
image = gtk_image_new_from_icon_name (icon_name);
gtk_widget_show (image);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]