2019-03-12 14:05:25 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2019 Benjamin Otte
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Authors: Benjamin Otte <otte@gnome.org>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include "node-editor-application.h"
|
|
|
|
|
|
|
|
|
|
#include "node-editor-window.h"
|
|
|
|
|
|
2021-02-12 04:35:26 +00:00
|
|
|
|
#include "demo_conf.h"
|
|
|
|
|
|
2019-05-07 15:19:58 +00:00
|
|
|
|
static const char *css =
|
|
|
|
|
"textview.editor {"
|
|
|
|
|
" color: rgb(192, 197, 206);"
|
2019-09-02 16:44:55 +00:00
|
|
|
|
" caret-color: currentColor;"
|
2019-05-07 15:19:58 +00:00
|
|
|
|
"}"
|
2019-09-02 16:44:55 +00:00
|
|
|
|
"textview.editor > text {"
|
2019-05-07 15:19:58 +00:00
|
|
|
|
" background-color: rgb(43, 48, 59);"
|
|
|
|
|
"}"
|
|
|
|
|
;
|
|
|
|
|
|
2019-03-12 14:05:25 +00:00
|
|
|
|
struct _NodeEditorApplication
|
|
|
|
|
{
|
|
|
|
|
GtkApplication parent;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _NodeEditorApplicationClass
|
|
|
|
|
{
|
|
|
|
|
GtkApplicationClass parent_class;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(NodeEditorApplication, node_editor_application, GTK_TYPE_APPLICATION);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
node_editor_application_init (NodeEditorApplication *app)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-06-29 03:43:13 +00:00
|
|
|
|
activate_about (GSimpleAction *action,
|
2019-03-12 14:05:25 +00:00
|
|
|
|
GVariant *parameter,
|
2020-06-29 03:43:13 +00:00
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkApplication *app = user_data;
|
|
|
|
|
char *version;
|
|
|
|
|
GString *s;
|
|
|
|
|
GskRenderer *gsk_renderer;
|
|
|
|
|
const char *renderer;
|
2020-08-10 00:28:56 +00:00
|
|
|
|
char *os_name;
|
|
|
|
|
char *os_version;
|
|
|
|
|
GtkWidget *dialog;
|
2020-06-29 03:43:13 +00:00
|
|
|
|
|
2020-08-10 00:28:56 +00:00
|
|
|
|
os_name = g_get_os_info (G_OS_INFO_KEY_NAME);
|
|
|
|
|
os_version = g_get_os_info (G_OS_INFO_KEY_VERSION_ID);
|
2020-06-29 03:43:13 +00:00
|
|
|
|
s = g_string_new ("");
|
2020-08-10 00:28:56 +00:00
|
|
|
|
if (os_name && os_version)
|
|
|
|
|
g_string_append_printf (s, "OS\t%s %s\n\n", os_name, os_version);
|
2020-06-29 03:43:13 +00:00
|
|
|
|
|
|
|
|
|
g_string_append (s, "System libraries\n");
|
|
|
|
|
g_string_append_printf (s, "\tGLib\t%d.%d.%d\n",
|
|
|
|
|
glib_major_version,
|
|
|
|
|
glib_minor_version,
|
|
|
|
|
glib_micro_version);
|
|
|
|
|
g_string_append_printf (s, "\tPango\t%s\n",
|
|
|
|
|
pango_version_string ());
|
2021-11-13 21:27:50 +00:00
|
|
|
|
g_string_append_printf (s, "\tGTK \t%d.%d.%d\n",
|
2020-06-29 03:43:13 +00:00
|
|
|
|
gtk_get_major_version (),
|
|
|
|
|
gtk_get_minor_version (),
|
|
|
|
|
gtk_get_micro_version ());
|
|
|
|
|
|
|
|
|
|
gsk_renderer = gtk_native_get_renderer (GTK_NATIVE (gtk_application_get_active_window (app)));
|
|
|
|
|
if (strcmp (G_OBJECT_TYPE_NAME (gsk_renderer), "GskVulkanRenderer") == 0)
|
|
|
|
|
renderer = "Vulkan";
|
|
|
|
|
else if (strcmp (G_OBJECT_TYPE_NAME (gsk_renderer), "GskGLRenderer") == 0)
|
|
|
|
|
renderer = "OpenGL";
|
|
|
|
|
else if (strcmp (G_OBJECT_TYPE_NAME (gsk_renderer), "GskCairoRenderer") == 0)
|
|
|
|
|
renderer = "Cairo";
|
|
|
|
|
else
|
|
|
|
|
renderer = "Unknown";
|
|
|
|
|
|
|
|
|
|
g_string_append_printf (s, "\nRenderer\n\t%s", renderer);
|
|
|
|
|
|
2021-02-12 04:35:26 +00:00
|
|
|
|
version = g_strdup_printf ("%s%s%s\nRunning against GTK %d.%d.%d",
|
2020-06-29 03:43:13 +00:00
|
|
|
|
PACKAGE_VERSION,
|
2021-02-12 04:35:26 +00:00
|
|
|
|
g_strcmp0 (PROFILE, "devel") == 0 ? "-" : "",
|
|
|
|
|
g_strcmp0 (PROFILE, "devel") == 0 ? VCS_TAG : "",
|
2020-06-29 03:43:13 +00:00
|
|
|
|
gtk_get_major_version (),
|
|
|
|
|
gtk_get_minor_version (),
|
|
|
|
|
gtk_get_micro_version ());
|
|
|
|
|
|
2020-08-10 00:28:56 +00:00
|
|
|
|
dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
|
|
|
|
|
"transient-for", gtk_application_get_active_window (app),
|
2021-02-12 04:35:26 +00:00
|
|
|
|
"program-name", g_strcmp0 (PROFILE, "devel") == 0
|
|
|
|
|
? "GTK Node Editor (Development)"
|
|
|
|
|
: "GTK Node Editor",
|
2020-06-29 03:43:13 +00:00
|
|
|
|
"version", version,
|
2021-02-12 04:35:26 +00:00
|
|
|
|
"copyright", "© 2019—2021 The GTK Team",
|
2020-06-29 03:43:13 +00:00
|
|
|
|
"license-type", GTK_LICENSE_LGPL_2_1,
|
|
|
|
|
"website", "http://www.gtk.org",
|
|
|
|
|
"comments", "Program to test GTK rendering",
|
|
|
|
|
"authors", (const char *[]){ "Benjamin Otte", "Timm Bäder", NULL},
|
2021-02-10 12:25:13 +00:00
|
|
|
|
"logo-icon-name", "org.gtk.gtk4.NodeEditor",
|
2020-06-29 03:43:13 +00:00
|
|
|
|
"title", "About GTK Node Editor",
|
|
|
|
|
"system-information", s->str,
|
|
|
|
|
NULL);
|
2020-08-10 00:28:56 +00:00
|
|
|
|
gtk_about_dialog_add_credit_section (GTK_ABOUT_DIALOG (dialog),
|
|
|
|
|
"Artwork by", (const char *[]) { "Jakub Steiner", NULL });
|
|
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
2020-06-29 03:43:13 +00:00
|
|
|
|
|
|
|
|
|
g_string_free (s, TRUE);
|
|
|
|
|
g_free (version);
|
2020-08-10 00:28:56 +00:00
|
|
|
|
g_free (os_name);
|
|
|
|
|
g_free (os_version);
|
2020-06-29 03:43:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
activate_quit (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2019-03-12 14:05:25 +00:00
|
|
|
|
{
|
|
|
|
|
g_application_quit (G_APPLICATION (data));
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 03:43:13 +00:00
|
|
|
|
static void
|
|
|
|
|
activate_inspector (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
gtk_window_set_interactive_debugging (TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 03:47:26 +00:00
|
|
|
|
static void
|
|
|
|
|
activate_help (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkBuilder *builder;
|
|
|
|
|
GtkWidget *window;
|
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
|
GBytes *bytes;
|
|
|
|
|
const char *text;
|
|
|
|
|
gsize len;
|
|
|
|
|
|
|
|
|
|
builder = gtk_builder_new ();
|
|
|
|
|
gtk_builder_add_from_resource (builder, "/org/gtk/gtk4/node-editor/help-window.ui", NULL);
|
|
|
|
|
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
|
|
|
|
buffer = GTK_TEXT_BUFFER (gtk_builder_get_object (builder, "buffer"));
|
|
|
|
|
|
|
|
|
|
bytes = g_resources_lookup_data ("/org/gtk/gtk4/node-editor/node-format.md",
|
|
|
|
|
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
|
|
|
|
NULL);
|
|
|
|
|
text = g_bytes_get_data (bytes, &len);
|
|
|
|
|
gtk_text_buffer_set_text (buffer, text, len);
|
|
|
|
|
g_bytes_unref (bytes);
|
|
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (window));
|
|
|
|
|
g_object_unref (builder);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 14:05:25 +00:00
|
|
|
|
static GActionEntry app_entries[] =
|
|
|
|
|
{
|
2020-06-29 03:43:13 +00:00
|
|
|
|
{ "about", activate_about, NULL, NULL, NULL },
|
|
|
|
|
{ "quit", activate_quit, NULL, NULL, NULL },
|
|
|
|
|
{ "inspector", activate_inspector, NULL, NULL, NULL },
|
2020-06-29 03:47:26 +00:00
|
|
|
|
{ "help", activate_help, NULL, NULL, NULL },
|
2019-03-12 14:05:25 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
node_editor_application_startup (GApplication *app)
|
|
|
|
|
{
|
2020-06-29 03:47:26 +00:00
|
|
|
|
const char *help_accels[2] = { "F1", NULL };
|
2019-05-04 07:22:01 +00:00
|
|
|
|
const char *quit_accels[2] = { "<Ctrl>Q", NULL };
|
|
|
|
|
const char *open_accels[2] = { "<Ctrl>O", NULL };
|
2019-05-07 15:19:58 +00:00
|
|
|
|
GtkCssProvider *provider;
|
2019-03-12 14:05:25 +00:00
|
|
|
|
|
|
|
|
|
G_APPLICATION_CLASS (node_editor_application_parent_class)->startup (app);
|
|
|
|
|
|
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (app),
|
|
|
|
|
app_entries, G_N_ELEMENTS (app_entries),
|
|
|
|
|
app);
|
2020-06-29 03:47:26 +00:00
|
|
|
|
gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.help", help_accels);
|
2019-05-04 07:22:01 +00:00
|
|
|
|
gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels);
|
|
|
|
|
gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.open", open_accels);
|
2019-05-07 15:19:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
provider = gtk_css_provider_new ();
|
|
|
|
|
gtk_css_provider_load_from_data (provider, css, -1);
|
|
|
|
|
gtk_style_context_add_provider_for_display (gdk_display_get_default (),
|
|
|
|
|
GTK_STYLE_PROVIDER (provider),
|
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
2019-03-12 14:05:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
node_editor_application_activate (GApplication *app)
|
|
|
|
|
{
|
|
|
|
|
NodeEditorWindow *win;
|
|
|
|
|
|
|
|
|
|
win = node_editor_window_new (NODE_EDITOR_APPLICATION (app));
|
2021-02-12 04:35:26 +00:00
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (PROFILE, "devel") == 0)
|
|
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (win), "devel");
|
|
|
|
|
|
2019-03-12 14:05:25 +00:00
|
|
|
|
gtk_window_present (GTK_WINDOW (win));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
node_editor_application_open (GApplication *app,
|
|
|
|
|
GFile **files,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int n_files,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *hint)
|
2019-03-12 14:05:25 +00:00
|
|
|
|
{
|
|
|
|
|
NodeEditorWindow *win;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i;
|
2019-03-12 14:05:25 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_files; i++)
|
|
|
|
|
{
|
|
|
|
|
win = node_editor_window_new (NODE_EDITOR_APPLICATION (app));
|
|
|
|
|
node_editor_window_load (win, files[i]);
|
|
|
|
|
gtk_window_present (GTK_WINDOW (win));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
node_editor_application_class_init (NodeEditorApplicationClass *class)
|
|
|
|
|
{
|
|
|
|
|
GApplicationClass *application_class = G_APPLICATION_CLASS (class);
|
|
|
|
|
|
|
|
|
|
application_class->startup = node_editor_application_startup;
|
|
|
|
|
application_class->activate = node_editor_application_activate;
|
|
|
|
|
application_class->open = node_editor_application_open;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NodeEditorApplication *
|
|
|
|
|
node_editor_application_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (NODE_EDITOR_APPLICATION_TYPE,
|
|
|
|
|
"application-id", "org.gtk.gtk4.NodeEditor",
|
|
|
|
|
"flags", G_APPLICATION_HANDLES_OPEN,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|