X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Ffind-dialog.c;h=c8f8451bd85be1cf8492ddc3391320afeb77d9c9;hb=aa6f8e301fab021ba2fea720a162e506612ba29f;hp=61f5a50f4ae36c8723de626fa8a3071a0d445d28;hpb=49ad45764ab062f60a205dd84d0c3b600f051727;p=pspp diff --git a/src/ui/gui/find-dialog.c b/src/ui/gui/find-dialog.c index 61f5a50f4a..c8f8451bd8 100644 --- a/src/ui/gui/find-dialog.c +++ b/src/ui/gui/find-dialog.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2009, 2011 Free Software Foundation + Copyright (C) 2007, 2009, 2011, 2012, 2015 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,36 +20,34 @@ which match particular strings */ #include -#include "find-dialog.h" -#include "psppire-selector.h" -#include "psppire-dialog.h" -#include "helper.h" -#include "psppire-data-window.h" -#include "dict-display.h" -#include -#include -#include -#include -#include "psppire-data-store.h" #include -#include -#include -#include -#include - #include +#include #include +#include -#include "xalloc.h" +#include "data/data-in.h" +#include "data/datasheet.h" +#include "data/format.h" +#include "data/value.h" +#include "libpspp/cast.h" +#include "libpspp/message.h" +#include "ui/gui/builder-wrapper.h" +#include "ui/gui/dict-display.h" +#include "ui/gui/find-dialog.h" +#include "ui/gui/helper.h" +#include "ui/gui/psppire-data-store.h" +#include "ui/gui/psppire-data-window.h" +#include "ui/gui/psppire-dialog.h" +#include "ui/gui/psppire-selector.h" + +#include "gl/xalloc.h" #include #define _(msgid) gettext (msgid) #define N_(msgid) msgid -/* FIXME: These shouldn't be here */ -#include "psppire-var-store.h" - struct find_dialog { GtkBuilder *xml; @@ -105,25 +103,17 @@ do_find (GObject *obj, const struct find_dialog *fd) gint column = -1; glong row; - g_object_get (fd->de->data_editor, "current-case", &row, NULL); - - if ( row < 0 ) - row = 0; + + row = 10; find_value (fd, row, &x, &column); - if ( x != -1) { gtk_notebook_set_current_page (GTK_NOTEBOOK (fd->de->data_editor), PSPPIRE_DATA_EDITOR_DATA_VIEW); - g_object_set (fd->de->data_editor, - "current-case", x, - "current-variable", column, - NULL); } - } /* Callback on the selector. @@ -195,13 +185,12 @@ find_dialog (PsppireDataWindow *de) GtkWidget *buttonbox; - PsppireVarStore *vs ; PsppireDataStore *ds ; fd.xml = builder_new ("find.ui"); fd.de = de; - find_button = gtk_button_new_from_stock (GTK_STOCK_FIND); + find_button = gtk_button_new_with_label (_("Find")); gtk_widget_show (find_button); buttonbox = get_widget_assert (fd.xml, "find-buttonbox"); @@ -214,12 +203,10 @@ find_dialog (PsppireDataWindow *de) selector = get_widget_assert (fd.xml, "find-selector"); g_object_get (de->data_editor, - "var-store", &vs, + "dictionary", &fd.dict, "data-store", &ds, NULL); - g_object_get (vs, "dictionary", &fd.dict, NULL); - fd.data = ds->datasheet; fd.variable_entry = get_widget_assert (fd.xml, "find-variable-entry"); @@ -322,6 +309,9 @@ cp1c (casenumber current, struct datasheet *data) static casenumber cm1 (casenumber current, struct datasheet *data) { + if (current == -1) + return datasheet_get_n_rows (data); + return current - 1; } @@ -331,6 +321,9 @@ cm1c (casenumber current, struct datasheet *data) { casenumber next = current; + if (current == -1) + return datasheet_get_n_rows (data); + backward_wrap (&next, data); return next; @@ -346,6 +339,9 @@ last (casenumber current, struct datasheet *data) static casenumber minus1 (casenumber current, struct datasheet *data) { + if (current == -1) + return 0; + return -1; } @@ -423,7 +419,6 @@ struct comparator { const struct variable *var; enum string_cmp_flags flags; - const PsppireDict *dict; bool (*compare) (const struct comparator *, const union value *); @@ -471,8 +466,13 @@ string_label_compare (const struct comparator *cmptr, const struct string_comparator *ssc = (const struct string_comparator *) cmptr; + int width; + const char *text = var_lookup_value_label (cmptr->var, val); - int width = strlen (text); + if (text == NULL) + return false; + + width = strlen (text); assert ( cmptr->flags & STR_CMP_LABELS); @@ -498,7 +498,7 @@ string_value_compare (const struct comparator *cmptr, g_return_val_if_fail (width > 0, false); assert ( ! (cmptr->flags & STR_CMP_LABELS)); - text = value_to_text (*val, cmptr->dict, *var_get_print_format (cmptr->var)); + text = value_to_text (*val, cmptr->var); if ( cmptr->flags & STR_CMP_SUBSTR) found = (NULL != g_strstr_len (text, width, ssc->pattern)); @@ -527,7 +527,7 @@ regexp_value_compare (const struct comparator *cmptr, g_return_val_if_fail (width > 0, false); - text = value_to_text (*val, cmptr->dict, *var_get_print_format (cmptr->var)); + text = value_to_text (*val, cmptr->var); /* We must remove trailing whitespace, otherwise $ will not match where one would expect */ g_strchomp (text); @@ -581,7 +581,7 @@ cmptr_value_destroy (struct comparator *cmptr) static struct comparator * -value_comparator_create (const struct variable *var, const PsppireDict *dict, const char *target) +value_comparator_create (const struct variable *var, const char *target) { struct value_comparator *vc = xzalloc (sizeof (*vc)); struct comparator *cmptr = &vc->parent; @@ -590,7 +590,6 @@ value_comparator_create (const struct variable *var, const PsppireDict *dict, co cmptr->var = var; cmptr->compare = value_compare ; cmptr->destroy = cmptr_value_destroy; - cmptr->dict = dict; text_to_value (target, var, &vc->pattern); @@ -598,8 +597,7 @@ value_comparator_create (const struct variable *var, const PsppireDict *dict, co } static struct comparator * -string_comparator_create (const struct variable *var, const PsppireDict *dict, - const char *target, +string_comparator_create (const struct variable *var, const char *target, enum string_cmp_flags flags) { struct string_comparator *ssc = xzalloc (sizeof (*ssc)); @@ -607,7 +605,6 @@ string_comparator_create (const struct variable *var, const PsppireDict *dict, cmptr->flags = flags; cmptr->var = var; - cmptr->dict = dict; if ( flags & STR_CMP_LABELS) cmptr->compare = string_label_compare; @@ -621,7 +618,7 @@ string_comparator_create (const struct variable *var, const PsppireDict *dict, static struct comparator * -regexp_comparator_create (const struct variable *var, const PsppireDict *dict, const char *target, +regexp_comparator_create (const struct variable *var, const char *target, enum string_cmp_flags flags) { int code; @@ -630,7 +627,6 @@ regexp_comparator_create (const struct variable *var, const PsppireDict *dict, c cmptr->flags = flags; cmptr->var = var; - cmptr->dict = dict; cmptr->compare = (flags & STR_CMP_LABELS) ? regexp_label_compare : regexp_value_compare ; @@ -680,16 +676,16 @@ comparator_destroy (struct comparator *cmptr) static struct comparator * -comparator_factory (const struct variable *var, const PsppireDict *dict, const char *str, +comparator_factory (const struct variable *var, const char *str, enum string_cmp_flags flags) { if ( flags & STR_CMP_REGEXP ) - return regexp_comparator_create (var, dict, str, flags); + return regexp_comparator_create (var, str, flags); if ( flags & (STR_CMP_SUBSTR | STR_CMP_LABELS) ) - return string_comparator_create (var, dict, str, flags); + return string_comparator_create (var, str, flags); - return value_comparator_create (var, dict, str); + return value_comparator_create (var, str); } @@ -707,7 +703,6 @@ find_value (const struct find_dialog *fd, casenumber current_row, const char *target_string = gtk_entry_get_text (GTK_ENTRY (fd->value_entry)); enum string_cmp_flags flags = 0; - g_assert (current_row >= 0); var = dict_lookup_var (fd->dict->dict, var_name); if ( ! var ) @@ -735,7 +730,7 @@ find_value (const struct find_dialog *fd, casenumber current_row, casenumber i; const struct casenum_iterator *ip = get_iteration_params (fd); struct comparator *cmptr = - comparator_factory (var, fd->dict, target_string, flags); + comparator_factory (var, target_string, flags); value_init (&val, width); if ( ! cmptr)