static gboolean
dialog_state_valid (PsppireDialogAction *da)
{
  PsppireDialogActionExamine *pae  = PSPPIRE_DIALOG_ACTION_EXAMINE (da);
  GtkTreeIter notused;
  GtkTreeModel *vars =
    gtk_tree_view_get_model (GTK_TREE_VIEW (pae->variables));

  return gtk_tree_model_get_iter_first (vars, &notused);
}
static void
dialog_refresh (PsppireDialogAction *da)
{
  PsppireDialogActionExamine *dae  = PSPPIRE_DIALOG_ACTION_EXAMINE (da);
  GtkTreeModel *liststore = NULL;

  liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dae->variables));
  gtk_list_store_clear (GTK_LIST_STORE (liststore));

  liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dae->factors));
  gtk_list_store_clear (GTK_LIST_STORE (liststore));

  gtk_entry_set_text (GTK_ENTRY (dae->id_var), "");
  dae->stats = 0x00;
  dae->opts = OPT_LISTWISE;
}
static void
psppire_dialog_action_examine_activate (GtkAction *a)
{
  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
  PsppireDialogActionExamine *act = PSPPIRE_DIALOG_ACTION_EXAMINE (a);

  GtkBuilder *xml = builder_new ("examine.ui");

  GtkWidget *stats_button = get_widget_assert (xml, "stats-button");
  GtkWidget *opts_button = get_widget_assert (xml, "opts-button");

  GtkWidget *dep_sel = get_widget_assert (xml, "psppire-selector1");

  pda->dialog    = get_widget_assert   (xml, "examine-dialog");
  pda->source    = get_widget_assert   (xml, "treeview1");
  act->variables = get_widget_assert   (xml, "treeview2");
  act->factors   = get_widget_assert   (xml, "treeview3");
  act->id_var    = get_widget_assert   (xml, "entry1");

  act->stats_dialog        = get_widget_assert (xml, "statistics-dialog");
  act->descriptives_button = get_widget_assert (xml, "descriptives-button");
  act->extremes_button     = get_widget_assert (xml, "extremes-button"); 
  act->percentiles_button  = get_widget_assert (xml, "percentiles-button");

  act->opts_dialog = get_widget_assert (xml, "options-dialog");
  act->listwise    = get_widget_assert (xml, "radiobutton1");
  act->pairwise    = get_widget_assert (xml, "radiobutton2");
  act->report      = get_widget_assert (xml, "radiobutton3");

  g_object_set (pda->source,
		"model", pda->dict,
		NULL);

  psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_sel), numeric_only);

  psppire_dialog_action_set_valid_predicate (pda, (void *) dialog_state_valid);
  psppire_dialog_action_set_refresh (pda, dialog_refresh);

  g_signal_connect_swapped (stats_button, "clicked",
		    G_CALLBACK (run_stats_dialog), act);

  g_signal_connect_swapped (opts_button, "clicked",
			    G_CALLBACK (run_opts_dialog), act);

  PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_examine_parent_class)->activate (pda);
}
static char *
generate_syntax (PsppireDialogAction *act)
{
  PsppireDialogActionExamine *ed  = PSPPIRE_DIALOG_ACTION_EXAMINE (act);

  const char *label;
  gchar *text = NULL;
  GString *str = g_string_new ("EXAMINE ");

  g_string_append (str, "\n\t/VARIABLES=");
  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->variables), 0, str);

  if ( 0  < gtk_tree_model_iter_n_children
       (gtk_tree_view_get_model (GTK_TREE_VIEW (ed->factors)), NULL))
    {
      g_string_append (str, "\n\tBY ");
      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (ed->factors), 0, str);
    }

  label = gtk_entry_get_text (GTK_ENTRY (ed->id_var));
  if ( 0 != strcmp (label, "") )
    {
      g_string_append (str, "\n\t/ID = ");
      g_string_append (str, label);
    }

  if ( ed->stats & (STAT_DESCRIPTIVES | STAT_EXTREMES))
    {
      g_string_append (str, "\n\t/STATISTICS =");

      if ( ed->stats & STAT_DESCRIPTIVES)
	g_string_append (str, " DESCRIPTIVES");

      if ( ed->stats & STAT_EXTREMES)
	g_string_append (str, " EXTREME");
    }

  if ( ed->stats & STAT_PERCENTILES)
    g_string_append (str, "\n\t/PERCENTILES");


  g_string_append (str, "\n\t/MISSING=");
  switch (ed->opts)
    {
    case OPT_REPORT:
      g_string_append (str, "REPORT");
      break;
    case OPT_PAIRWISE:
      g_string_append (str, "PAIRWISE");
      break;
    default:
      g_string_append (str, "LISTWISE");
      break;
    };

  g_string_append (str, ".");
  text = str->str;

  g_string_free (str, FALSE);

  return text;
}