5 show_about (GSimpleAction *action,
9 GtkWindow *window = user_data;
11 gtk_show_about_dialog (window,
12 "program-name", "Bloatpad",
13 "title", "About Bloatpad",
14 "comments", "Not much to say, really.",
19 activate_toggle (GSimpleAction *action,
25 state = g_action_get_state (G_ACTION (action));
26 g_action_change_state (G_ACTION (action), g_variant_new_boolean (!g_variant_get_boolean (state)));
27 g_object_unref (state);
31 change_fullscreen_state (GSimpleAction *action,
35 if (g_variant_get_boolean (state))
36 gtk_window_fullscreen (user_data);
38 gtk_window_unfullscreen (user_data);
40 g_simple_action_set_state (action, state);
43 static GActionEntry win_entries[] = {
44 { "about", show_about },
45 { "fullscreen", activate_toggle, NULL, "false", change_fullscreen_state }
49 new_window (GApplication *app,
52 GtkWidget *window, *button, *grid, *scrolled, *view;
55 window = gtk_application_window_new (GTK_APPLICATION (app));
56 g_action_map_add_action_entries (G_ACTION_MAP (window), win_entries, G_N_ELEMENTS (win_entries), window);
57 gtk_window_set_title (GTK_WINDOW (window), "Bloatpad");
59 grid = gtk_grid_new ();
60 gtk_container_add (GTK_CONTAINER (window), grid);
62 button = gtk_application_menu_button_new ();
63 gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_icon_name ("help-about", GTK_ICON_SIZE_MENU));
64 gtk_widget_set_halign (button, GTK_ALIGN_START);
65 gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
67 scrolled = gtk_scrolled_window_new (NULL, NULL);
68 gtk_widget_set_hexpand (scrolled, TRUE);
69 gtk_widget_set_vexpand (scrolled, TRUE);
70 view = gtk_text_view_new ();
72 gtk_container_add (GTK_CONTAINER (scrolled), view);
74 gtk_grid_attach (GTK_GRID (grid), scrolled, 0, 1, 1, 1);
81 if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
83 GtkTextBuffer *buffer;
85 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
86 gtk_text_buffer_set_text (buffer, contents, length);
91 gtk_widget_show_all (GTK_WIDGET (window));
95 bloat_pad_activate (GApplication *application)
97 new_window (application, NULL);
101 bloat_pad_open (GApplication *application,
108 for (i = 0; i < n_files; i++)
109 new_window (application, files[i]);
112 typedef GtkApplication BloatPad;
113 typedef GtkApplicationClass BloatPadClass;
115 G_DEFINE_TYPE (BloatPad, bloat_pad, GTK_TYPE_APPLICATION)
118 bloat_pad_finalize (GObject *object)
120 G_OBJECT_CLASS (bloat_pad_parent_class)->finalize (object);
124 show_help (GSimpleAction *action,
128 g_print ("Want help, eh ?!\n");
132 quit_app (GSimpleAction *action,
139 g_print ("Going down...\n");
141 list = gtk_application_get_windows (GTK_APPLICATION (g_application_get_default ()));
147 gtk_widget_destroy (GTK_WIDGET (win));
153 static GSimpleActionGroup *actions = NULL;
154 static GMenu *menu = NULL;
157 remove_action (GSimpleAction *action,
163 g_menu_remove (menu, g_menu_model_get_n_items (G_MENU_MODEL (menu)) - 1);
164 g_simple_action_set_enabled (action, FALSE);
165 add = g_simple_action_group_lookup (actions, "add");
166 g_simple_action_set_enabled (G_SIMPLE_ACTION (add), TRUE);
170 add_action (GSimpleAction *action,
176 g_menu_append (menu, "Remove", "app.remove");
177 g_simple_action_set_enabled (action, FALSE);
178 remove = g_simple_action_group_lookup (actions, "remove");
179 g_simple_action_set_enabled (G_SIMPLE_ACTION (remove), TRUE);
182 static GActionEntry app_entries[] = {
183 { "help", show_help, NULL, NULL, NULL },
184 { "quit", quit_app, NULL, NULL, NULL },
185 { "add", add_action, NULL, NULL, NULL },
186 { "remove", remove_action, NULL, NULL, NULL }
189 static GActionGroup *
192 actions = g_simple_action_group_new ();
193 g_simple_action_group_add_entries (actions,
194 app_entries, G_N_ELEMENTS (app_entries),
197 return G_ACTION_GROUP (actions);
203 menu = g_menu_new ();
204 g_menu_append (menu, "Help", "app.help");
205 g_menu_append (menu, "About Bloatpad", "win.about");
206 g_menu_append (menu, "Fullscreen", "win.fullscreen");
207 g_menu_append (menu, "Quit", "app.quit");
208 g_menu_append (menu, "Add", "app.add");
210 return G_MENU_MODEL (menu);
214 bloat_pad_init (BloatPad *app)
216 g_application_set_action_group (G_APPLICATION (app), get_actions ());
217 g_application_set_menu (G_APPLICATION (app), get_menu ());
221 bloat_pad_class_init (BloatPadClass *class)
223 G_OBJECT_CLASS (class)->finalize= bloat_pad_finalize;
225 G_APPLICATION_CLASS (class)->activate = bloat_pad_activate;
226 G_APPLICATION_CLASS (class)->open = bloat_pad_open;
234 return g_object_new (bloat_pad_get_type (),
235 "application-id", "org.gtk.Test.bloatpad",
236 "flags", G_APPLICATION_HANDLES_OPEN,
241 main (int argc, char **argv)
246 bloat_pad = bloat_pad_new ();
247 status = g_application_run (G_APPLICATION (bloat_pad), argc, argv);
248 g_object_unref (bloat_pad);