From: John Darrington Date: Sat, 17 Dec 2011 17:00:47 +0000 (+0100) Subject: Added a callback to the dialog help buttons, and a handler to call X-Git-Tag: v0.7.9~55 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73a2e47de094934075e66d1e5185fce93d47fe5e;p=pspp-builds.git Added a callback to the dialog help buttons, and a handler to call the manual when clicked. --- diff --git a/src/ui/gui/help-menu.c b/src/ui/gui/help-menu.c index 58a19bb7..73358077 100644 --- a/src/ui/gui/help-menu.c +++ b/src/ui/gui/help-menu.c @@ -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) { diff --git a/src/ui/gui/help-menu.h b/src/ui/gui/help-menu.h index ff3740fb..4d5e2303 100644 --- a/src/ui/gui/help-menu.h +++ b/src/ui/gui/help-menu.h @@ -22,4 +22,7 @@ void merge_help_menu (GtkUIManager *uim); +void online_help (const char *page); + + #endif diff --git a/src/ui/gui/helper.c b/src/ui/gui/helper.c index 09bfe7ac..3c7d7bcf 100644 --- a/src/ui/gui/helper.c +++ b/src/ui/gui/helper.c @@ -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, diff --git a/src/ui/gui/psppire-buttonbox.c b/src/ui/gui/psppire-buttonbox.c index de265e1f..7b52d2f2 100644 --- a/src/ui/gui/psppire-buttonbox.c +++ b/src/ui/gui/psppire-buttonbox.c @@ -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 } }; diff --git a/src/ui/gui/psppire-dialog.c b/src/ui/gui/psppire-dialog.c index 99d32197..de2490a0 100644 --- a/src/ui/gui/psppire-dialog.c +++ b/src/ui/gui/psppire-dialog.c @@ -24,6 +24,7 @@ #include "psppire-conf.h" #include #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