[gtk/wip/matthiasc/context-menu] text view: Support toggle actions
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/context-menu] text view: Support toggle actions
- Date: Tue, 5 Feb 2019 00:00:44 +0000 (UTC)
commit e500d0963bdb81f7dee98e7c952bf136e8e5c2ed
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jan 28 19:56:08 2019 -0500
text view: 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 8efc6d8f79..d266a0098d 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -56,6 +56,8 @@
#include "gtktoolbar.h"
#include "gtkmagnifierprivate.h"
#include "gtkemojichooser.h"
+#include "gtkwidgetprivate.h"
+#include "gtkactionmuxerprivate.h"
#include "a11y/gtktextviewaccessibleprivate.h"
@@ -8787,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)
@@ -8818,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]