X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-dict.c;h=32a5cc13e26fa40d4c477023984c23d109141c77;hb=e0cbdf0daefcca81be9572aab0deedf945687f5a;hp=9f95f440afb3eff593c6ef761f39c9bc543109f4;hpb=40fb94bbe38b3e444df7952631ec5fe83f7f1086;p=pspp diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 9f95f440af..32a5cc13e2 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -50,7 +50,8 @@ GType role_enum_type; enum { VARIABLE_CHANGED, VARIABLE_INSERTED, - VARIABLE_DELETED, + VARIABLES_DELETED, + VARIABLE_MOVED, WEIGHT_CHANGED, FILTER_CHANGED, @@ -74,7 +75,7 @@ gni (GListModel *list) { PsppireDict *dict = PSPPIRE_DICT (list); - return psppire_dict_get_var_cnt (dict); + return psppire_dict_get_n_vars (dict); } static GType @@ -90,7 +91,7 @@ gi (GListModel *list, guint id) PsppireDict *dict = PSPPIRE_DICT (list); - if (id >= psppire_dict_get_var_cnt (dict)) + if (id >= psppire_dict_get_n_vars (dict)) { gtk_button_set_label (GTK_BUTTON (button), _("Var")); } @@ -191,18 +192,29 @@ psppire_dict_class_init (PsppireDictClass *class) 1, G_TYPE_INT); - signals [VARIABLE_DELETED] = - g_signal_new ("variable-deleted", + signals [VARIABLES_DELETED] = + g_signal_new ("variables-deleted", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, - psppire_marshal_VOID__POINTER_INT_INT, + psppire_marshal_VOID__INT_UINT, G_TYPE_NONE, - 3, - G_TYPE_POINTER, + 2, G_TYPE_INT, - G_TYPE_INT); + G_TYPE_UINT); + + signals [VARIABLE_MOVED] = + g_signal_new ("variable-moved", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + psppire_marshal_VOID__INT_INT, + G_TYPE_NONE, + 2, + G_TYPE_INT, + G_TYPE_INT); signals [WEIGHT_CHANGED] = g_signal_new ("weight-changed", @@ -256,7 +268,7 @@ psppire_dict_dispose (GObject *object) /* Pass on callbacks from src/data/dictionary, as signals in the Gtk library */ static void -addcb (struct dictionary *d, int idx, void *pd) +var_added_callback (struct dictionary *d, int idx, void *pd) { PsppireDict *dict = PSPPIRE_DICT (pd); @@ -268,16 +280,20 @@ addcb (struct dictionary *d, int idx, void *pd) } static void -delcb (struct dictionary *d, const struct variable *var, - int dict_idx, int case_idx, void *pd) +vars_deleted_callback (struct dictionary *d, int dict_idx, unsigned int n, void *pd) { - g_signal_emit (pd, signals [VARIABLE_DELETED], 0, - var, dict_idx, case_idx); + g_signal_emit (pd, signals [VARIABLES_DELETED], 0, dict_idx, n); g_signal_emit_by_name (pd, "items-changed", dict_idx, 1, 0); } static void -mutcb (struct dictionary *d, int idx, unsigned int what, const struct variable *oldvar, void *pd) +var_moved_callback (struct dictionary *d, int new_dict_index, int old_dict_index, void *pd) +{ + g_signal_emit (pd, signals [VARIABLE_MOVED], 0, new_dict_index, old_dict_index); +} + +static void +var_changed_callback (struct dictionary *d, int idx, unsigned int what, const struct variable *oldvar, void *pd) { g_signal_emit (pd, signals [VARIABLE_CHANGED], 0, idx, what, oldvar); g_signal_emit_by_name (pd, "items-changed", idx, 1, 1); @@ -303,12 +319,13 @@ split_changed_callback (struct dictionary *d, void *pd) static const struct dict_callbacks gui_callbacks = { - addcb, - delcb, - mutcb, - weight_changed_callback, - filter_changed_callback, - split_changed_callback + .var_added = var_added_callback, + .vars_deleted = vars_deleted_callback, + .var_moved = var_moved_callback, + .var_changed = var_changed_callback, + .weight_changed = weight_changed_callback, + .filter_changed = filter_changed_callback, + .split_changed = split_changed_callback }; static void @@ -345,8 +362,8 @@ psppire_dict_replace_dictionary (PsppireDict *dict, struct dictionary *d) struct dictionary *old_dict = dict->dict; - guint old_n = dict_get_var_cnt (dict->dict); - guint new_n = dict_get_var_cnt (d); + guint old_n = dict_get_n_vars (dict->dict); + guint new_n = dict_get_n_vars (d); dict->dict = dict_ref (d); dict_unref (old_dict); @@ -438,7 +455,7 @@ psppire_dict_delete_variables (PsppireDict *d, gint first, gint n) g_return_if_fail (d); g_return_if_fail (d->dict); g_return_if_fail (PSPPIRE_IS_DICT (d)); - size_t varcnt = dict_get_var_cnt (d->dict); + size_t varcnt = dict_get_n_vars (d->dict); g_return_if_fail (first < varcnt); g_return_if_fail (first >= 0); g_return_if_fail (n > 0); @@ -454,10 +471,10 @@ psppire_dict_set_name (PsppireDict* d, gint idx, const gchar *name) g_assert (d); g_assert (PSPPIRE_IS_DICT (d)); - if (! dict_id_is_valid (d->dict, name, false)) + if (! dict_id_is_valid (d->dict, name)) return FALSE; - if (idx < dict_get_var_cnt (d->dict)) + if (idx < dict_get_n_vars (d->dict)) { /* This is an existing variable? */ struct variable * var = dict_get_var (d->dict, idx); @@ -483,7 +500,7 @@ psppire_dict_get_variable (const PsppireDict *d, gint idx) g_return_val_if_fail (d, NULL); g_return_val_if_fail (d->dict, NULL); - if (dict_get_var_cnt (d->dict) <= idx) + if (dict_get_n_vars (d->dict) <= idx) return NULL; return dict_get_var (d->dict, idx); @@ -492,23 +509,12 @@ psppire_dict_get_variable (const PsppireDict *d, gint idx) /* Return the number of variables in the dictionary */ gint -psppire_dict_get_var_cnt (const PsppireDict *d) -{ - g_return_val_if_fail (d, -1); - g_return_val_if_fail (d->dict, -1); - - return dict_get_var_cnt (d->dict); -} - - -/* Return the number of `union value's in the dictionary */ -size_t -psppire_dict_get_value_cnt (const PsppireDict *d) +psppire_dict_get_n_vars (const PsppireDict *d) { g_return_val_if_fail (d, -1); g_return_val_if_fail (d->dict, -1); - return dict_get_next_value_idx (d->dict); + return dict_get_n_vars (d->dict); } @@ -550,33 +556,15 @@ psppire_dict_clear (PsppireDict *d) /* Return true if NAME would be a valid name of a variable to add to the dictionary. False otherwise. - If REPORT is true, then invalid names will be reported as such as errors */ gboolean psppire_dict_check_name (const PsppireDict *dict, - const gchar *name, gboolean report) -{ - if (! dict_id_is_valid (dict->dict, name, report)) - return FALSE; - - if (psppire_dict_lookup_var (dict, name)) - { - if (report) - msg (ME, _("Duplicate variable name.")); - return FALSE; - } - - return TRUE; -} - - -gint -psppire_dict_get_next_value_idx (const PsppireDict *dict) + const gchar *name) { - return dict_get_next_value_idx (dict->dict); + return (dict_id_is_valid (dict->dict, name) + && !psppire_dict_lookup_var (dict, name)); } - /* Tree Model Stuff */ static GtkTreeModelFlags tree_model_get_flags (GtkTreeModel *model); @@ -714,7 +702,7 @@ tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path) n = indices [0]; - if (n < 0 || n >= psppire_dict_get_var_cnt (dict)) + if (n < 0 || n >= psppire_dict_get_n_vars (dict)) { iter->stamp = 0; iter->user_data = NULL; @@ -748,7 +736,7 @@ tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter) idx = var_get_dict_index (var); - if (idx + 1 >= psppire_dict_get_var_cnt (dict)) + if (idx + 1 >= psppire_dict_get_n_vars (dict)) { iter->user_data = NULL; iter->stamp = 0; @@ -781,7 +769,7 @@ tree_model_get_path (GtkTreeModel *model, GtkTreeIter *iter) return path; } -const struct fmt_spec *var_get_write_format (const struct variable *); +struct fmt_spec var_get_write_format (const struct variable *); static void tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, @@ -794,7 +782,7 @@ tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, var = iter->user_data; - const struct fmt_spec *fs = var_get_write_format (var); + struct fmt_spec fs = var_get_write_format (var); switch (column) { @@ -804,11 +792,11 @@ tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, break; case DICT_TVM_COL_WIDTH: g_value_init (value, G_TYPE_INT); - g_value_set_int (value, fs->w); + g_value_set_int (value, fs.w); break; case DICT_TVM_COL_DECIMAL: g_value_init (value, G_TYPE_INT); - g_value_set_int (value, fs->d); + g_value_set_int (value, fs.d); break; case DICT_TVM_COL_LABEL: g_value_init (value, G_TYPE_STRING); @@ -856,7 +844,7 @@ tree_model_n_children (GtkTreeModel *model, PsppireDict *dict = PSPPIRE_DICT (model); if (iter == NULL) - return psppire_dict_get_var_cnt (dict); + return psppire_dict_get_n_vars (dict); return 0; } @@ -874,7 +862,7 @@ tree_model_nth_child (GtkTreeModel *model, GtkTreeIter *iter, if (parent) return FALSE; - if (n >= psppire_dict_get_var_cnt (dict)) + if (n >= psppire_dict_get_n_vars (dict)) return FALSE; iter->stamp = dict->stamp; @@ -891,7 +879,7 @@ gboolean psppire_dict_rename_var (PsppireDict *dict, struct variable *v, const gchar *name) { - if (! dict_id_is_valid (dict->dict, name, false)) + if (! dict_id_is_valid (dict->dict, name)) return FALSE; /* Make sure no other variable has this name */