mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 21:21:21 +00:00
inspector: show GMenus
This does not quite work yet, and I have no idea why.
This commit is contained in:
parent
8011d853e1
commit
2346ccde43
@ -35,6 +35,8 @@ libgtkinspector_la_SOURCES = \
|
||||
init.h \
|
||||
init.c \
|
||||
inspect-button.c \
|
||||
menu.h \
|
||||
menu.c \
|
||||
object-hierarchy.h \
|
||||
object-hierarchy.c \
|
||||
prop-editor.h \
|
||||
@ -91,6 +93,7 @@ templates = \
|
||||
css-editor.ui \
|
||||
data-list.ui \
|
||||
general.ui \
|
||||
menu.ui \
|
||||
object-hierarchy.ui \
|
||||
prop-list.ui \
|
||||
resource-list.ui \
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "data-list.h"
|
||||
#include "general.h"
|
||||
#include "gestures.h"
|
||||
#include "menu.h"
|
||||
#include "object-hierarchy.h"
|
||||
#include "prop-list.h"
|
||||
#include "python-hooks.h"
|
||||
@ -57,6 +58,7 @@ gtk_inspector_init (void)
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_DATA_LIST);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_GENERAL);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_GESTURES);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_MENU);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_OBJECT_HIERARCHY);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_PROP_LIST);
|
||||
g_type_ensure (GTK_TYPE_INSPECTOR_PYTHON_SHELL);
|
||||
|
@ -7,6 +7,7 @@
|
||||
<file compressed="true">css-editor.ui</file>
|
||||
<file compressed="true">data-list.ui</file>
|
||||
<file compressed="true">general.ui</file>
|
||||
<file compressed="true">menu.ui</file>
|
||||
<file compressed="true">object-hierarchy.ui</file>
|
||||
<file compressed="true">prop-list.ui</file>
|
||||
<file compressed="true">resource-list.ui</file>
|
||||
|
118
gtk/inspector/menu.c
Normal file
118
gtk/inspector/menu.c
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include "menu.h"
|
||||
#include "gtkwidgetprivate.h"
|
||||
|
||||
enum
|
||||
{
|
||||
COLUMN_TYPE,
|
||||
COLUMN_LABEL,
|
||||
COLUMN_ACTION,
|
||||
COLUMN_TARGET,
|
||||
COLUMN_ICON
|
||||
};
|
||||
|
||||
struct _GtkInspectorMenuPrivate
|
||||
{
|
||||
GtkTreeStore *model;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorMenu, gtk_inspector_menu, GTK_TYPE_BOX)
|
||||
|
||||
static void
|
||||
gtk_inspector_menu_init (GtkInspectorMenu *sl)
|
||||
{
|
||||
sl->priv = gtk_inspector_menu_get_instance_private (sl);
|
||||
gtk_widget_init_template (GTK_WIDGET (sl));
|
||||
}
|
||||
|
||||
static void
|
||||
add_item (GtkInspectorMenu *sl,
|
||||
GMenuModel *menu,
|
||||
gint idx,
|
||||
GtkTreeIter *parent)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GVariant *value;
|
||||
gchar *label = NULL;
|
||||
gchar *action = NULL;
|
||||
gchar *target = NULL;
|
||||
gchar *icon = NULL;
|
||||
|
||||
g_menu_model_get_item_attribute (menu, idx, G_MENU_ATTRIBUTE_LABEL, "s", &label);
|
||||
g_menu_model_get_item_attribute (menu, idx, G_MENU_ATTRIBUTE_ACTION, "s", &action);
|
||||
value = g_menu_model_get_item_attribute_value (menu, idx, G_MENU_ATTRIBUTE_TARGET, NULL);
|
||||
if (value)
|
||||
{
|
||||
target = g_variant_print (value, FALSE);
|
||||
g_variant_unref (value);
|
||||
}
|
||||
|
||||
gtk_tree_store_append (sl->priv->model, &iter, parent);
|
||||
gtk_tree_store_set (sl->priv->model, &iter,
|
||||
COLUMN_TYPE, "item",
|
||||
COLUMN_LABEL, label,
|
||||
COLUMN_ACTION, action,
|
||||
COLUMN_TARGET, target,
|
||||
COLUMN_ICON, icon,
|
||||
-1);
|
||||
|
||||
g_free (label);
|
||||
g_free (action);
|
||||
g_free (target);
|
||||
g_free (icon);
|
||||
}
|
||||
|
||||
static void
|
||||
add_menu (GtkInspectorMenu *sl,
|
||||
GMenuModel *menu,
|
||||
GtkTreeIter *parent)
|
||||
{
|
||||
gint n_items;
|
||||
gint i;
|
||||
|
||||
gtk_widget_show (GTK_WIDGET (sl));
|
||||
|
||||
n_items = g_menu_model_get_n_items (menu);
|
||||
for (i = 0; i < n_items; i++)
|
||||
add_item (sl, menu, i, parent);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_inspector_menu_set_object (GtkInspectorMenu *sl,
|
||||
GObject *object)
|
||||
{
|
||||
gtk_widget_hide (GTK_WIDGET (sl));
|
||||
gtk_tree_store_clear (sl->priv->model);
|
||||
|
||||
if (G_IS_MENU_MODEL (object))
|
||||
add_menu (sl, G_MENU_MODEL (object), NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_inspector_menu_class_init (GtkInspectorMenuClass *klass)
|
||||
{
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/inspector/menu.ui");
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMenu, model);
|
||||
}
|
||||
|
||||
// vim: set et sw=2 ts=2:
|
83
gtk/inspector/menu.ui
Normal file
83
gtk/inspector/menu.ui
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface domain="gtk30">
|
||||
<object class="GtkTreeStore" id="model">
|
||||
<columns>
|
||||
<column type="gchararray"/> <!-- type -->
|
||||
<column type="gchararray"/> <!-- label -->
|
||||
<column type="gchararray"/> <!-- action -->
|
||||
<column type="gchararray"/> <!-- target -->
|
||||
<column type="gchararray"/> <!-- icon -->
|
||||
</columns>
|
||||
</object>
|
||||
<template class="GtkInspectorMenu" parent="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="hscrollbar-policy">automatic</property>
|
||||
<property name="vscrollbar-policy">always</property>
|
||||
<property name="shadow-type">in</property>
|
||||
<child>
|
||||
<object class= "GtkTreeView">
|
||||
<property name="visible">True</property>
|
||||
<property name="model">model</property>
|
||||
<property name="activate-on-single-click">True</property>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="title" translatable="yes">Label</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText">
|
||||
<property name="scale">0.8</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="title" translatable="yes">Action</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText">
|
||||
<property name="scale">0.8</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">2</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="title" translatable="yes">Target</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText">
|
||||
<property name="scale">0.8</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">3</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="title" translatable="yes">Icon</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText">
|
||||
<property name="scale">0.8</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="text">4</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
@ -36,9 +36,10 @@
|
||||
#include "button-path.h"
|
||||
#include "size-groups.h"
|
||||
#include "data-list.h"
|
||||
#include "gestures.h"
|
||||
#include "signals-list.h"
|
||||
#include "actions.h"
|
||||
#include "menu.h"
|
||||
#include "gestures.h"
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GtkInspectorWindow, gtk_inspector_window, GTK_TYPE_WINDOW)
|
||||
@ -78,6 +79,7 @@ on_widget_tree_selection_changed (GtkInspectorWidgetTree *wt,
|
||||
gtk_inspector_size_groups_set_object (GTK_INSPECTOR_SIZE_GROUPS (iw->size_groups), selected);
|
||||
gtk_inspector_data_list_set_object (GTK_INSPECTOR_DATA_LIST (iw->data_list), selected);
|
||||
gtk_inspector_actions_set_object (GTK_INSPECTOR_ACTIONS (iw->actions), selected);
|
||||
gtk_inspector_menu_set_object (GTK_INSPECTOR_MENU (iw->menu), selected);
|
||||
gtk_inspector_gestures_set_object (GTK_INSPECTOR_GESTURES (iw->gestures), selected);
|
||||
|
||||
notebook = gtk_widget_get_parent (iw->prop_list);
|
||||
@ -198,6 +200,7 @@ gtk_inspector_window_class_init (GtkInspectorWindowClass *klass)
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, size_groups);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, data_list);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, actions);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, menu);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkInspectorWindow, gestures);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_inspect);
|
||||
|
@ -54,6 +54,7 @@ typedef struct
|
||||
GtkWidget *size_groups;
|
||||
GtkWidget *data_list;
|
||||
GtkWidget *actions;
|
||||
GtkWidget *menu;
|
||||
GtkWidget *gestures;
|
||||
|
||||
GtkWidget *widget_popup;
|
||||
|
@ -239,6 +239,20 @@
|
||||
<property name="label" translatable="yes">Actions</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInspectorMenu" id="menu">
|
||||
</object>
|
||||
<packing>
|
||||
<property name="tab_expand">True</property>
|
||||
<property name="tab_fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Menu</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkInspectorGestures" id="gestures">
|
||||
<property name="widget-tree">widget_tree</property>
|
||||
|
@ -281,6 +281,7 @@ gtk/inspector/data-list.ui.h
|
||||
gtk/inspector/general.ui.h
|
||||
gtk/inspector/gestures.c
|
||||
gtk/inspector/inspect-button.c
|
||||
gtk/inspector/menu.ui.h
|
||||
gtk/inspector/object-hierarchy.ui.h
|
||||
gtk/inspector/prop-editor.c
|
||||
gtk/inspector/prop-list.ui.h
|
||||
|
Loading…
Reference in New Issue
Block a user