From d8bbc62e9fdd8e0833c123742493f827f61db9f5 Mon Sep 17 00:00:00 2001 From: raveit65 Date: Tue, 7 Feb 2017 20:47:28 +0100 Subject: theme-viewer: port GtkAction to GAction --- src/ui/theme-viewer.c | 199 ++++++++++++++++++++++++++++---------------------- 1 file changed, 113 insertions(+), 86 deletions(-) diff --git a/src/ui/theme-viewer.c b/src/ui/theme-viewer.c index 27e278f1..9643f07a 100644 --- a/src/ui/theme-viewer.c +++ b/src/ui/theme-viewer.c @@ -65,108 +65,127 @@ static double milliseconds_to_draw_frame = 0.0; static void run_theme_benchmark (void); - -static const gchar *menu_item_string = - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n"; - -static GtkActionEntry menu_items[] = +static const gchar *xml = + "" + "" + "" + "Windows" + "
" + "" + "Dialog" + "theme-viewer.dialog1" + "<control>d" + "" + "" + "Modal dialog" + "theme-viewer.dialog2" + "" + "" + "Utility" + "theme-viewer.utility" + "<control>u" + "" + "" + "Splashscreen" + "theme-viewer.splashscreen" + "<control>s" + "" + "" + "Top dock" + "theme-viewer.top-dock" + "" + "" + "Bottom dock" + "theme-viewer.bottom-dock" + "" + "" + "Left dock" + "theme-viewer.left-dock" + "" + "" + "Right dock" + "theme-viewer.right-dock" + "" + "" + "All docks" + "theme-viewer.all-docks" + "" + "" + "Desktop" + "theme-viewer.desktop" + "" + "
" + "
" + "
" + "
"; + +static GActionEntry theme_viewer_entries[] = { - { "Windows", NULL, N_("_Windows"), NULL, NULL, NULL }, - { "Dialog", NULL, N_("_Dialog"), "d", NULL, NULL }, - { "Modal dialog", NULL, N_("_Modal dialog"), NULL, NULL, NULL }, - { "Utility", NULL, N_("_Utility"), "u", NULL, NULL }, - { "Splashscreen", NULL, N_("_Splashscreen"), "s", NULL, NULL }, - { "Top dock", NULL, N_("_Top dock"), NULL, NULL, NULL }, - { "Bottom dock", NULL, N_("_Bottom dock"), NULL, NULL, NULL }, - { "Left dock", NULL, N_("_Left dock"), NULL, NULL, NULL }, - { "Right dock", NULL, N_("_Right dock"), NULL, NULL, NULL }, - { "All docks", NULL, N_("_All docks"), NULL, NULL, NULL }, - { "Desktop", NULL, N_("Des_ktop"), NULL, NULL, NULL } + /* menubar */ + { "dialog1", NULL, NULL, NULL, NULL, {} }, + { "dialog2", NULL, NULL, NULL, NULL, {} }, + { "utility", NULL, NULL, NULL, NULL, {} }, + { "splashscreen", NULL, NULL, NULL, NULL, {} }, + { "top-dock", NULL, NULL, NULL, NULL, {} }, + { "bottom-dock", NULL, NULL, NULL, NULL, {} }, + { "left-dock", NULL, NULL, NULL, NULL, {} }, + { "right-dock", NULL, NULL, NULL, NULL, {} }, + { "all-docks", NULL, NULL, NULL, NULL, {} }, + { "desktop", NULL, NULL, NULL, NULL, {} }, + /* toolbar */ + { "new", NULL, NULL, NULL, NULL, {} }, + { "open", NULL, NULL, NULL, NULL, {} }, + { "quit", NULL, NULL, NULL, NULL, {} } }; -static GtkActionEntry tool_items[] = +static GtkWidget * +create_toolbar (void) { - { "New", GTK_STOCK_NEW, NULL, NULL, - N_("Open another one of these windows"), NULL }, - { "Open", GTK_STOCK_OPEN, NULL, NULL, - N_("This is a demo button with an 'open' icon"), NULL }, - { "Quit", GTK_STOCK_QUIT, NULL, NULL, - N_("This is a demo button with a 'quit' icon"), NULL } -}; + GtkWidget *toolbar; + GtkToolItem *item; + + toolbar = gtk_toolbar_new (); + + item = gtk_tool_button_new (gtk_image_new_from_icon_name ("document-new", GTK_ICON_SIZE_SMALL_TOOLBAR), NULL); + gtk_tool_item_set_tooltip_markup (item, "Open another one of these windows"); + gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "theme-viewer.new"); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); + + item = gtk_tool_button_new (gtk_image_new_from_icon_name ("document-open", GTK_ICON_SIZE_SMALL_TOOLBAR), NULL); + gtk_tool_item_set_tooltip_markup (item, "This is a demo button with an 'open' icon"); + gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "theme-viewer.open"); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); + + item = gtk_tool_button_new (gtk_image_new_from_icon_name ("application-exit", GTK_ICON_SIZE_SMALL_TOOLBAR), NULL); + gtk_tool_item_set_tooltip_markup (item, "This is a demo button with a 'quit' icon"); + gtk_actionable_set_action_name (GTK_ACTIONABLE (item), "theme-viewer.quit"); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); + + return toolbar; +} static GtkWidget * normal_contents (void) { GtkWidget *grid; - GtkWidget *handlebox; GtkWidget *statusbar; GtkWidget *contents; GtkWidget *sw; - GtkActionGroup *action_group; - GtkUIManager *ui_manager; + GtkBuilder *builder; grid = gtk_grid_new (); - - /* Create the menubar - */ - - action_group = gtk_action_group_new ("mainmenu"); - gtk_action_group_add_actions (action_group, - menu_items, - G_N_ELEMENTS (menu_items), - NULL); - gtk_action_group_add_actions (action_group, - tool_items, - G_N_ELEMENTS (tool_items), - NULL); - - ui_manager = gtk_ui_manager_new (); - - gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + builder = gtk_builder_new_from_string (xml, -1); /* create menu items */ - gtk_ui_manager_add_ui_from_string (ui_manager, menu_item_string, -1, NULL); - - gtk_widget_set_hexpand (gtk_ui_manager_get_widget (ui_manager, "/ui/menubar"), - TRUE); - - gtk_grid_attach (GTK_GRID (grid), - gtk_ui_manager_get_widget (ui_manager, "/ui/menubar"), - 0, 0, 1, 1); - - + GMenuModel *model = G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")); + GtkWidget *menubar = gtk_menu_bar_new_from_model (model); + gtk_grid_attach (GTK_GRID (grid), menubar, 0, 0, 1, 1); + gtk_widget_set_hexpand (menubar, TRUE); - - handlebox = gtk_handle_box_new (); - gtk_widget_set_hexpand (handlebox, TRUE); - - gtk_container_add (GTK_CONTAINER (handlebox), - gtk_ui_manager_get_widget (ui_manager, "/ui/toolbar")); - - gtk_grid_attach (GTK_GRID (grid), - handlebox, - 0, 1, 1, 1); + /* Create the toolbar */ + GtkWidget *toolbar = create_toolbar (); + gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 1, 1, 1); + gtk_widget_set_hexpand (toolbar, TRUE); /* Create document */ @@ -203,7 +222,7 @@ normal_contents (void) gtk_widget_show_all (grid); - g_object_unref (ui_manager); + g_object_unref (builder); return grid; } @@ -485,6 +504,14 @@ preview_collection (int font_size, gtk_container_add (GTK_CONTAINER (sw), eventbox); + GSimpleActionGroup *action_group = g_simple_action_group_new (); + g_action_map_add_action_entries (G_ACTION_MAP (action_group), + theme_viewer_entries, + G_N_ELEMENTS (theme_viewer_entries), + NULL); + gtk_widget_insert_action_group (sw, "theme-viewer", G_ACTION_GROUP (action_group)); + g_object_unref (action_group); + desktop_color.red = 0.32; desktop_color.green = 0.46; desktop_color.blue = 0.65; -- cgit v1.2.1