inspector: Fix actionable handling

This commit is contained in:
Matthias Clasen 2019-06-15 22:05:54 +00:00
parent 00c828e752
commit 44970b5182

View File

@ -1255,8 +1255,6 @@ action_ancestor (GtkWidget *widget)
{ {
if (GTK_IS_MENU (widget)) if (GTK_IS_MENU (widget))
return gtk_menu_get_attach_widget (GTK_MENU (widget)); return gtk_menu_get_attach_widget (GTK_MENU (widget));
else if (GTK_IS_POPOVER (widget))
return gtk_popover_get_relative_to (GTK_POPOVER (widget));
else else
return gtk_widget_get_parent (widget); return gtk_widget_get_parent (widget);
} }
@ -1266,27 +1264,19 @@ find_action_owner (GtkActionable *actionable)
{ {
GtkWidget *widget = GTK_WIDGET (actionable); GtkWidget *widget = GTK_WIDGET (actionable);
const gchar *full_name; const gchar *full_name;
const gchar *dot;
const gchar *name;
gchar *prefix;
GtkWidget *win; GtkWidget *win;
GActionGroup *group;
full_name = gtk_actionable_get_action_name (actionable); full_name = gtk_actionable_get_action_name (actionable);
if (!full_name) if (!full_name)
return NULL; return NULL;
dot = strchr (full_name, '.');
prefix = g_strndup (full_name, dot - full_name);
name = dot + 1;
win = gtk_widget_get_ancestor (widget, GTK_TYPE_APPLICATION_WINDOW); win = gtk_widget_get_ancestor (widget, GTK_TYPE_APPLICATION_WINDOW);
if (g_strcmp0 (prefix, "win") == 0) if (g_str_has_prefix (full_name, "win.") == 0)
{ {
if (G_IS_OBJECT (win)) if (G_IS_OBJECT (win))
return (GObject *)win; return (GObject *)win;
} }
else if (g_strcmp0 (prefix, "app") == 0) else if (g_str_has_prefix (full_name, "app.") == 0)
{ {
if (GTK_IS_WINDOW (win)) if (GTK_IS_WINDOW (win))
return (GObject *)gtk_window_get_application (GTK_WINDOW (win)); return (GObject *)gtk_window_get_application (GTK_WINDOW (win));
@ -1294,9 +1284,12 @@ find_action_owner (GtkActionable *actionable)
while (widget != NULL) while (widget != NULL)
{ {
group = gtk_widget_get_action_group (widget, prefix); GtkActionMuxer *muxer;
if (group && g_action_group_has_action (group, name))
muxer = _gtk_widget_get_action_muxer (widget, FALSE);
if (muxer && gtk_action_muxer_find (muxer, full_name, NULL))
return (GObject *)widget; return (GObject *)widget;
widget = action_ancestor (widget); widget = action_ancestor (widget);
} }