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_variant_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, *grid, *scrolled, *view;
54 window = gtk_application_window_new (GTK_APPLICATION (app));
55 g_action_map_add_action_entries (G_ACTION_MAP (window), win_entries, G_N_ELEMENTS (win_entries), window);
56 gtk_window_set_title (GTK_WINDOW (window), "Bloatpad");
58 grid = gtk_grid_new ();
59 gtk_container_add (GTK_CONTAINER (window), grid);
61 scrolled = gtk_scrolled_window_new (NULL, NULL);
62 gtk_widget_set_hexpand (scrolled, TRUE);
63 gtk_widget_set_vexpand (scrolled, TRUE);
64 view = gtk_text_view_new ();
66 gtk_container_add (GTK_CONTAINER (scrolled), view);
68 gtk_grid_attach (GTK_GRID (grid), scrolled, 0, 0, 1, 1);
75 if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
77 GtkTextBuffer *buffer;
79 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
80 gtk_text_buffer_set_text (buffer, contents, length);
85 gtk_widget_show_all (GTK_WIDGET (window));
89 bloat_pad_activate (GApplication *application)
91 new_window (application, NULL);
95 bloat_pad_open (GApplication *application,
102 for (i = 0; i < n_files; i++)
103 new_window (application, files[i]);
106 typedef GtkApplication BloatPad;
107 typedef GtkApplicationClass BloatPadClass;
109 G_DEFINE_TYPE (BloatPad, bloat_pad, GTK_TYPE_APPLICATION)
112 bloat_pad_finalize (GObject *object)
114 G_OBJECT_CLASS (bloat_pad_parent_class)->finalize (object);
118 show_help (GSimpleAction *action,
122 g_print ("Want help, eh ?!\n");
126 quit_app (GSimpleAction *action,
133 g_print ("Going down...\n");
135 list = gtk_application_get_windows (GTK_APPLICATION (g_application_get_default ()));
141 gtk_widget_destroy (GTK_WIDGET (win));
147 static GSimpleActionGroup *actions = NULL;
148 static GMenu *menu = NULL;
151 remove_action (GSimpleAction *action,
157 g_menu_remove (menu, g_menu_model_get_n_items (G_MENU_MODEL (menu)) - 1);
158 g_simple_action_set_enabled (action, FALSE);
159 add = g_simple_action_group_lookup (actions, "add");
160 g_simple_action_set_enabled (G_SIMPLE_ACTION (add), TRUE);
164 add_action (GSimpleAction *action,
170 g_menu_append (menu, "Remove", "app.remove");
171 g_simple_action_set_enabled (action, FALSE);
172 remove = g_simple_action_group_lookup (actions, "remove");
173 g_simple_action_set_enabled (G_SIMPLE_ACTION (remove), TRUE);
176 static GActionEntry app_entries[] = {
177 { "help", show_help, NULL, NULL, NULL },
178 { "quit", quit_app, NULL, NULL, NULL },
179 { "add", add_action, NULL, NULL, NULL },
180 { "remove", remove_action, NULL, NULL, NULL }
183 static GActionGroup *
186 actions = g_simple_action_group_new ();
187 g_simple_action_group_add_entries (actions,
188 app_entries, G_N_ELEMENTS (app_entries),
191 return G_ACTION_GROUP (actions);
197 menu = g_menu_new ();
198 g_menu_append (menu, "Help", "app.help");
199 g_menu_append (menu, "About Bloatpad", "win.about");
200 g_menu_append (menu, "Fullscreen", "win.fullscreen");
201 g_menu_append (menu, "Quit", "app.quit");
202 g_menu_append (menu, "Add", "app.add");
204 return G_MENU_MODEL (menu);
208 bloat_pad_init (BloatPad *app)
210 g_application_set_action_group (G_APPLICATION (app), get_actions ());
211 g_application_set_menu (G_APPLICATION (app), get_menu ());
215 bloat_pad_class_init (BloatPadClass *class)
217 G_OBJECT_CLASS (class)->finalize = bloat_pad_finalize;
219 G_APPLICATION_CLASS (class)->activate = bloat_pad_activate;
220 G_APPLICATION_CLASS (class)->open = bloat_pad_open;
228 return g_object_new (bloat_pad_get_type (),
229 "application-id", "org.gtk.Test.bloatpad",
230 "flags", G_APPLICATION_HANDLES_OPEN,
235 main (int argc, char **argv)
240 bloat_pad = bloat_pad_new ();
241 status = g_application_run (G_APPLICATION (bloat_pad), argc, argv);
242 g_object_unref (bloat_pad);