gtk-demo: Get rid of toolbars

This commit is contained in:
Benjamin Otte 2020-02-03 04:52:15 +01:00
parent 8a60f5dc78
commit 68dbb3f31a
6 changed files with 32 additions and 51 deletions

View File

@ -14,7 +14,7 @@ typedef struct {
GtkWidget *message;
GtkWidget *infobar;
GtkWidget *status;
GtkWidget *menutool;
GtkWidget *menubutton;
GMenuModel *toolmenu;
GtkTextBuffer *buffer;
@ -428,8 +428,8 @@ demo_application_window_init (DemoApplicationWindow *window)
gtk_widget_init_template (GTK_WIDGET (window));
popover = gtk_popover_menu_new_from_model (window->menutool, window->toolmenu);
gtk_menu_tool_button_set_popover (GTK_MENU_TOOL_BUTTON (window->menutool), popover);
popover = gtk_popover_menu_new_from_model (window->menubutton, window->toolmenu);
gtk_menu_button_set_popover (GTK_MENU_BUTTON (window->menubutton), popover);
g_action_map_add_action_entries (G_ACTION_MAP (window),
win_entries, G_N_ELEMENTS (win_entries),
@ -528,7 +528,7 @@ demo_application_window_class_init (DemoApplicationWindowClass *class)
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, infobar);
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, status);
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, buffer);
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, menutool);
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, menubutton);
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, toolmenu);
gtk_widget_class_bind_template_callback (widget_class, clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, update_statusbar);

View File

@ -8,27 +8,24 @@
<child>
<object class="GtkGrid">
<child>
<object class="GtkToolbar">
<object class="GtkBox">
<property name="hexpand">1</property>
<style>
<class name="primary-toolbar"/>
</style>
<child>
<object class="GtkMenuToolButton" id="menutool">
<object class="GtkMenuButton" id="menubutton">
<property name="icon-name">document-open</property>
</object>
</child>
<child>
<object class="GtkToolButton">
<object class="GtkButton">
<property name="icon-name">application-exit</property>
<property name="action-name">app.quit</property>
</object>
</child>
<child>
<object class="GtkSeparatorToolItem"/>
<object class="GtkSeparator"/>
</child>
<child>
<object class="GtkToolButton">
<object class="GtkButton">
<property name="icon-name">applications-other</property>
<property name="action-name">win.logo</property>
</object>

View File

@ -63,7 +63,6 @@ GtkWidget *
do_builder (GtkWidget *do_widget)
{
static GtkWidget *window = NULL;
GtkWidget *toolbar;
GActionGroup *actions;
if (!window)
@ -77,9 +76,6 @@ do_builder (GtkWidget *do_widget)
gtk_widget_get_display (do_widget));
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
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),

View File

@ -62,22 +62,19 @@ GtkWidget *
create_toolbar (void)
{
GtkWidget *toolbar;
GtkToolItem *item;
GtkWidget *item;
toolbar = gtk_toolbar_new ();
toolbar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_widget_set_valign (toolbar, GTK_ALIGN_CENTER);
item = gtk_tool_button_new (NULL, NULL);
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-next");
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
item = gtk_button_new_from_icon_name ("go-next");
gtk_container_add (GTK_CONTAINER (toolbar), item);
item = gtk_tool_button_new (NULL, NULL);
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-previous");
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
item = gtk_button_new_from_icon_name ("go-previous");
gtk_container_add (GTK_CONTAINER (toolbar), item);
item = gtk_tool_button_new (NULL, "Hello World");
gtk_tool_item_set_is_important (item, TRUE);
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
item = gtk_button_new_with_label ("Hello World");
gtk_container_add (GTK_CONTAINER (toolbar), item);
return toolbar;
}

View File

@ -111,53 +111,52 @@
</object>
</child>
<child>
<object class="GtkToolbar" id="toolbar1">
<object class="GtkBox" id="toolbar1">
<child internal-child="accessible">
<object class="AtkObject" id="a11y-toolbar">
<property name="AtkObject::accessible-name">The toolbar</property>
</object>
</child>
<child>
<object class="GtkToolButton">
<object class="GtkButton">
<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">
<object class="GtkButton">
<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">
<object class="GtkButton">
<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">1</property>
</object>
</child>
<child>
<object class="GtkSeparatorToolItem"/>
<object class="GtkSeparator"/>
</child>
<child>
<object class="GtkToolButton">
<object class="GtkButton">
<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">
<object class="GtkButton">
<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">
<object class="GtkButton">
<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>

View File

@ -26,7 +26,7 @@ enum
static GdkPixbuf *file_pixbuf, *folder_pixbuf;
gchar *parent;
GtkToolItem *up_button;
GtkWidget *up_button;
/* Loads the images for the demo and returns whether the operation succeeded */
static void
@ -248,7 +248,7 @@ do_iconview (GtkWidget *do_widget)
GtkListStore *store;
GtkWidget *vbox;
GtkWidget *tool_bar;
GtkToolItem *home_button;
GtkWidget *home_button;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 650, 400);
@ -265,23 +265,15 @@ do_iconview (GtkWidget *do_widget)
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
tool_bar = gtk_toolbar_new ();
tool_bar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (vbox), tool_bar);
up_button = gtk_tool_button_new (NULL, NULL);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (up_button), _("_Up"));
gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (up_button), TRUE);
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (up_button), "go-up");
gtk_tool_item_set_is_important (up_button, TRUE);
up_button = gtk_button_new_with_mnemonic ("_Up");
gtk_widget_set_sensitive (GTK_WIDGET (up_button), FALSE);
gtk_toolbar_insert (GTK_TOOLBAR (tool_bar), up_button, -1);
gtk_container_add (GTK_CONTAINER (tool_bar), up_button);
home_button = gtk_tool_button_new (NULL, NULL);
gtk_tool_button_set_label (GTK_TOOL_BUTTON (home_button), _("_Home"));
gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (home_button), TRUE);
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (home_button), "go-home");
gtk_tool_item_set_is_important (home_button, TRUE);
gtk_toolbar_insert (GTK_TOOLBAR (tool_bar), home_button, -1);
home_button = gtk_button_new_with_mnemonic ("_Home");
gtk_container_add (GTK_CONTAINER (tool_bar), home_button);
sw = gtk_scrolled_window_new (NULL, NULL);