Improve error messages for format specifiers.
[pspp] / src / ui / gui / psppire-dialog-action-aggregate.c
index ac667ef822851bcbb2b8d18f591f5a74e619e569..33f6d78f5318c194d8f879e6ead506a509a560b8 100644 (file)
@@ -62,7 +62,7 @@ append_summary_variable_syntax (const PsppireDialogActionAggregate *agg,  GStrin
   for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (acr_model), &iter);
        ok ;
        ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (acr_model), &iter)
-       )
+)
     {
       g_string_append (string, "\n\t/");
 
@@ -73,7 +73,7 @@ append_summary_variable_syntax (const PsppireDialogActionAggregate *agg,  GStrin
 static void
 append_destination_filename (const PsppireDialogActionAggregate *agg, GString *gs)
 {
-  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->filename_radiobutton)))
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->filename_radiobutton)))
     {
       struct string ss;
       const gchar *s = gtk_label_get_text (GTK_LABEL (agg->filename_label));
@@ -86,7 +86,7 @@ append_destination_filename (const PsppireDialogActionAggregate *agg, GString *g
     {
       g_string_append (gs, "* ");
 
-      if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->replace_radiobutton)))
+      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->replace_radiobutton)))
        g_string_append (gs, "MODE=REPLACE");
       else
        g_string_append (gs, "MODE=ADDVARIABLES");
@@ -105,7 +105,7 @@ generate_syntax (const PsppireDialogAction *act)
 
   append_destination_filename (agg, string);
 
-  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->sorted_button)))
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->sorted_button)))
     g_string_append (string, "\n\t/PRESORTED");
 
   g_string_append (string, "\n\t/BREAK=");
@@ -132,12 +132,12 @@ dialog_state_valid (gpointer user_data)
   GtkTreeModel *liststore =
     gtk_tree_view_get_model (GTK_TREE_VIEW (agg->break_variables));
 
-  if ( ! gtk_tree_model_get_iter_first  (liststore, &iter))
+  if (! gtk_tree_model_get_iter_first  (liststore, &iter))
     return FALSE;
 
   liststore = GTK_TREE_MODEL (PSPPIRE_ACR (agg->summary_acr)->list_store);
 
-  if ( ! gtk_tree_model_get_iter_first (liststore, &iter))
+  if (! gtk_tree_model_get_iter_first (liststore, &iter))
     return FALSE;
 
   return TRUE;
@@ -168,7 +168,7 @@ refresh (PsppireDialogAction *fd_)
   gtk_entry_set_text (GTK_ENTRY (agg->summary_var_name_entry), "N_BREAK");
   gtk_editable_select_region (GTK_EDITABLE (agg->summary_var_name_entry), 0, -1);
 
-  gtk_combo_box_set_active (GTK_COMBO_BOX (agg->function_combo), N);
+  gtk_combo_box_set_active (GTK_COMBO_BOX (agg->function_combo), AGRF_N);
 
   gtk_list_store_clear (PSPPIRE_ACR (agg->summary_acr)->list_store);
 
@@ -354,7 +354,7 @@ summary_complete (const PsppireDialogActionAggregate *agg)
   gboolean ok;
   GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (agg->function_combo));
 
-  if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (agg->summary_var_name_entry))))
+  if (0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (agg->summary_var_name_entry))))
     return FALSE;
 
   ok = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (agg->function_combo), &iter);
@@ -370,19 +370,19 @@ summary_complete (const PsppireDialogActionAggregate *agg)
                       COMBO_MODEL_COL_SRC_VARS, &src_vars,
                       -1);
 
-  if ( src_vars == AGR_SV_YES )
+  if (src_vars == AGR_SV_YES)
     {
       if (0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (agg->summary_sv_entry))))
        return FALSE;
     }
 
-  if ( n_args >= 2)
+  if (n_args >= 2)
     {
       if (0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (agg->summary_arg2_entry))))
        return FALSE;
     }
 
-  if ( n_args >= 1)
+  if (n_args >= 1)
     {
       if (0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (agg->summary_arg1_entry))))
        return FALSE;
@@ -457,7 +457,7 @@ update_arguments (PsppireDialogActionAggregate *agg)
 
   gboolean ok = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (agg->function_combo), &iter);
 
-  if ( ok)
+  if (ok)
     {
       GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (agg->function_combo));
       int n_args;
@@ -482,124 +482,116 @@ update_arguments (PsppireDialogActionAggregate *agg)
 
 
 
