Commit 24b487de authored by Morten Welinder's avatar Morten Welinder

Search: eliminate use of lazy-list.

GtkListStore works fine.
parent c95e038e
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#include <selection.h> #include <selection.h>
#include <widgets/gnumeric-expr-entry.h> #include <widgets/gnumeric-expr-entry.h>
#include <widgets/gnumeric-lazy-list.h>
#include <string.h> #include <string.h>
#define SEARCH_KEY "search-dialog" #define SEARCH_KEY "search-dialog"
...@@ -55,6 +54,10 @@ enum { ...@@ -55,6 +54,10 @@ enum {
COL_CONTENTS COL_CONTENTS
}; };
enum {
ITEM_MATCH
};
typedef struct { typedef struct {
WBCGtk *wbcg; WBCGtk *wbcg;
...@@ -92,123 +95,23 @@ static const char * const direction_group[] = { ...@@ -92,123 +95,23 @@ static const char * const direction_group[] = {
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
static GtkTreeModel *
/* ------------------------------------------------------------------------- */ make_matches_model (DialogState *dd)
static void
search_get_value (gint row, gint column, gpointer _dd, GValue *value)
{ {
DialogState *dd = (DialogState *)_dd; GtkListStore *list_store = gtk_list_store_new (1, G_TYPE_POINTER);
GnumericLazyList *ll = GNM_LAZY_LIST (gtk_tree_view_get_model (dd->matches_table)); unsigned ui;
GnmSearchFilterResult *item = g_ptr_array_index (dd->matches, row); GPtrArray *matches = dd->matches;
GnmCell *cell;
GnmComment *comment;
if (item->locus == GNM_SRL_COMMENT) {
cell = NULL;
comment = sheet_get_comment (item->ep.sheet, &item->ep.eval);
} else {
cell = sheet_cell_get (item->ep.sheet,
item->ep.eval.col,
item->ep.eval.row);
comment = NULL;
}
g_value_init (value, ll->column_headers[column]);
#if 0
g_print ("col=%d,row=%d\n", column, row);
#endif
switch (column) {
case COL_SHEET:
g_value_set_string (value, item->ep.sheet->name_unquoted);
return;
case COL_CELL:
g_value_set_string (value, cellpos_as_string (&item->ep.eval));
return;
case COL_TYPE:
switch (item->locus) {
case GNM_SRL_COMMENT:
g_value_set_static_string (value, _("Comment"));
return;
case GNM_SRL_VALUE:
g_value_set_static_string (value, _("Result"));
return;
case GNM_SRL_CONTENTS: {
GnmValue *v = cell ? cell->value : NULL;
char const *type;
gboolean is_expr = cell && gnm_cell_has_expr (cell); for (ui = 0; ui < matches->len; ui++) {
gboolean is_value = !is_expr && !gnm_cell_is_empty (cell) && v; GtkTreeIter iter;
if (!cell) gtk_list_store_append (list_store, &iter);
type = _("Deleted"); gtk_list_store_set (list_store, &iter,
else if (is_expr) ITEM_MATCH, g_ptr_array_index (matches, ui),
type = _("Expression"); -1);
else if (is_value && VALUE_IS_STRING (v))
type = _("String");
else if (is_value && VALUE_IS_FLOAT (v))
type = _("Number");
else
type = _("Other value");
g_value_set_static_string (value, type);
return;
}
#ifndef DEBUG_SWITCH_ENUM
default:
g_assert_not_reached ();
#endif
}
case COL_CONTENTS:
switch (item->locus) {
case GNM_SRL_COMMENT:
if (comment)
g_value_set_string (value, cell_comment_text_get (comment));
else
g_value_set_static_string (value, _("Deleted"));
return;
case GNM_SRL_VALUE:
if (cell && cell->value)
g_value_take_string (value, value_get_as_string (cell->value));
else
g_value_set_static_string (value, _("Deleted"));
return;
case GNM_SRL_CONTENTS:
if (cell)
g_value_take_string (value, gnm_cell_get_entered_text (cell));
else
g_value_set_static_string (value, _("Deleted"));
return;
#ifndef DEBUG_SWITCH_ENUM
default:
g_assert_not_reached ();
#endif
}
#ifndef DEBUG_SWITCH_ENUM
default:
g_assert_not_reached ();
#endif
} }
}
/* ------------------------------------------------------------------------- */ return GTK_TREE_MODEL (list_store);
static GnumericLazyList *
make_matches_model (DialogState *dd, int rows)
{
return gnumeric_lazy_list_new (search_get_value,
dd,
rows,
4,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
} }
static void static void
...@@ -364,7 +267,7 @@ search_clicked (G_GNUC_UNUSED GtkWidget *widget, DialogState *dd) ...@@ -364,7 +267,7 @@ search_clicked (G_GNUC_UNUSED GtkWidget *widget, DialogState *dd)
dialog_search_save_in_prefs (dd); dialog_search_save_in_prefs (dd);
{ {
GnumericLazyList *ll; GtkTreeModel *model;
GPtrArray *cells; GPtrArray *cells;
/* Clear current table. */ /* Clear current table. */
...@@ -375,9 +278,9 @@ search_clicked (G_GNUC_UNUSED GtkWidget *widget, DialogState *dd) ...@@ -375,9 +278,9 @@ search_clicked (G_GNUC_UNUSED GtkWidget *widget, DialogState *dd)
dd->matches = gnm_search_filter_matching (sr, cells); dd->matches = gnm_search_filter_matching (sr, cells);
gnm_search_collect_cells_free (cells); gnm_search_collect_cells_free (cells);
ll = make_matches_model (dd, dd->matches->len); model = make_matches_model (dd);
gtk_tree_view_set_model (dd->matches_table, GTK_TREE_MODEL (ll)); gtk_tree_view_set_model (dd->matches_table, model);
g_object_unref (ll); g_object_unref (model);
/* Set sensitivity of buttons. */ /* Set sensitivity of buttons. */
cursor_change (dd->matches_table, dd); cursor_change (dd->matches_table, dd);
...@@ -430,41 +333,129 @@ cb_focus_on_entry (GtkWidget *widget, GtkWidget *entry) ...@@ -430,41 +333,129 @@ cb_focus_on_entry (GtkWidget *widget, GtkWidget *entry)
(GNM_EXPR_ENTRY (entry)))); (GNM_EXPR_ENTRY (entry))));
} }
static const struct { static void
const char *title; match_renderer_func (GtkTreeViewColumn *tree_column,
const char *type; GtkCellRenderer *cr,
} columns[] = { GtkTreeModel *model,
{ N_("Sheet"), "text" }, GtkTreeIter *iter,
{ N_("Cell"), "text" }, gpointer user_data)
{ N_("Type"), "text" }, {
{ N_("Content"), "text" } int column = GPOINTER_TO_INT (user_data);
}; GnmSearchFilterResult *m;
GnmCell *cell;
GnmComment *comment;
const char *text = NULL;
char *free_text = NULL;
gtk_tree_model_get (model, iter, ITEM_MATCH, &m, -1);
if (m->locus == GNM_SRL_COMMENT) {
cell = NULL;
comment = sheet_get_comment (m->ep.sheet, &m->ep.eval);
} else {
cell = sheet_cell_get (m->ep.sheet,
m->ep.eval.col,
m->ep.eval.row);
comment = NULL;
}
switch (column) {
case COL_SHEET:
text = m->ep.sheet->name_unquoted;
break;
case COL_CELL:
text = cellpos_as_string (&m->ep.eval);
break;
case COL_TYPE:
switch (m->locus) {
case GNM_SRL_COMMENT:
text = _("Comment");
break;
case GNM_SRL_VALUE:
text = _("Result");
break;
case GNM_SRL_CONTENTS: {
GnmValue *v = cell ? cell->value : NULL;
gboolean is_expr = cell && gnm_cell_has_expr (cell);
gboolean is_value = !is_expr && !gnm_cell_is_empty (cell) && v;
if (!cell)
text = _("Deleted");
else if (is_expr)
text = _("Expression");
else if (is_value && VALUE_IS_STRING (v))
text = _("String");
else if (is_value && VALUE_IS_FLOAT (v))
text = _("Number");
else
text = _("Other value");
break;
}
default:
g_assert_not_reached ();
}
break;
case COL_CONTENTS:
switch (m->locus) {
case GNM_SRL_COMMENT:
text = comment
? cell_comment_text_get (comment)
: _("Deleted");
break;
case GNM_SRL_VALUE:
text = cell && cell->value
? value_peek_string (cell->value)
: _("Deleted");
break;
case GNM_SRL_CONTENTS:
text = cell
? (free_text = gnm_cell_get_entered_text (cell))
: _("Deleted");
break;
default:
g_assert_not_reached ();
}
break;
default:
g_assert_not_reached ();
}
g_object_set (cr, "text", text, NULL);
g_free (free_text);
}
static GtkTreeView * static GtkTreeView *
make_matches_table (DialogState *dd) make_matches_table (DialogState *dd)
{ {
GtkTreeView *tree_view; GtkTreeView *tree_view;
GtkTreeModel *model = GTK_TREE_MODEL (make_matches_model (dd, 0)); GtkTreeModel *model = GTK_TREE_MODEL (make_matches_model (dd));
int i; int i;
static const char *const columns[4] = {
N_("Sheet"), N_("Cell"), N_("Type"), N_("Content")
};
tree_view = GTK_TREE_VIEW (gtk_tree_view_new_with_model (model)); tree_view = GTK_TREE_VIEW (gtk_tree_view_new_with_model (model));
#ifdef NOT_YET
/* Gtk+ isn't ready yet -- 20031224. */
g_object_set (tree_view, "fixed-height-mode", TRUE, NULL);
#endif
for (i = 0; i < (int)G_N_ELEMENTS (columns); i++) { for (i = 0; i < (int)G_N_ELEMENTS (columns); i++) {
GtkCellRenderer *cell = gtk_cell_renderer_text_new (); GtkTreeViewColumn *tvc = gtk_tree_view_column_new ();
GtkTreeViewColumn *column = GtkCellRenderer *cr = gtk_cell_renderer_text_new ();
gtk_tree_view_column_new_with_attributes (_(columns[i].title), cell,
columns[i].type, i, g_object_set (cr, "single-paragraph-mode", TRUE, NULL);
NULL);
/* Set single_paragraph_mode to ensure fixed height. */
g_object_set (cell, "single-paragraph-mode", TRUE, NULL);
if (i == COL_CONTENTS) if (i == COL_CONTENTS)
g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL); g_object_set (cr, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
gtk_tree_view_append_column (tree_view, column); gtk_tree_view_column_set_title (tvc, _(columns[i]));
gtk_tree_view_column_set_cell_data_func
(tvc, cr,
match_renderer_func,
GINT_TO_POINTER (i), NULL);
gtk_tree_view_column_pack_start (tvc, cr, TRUE);
gtk_tree_view_column_set_sizing (tvc, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
gtk_tree_view_append_column (tree_view, tvc);
} }
g_object_unref (model); g_object_unref (model);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment