[gtk/wip/matthiasc/context-menu: 196/202] textview: Support toggle actions
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/context-menu: 196/202] textview: Support toggle actions
- Date: Thu, 18 Apr 2019 05:07:46 +0000 (UTC)
commit 57cce72c3f6ed49ca7a798241cfdae3fa3ddcaf5
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 | 42 +++++++++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 3a8d340b1d..522c27a97b 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -56,7 +56,8 @@
#include "gtktoolbar.h"
#include "gtkmagnifierprivate.h"
#include "gtkemojichooser.h"
-#include "gtkpango.h"
+#include "gtkwidgetprivate.h"
+#include "gtkactionmuxerprivate.h"
#include "a11y/gtktextviewaccessibleprivate.h"
@@ -8788,13 +8789,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)
@@ -8819,14 +8820,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]