node-editor: Add a help window

Add a Help item to the gear menu that opens the
node-format.md file in a new window. This could
be improved if we could parse markdown and apply
tags, similar to how we can load pango markup.
This commit is contained in:
Matthias Clasen 2020-06-28 23:47:26 -04:00
parent 2b6f243578
commit d4ff275002
4 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window">
<style>
<class name="devel"/>
</style>
<property name="title" translatable="yes">Help</property>
<property name="default-width">720</property>
<property name="default-height">520</property>
<child>
<object class="GtkScrolledWindow">
<child>
<object class="GtkTextView" id="text_view">
<property name="wrap-mode">word</property>
<property name="left-margin">20</property>
<property name="right-margin">20</property>
<property name="top-margin">20</property>
<property name="bottom-margin">20</property>
<property name="buffer">
<object class="GtkTextBuffer" id="buffer"/>
</property>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -126,16 +126,46 @@ activate_inspector (GSimpleAction *action,
gtk_window_set_interactive_debugging (TRUE);
}
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);
}
static GActionEntry app_entries[] =
{
{ "about", activate_about, NULL, NULL, NULL },
{ "quit", activate_quit, NULL, NULL, NULL },
{ "inspector", activate_inspector, NULL, NULL, NULL },
{ "help", activate_help, NULL, NULL, NULL },
};
static void
node_editor_application_startup (GApplication *app)
{
const char *help_accels[2] = { "F1", NULL };
const char *quit_accels[2] = { "<Ctrl>Q", NULL };
const char *open_accels[2] = { "<Ctrl>O", NULL };
GtkCssProvider *provider;
@ -145,6 +175,7 @@ node_editor_application_startup (GApplication *app)
g_action_map_add_action_entries (G_ACTION_MAP (app),
app_entries, G_N_ELEMENTS (app_entries),
app);
gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.help", help_accels);
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);

View File

@ -2,6 +2,10 @@
<interface>
<menu id="gear_menu">
<section>
<item>
<attribute name="label" translatable="yes">_Help</attribute>
<attribute name="action">app.help</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Inspector</attribute>
<attribute name="action">app.inspector</attribute>

View File

@ -2,5 +2,7 @@
<gresources>
<gresource prefix="/org/gtk/gtk4/node-editor">
<file preprocess="xml-stripblanks">node-editor-window.ui</file>
<file preprocess="xml-stripblanks">help-window.ui</file>
<file>node-format.md</file>
</gresource>
</gresources>