psppire_dialog_close (dialog);
}
+static gboolean
+is_acceptable (GtkWidget *w)
+{
+ GtkWidget *toplevel = gtk_widget_get_toplevel (w);
+
+ return (PSPPIRE_IS_DIALOG (toplevel)
+ && psppire_dialog_is_acceptable (PSPPIRE_DIALOG (toplevel)));
+}
static void
close_dialog (GtkWidget *w, gpointer data)
static void
continue_button_clicked (GtkWidget *w, gpointer data)
{
- close_and_respond (w, PSPPIRE_RESPONSE_CONTINUE);
+ if (is_acceptable (w))
+ close_and_respond (w, PSPPIRE_RESPONSE_CONTINUE);
}
static void
ok_button_clicked (GtkWidget *w, gpointer data)
{
- close_and_respond (w, GTK_RESPONSE_OK);
+ if (is_acceptable (w))
+ close_and_respond (w, GTK_RESPONSE_OK);
}
static void
paste_button_clicked (GtkWidget *w, gpointer data)
{
- close_and_respond (w, PSPPIRE_RESPONSE_PASTE);
+ if (is_acceptable (w))
+ close_and_respond (w, PSPPIRE_RESPONSE_PASTE);
}
static void
goto_button_clicked (GtkWidget *w, gpointer data)
{
- close_and_respond (w, PSPPIRE_RESPONSE_GOTO);
+ if (is_acceptable (w))
+ close_and_respond (w, PSPPIRE_RESPONSE_GOTO);
}
dialog->box = NULL;
dialog->contents_are_valid = NULL;
dialog->validity_data = NULL;
+ dialog->contents_are_acceptable = NULL;
+ dialog->acceptable_data = NULL;
dialog->slidable = FALSE;
g_value_init (&value, orientation_spec->value_type);
}
+/* Sets a predicate function that is checked after each change that the user
+ makes to the dialog's state. If the predicate function returns false, then
+ "OK" and other buttons that accept the dialog's settings will be
+ disabled. */
void
psppire_dialog_set_valid_predicate (PsppireDialog *dialog,
ContentsAreValid contents_are_valid,
dialog->validity_data = data;
}
+/* Sets a predicate function that is called after "OK" or another button that
+ accepts the dialog's settings is pushed. If the predicate function returns
+ false, then the button push is ignored. (If the predicate function returns
+ false, then it should take some action to notify the user why the contents
+ are unacceptable, e.g. pop up a dialog box.)
+
+ An accept predicate is preferred over a validity predicate when the reason
+ why the dialog settings are unacceptable may not be obvious to the user, so
+ that the user needs a helpful message to explain. */
+void
+psppire_dialog_set_accept_predicate (PsppireDialog *dialog,
+ ContentsAreValid contents_are_acceptable,
+ gpointer data)
+{
+ dialog->contents_are_acceptable = contents_are_acceptable;
+ dialog->acceptable_data = data;
+}
+
+gboolean
+psppire_dialog_is_acceptable (const PsppireDialog *dialog)
+{
+ return (dialog->contents_are_acceptable == NULL
+ || dialog->contents_are_acceptable (dialog->acceptable_data));
+}
ContentsAreValid contents_are_valid;
gpointer validity_data;
+ ContentsAreValid contents_are_acceptable;
+ gpointer acceptable_data;
gboolean slidable;
PsppireOrientation orientation;
};
void psppire_dialog_set_valid_predicate (PsppireDialog *,
ContentsAreValid,
gpointer );
+void psppire_dialog_set_accept_predicate (PsppireDialog *,
+ ContentsAreValid,
+ gpointer );
+gboolean psppire_dialog_is_acceptable (const PsppireDialog *);
void psppire_dialog_notify_change (PsppireDialog *);