+ return g_object_new (PSPPIRE_VAR_SHEET_TYPE, NULL);
+}
+
+PsppireDict *
+psppire_var_sheet_get_dictionary (PsppireVarSheet *var_sheet)
+{
+ return var_sheet->dict;
+}
+
+static void
+refresh_model (PsppireVarSheet *var_sheet)
+{
+ pspp_sheet_view_set_model (PSPP_SHEET_VIEW (var_sheet), NULL);
+
+ if (var_sheet->dict != NULL)
+ {
+ PsppireEmptyListStore *store;
+ int n_rows;
+
+ n_rows = (psppire_dict_get_var_cnt (var_sheet->dict)
+ + var_sheet->may_create_vars);
+ store = psppire_empty_list_store_new (n_rows);
+ pspp_sheet_view_set_model (PSPP_SHEET_VIEW (var_sheet),
+ GTK_TREE_MODEL (store));
+ g_object_unref (store);
+ }
+}
+
+static void
+on_var_changed (PsppireDict *dict, glong row,
+ guint what, const struct variable *oldvar,
+ PsppireVarSheet *var_sheet)
+{
+ PsppireEmptyListStore *store;
+
+ g_return_if_fail (dict == var_sheet->dict);
+
+ store = PSPPIRE_EMPTY_LIST_STORE (pspp_sheet_view_get_model (
+ PSPP_SHEET_VIEW (var_sheet)));
+ g_return_if_fail (store != NULL);
+
+ psppire_empty_list_store_row_changed (store, row);
+}
+
+static void
+on_var_inserted (PsppireDict *dict, glong row, PsppireVarSheet *var_sheet)
+{
+ PsppireEmptyListStore *store;
+ int n_rows;
+
+ g_return_if_fail (dict == var_sheet->dict);
+
+ store = PSPPIRE_EMPTY_LIST_STORE (pspp_sheet_view_get_model (
+ PSPP_SHEET_VIEW (var_sheet)));
+ g_return_if_fail (store != NULL);
+
+ n_rows = (psppire_dict_get_var_cnt (var_sheet->dict)
+ + var_sheet->may_create_vars);
+ psppire_empty_list_store_set_n_rows (store, n_rows);
+ psppire_empty_list_store_row_inserted (store, row);
+}
+
+static void
+on_var_deleted (PsppireDict *dict,
+ const struct variable *var, int dict_idx, int case_idx,
+ PsppireVarSheet *var_sheet)
+{
+ PsppireEmptyListStore *store;
+ int n_rows;
+
+ g_return_if_fail (dict == var_sheet->dict);
+
+ store = PSPPIRE_EMPTY_LIST_STORE (pspp_sheet_view_get_model (
+ PSPP_SHEET_VIEW (var_sheet)));
+ g_return_if_fail (store != NULL);
+
+ n_rows = (psppire_dict_get_var_cnt (var_sheet->dict)
+ + var_sheet->may_create_vars);
+ psppire_empty_list_store_set_n_rows (store, n_rows);
+ psppire_empty_list_store_row_deleted (store, dict_idx);
+}
+
+static void
+on_backend_changed (PsppireDict *dict, PsppireVarSheet *var_sheet)
+{
+ g_return_if_fail (dict == var_sheet->dict);
+ refresh_model (var_sheet);
+}
+
+void
+psppire_var_sheet_set_dictionary (PsppireVarSheet *var_sheet,
+ PsppireDict *dict)
+{
+ if (var_sheet->dict != NULL)
+ {
+ int i;
+
+ for (i = 0; i < PSPPIRE_VAR_SHEET_N_SIGNALS; i++)
+ {
+ if (var_sheet->dict_signals[i])
+ g_signal_handler_disconnect (var_sheet->dict,
+ var_sheet->dict_signals[i]);
+
+ var_sheet->dict_signals[i] = 0;
+ }
+
+ g_object_unref (var_sheet->dict);
+ }
+
+ var_sheet->dict = dict;
+
+ if (dict != NULL)
+ {
+ g_object_ref (dict);
+
+ var_sheet->dict_signals[PSPPIRE_VAR_SHEET_BACKEND_CHANGED]
+ = g_signal_connect (dict, "backend-changed",
+ G_CALLBACK (on_backend_changed), var_sheet);
+
+ var_sheet->dict_signals[PSPPIRE_VAR_SHEET_VARIABLE_CHANGED]
+ = g_signal_connect (dict, "variable-changed",
+ G_CALLBACK (on_var_changed), var_sheet);
+
+ var_sheet->dict_signals[PSPPIRE_VAR_SHEET_VARIABLE_DELETED]
+ = g_signal_connect (dict, "variable-inserted",
+ G_CALLBACK (on_var_inserted), var_sheet);
+
+ var_sheet->dict_signals[PSPPIRE_VAR_SHEET_VARIABLE_INSERTED]
+ = g_signal_connect (dict, "variable-deleted",
+ G_CALLBACK (on_var_deleted), var_sheet);
+ }
+
+ refresh_model (var_sheet);
+}
+
+gboolean
+psppire_var_sheet_get_may_create_vars (PsppireVarSheet *var_sheet)
+{
+ return var_sheet->may_create_vars;
+}