-static void
-psppire_dialog_action_aggregate_activate (PsppireDialogAction *a)
+static GtkBuilder *
+psppire_dialog_action_aggregate_activate (PsppireDialogAction *a, GVariant *param)
 {
   PsppireDialogActionAggregate *act = PSPPIRE_DIALOG_ACTION_AGGREGATE (a);
   PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
 
-  GHashTable *thing = psppire_dialog_action_get_hash_table (pda);
-  GtkBuilder *xml = g_hash_table_lookup (thing, a);
-  if (!xml)
-    {
-      xml = builder_new ("aggregate.ui");
-      g_hash_table_insert (thing, a, xml);
-
-
-      pda->dialog = get_widget_assert (xml, "aggregate-dialog");
-      pda->source = get_widget_assert (xml, "dict-view");
-
+  GtkBuilder *xml = builder_new ("aggregate.ui");
 
+  pda->dialog = get_widget_assert (xml, "aggregate-dialog");
+  pda->source = get_widget_assert (xml, "dict-view");
 
-      GtkWidget *break_selector = get_widget_assert   (xml, "break-selector");
+  GtkWidget *break_selector = get_widget_assert   (xml, "break-selector");
 
-      act->pane = get_widget_assert (xml, "hbox1");
+  act->pane = get_widget_assert (xml, "hbox1");
 
-      act->break_variables = get_widget_assert (xml, "psppire-var-view1");
-      act->filename_radiobutton = get_widget_assert (xml, "filename-radiobutton");
-      act->filename_button = get_widget_assert (xml, "filename-button");
-      act->filename_box = get_widget_assert (xml, "filename-box");
-      act->filename_label = get_widget_assert (xml, "filename-label");
-      act->replace_radiobutton = get_widget_assert (xml, "replace-radiobutton");
-      act->add_radiobutton = get_widget_assert (xml, "add-radiobutton");
-      act->function_combo = get_widget_assert (xml, "function-combo");
+  act->break_variables = get_widget_assert (xml, "psppire-var-view1");
+  act->filename_radiobutton = get_widget_assert (xml, "filename-radiobutton");
+  act->filename_button = get_widget_assert (xml, "filename-button");
+  act->filename_box = get_widget_assert (xml, "filename-box");
+  act->filename_label = get_widget_assert (xml, "filename-label");
+  act->replace_radiobutton = get_widget_assert (xml, "replace-radiobutton");
+  act->add_radiobutton = get_widget_assert (xml, "add-radiobutton");
+  act->function_combo = get_widget_assert (xml, "function-combo");
 
-      act->summary_acr = get_widget_assert (xml, "psppire-acr1");
-      act->summary_var_name_entry = get_widget_assert (xml, "summary-var-name-entry");
+  act->summary_acr = get_widget_assert (xml, "psppire-acr1");
+  act->summary_var_name_entry = get_widget_assert (xml, "summary-var-name-entry");
 
-      act->summary_arg1 = get_widget_assert (xml, "summary-arg1");
-      act->summary_arg2 = get_widget_assert (xml, "summary-arg2");
+  act->summary_arg1 = get_widget_assert (xml, "summary-arg1");
+  act->summary_arg2 = get_widget_assert (xml, "summary-arg2");
 
-      act->summary_arg1_entry = get_widget_assert (xml, "summary-arg-entry1");
-      act->summary_arg2_entry = get_widget_assert (xml, "summary-arg-entry2");
+  act->summary_arg1_entry = get_widget_assert (xml, "summary-arg-entry1");
+  act->summary_arg2_entry = get_widget_assert (xml, "summary-arg-entry2");
 
-      act->summary_var_label_entry = get_widget_assert (xml, "summary-var-label-entry");
+  act->summary_var_label_entry = get_widget_assert (xml, "summary-var-label-entry");
 
-      act->summary_sv = get_widget_assert (xml, "source-var");
-      act->summary_sv_entry = get_widget_assert (xml, "source-var-entry");
+  act->summary_sv = get_widget_assert (xml, "source-var");
+  act->summary_sv_entry = get_widget_assert (xml, "source-var-entry");
 
-      act->sorted_button = get_widget_assert (xml, "sorted-radiobutton");
-      act->needs_sort_button = get_widget_assert (xml, "needs-sort-radiobutton");
+  act->sorted_button = get_widget_assert (xml, "sorted-radiobutton");
+  act->needs_sort_button = get_widget_assert (xml, "needs-sort-radiobutton");
 
-      {
-       GtkTreeViewColumn *column ;
+  {
+    GtkTreeViewColumn *column ;
 
-       GList *l ;
+    GList *l ;
 
-       GtkCellRenderer *cell_renderer ;
+    GtkCellRenderer *cell_renderer ;
 
-       GtkListStore *list = gtk_list_store_new (6,
-                                                G_TYPE_STRING,
-                                                G_TYPE_STRING,
-                                                G_TYPE_INT,
-                                                G_TYPE_STRING,
-                                                G_TYPE_DOUBLE,
-                                                G_TYPE_DOUBLE);
+    GtkListStore *list = gtk_list_store_new (6,
+                                            G_TYPE_STRING,
+                                            G_TYPE_STRING,
+                                            G_TYPE_INT,
+                                            G_TYPE_STRING,
+                                            G_TYPE_DOUBLE,
+                                            G_TYPE_DOUBLE);
 
-       psppire_acr_set_model (PSPPIRE_ACR (act->summary_acr), list);
-       g_object_unref (list);
+    psppire_acr_set_model (PSPPIRE_ACR (act->summary_acr), list);
+    g_object_unref (list);
 
-       psppire_acr_set_get_value_func (PSPPIRE_ACR (act->summary_acr),
-                                       get_summary_spec, act);
+    psppire_acr_set_get_value_func (PSPPIRE_ACR (act->summary_acr),
+                                   get_summary_spec, act);
 
-       column = gtk_tree_view_get_column (PSPPIRE_ACR (act->summary_acr)->tv, 0);
+    column = gtk_tree_view_get_column (PSPPIRE_ACR (act->summary_acr)->tv, 0);
 
-       l = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
+    l = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
 
-       cell_renderer = l->data;
+    cell_renderer = l->data;
 
-       gtk_tree_view_column_set_cell_data_func (column,
-                                                cell_renderer,
-                                                render_summary,
-                                                act,
-                                                NULL);
+    gtk_tree_view_column_set_cell_data_func (column,
+                                            cell_renderer,
+                                            render_summary,
+                                            act,
+                                            NULL);
 
-       g_signal_connect_swapped (PSPPIRE_ACR (act->summary_acr)->tv,
-                                 "cursor-changed", G_CALLBACK (on_acr_change), act);
-      }
+    g_signal_connect_swapped (PSPPIRE_ACR (act->summary_acr)->tv,
+                             "cursor-changed", G_CALLBACK (on_acr_change), act);
+  }
 
-      g_signal_connect_swapped (act->summary_var_name_entry, "changed", G_CALLBACK (update_acr),  act);
-      g_signal_connect_swapped (act->function_combo, "changed", G_CALLBACK (update_acr),  act);
-      g_signal_connect_swapped (act->summary_sv_entry, "changed", G_CALLBACK (update_acr),  act);
-      g_signal_connect_swapped (act->summary_arg1_entry, "changed", G_CALLBACK (update_acr),  act);
-      g_signal_connect_swapped (act->summary_arg2_entry, "changed", G_CALLBACK (update_acr),  act);
+  g_signal_connect_swapped (act->summary_var_name_entry, "changed", G_CALLBACK (update_acr),  act);
+  g_signal_connect_swapped (act->function_combo, "changed", G_CALLBACK (update_acr),  act);
+  g_signal_connect_swapped (act->summary_sv_entry, "changed", G_CALLBACK (update_acr),  act);
+  g_signal_connect_swapped (act->summary_arg1_entry, "changed", G_CALLBACK (update_acr),  act);
+  g_signal_connect_swapped (act->summary_arg2_entry, "changed", G_CALLBACK (update_acr),  act);
 
 
-      g_signal_connect_swapped (act->function_combo, "changed",
-                               G_CALLBACK (update_arguments),  act);
+  g_signal_connect_swapped (act->function_combo, "changed",
+                           G_CALLBACK (update_arguments),  act);
 
-      populate_combo_model (GTK_COMBO_BOX (act->function_combo));
+  populate_combo_model (GTK_COMBO_BOX (act->function_combo));
 
 
-      psppire_selector_set_filter_func (PSPPIRE_SELECTOR (break_selector), NULL);
+  psppire_selector_set_filter_func (PSPPIRE_SELECTOR (break_selector), NULL);
 
 
-      g_signal_connect (act->filename_radiobutton, "toggled",
-                       G_CALLBACK (set_sensitivity_from_toggle), act->filename_box );
+  g_signal_connect (act->filename_radiobutton, "toggled",
+                   G_CALLBACK (set_sensitivity_from_toggle), act->filename_box);
 
-      g_signal_connect_swapped (act->filename_button, "clicked",
-                               G_CALLBACK (choose_filename), act);
+  g_signal_connect_swapped (act->filename_button, "clicked",
+                           G_CALLBACK (choose_filename), act);
 
-      psppire_dialog_action_set_refresh (pda, refresh);
-      psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
-    }
+  psppire_dialog_action_set_refresh (pda, refresh);
+  psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
 
+  return xml;
 }
 
 static void
 psppire_dialog_action_aggregate_class_init (PsppireDialogActionAggregateClass *class)
 {
-  psppire_dialog_action_set_activation (class, psppire_dialog_action_aggregate_activate);
+  PSPPIRE_DIALOG_ACTION_CLASS (class)->initial_activate = psppire_dialog_action_aggregate_activate;
   PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
 }
 
@@ -661,17 +653,17 @@ append_summary_spec (const PsppireDialogActionAggregate *agg, GtkTreeIter *iter,
 
   g_string_append_printf (string, " = %s", funcname);
 
-  if ( has_src_vars != AGR_SV_NO)
+  if (has_src_vars != AGR_SV_NO)
     {
       struct string dss;
       ds_init_cstr (&dss, " (");
 
       ds_put_cstr (&dss, srcvar);
 
-      if ( arity > 0)
+      if (arity > 0)
        ds_put_c_format (&dss, ", %.*g", DBL_DIG + 1, arg1);
 
-      if ( arity > 1)
+      if (arity > 1)
        ds_put_c_format (&dss, ", %.*g", DBL_DIG + 1, arg2);
 
       ds_put_cstr (&dss, ")");