Added a callback to the dialog help buttons, and a handler to call
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 17 Dec 2011 17:00:47 +0000 (18:00 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 17 Dec 2011 17:00:47 +0000 (18:00 +0100)
the manual when clicked.

src/ui/gui/help-menu.c
src/ui/gui/help-menu.h
src/ui/gui/helper.c
src/ui/gui/psppire-buttonbox.c
src/ui/gui/psppire-dialog.c

index 58a19bb7f2584233c8a28c7227211504cddac886..733580770bbea035a38432e35768b1665a1a18b5 100644 (file)
@@ -85,12 +85,19 @@ about_new (GtkMenuItem *m, GtkWindow *parent)
   gtk_widget_hide (about);
 }
 
-
-static void
-reference_manual (GtkMenuItem *menu, gpointer data)
+/* Open the manual at PAGE */
+void
+online_help (const char *page)
 {
   GError *err = NULL;
-  gchar *cmd = g_strdup_printf ("yelp file://%s", relocate (DOCDIR "/pspp.xml"));
+  gchar *cmd = NULL;
+
+  if (page == NULL)
+    cmd = g_strdup_printf ("yelp file://%s", relocate (DOCDIR "/pspp.xml"));
+  else
+    cmd = g_strdup_printf ("yelp file://%s#%s", relocate (DOCDIR "/pspp.xml"), page);
+
+  g_print ("%s\n",cmd);
 
   if ( ! g_spawn_command_line_async (cmd, &err) )
     {
@@ -104,6 +111,14 @@ reference_manual (GtkMenuItem *menu, gpointer data)
   g_clear_error (&err);
 }
 
+static void
+reference_manual (GtkMenuItem *menu, gpointer data)
+{
+  online_help (NULL);
+}
+
+
+
 void
 merge_help_menu (GtkUIManager *uim)
 {
index ff3740fba6291c46598272c17fc7211667a82184..4d5e2303e6f4aed03498a38b455d4465111034ff 100644 (file)
@@ -22,4 +22,7 @@
 
 void merge_help_menu (GtkUIManager *uim);
 
+void online_help (const char *page);
+
+
 #endif
index 09bfe7acae61d81e285ab9762a1b58a93c4c1a8b..3c7d7bcff072df218068595d6c8231a4535e5f0b 100644 (file)
@@ -156,7 +156,11 @@ get_action_assert (GtkBuilder *builder, const gchar *name)
 GtkWidget *
 get_widget_assert (GtkBuilder *builder, const gchar *name)
 {
-  return GTK_WIDGET (get_object_assert (builder, name, GTK_TYPE_WIDGET));
+  GtkWidget *w = GTK_WIDGET (get_object_assert (builder, name, GTK_TYPE_WIDGET));
+  
+  g_object_set (w, "name", name, NULL);
+
+  return w;
 }
 
 /* This function must be used whenever a filename generated by glib,
index de265e1fcdf32480d767bb231f81f4780db0fcd1..7b52d2f2b664b9876c471a93f43ee2648f0ddc52 100644 (file)
@@ -264,6 +264,22 @@ refresh_clicked (GtkWidget *w, gpointer data)
 
 
 
+static void
+help_clicked (GtkWidget *w, gpointer data)
+{
+  GtkWidget *toplevel = gtk_widget_get_toplevel (w);
+  PsppireDialog *dialog;
+
+  if ( ! PSPPIRE_IS_DIALOG (toplevel))
+    return;
+
+  dialog = PSPPIRE_DIALOG (toplevel);
+
+  psppire_dialog_help (dialog);
+}
+
+
+
 static void
 on_validity_change (GtkWidget *toplevel, gboolean valid, gpointer data)
 {
@@ -343,6 +359,8 @@ psppire_button_box_init (PsppireButtonBox *bb)
 
 
   bb->button[PSPPIRE_BUTTON_HELP] = gtk_button_new_from_stock (GTK_STOCK_HELP);
+  g_signal_connect (bb->button[PSPPIRE_BUTTON_HELP], "clicked",
+                   G_CALLBACK (help_clicked), NULL);
   psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_HELP]);
   g_object_set (bb->button[PSPPIRE_BUTTON_HELP], "no-show-all", TRUE, NULL);
 
@@ -464,13 +482,13 @@ psppire_button_flags_get_type (void)
     {
       static const GFlagsValue values[] =
        {
-         { PSPPIRE_BUTTON_OK_MASK,     "PSPPIRE_BUTTON_OK_MASK",     N_("OK") },
-         { PSPPIRE_BUTTON_GOTO_MASK,   "PSPPIRE_BUTTON_GOTO_MASK", N_("Go To") },
+         { PSPPIRE_BUTTON_OK_MASK,      "PSPPIRE_BUTTON_OK_MASK",       N_("OK") },
+         { PSPPIRE_BUTTON_GOTO_MASK,    "PSPPIRE_BUTTON_GOTO_MASK",     N_("Go To") },
          { PSPPIRE_BUTTON_CONTINUE_MASK,"PSPPIRE_BUTTON_CONTINUE_MASK", N_("Continue") },
-         { PSPPIRE_BUTTON_CANCEL_MASK, "PSPPIRE_BUTTON_CANCEL_MASK", N_("Cancel") },
-         { PSPPIRE_BUTTON_HELP_MASK,   "PSPPIRE_BUTTON_HELP_MASK",   N_("Help") },
-         { PSPPIRE_BUTTON_RESET_MASK,  "PSPPIRE_BUTTON_RESET_MASK",  N_("Reset") },
-         { PSPPIRE_BUTTON_PASTE_MASK,  "PSPPIRE_BUTTON_PASTE_MASK",  N_("Paste") },
+         { PSPPIRE_BUTTON_CANCEL_MASK,  "PSPPIRE_BUTTON_CANCEL_MASK",   N_("Cancel") },
+         { PSPPIRE_BUTTON_HELP_MASK,    "PSPPIRE_BUTTON_HELP_MASK",     N_("Help") },
+         { PSPPIRE_BUTTON_RESET_MASK,   "PSPPIRE_BUTTON_RESET_MASK",    N_("Reset") },
+         { PSPPIRE_BUTTON_PASTE_MASK,   "PSPPIRE_BUTTON_PASTE_MASK",    N_("Paste") },
          { 0, NULL, NULL }
        };
 
index 99d32197ec28551e6e20f1d2ce6acaa543640f21..de2490a016e5f3862d9ed32170404c8de5381e21 100644 (file)
@@ -24,6 +24,7 @@
 #include "psppire-conf.h"
 #include <string.h>
 #include "helper.h"
+#include "help-menu.h"
 
 static void psppire_dialog_class_init          (PsppireDialogClass *);
 static void psppire_dialog_init                (PsppireDialog      *);
@@ -31,6 +32,7 @@ static void psppire_dialog_init                (PsppireDialog      *);
 
 enum  {DIALOG_REFRESH,
        VALIDITY_CHANGED,
+       DIALOG_HELP,
        n_SIGNALS};
 
 static guint signals [n_SIGNALS];
@@ -223,8 +225,6 @@ psppire_dialog_class_init (PsppireDialogClass *class)
                          FALSE,
                          G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
 
-
-
   object_class->set_property = psppire_dialog_set_property;
   object_class->get_property = psppire_dialog_get_property;
 
@@ -237,8 +237,6 @@ psppire_dialog_class_init (PsppireDialogClass *class)
                                    PROP_SLIDING,
                                    sliding_spec);
 
-
-
   signals [DIALOG_REFRESH] =
     g_signal_new ("refresh",
                  G_TYPE_FROM_CLASS (class),
@@ -262,6 +260,18 @@ psppire_dialog_class_init (PsppireDialogClass *class)
                  G_TYPE_BOOLEAN);
 
 
+  signals [DIALOG_HELP] =
+    g_signal_new ("help",
+                 G_TYPE_FROM_CLASS (class),
+                 G_SIGNAL_RUN_FIRST,
+                 0,
+                 NULL, NULL,
+                 g_cclosure_marshal_VOID__STRING,
+                 G_TYPE_NONE,
+                 1,
+                 G_TYPE_STRING);
+
+
   object_class->finalize = psppire_dialog_finalize;
 }
 
@@ -393,8 +403,6 @@ connect_notify_signal (GtkWidget *w, gpointer data)
   if ( PSPPIRE_IS_BUTTONBOX (w))
     return;
 
-
-
   if ( GTK_IS_CONTAINER (w))
     {
       gtk_container_foreach (GTK_CONTAINER (w),
@@ -527,6 +535,16 @@ psppire_dialog_reload (PsppireDialog *dialog)
 }
 
 
+void
+psppire_dialog_help (PsppireDialog *dialog)
+{
+  char *name = NULL;
+  g_object_get (dialog, "name", &name, NULL);
+
+  online_help (name);
+
+  g_signal_emit (dialog, signals [DIALOG_HELP], 0, name);
+}
 
 
 GType