summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/help.c81
1 files changed, 12 insertions, 69 deletions
diff --git a/gui/help.c b/gui/help.c
index 545a257..a57238a 100644
--- a/gui/help.c
+++ b/gui/help.c
@@ -14,90 +14,33 @@
#include <gtk/gtk.h>
+#include "gui/view.h"
#include "gui/help.h"
-static GtkWidget *window = NULL;
-static bool visible;
-
-
-static void destroy_help(GtkWidget *object, gpointer user_data)
+static void key_press(void *user, struct view *view, guint keyval)
{
- gtk_widget_destroy(window);
- window = NULL;
-}
-
-
-static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
- gpointer data)
-{
- switch (event->keyval) {
+ switch (keyval) {
case GDK_KEY_h:
case GDK_KEY_Help:
case GDK_KEY_q:
case GDK_KEY_Escape:
- gtk_widget_hide(window);
- visible = 0;
+ view_visible(view, 0);
break;
}
- return TRUE;
}
-static GtkWidget *help_content(void)
+void help(void)
{
- GtkWidget *scroll, *label;
+ static struct view *view = NULL;
- scroll = gtk_scrolled_window_new(NULL, NULL);
- label = gtk_label_new(NULL);
-
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
- GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-
- gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
- gtk_label_set_selectable(GTK_LABEL(label), TRUE);
- gtk_label_set_markup(GTK_LABEL(label),
+ if (!view || !view_visible_toggle(view)) {
+ if (view)
+ view_close(view);
+ view = view_open(key_press, NULL);
+ view_update(view,
#include "../help.inc"
- );
-
- gtk_container_add(GTK_CONTAINER(scroll), label);
-
- return scroll;
-}
-
-
-static void new_help_window(void)
-{
- GtkWidget *content;
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- content = help_content();
-
- gtk_container_add(GTK_CONTAINER(window), content);
- gtk_window_set_default_size(GTK_WINDOW(window), 480, 360);
- gtk_widget_show_all(window);
-
- gtk_widget_set_can_focus(content, TRUE);
- gtk_widget_add_events(content, GDK_KEY_PRESS_MASK);
-
- g_signal_connect(G_OBJECT(content), "key_press_event",
- G_CALLBACK(key_press_event), NULL);
- g_signal_connect(window, "destroy", G_CALLBACK(destroy_help), NULL);
-
- gtk_widget_show_all(window);
-}
-
-
-void help(void)
-{
- if (!window) {
- new_help_window();
- visible = 1;
- } else {
- visible = !visible;
- if (visible)
- gtk_widget_show(window);
- else
- gtk_widget_hide(window);
+ , 1);
}
}