X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Ffind-dialog.c;h=1a3a0a5c91afcfeb70067d2e29bf56887880eba6;hb=ea17c5b225557fc0760810861451a84dc241d462;hp=0c16bfa8140c0a78f4036c2c2ef2e3eeadb5023a;hpb=cb72db62c20ecab427229110820c5b053d0663c4;p=pspp diff --git a/src/ui/gui/find-dialog.c b/src/ui/gui/find-dialog.c index 0c16bfa814..1a3a0a5c91 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 Free Software Foundation + Copyright (C) 2007, 2009, 2011, 2012 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,35 @@ 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-sheet.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; @@ -101,12 +100,13 @@ refresh (GObject *obj, const struct find_dialog *fd) static void do_find (GObject *obj, const struct find_dialog *fd) { + PsppireDataSheet *data_sheet; casenumber x = -1; gint column = -1; glong row; - g_object_get (fd->de->data_editor, "current-case", &row, NULL); - + data_sheet = psppire_data_editor_get_active_data_sheet (fd->de->data_editor); + row = psppire_data_sheet_get_selected_case (data_sheet); if ( row < 0 ) row = 0; @@ -118,10 +118,8 @@ do_find (GObject *obj, const struct find_dialog *fd) 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); + psppire_data_sheet_goto_case (data_sheet, x); + psppire_data_sheet_goto_variable (data_sheet, column); } } @@ -184,10 +182,8 @@ value_labels_toggled (GtkToggleButton *tb, gpointer data) /* Pops up the Find dialog box */ void -find_dialog (GObject *o, gpointer data) +find_dialog (PsppireDataWindow *de) { - PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data); - struct find_dialog fd; GtkWidget *dialog ; @@ -197,7 +193,6 @@ find_dialog (GObject *o, gpointer data) GtkWidget *buttonbox; - PsppireVarStore *vs ; PsppireDataStore *ds ; fd.xml = builder_new ("find.ui"); @@ -208,7 +203,7 @@ find_dialog (GObject *o, gpointer data) buttonbox = get_widget_assert (fd.xml, "find-buttonbox"); - gtk_box_pack_start_defaults (GTK_BOX (buttonbox), find_button); + psppire_box_pack_start_defaults (GTK_BOX (buttonbox), find_button); gtk_box_reorder_child (GTK_BOX (buttonbox), find_button, 0); dialog = get_widget_assert (fd.xml, "find-dialog"); @@ -216,12 +211,10 @@ find_dialog (GObject *o, gpointer data) 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"); @@ -243,17 +236,13 @@ find_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - g_object_set (source, "dictionary", fd.dict, + g_object_set (source, "model", fd.dict, "selection-mode", GTK_SELECTION_SINGLE, NULL); - psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector), - source, - fd.variable_entry, - insert_source_row_into_entry, - is_currently_in_entry, - NULL - ); + + psppire_selector_set_filter_func (PSPPIRE_SELECTOR (selector), + is_currently_in_entry); g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &fd); @@ -429,7 +418,6 @@ struct comparator { const struct variable *var; enum string_cmp_flags flags; - const PsppireDict *dict; bool (*compare) (const struct comparator *, const union value *); @@ -477,8 +465,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); @@ -504,7 +497,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_write_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)); @@ -533,7 +526,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_write_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); @@ -587,7 +580,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; @@ -596,16 +589,14 @@ 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, dict, var, &vc->pattern); + text_to_value (target, var, &vc->pattern); return cmptr; } 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)); @@ -613,7 +604,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; @@ -627,7 +617,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; @@ -636,7 +626,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 ; @@ -686,16 +675,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); } @@ -741,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)