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 *message;
GtkWidget *infobar; GtkWidget *infobar;
GtkWidget *status; GtkWidget *status;
GtkWidget *menutool; GtkWidget *menubutton;
GMenuModel *toolmenu; GMenuModel *toolmenu;
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
@ -428,8 +428,8 @@ demo_application_window_init (DemoApplicationWindow *window)
gtk_widget_init_template (GTK_WIDGET (window)); gtk_widget_init_template (GTK_WIDGET (window));
popover = gtk_popover_menu_new_from_model (window->menutool, window->toolmenu); popover = gtk_popover_menu_new_from_model (window->menubutton, window->toolmenu);
gtk_menu_tool_button_set_popover (GTK_MENU_TOOL_BUTTON (window->menutool), popover); gtk_menu_button_set_popover (GTK_MENU_BUTTON (window->menubutton), popover);
g_action_map_add_action_entries (G_ACTION_MAP (window), g_action_map_add_action_entries (G_ACTION_MAP (window),
win_entries, G_N_ELEMENTS (win_entries), 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, infobar);
gtk_widget_class_bind_template_child (widget_class, DemoApplicationWindow, status); 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, 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_child (widget_class, DemoApplicationWindow, toolmenu);
gtk_widget_class_bind_template_callback (widget_class, clicked_cb); gtk_widget_class_bind_template_callback (widget_class, clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, update_statusbar); gtk_widget_class_bind_template_callback (widget_class, update_statusbar);

View File

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

View File

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

View File

@ -62,22 +62,19 @@ GtkWidget *
create_toolbar (void) create_toolbar (void)
{ {
GtkWidget *toolbar; 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); gtk_widget_set_valign (toolbar, GTK_ALIGN_CENTER);
item = gtk_tool_button_new (NULL, NULL); item = gtk_button_new_from_icon_name ("go-next");
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-next"); gtk_container_add (GTK_CONTAINER (toolbar), item);
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
item = gtk_tool_button_new (NULL, NULL); item = gtk_button_new_from_icon_name ("go-previous");
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-previous"); gtk_container_add (GTK_CONTAINER (toolbar), item);
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
item = gtk_tool_button_new (NULL, "Hello World"); item = gtk_button_new_with_label ("Hello World");
gtk_tool_item_set_is_important (item, TRUE); gtk_container_add (GTK_CONTAINER (toolbar), item);
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
return toolbar; return toolbar;
} }

View File

@ -111,53 +111,52 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkToolbar" id="toolbar1"> <object class="GtkBox" id="toolbar1">
<child internal-child="accessible"> <child internal-child="accessible">
<object class="AtkObject" id="a11y-toolbar"> <object class="AtkObject" id="a11y-toolbar">
<property name="AtkObject::accessible-name">The toolbar</property> <property name="AtkObject::accessible-name">The toolbar</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkToolButton"> <object class="GtkButton">
<property name="label" translatable="yes">New</property> <property name="label" translatable="yes">New</property>
<property name="tooltip-text" translatable="yes">Create a new file</property> <property name="tooltip-text" translatable="yes">Create a new file</property>
<property name="icon-name">document-new</property> <property name="icon-name">document-new</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkToolButton"> <object class="GtkButton">
<property name="label" translatable="yes">Open</property> <property name="label" translatable="yes">Open</property>
<property name="tooltip-text" translatable="yes">Open a file</property> <property name="tooltip-text" translatable="yes">Open a file</property>
<property name="icon-name">document-open</property> <property name="icon-name">document-open</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkToolButton"> <object class="GtkButton">
<property name="label" translatable="yes">Save</property> <property name="label" translatable="yes">Save</property>
<property name="tooltip-text" translatable="yes">Save a file</property> <property name="tooltip-text" translatable="yes">Save a file</property>
<property name="icon-name">document-save</property> <property name="icon-name">document-save</property>
<property name="is-important">1</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkSeparatorToolItem"/> <object class="GtkSeparator"/>
</child> </child>
<child> <child>
<object class="GtkToolButton"> <object class="GtkButton">
<property name="label" translatable="yes">Copy</property> <property name="label" translatable="yes">Copy</property>
<property name="tooltip-text" translatable="yes">Copy selected object into the clipboard</property> <property name="tooltip-text" translatable="yes">Copy selected object into the clipboard</property>
<property name="icon-name">edit-copy</property> <property name="icon-name">edit-copy</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkToolButton"> <object class="GtkButton">
<property name="label" translatable="yes">Cut</property> <property name="label" translatable="yes">Cut</property>
<property name="tooltip-text" translatable="yes">Cut selected object into the clipboard</property> <property name="tooltip-text" translatable="yes">Cut selected object into the clipboard</property>
<property name="icon-name">edit-cut</property> <property name="icon-name">edit-cut</property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkToolButton"> <object class="GtkButton">
<property name="label" translatable="yes">Paste</property> <property name="label" translatable="yes">Paste</property>
<property name="tooltip-text" translatable="yes">Paste object from the clipboard</property> <property name="tooltip-text" translatable="yes">Paste object from the clipboard</property>
<property name="icon-name">edit-paste</property> <property name="icon-name">edit-paste</property>

View File

@ -26,7 +26,7 @@ enum
static GdkPixbuf *file_pixbuf, *folder_pixbuf; static GdkPixbuf *file_pixbuf, *folder_pixbuf;
gchar *parent; gchar *parent;
GtkToolItem *up_button; GtkWidget *up_button;
/* Loads the images for the demo and returns whether the operation succeeded */ /* Loads the images for the demo and returns whether the operation succeeded */
static void static void
@ -248,7 +248,7 @@ do_iconview (GtkWidget *do_widget)
GtkListStore *store; GtkListStore *store;
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *tool_bar; GtkWidget *tool_bar;
GtkToolItem *home_button; GtkWidget *home_button;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL); window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 650, 400); 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); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (window), vbox); 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); gtk_container_add (GTK_CONTAINER (vbox), tool_bar);
up_button = gtk_tool_button_new (NULL, NULL); up_button = gtk_button_new_with_mnemonic ("_Up");
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);
gtk_widget_set_sensitive (GTK_WIDGET (up_button), FALSE); 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); home_button = gtk_button_new_with_mnemonic ("_Home");
gtk_tool_button_set_label (GTK_TOOL_BUTTON (home_button), _("_Home")); gtk_container_add (GTK_CONTAINER (tool_bar), home_button);
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);
sw = gtk_scrolled_window_new (NULL, NULL); sw = gtk_scrolled_window_new (NULL, NULL);