widget-factory: populate the second page more

Add back a menubar example that was lost a while ago, and also
include a searchbar and an infobar.
This commit is contained in:
Matthias Clasen 2014-04-29 21:43:11 -04:00
parent bc057d849a
commit 4d36fab72a
2 changed files with 527 additions and 14 deletions

View File

@ -23,18 +23,6 @@
#include "config.h" #include "config.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
static void
activate_toggle (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GVariant *state;
state = g_action_get_state (G_ACTION (action));
g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state)));
g_variant_unref (state);
}
static void static void
change_theme_state (GSimpleAction *action, change_theme_state (GSimpleAction *action,
GVariant *state, GVariant *state,
@ -50,6 +38,44 @@ change_theme_state (GSimpleAction *action,
g_simple_action_set_state (action, state); g_simple_action_set_state (action, state);
} }
static void
change_toolbar_state (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
GtkWidget *window = user_data;
GtkWidget *toolbar;
toolbar = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "toolbar"));
gtk_widget_set_visible (toolbar, g_variant_get_boolean (state));
g_simple_action_set_state (action, state);
}
static void
activate_search (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkWidget *window = user_data;
GtkWidget *searchbar;
searchbar = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "searchbar"));
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (searchbar), TRUE);
}
static void
activate_delete (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkWidget *window = user_data;
GtkWidget *infobar;
infobar = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "infobar"));
gtk_widget_show (infobar);
}
static void static void
activate_about (GSimpleAction *action, activate_about (GSimpleAction *action,
GVariant *parameter, GVariant *parameter,
@ -236,6 +262,13 @@ update_header (GtkListBoxRow *row,
} }
} }
static void
info_bar_response (GtkWidget *infobar, gint response_id)
{
if (response_id == GTK_RESPONSE_CLOSE)
gtk_widget_hide (infobar);
}
static void static void
activate (GApplication *app) activate (GApplication *app)
{ {
@ -244,7 +277,10 @@ activate (GApplication *app)
GtkWidget *widget; GtkWidget *widget;
GtkAdjustment *adj; GtkAdjustment *adj;
static GActionEntry win_entries[] = { static GActionEntry win_entries[] = {
{ "dark", activate_toggle, NULL, "false", change_theme_state } { "dark", NULL, NULL, "false", change_theme_state },
{ "toolbar", NULL, NULL, "true", change_toolbar_state },
{ "search", activate_search, NULL, NULL, NULL },
{ "delete", activate_delete, NULL, NULL, NULL }
}; };
builder = gtk_builder_new (); builder = gtk_builder_new ();
@ -274,6 +310,16 @@ activate (GApplication *app)
widget = (GtkWidget *)gtk_builder_get_object (builder, "listbox"); widget = (GtkWidget *)gtk_builder_get_object (builder, "listbox");
gtk_list_box_set_header_func (GTK_LIST_BOX (widget), update_header, NULL, NULL); gtk_list_box_set_header_func (GTK_LIST_BOX (widget), update_header, NULL, NULL);
widget = (GtkWidget *)gtk_builder_get_object (builder, "toolbar");
g_object_set_data (G_OBJECT (window), "toolbar", widget);
widget = (GtkWidget *)gtk_builder_get_object (builder, "searchbar");
g_object_set_data (G_OBJECT (window), "searchbar", widget);
widget = (GtkWidget *)gtk_builder_get_object (builder, "infobar");
g_signal_connect (widget, "response", G_CALLBACK (info_bar_response), NULL);
g_object_set_data (G_OBJECT (window), "infobar", widget);
gtk_widget_show_all (GTK_WIDGET (window)); gtk_widget_show_all (GTK_WIDGET (window));
g_object_unref (builder); g_object_unref (builder);

View File

@ -2031,7 +2031,7 @@ Suspendisse feugiat quam quis dolor accumsan cursus. </property>
</object> </object>
</child> </child>
<child> <child>
<object class="GtkFrame" id="frame"> <object class="GtkFrame" id="page2frame1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="hexpand">False</property> <property name="hexpand">False</property>
<child> <child>
@ -2188,8 +2188,475 @@ Suspendisse feugiat quam quis dolor accumsan cursus. </property>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">10</property>
<child>
<object class="GtkFrame" id="page2frame2">
<property name="visible">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar">
<property name="visible">True</property>
<child>
<object class="GtkMenuItem" id="menuitem1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">_File</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="menuitem101">
<property name="label" translatable="yes">_New</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem102">
<property name="label" translatable="yes">_Open</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem103">
<property name="label" translatable="yes">_Save</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem104">
<property name="label" translatable="yes">Save _As</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem105">
<property name="label" translatable="yes">_Quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="action_name">app.quit</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">_Edit</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="menuitem106">
<property name="label" translatable="yes">Cu_t</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem107">
<property name="label" translatable="yes">_Copy</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem108">
<property name="label" translatable="yes">_Paste</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem109">
<property name="label" translatable="yes">_Delete</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="action_name">win.delete</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="searchmenuitem">
<property name="label" translatable="yes">_Search</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="action_name">win.search</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="togglesmenuitem">
<property name="label">Checks &amp; Radios</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="use_stock">False</property>
<child type="submenu">
<object class="GtkMenu" id="togglessubmenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckMenuItem" id="checkmenuitem1">
<property name="label">_Check</property>
<property name="active">True</property>
<property name="visible">True</property>
<property name="sensitive">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="checkmenuitem2">
<property name="label">_Check</property>
<property name="active">True</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="checkmenuitem3">
<property name="label">_Check</property>
<property name="active">False</property>
<property name="visible">True</property>
<property name="inconsistent">True</property>
<property name="sensitive">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="checkmenuitem4">
<property name="label">_Check</property>
<property name="active">False</property>
<property name="visible">True</property>
<property name="sensitive">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="checkmenuitem5">
<property name="label">_Check</property>
<property name="active">False</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="checkmenuitem6">
<property name="label">_Check</property>
<property name="active">False</property>
<property name="visible">True</property>
<property name="inconsistent">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem">
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="radiomenuitem1">
<property name="label">_Radio</property>
<property name="active">True</property>
<property name="visible">True</property>
<property name="sensitive">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="radiomenuitem2">
<property name="label">_Radio</property>
<property name="active">True</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="radiomenuitem3">
<property name="label">_Radio</property>
<property name="active">False</property>
<property name="visible">True</property>
<property name="inconsistent">True</property>
<property name="sensitive">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="radiomenuitem4">
<property name="label">_Radio</property>
<property name="active">False</property>
<property name="visible">True</property>
<property name="sensitive">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="radiomenuitem5">
<property name="label">_Radio</property>
<property name="active">False</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="radiomenuitem6">
<property name="label">_Radio</property>
<property name="active">False</property>
<property name="visible">True</property>
<property name="inconsistent">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">_View</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="view-menu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckMenuItem" id="darkmenuitem">
<property name="label">_Dark theme</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="action_name">win.dark</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="toolbarmenuitem">
<property name="label">_Toolbar</property>
<property name="visible">True</property>
<property name="active">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="action_name">win.toolbar</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="label" translatable="yes">_Help</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu" id="menu3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="aboutmenuitem">
<property name="label" translatable="yes">_About</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="action_name">app.about</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkToolbar" id="toolbar">
<property name="visible">True</property>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="label">New</property>
<property name="icon-name">document-new</property>
</object>
</child>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="label">Save</property>
<property name="icon-name">document-save</property>
</object>
</child>
<child>
<object class="GtkToolButton">
<property name="visible">True</property>
<property name="label">Search</property>
<property name="icon-name">search</property>
<property name="action-name">win.search</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSearchBar" id="searchbar">
<property name="visible">True</property>
<child>
<object class="GtkSearchEntry">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkInfoBar" id="infobar">
<property name="show-close-button">True</property>
<property name="no-show-all">True</property>
<child internal-child="content_area">
<object class="GtkBox">
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="label">You wanted to delete something.</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="shadow_type">in</property>
<property name="vexpand">True</property>
<child>
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="buffer">textbuffer1</property>
<property name="wrap_mode">2</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
</object>
<packing>
<property name="expand">True</property>
</packing>
</child>
</object> </object>
</child> </child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="orientation">vertical</property>
</object>
</child>
<child>
<object class="GtkBox" id="filler2">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
</packing>
</child>
</object> </object>
</child> </child>
</object> </object>