5 new_window (GApplication *app,
8 GtkWidget *window, *scrolled, *view, *overlay;
12 window = gtk_application_window_new (GTK_APPLICATION (app));
13 gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), FALSE);
14 gtk_window_set_default_size ((GtkWindow*)window, 640, 480);
15 gtk_window_set_title (GTK_WINDOW (window), "Sunny");
17 overlay = gtk_overlay_new ();
18 gtk_container_add (GTK_CONTAINER (window), overlay);
20 settings = gtk_settings_get_default ();
21 g_object_get (settings, "gtk-shell-shows-app-menu", &appmenu, NULL);
28 model = gtk_application_get_app_menu (GTK_APPLICATION (app));
29 menu = gtk_menu_button_new ();
30 gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menu), model);
31 gtk_widget_set_halign (menu, GTK_ALIGN_END);
32 gtk_widget_set_valign (menu, GTK_ALIGN_START);
33 image = gtk_image_new ();
34 gtk_image_set_from_icon_name (GTK_IMAGE (image),
37 gtk_button_set_image (GTK_BUTTON (menu), image);
38 gtk_overlay_add_overlay (GTK_OVERLAY (overlay), menu);
41 scrolled = gtk_scrolled_window_new (NULL, NULL);
42 gtk_widget_set_hexpand (scrolled, TRUE);
43 gtk_widget_set_vexpand (scrolled, TRUE);
44 view = gtk_text_view_new ();
46 gtk_container_add (GTK_CONTAINER (scrolled), view);
47 gtk_container_add (GTK_CONTAINER (overlay), scrolled);
54 if (g_file_load_contents (file, NULL, &contents, &length, NULL, NULL))
56 GtkTextBuffer *buffer;
58 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
59 gtk_text_buffer_set_text (buffer, contents, length);
64 gtk_widget_show_all (GTK_WIDGET (window));
68 activate (GApplication *application)
70 new_window (application, NULL);
74 open (GApplication *application,
81 for (i = 0; i < n_files; i++)
82 new_window (application, files[i]);
85 typedef GtkApplication MenuButton;
86 typedef GtkApplicationClass MenuButtonClass;
88 G_DEFINE_TYPE (MenuButton, menu_button, GTK_TYPE_APPLICATION)
91 show_about (GSimpleAction *action,
95 gtk_show_about_dialog (NULL,
96 "program-name", "Sunny",
97 "title", "About Sunny",
98 "logo-icon-name", "sunny",
99 "comments", "A cheap Bloatpad clone.",
105 quit_app (GSimpleAction *action,
112 g_print ("Going down...\n");
114 list = gtk_application_get_windows (GTK_APPLICATION (g_application_get_default ()));
120 gtk_widget_destroy (GTK_WIDGET (win));
127 new_activated (GSimpleAction *action,
131 GApplication *app = user_data;
133 g_application_activate (app);
136 static GActionEntry app_entries[] = {
137 { "about", show_about, NULL, NULL, NULL },
138 { "quit", quit_app, NULL, NULL, NULL },
139 { "new", new_activated, NULL, NULL, NULL }
143 startup (GApplication *application)
147 G_APPLICATION_CLASS (menu_button_parent_class)->startup (application);
149 g_action_map_add_action_entries (G_ACTION_MAP (application), app_entries, G_N_ELEMENTS (app_entries), application);
151 builder = gtk_builder_new ();
152 gtk_builder_add_from_string (builder,
154 " <menu id='app-menu'>"
157 " <attribute name='label' translatable='yes'>_New Window</attribute>"
158 " <attribute name='action'>app.new</attribute>"
161 " <attribute name='label' translatable='yes'>_About Sunny</attribute>"
162 " <attribute name='action'>app.about</attribute>"
165 " <attribute name='label' translatable='yes'>_Quit</attribute>"
166 " <attribute name='action'>app.quit</attribute>"
167 " <attribute name='accel'><Primary>q</attribute>"
171 "</interface>", -1, NULL);
172 gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
173 g_object_unref (builder);
177 menu_button_init (MenuButton *app)
182 menu_button_class_init (MenuButtonClass *class)
184 GApplicationClass *application_class = G_APPLICATION_CLASS (class);
186 application_class->startup = startup;
187 application_class->activate = activate;
188 application_class->open = open;
192 menu_button_new (void)
194 return g_object_new (menu_button_get_type (),
195 "application-id", "org.gtk.Test.Sunny",
196 "flags", G_APPLICATION_HANDLES_OPEN,
201 main (int argc, char **argv)
203 MenuButton *menu_button;
206 menu_button = menu_button_new ();
207 status = g_application_run (G_APPLICATION (menu_button), argc, argv);
208 g_object_unref (menu_button);