1/*
2 * Copyright © 2019 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Matthias Clasen
18 */
19
20#include "config.h"
21
22#include "constraint-editor-application.h"
23#include "constraint-editor-window.h"
24
25struct _ConstraintEditorApplication
26{
27 GtkApplication parent_instance;
28};
29
30G_DEFINE_TYPE(ConstraintEditorApplication, constraint_editor_application, GTK_TYPE_APPLICATION);
31
32static void
33constraint_editor_application_init (ConstraintEditorApplication *app)
34{
35}
36
37static void
38quit_activated (GSimpleAction *action,
39 GVariant *parameter,
40 gpointer data)
41{
42 g_application_quit (G_APPLICATION (data));
43}
44
45static GActionEntry app_entries[] =
46{
47 { "quit", quit_activated, NULL, NULL, NULL }
48};
49
50static void
51constraint_editor_application_startup (GApplication *app)
52{
53 const char *quit_accels[2] = { "<Ctrl>Q", NULL };
54 const char *open_accels[2] = { "<Ctrl>O", NULL };
55 GtkCssProvider *provider;
56
57 G_APPLICATION_CLASS (constraint_editor_application_parent_class)->startup (app);
58
59 g_action_map_add_action_entries (G_ACTION_MAP (app),
60 app_entries, G_N_ELEMENTS (app_entries),
61 app);
62 gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels);
63 gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.open", open_accels);
64
65 provider = gtk_css_provider_new ();
66 gtk_css_provider_load_from_resource (provider, "/org/gtk/gtk4/constraint-editor/constraint-editor.css");
67 gtk_style_context_add_provider_for_display (gdk_display_get_default (),
68 GTK_STYLE_PROVIDER (provider),
69 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
70}
71
72static void
73constraint_editor_application_activate (GApplication *app)
74{
75 ConstraintEditorWindow *win;
76
77 win = constraint_editor_window_new (CONSTRAINT_EDITOR_APPLICATION (app));
78 gtk_window_present (GTK_WINDOW (win));
79}
80
81static void
82constraint_editor_application_open (GApplication *app,
83 GFile **files,
84 int n_files,
85 const char *hint)
86{
87 ConstraintEditorWindow *win;
88 int i;
89
90 for (i = 0; i < n_files; i++)
91 {
92 win = constraint_editor_window_new (CONSTRAINT_EDITOR_APPLICATION (app));
93 constraint_editor_window_load (win, files[i]);
94 gtk_window_present (GTK_WINDOW (win));
95 }
96}
97
98static void
99constraint_editor_application_class_init (ConstraintEditorApplicationClass *class)
100{
101 GApplicationClass *application_class = G_APPLICATION_CLASS (class);
102
103 application_class->startup = constraint_editor_application_startup;
104 application_class->activate = constraint_editor_application_activate;
105 application_class->open = constraint_editor_application_open;
106}
107
108ConstraintEditorApplication *
109constraint_editor_application_new (void)
110{
111 return g_object_new (CONSTRAINT_EDITOR_APPLICATION_TYPE,
112 "application-id", "org.gtk.gtk4.ConstraintEditor",
113 "flags", G_APPLICATION_HANDLES_OPEN,
114 NULL);
115}
116

source code of gtk/demos/constraint-editor/constraint-editor-application.c