const struct dict_callbacks *callbacks; /* Callbacks on dictionary
modification */
void *cb_data ; /* Data passed to callbacks */
+
+ void (*changed) (struct dictionary *, void *); /* Generic change callback */
+ void *changed_data;
};
+void
+dict_set_change_callback (struct dictionary *d,
+ void (*changed) (struct dictionary *, void*),
+ void *data)
+{
+ d->changed = changed;
+ d->changed_data = data;
+}
+
+
/* Print a representation of dictionary D to stdout, for
debugging purposes. */
void
d->var[d->var_cnt++] = v;
hsh_force_insert (d->name_tab, v);
+ if ( d->changed ) d->changed (d, d->changed_data);
if ( d->callbacks && d->callbacks->var_added )
d->callbacks->var_added (d, var_get_dict_index (v), d->cb_data);
vdi.dict_index = dict_index;
var_set_vardict (v, &vdi);
+ if ( d->changed ) d->changed (d, d->changed_data);
if ( d->callbacks && d->callbacks->var_changed )
d->callbacks->var_changed (d, dict_index, d->cb_data);
}
var_clear_vardict (v);
var_destroy (v);
-
+ if ( d->changed ) d->changed (d, d->changed_data);
if (d->callbacks && d->callbacks->var_deleted )
d->callbacks->var_deleted (d, dict_index, case_index, val_cnt, d->cb_data);
}
if (settings_get_algorithm () == ENHANCED)
var_clear_short_names (v);
+ if ( d->changed ) d->changed (d, d->changed_data);
if ( d->callbacks && d->callbacks->var_changed )
d->callbacks->var_changed (d, var_get_dict_index (v), d->cb_data);
}
d->weight = v;
+ if (d->changed) d->changed (d, d->changed_data);
if ( d->callbacks && d->callbacks->weight_changed )
d->callbacks->weight_changed (d,
v ? var_get_dict_index (v) : -1,
d->filter = v;
+ if (d->changed) d->changed (d, d->changed_data);
if ( d->callbacks && d->callbacks->filter_changed )
d->callbacks->filter_changed (d,
v ? var_get_dict_index (v) : -1,
&v, compare_var_ptrs, NULL);
if (orig_count != d->split_cnt)
{
+ if (d->changed) d->changed (d, d->changed_data);
/* We changed the set of split variables so invoke the
callback. */
if (d->callbacks && d->callbacks->split_changed)
d->split = NULL;
}
+ if (d->changed) d->changed (d, d->changed_data);
if ( d->callbacks && d->callbacks->split_changed )
d->callbacks->split_changed (d, d->cb_data);
}
const struct vardict_info *vdi = var_get_vardict (v);
struct dictionary *d = vdi->dict;
+ if (d->changed ) d->changed (d, d->changed_data);
if ( d->callbacks && d->callbacks->var_changed )
d->callbacks->var_changed (d, var_get_dict_index (v), d->cb_data);
}
dict_pad_values (d, var_get_case_index(v) + 1, delta);
+ if (d->changed) d->changed (d, d->changed_data);
if ( d->callbacks && d->callbacks->var_resized )
d->callbacks->var_resized (d, var_get_dict_index (v), delta, d->cb_data);
}
d = vdi->dict;
+ if (d->changed) d->changed (d, d->changed_data);
if ( d->callbacks && d->callbacks->var_display_width_changed )
d->callbacks->var_display_width_changed (d, var_get_dict_index (v), d->cb_data);
}
proc_state;
casenumber cases_written; /* Cases output so far. */
bool ok; /* Error status. */
+
+ void (*callback) (void *); /* Callback for when the dataset changes */
+ void *cb_data;
+
}; /* struct dataset */
static void add_filter_trns (struct dataset *ds);
static void update_last_proc_invocation (struct dataset *ds);
+
+static void
+dataset_set_unsaved (const struct dataset *ds)
+{
+ if (ds->callback) ds->callback (ds->cb_data);
+}
+
\f
/* Public functions. */
+void
+dataset_set_callback (struct dataset *ds, void (*cb) (void *), void *cb_data)
+{
+ ds->callback = cb;
+ ds->cb_data = cb_data;
+}
+
+
/* Returns the last time the data was read. */
time_t
time_of_last_procedure (struct dataset *ds)
assert (ds->proc_state == PROC_CLOSED);
ds->proc_state = PROC_COMMITTED;
+ dataset_set_unsaved (ds);
+
/* Free memory for lagged cases. */
while (!deque_is_empty (&ds->lag))
case_unref (ds->lag_cases[deque_pop_back (&ds->lag)]);
return ok;
}
\f
+
+static void
+dict_callback (struct dictionary *d UNUSED, void *ds_)
+{
+ struct dataset *ds = ds_;
+ dataset_set_unsaved (ds);
+}
+
/* Initializes procedure handling. */
struct dataset *
create_dataset (void)
{
struct dataset *ds = xzalloc (sizeof(*ds));
ds->dict = dict_create ();
+
+ dict_set_change_callback (ds->dict, dict_callback, ds);
+
ds->caseinit = caseinit_create ();
proc_cancel_all_transformations (ds);
return ds;
dict_destroy (ds->dict);
ds->dict = dict;
+ dict_set_change_callback (ds->dict, dict_callback, ds);
proc_set_active_file_data (ds, source);
}
psppire_window_set_filename (PSPPIRE_WINDOW (de), file_name);
add_most_recent (file_name);
}
+
+ psppire_window_set_unsaved (PSPPIRE_WINDOW (de), FALSE);
}
ds_destroy (&file_name);
execute_syntax (sss);
+
+ psppire_window_set_unsaved (PSPPIRE_WINDOW (de), FALSE);
}
}
-
+static void
+set_unsaved (gpointer w)
+{
+ psppire_window_set_unsaved (PSPPIRE_WINDOW (w), TRUE);
+}
static void
psppire_data_window_init (PsppireDataWindow *de)
de->data_editor =
PSPPIRE_DATA_EDITOR (psppire_data_editor_new (the_var_store, the_data_store));
+ g_signal_connect_swapped (the_data_store, "case-changed",
+ G_CALLBACK (set_unsaved), de);
+
+ g_signal_connect_swapped (the_data_store, "case-inserted",
+ G_CALLBACK (set_unsaved), de);
+
+ g_signal_connect_swapped (the_data_store, "cases-deleted",
+ G_CALLBACK (set_unsaved), de);
+
+ dataset_set_callback (the_dataset, set_unsaved, de);
+
connect_help (de->xml);
g_object_ref (menubar);