mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 06:00:22 +00:00
gtk-demo: Port builder example away from GtkUIManager
This makes gtk3-demo deprecation-free.
This commit is contained in:
parent
d89766ce41
commit
9d921ec148
@ -2,13 +2,15 @@
|
||||
*
|
||||
* Demonstrates an interface loaded from a XML description.
|
||||
*/
|
||||
#undef GTK_DISABLE_DEPRECATED
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static GtkBuilder *builder;
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
quit_activate (GtkAction *action)
|
||||
static void
|
||||
quit_activate (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkWidget *window;
|
||||
|
||||
@ -16,8 +18,10 @@ quit_activate (GtkAction *action)
|
||||
gtk_widget_destroy (window);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
about_activate (GtkAction *action)
|
||||
static void
|
||||
about_activate (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkWidget *about_dlg;
|
||||
|
||||
@ -26,18 +30,29 @@ about_activate (GtkAction *action)
|
||||
gtk_widget_hide (about_dlg);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
help_activate (GtkAction *action)
|
||||
static void
|
||||
help_activate (GSimpleAction *action,
|
||||
GVariant *parameter,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_print ("Help not available\n");
|
||||
}
|
||||
|
||||
static GActionEntry win_entries[] = {
|
||||
{ "quit", quit_activate, NULL, NULL, NULL },
|
||||
{ "about", about_activate, NULL, NULL, NULL },
|
||||
{ "help", help_activate, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
GtkWidget *
|
||||
do_builder (GtkWidget *do_widget)
|
||||
{
|
||||
static GtkWidget *window = NULL;
|
||||
GError *err = NULL;
|
||||
GtkWidget *toolbar;
|
||||
GActionGroup *actions;
|
||||
GtkAccelGroup *accel_group;
|
||||
GtkWidget *item;
|
||||
|
||||
if (!window)
|
||||
{
|
||||
@ -57,6 +72,49 @@ do_builder (GtkWidget *do_widget)
|
||||
toolbar = GTK_WIDGET (gtk_builder_get_object (builder, "toolbar1"));
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
|
||||
"primary-toolbar");
|
||||
actions = (GActionGroup*)g_simple_action_group_new ();
|
||||
g_action_map_add_action_entries (G_ACTION_MAP (actions),
|
||||
win_entries, G_N_ELEMENTS (win_entries),
|
||||
NULL);
|
||||
gtk_widget_insert_action_group (window, "win", actions);
|
||||
accel_group = gtk_accel_group_new ();
|
||||
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
|
||||
|
||||
item = (GtkWidget*)gtk_builder_get_object (builder, "new_item");
|
||||
gtk_widget_add_accelerator (item, "activate", accel_group,
|
||||
GDK_KEY_n, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
|
||||
|
||||
item = (GtkWidget*)gtk_builder_get_object (builder, "open_item");
|
||||
gtk_widget_add_accelerator (item, "activate", accel_group,
|
||||
GDK_KEY_o, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
|
||||
|
||||
item = (GtkWidget*)gtk_builder_get_object (builder, "save_item");
|
||||
gtk_widget_add_accelerator (item, "activate", accel_group,
|
||||
GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
|
||||
|
||||
item = (GtkWidget*)gtk_builder_get_object (builder, "quit_item");
|
||||
gtk_widget_add_accelerator (item, "activate", accel_group,
|
||||
GDK_KEY_q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
|
||||
|
||||
item = (GtkWidget*)gtk_builder_get_object (builder, "copy_item");
|
||||
gtk_widget_add_accelerator (item, "activate", accel_group,
|
||||
GDK_KEY_c, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
|
||||
|
||||
item = (GtkWidget*)gtk_builder_get_object (builder, "cut_item");
|
||||
gtk_widget_add_accelerator (item, "activate", accel_group,
|
||||
GDK_KEY_x, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
|
||||
|
||||
item = (GtkWidget*)gtk_builder_get_object (builder, "paste_item");
|
||||
gtk_widget_add_accelerator (item, "activate", accel_group,
|
||||
GDK_KEY_v, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
|
||||
|
||||
item = (GtkWidget*)gtk_builder_get_object (builder, "help_item");
|
||||
gtk_widget_add_accelerator (item, "activate", accel_group,
|
||||
GDK_KEY_F1, 0, GTK_ACCEL_VISIBLE);
|
||||
|
||||
item = (GtkWidget*)gtk_builder_get_object (builder, "about_item");
|
||||
gtk_widget_add_accelerator (item, "activate", accel_group,
|
||||
GDK_KEY_F7, 0, GTK_ACCEL_VISIBLE);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!--*- mode: xml -*-->
|
||||
<interface>
|
||||
<object class="GtkListStore" id="liststore1">
|
||||
<columns>
|
||||
@ -22,133 +23,6 @@
|
||||
</row>
|
||||
</data>
|
||||
</object>
|
||||
<object class="GtkUIManager" id="uimanager">
|
||||
<child>
|
||||
<object class="GtkActionGroup" id="DefaultActions">
|
||||
<child>
|
||||
<object class="GtkAction" id="Copy">
|
||||
<property name="name">Copy</property>
|
||||
<property name="tooltip" translatable="yes">Copy selected object into the clipboard</property>
|
||||
<property name="stock_id">gtk-copy</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="Cut">
|
||||
<property name="name">Cut</property>
|
||||
<property name="tooltip" translatable="yes">Cut selected object into the clipboard</property>
|
||||
<property name="stock_id">gtk-cut</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="EditMenu">
|
||||
<property name="name">EditMenu</property>
|
||||
<property name="label" translatable="yes">_Edit</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="FileMenu">
|
||||
<property name="name">FileMenu</property>
|
||||
<property name="label" translatable="yes">_File</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="New">
|
||||
<property name="name">New</property>
|
||||
<property name="tooltip" translatable="yes">Create a new file</property>
|
||||
<property name="stock_id">gtk-new</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="Open">
|
||||
<property name="name">Open</property>
|
||||
<property name="tooltip" translatable="yes">Open a file</property>
|
||||
<property name="stock_id">gtk-open</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="Paste">
|
||||
<property name="name">Paste</property>
|
||||
<property name="tooltip" translatable="yes">Paste object from the Clipboard</property>
|
||||
<property name="stock_id">gtk-paste</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="Quit">
|
||||
<property name="name">Quit</property>
|
||||
<property name="tooltip" translatable="yes">Quit the program</property>
|
||||
<property name="stock_id">gtk-quit</property>
|
||||
<signal handler="quit_activate" name="activate"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="Save">
|
||||
<property name="name">Save</property>
|
||||
<property name="is_important">True</property>
|
||||
<property name="tooltip" translatable="yes">Save a file</property>
|
||||
<property name="stock_id">gtk-save</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="SaveAs">
|
||||
<property name="name">SaveAs</property>
|
||||
<property name="tooltip" translatable="yes">Save with a different name</property>
|
||||
<property name="stock_id">gtk-save-as</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="HelpMenu">
|
||||
<property name="name">HelpMenu</property>
|
||||
<property name="label" translatable="yes">_Help</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="About">
|
||||
<property name="name">About</property>
|
||||
<property name="stock_id">gtk-about</property>
|
||||
<signal handler="about_activate" name="activate"/>
|
||||
</object>
|
||||
<accelerator key="F7"/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkAction" id="Help">
|
||||
<property name="name">Help</property>
|
||||
<property name="stock_id">gtk-help</property>
|
||||
<signal handler="help_activate" name="activate"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<ui>
|
||||
<menubar name="menubar1">
|
||||
<menu action="FileMenu" name="FileMenu">
|
||||
<menuitem action="New" name="New"/>
|
||||
<menuitem action="Open" name="Open"/>
|
||||
<menuitem action="Save" name="Save"/>
|
||||
<menuitem action="SaveAs" name="SaveAs"/>
|
||||
<separator/>
|
||||
<menuitem action="Quit" name="Quit"/>
|
||||
</menu>
|
||||
<menu action="EditMenu">
|
||||
<menuitem action="Copy" name="Copy"/>
|
||||
<menuitem action="Cut" name="Cut"/>
|
||||
<menuitem action="Paste" name="Paste"/>
|
||||
</menu>
|
||||
<menu action="HelpMenu" name="HelpMenu">
|
||||
<menuitem action="Help" name="Help"/>
|
||||
<menuitem action="About" name="About"/>
|
||||
</menu>
|
||||
</menubar>
|
||||
<toolbar name="toolbar1">
|
||||
<toolitem action="New" name="New"/>
|
||||
<toolitem action="Open" name="Open"/>
|
||||
<toolitem action="Save" name="Save"/>
|
||||
<separator/>
|
||||
<toolitem action="Copy" name="Copy"/>
|
||||
<toolitem action="Cut" name="Cut"/>
|
||||
<toolitem action="Paste" name="Paste"/>
|
||||
</toolbar>
|
||||
</ui>
|
||||
</object>
|
||||
<object class="GtkAboutDialog" id="aboutdialog1">
|
||||
<property name="program-name" translatable="yes">GtkBuilder demo</property>
|
||||
<property name="logo-icon-name" translatable="yes">gtk3-demo</property>
|
||||
@ -164,38 +38,201 @@
|
||||
<object class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<object constructor="uimanager" class="GtkMenuBar" id="menubar1">
|
||||
<object class="GtkMenuBar" id="menubar1">
|
||||
<property name="visible">True</property>
|
||||
<child internal-child="accessible">
|
||||
<object class="AtkObject" id="a11y-menubar">
|
||||
<property name="AtkObject::accessible-name">The menubar</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_File</property>
|
||||
<property name="use-underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu">
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="new_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_New</property>
|
||||
<property name="use-underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="open_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Open</property>
|
||||
<property name="use-underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="save_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Save</property>
|
||||
<property name="use-underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="save_as_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Save _As</property>
|
||||
<property name="use-underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorMenuItem">
|
||||
<property name="visible">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="quit_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Quit</property>
|
||||
<property name="use-underline">True</property>
|
||||
<property name="action-name">win.quit</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Edit</property>
|
||||
<property name="use-underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu">
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="copy_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Copy</property>
|
||||
<property name="use-underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="cut_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Cut</property>
|
||||
<property name="use-underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="paste_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Paste</property>
|
||||
<property name="use-underline">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Help</property>
|
||||
<property name="use-underline">True</property>
|
||||
<child type="submenu">
|
||||
<object class="GtkMenu">
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="help_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Help</property>
|
||||
<property name="use-underline">True</property>
|
||||
<property name="action-name">win.help</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="about_item">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_About</property>
|
||||
<property name="use-underline">True</property>
|
||||
<property name="action-name">win.about</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object constructor="uimanager" class="GtkToolbar" id="toolbar1">
|
||||
<object class="GtkToolbar" id="toolbar1">
|
||||
<property name="visible">True</property>
|
||||
<child internal-child="accessible">
|
||||
<object class="AtkObject" id="a11y-toolbar">
|
||||
<property name="AtkObject::accessible-name">The toolbar</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">New</property>
|
||||
<property name="tooltip-text" translatable="yes">Create a new file</property>
|
||||
<property name="icon-name">document-new</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Open</property>
|
||||
<property name="tooltip-text" translatable="yes">Open a file</property>
|
||||
<property name="icon-name">document-open</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Save</property>
|
||||
<property name="tooltip-text" translatable="yes">Save a file</property>
|
||||
<property name="icon-name">document-save</property>
|
||||
<property name="is-important">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparatorToolItem">
|
||||
<property name="visible">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Copy</property>
|
||||
<property name="tooltip-text" translatable="yes">Copy selected object into the clipboard</property>
|
||||
<property name="icon-name">edit-copy</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Cut</property>
|
||||
<property name="tooltip-text" translatable="yes">Cut selected object into the clipboard</property>
|
||||
<property name="icon-name">edit-cut</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Paste</property>
|
||||
<property name="tooltip-text" translatable="yes">Paste object from the clipboard</property>
|
||||
<property name="icon-name">edit-paste</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">1</property>
|
||||
<property name="expand">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="hscrollbar_policy">automatic</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="vscrollbar_policy">automatic</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="treeview1">
|
||||
<property name="visible">True</property>
|
||||
@ -247,6 +284,7 @@
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
<property name="expand">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
@ -254,8 +292,8 @@
|
||||
<property name="visible">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">3</property>
|
||||
<property name="expand">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
Loading…
Reference in New Issue
Block a user