diff options
author | raveit65 <[email protected]> | 2017-02-07 20:47:28 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2017-02-07 20:47:28 +0100 |
commit | d8bbc62e9fdd8e0833c123742493f827f61db9f5 (patch) | |
tree | 5fd48b7700fdc6a4ff6196f80f6d426128f21620 /src/ui/theme-viewer.c | |
parent | 2f953695fc3d46fb1d6aae4654024e406cd08277 (diff) | |
download | marco-d8bbc62e9fdd8e0833c123742493f827f61db9f5.tar.bz2 marco-d8bbc62e9fdd8e0833c123742493f827f61db9f5.tar.xz |
theme-viewer: port GtkAction to GAction
Diffstat (limited to 'src/ui/theme-viewer.c')
-rw-r--r-- | src/ui/theme-viewer.c | 199 |
1 files 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 = - "<ui>\n" - "<menubar>\n" - "<menu name='Windows' action='Windows'>\n" - "<menuitem name='Dialog' action='Dialog'/>\n" - "<menuitem name='Modal dialog' action='Modal dialog'/>\n" - "<menuitem name='Utility' action='Utility'/>\n" - "<menuitem name='Splashscreen' action='Splashscreen'/>\n" - "<menuitem name='Top dock' action='Top dock'/>\n" - "<menuitem name='Bottom dock' action='Bottom dock'/>\n" - "<menuitem name='Left dock' action='Left dock'/>\n" - "<menuitem name='Right dock' action='Right dock'/>\n" - "<menuitem name='Desktop' action='Desktop'/>\n" - "</menu>\n" - "</menubar>\n" - "<toolbar>\n" - "<separator/>\n" - "<toolitem name='New' action='New'/>\n" - "<toolitem name='Open' action='Open'/>\n" - "<toolitem name='Quit' action='Quit'/>\n" - "<separator/>\n" - "</toolbar>\n" - "</ui>\n"; - -static GtkActionEntry menu_items[] = +static const gchar *xml = + "<interface>" + "<menu id='menubar'>" + "<submenu>" + "<attribute name='label'>Windows</attribute>" + "<section>" + "<item>" + "<attribute name='label'>Dialog</attribute>" + "<attribute name='action'>theme-viewer.dialog1</attribute>" + "<attribute name='accel'><control>d</attribute>" + "</item>" + "<item>" + "<attribute name='label'>Modal dialog</attribute>" + "<attribute name='action'>theme-viewer.dialog2</attribute>" + "</item>" + "<item>" + "<attribute name='label'>Utility</attribute>" + "<attribute name='action'>theme-viewer.utility</attribute>" + "<attribute name='accel'><control>u</attribute>" + "</item>" + "<item>" + "<attribute name='label'>Splashscreen</attribute>" + "<attribute name='action'>theme-viewer.splashscreen</attribute>" + "<attribute name='accel'><control>s</attribute>" + "</item>" + "<item>" + "<attribute name='label'>Top dock</attribute>" + "<attribute name='action'>theme-viewer.top-dock</attribute>" + "</item>" + "<item>" + "<attribute name='label'>Bottom dock</attribute>" + "<attribute name='action'>theme-viewer.bottom-dock</attribute>" + "</item>" + "<item>" + "<attribute name='label'>Left dock</attribute>" + "<attribute name='action'>theme-viewer.left-dock</attribute>" + "</item>" + "<item>" + "<attribute name='label'>Right dock</attribute>" + "<attribute name='action'>theme-viewer.right-dock</attribute>" + "</item>" + "<item>" + "<attribute name='label'>All docks</attribute>" + "<attribute name='action'>theme-viewer.all-docks</attribute>" + "</item>" + "<item>" + "<attribute name='label'>Desktop</attribute>" + "<attribute name='action'>theme-viewer.desktop</attribute>" + "</item>" + "</section>" + "</submenu>" + "</menu>" + "</interface>"; + +static GActionEntry theme_viewer_entries[] = { - { "Windows", NULL, N_("_Windows"), NULL, NULL, NULL }, - { "Dialog", NULL, N_("_Dialog"), "<control>d", NULL, NULL }, - { "Modal dialog", NULL, N_("_Modal dialog"), NULL, NULL, NULL }, - { "Utility", NULL, N_("_Utility"), "<control>u", NULL, NULL }, - { "Splashscreen", NULL, N_("_Splashscreen"), "<control>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; |