Replaced e_marshal_BOOL__STRING with this since the function it was used
2002-03-13 Christopher James Lahey <clahey@ximian.com> * gal/util/e-util.c, gal/util/e-util.h (e_marshal_BOOL__STRING_INT): Replaced e_marshal_BOOL__STRING with this since the function it was used for has been modified. From gal/e-table/ChangeLog: 2002-03-13 Christopher James Lahey <clahey@ximian.com> * e-table-extras.c (e_string_search): Check for a NULL haystack here. * e-table-search.c, e-table-search.h: Added a parameter to the search signal here to pass in flags. Specifically, added the E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST flag. Improved the search behavior here. * e-table.c, e-tree.c: Handle the new signature for the search signal here. svn path=/trunk/; revision=16139
This commit is contained in:

committed by
Chris Lahey

parent
e03e086323
commit
abd6567ea0
@ -834,24 +834,26 @@ e_marshal_NONE__DOUBLE (GtkObject *object,
|
||||
func_data);
|
||||
}
|
||||
|
||||
typedef gboolean (*GtkSignal_BOOL__STRING) (GtkObject *,
|
||||
char *,
|
||||
gpointer user_data);
|
||||
typedef gboolean (*GtkSignal_BOOL__STRING_INT) (GtkObject *,
|
||||
char *,
|
||||
gint,
|
||||
gpointer user_data);
|
||||
|
||||
void
|
||||
e_marshal_BOOL__STRING (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
GtkArg *args)
|
||||
e_marshal_BOOL__STRING_INT (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
GtkArg *args)
|
||||
{
|
||||
GtkSignal_BOOL__STRING rfunc;
|
||||
GtkSignal_BOOL__STRING_INT rfunc;
|
||||
gboolean *return_val;
|
||||
|
||||
rfunc = (GtkSignal_BOOL__STRING) func;
|
||||
return_val = GTK_RETLOC_BOOL (args[1]);
|
||||
rfunc = (GtkSignal_BOOL__STRING_INT) func;
|
||||
return_val = GTK_RETLOC_BOOL (args[2]);
|
||||
|
||||
*return_val = (*rfunc) (object,
|
||||
GTK_VALUE_STRING (args[0]),
|
||||
GTK_VALUE_INT (args[1]),
|
||||
func_data);
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,9 @@ void e_marshal_NONE__DOUBLE (GtkO
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
GtkArg *args);
|
||||
void e_marshal_BOOL__STRING (GtkObject *object,
|
||||
|
||||
#define e_marshal_BOOL__STRING_ENUM e_marshal_BOOL__STRING_INT
|
||||
void e_marshal_BOOL__STRING_INT (GtkObject *object,
|
||||
GtkSignalFunc func,
|
||||
gpointer func_data,
|
||||
GtkArg *args);
|
||||
|
@ -102,7 +102,11 @@ e_strint_compare(gconstpointer data1, gconstpointer data2)
|
||||
static gboolean
|
||||
e_string_search(gconstpointer haystack, const char *needle)
|
||||
{
|
||||
int length = g_utf8_strlen (needle, -1);
|
||||
int length;
|
||||
if (haystack == NULL)
|
||||
return FALSE;
|
||||
|
||||
length = g_utf8_strlen (needle, -1);
|
||||
if (g_utf8_strncasecmp (haystack, needle, length) == 0)
|
||||
return TRUE;
|
||||
else
|
||||
|
@ -52,14 +52,14 @@ enum {
|
||||
static guint e_table_search_signals [LAST_SIGNAL] = { 0, };
|
||||
|
||||
static gboolean
|
||||
e_table_search_search (ETableSearch *e_table_search, char *string)
|
||||
e_table_search_search (ETableSearch *e_table_search, char *string, ETableSearchFlags flags)
|
||||
{
|
||||
gboolean ret_val;
|
||||
g_return_val_if_fail (e_table_search != NULL, FALSE);
|
||||
g_return_val_if_fail (E_IS_TABLE_SEARCH (e_table_search), FALSE);
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (e_table_search),
|
||||
e_table_search_signals [SEARCH_SEARCH], string, &ret_val);
|
||||
e_table_search_signals [SEARCH_SEARCH], string, flags, &ret_val);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
@ -124,8 +124,8 @@ e_table_search_class_init (GtkObjectClass *object_class)
|
||||
GTK_RUN_LAST,
|
||||
E_OBJECT_CLASS_TYPE (object_class),
|
||||
GTK_SIGNAL_OFFSET (ETableSearchClass, search),
|
||||
e_marshal_BOOL__STRING,
|
||||
GTK_TYPE_BOOL, 1, GTK_TYPE_STRING);
|
||||
e_marshal_BOOL__STRING_ENUM,
|
||||
GTK_TYPE_BOOL, 2, GTK_TYPE_STRING, GTK_TYPE_ENUM);
|
||||
|
||||
e_table_search_signals [SEARCH_ACCEPT] =
|
||||
gtk_signal_new ("accept",
|
||||
@ -195,25 +195,28 @@ void
|
||||
e_table_search_input_character (ETableSearch *ets, gunichar character)
|
||||
{
|
||||
char character_utf8[7];
|
||||
char *temp_string;
|
||||
|
||||
g_return_if_fail (ets != NULL);
|
||||
g_return_if_fail (E_IS_TABLE_SEARCH (ets));
|
||||
|
||||
character_utf8 [g_unichar_to_utf8 (character, character_utf8)] = 0;
|
||||
|
||||
if (character != ets->priv->last_character) {
|
||||
char *temp_string;
|
||||
temp_string = g_strdup_printf ("%s%s", ets->priv->search_string, character_utf8);
|
||||
if (e_table_search_search (ets, temp_string)) {
|
||||
g_free (ets->priv->search_string);
|
||||
ets->priv->search_string = temp_string;
|
||||
add_timeout (ets);
|
||||
} else {
|
||||
g_free (temp_string);
|
||||
}
|
||||
} else {
|
||||
e_table_search_search (ets, ets->priv->search_string);
|
||||
temp_string = g_strdup_printf ("%s%s", ets->priv->search_string, character_utf8);
|
||||
if (e_table_search_search (ets, temp_string,
|
||||
ets->priv->last_character != 0 ? E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST : 0)) {
|
||||
g_free (ets->priv->search_string);
|
||||
ets->priv->search_string = temp_string;
|
||||
add_timeout (ets);
|
||||
ets->priv->last_character = character;
|
||||
return;
|
||||
} else {
|
||||
g_free (temp_string);
|
||||
}
|
||||
|
||||
if (character == ets->priv->last_character) {
|
||||
if (ets->priv->search_string && e_table_search_search (ets, ets->priv->search_string, 0)) {
|
||||
add_timeout (ets);
|
||||
}
|
||||
}
|
||||
ets->priv->last_character = character;
|
||||
}
|
||||
|
@ -38,6 +38,10 @@ BEGIN_GNOME_DECLS
|
||||
|
||||
typedef struct _ETableSearchPrivate ETableSearchPrivate;
|
||||
|
||||
typedef enum {
|
||||
E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST = 1 << 0
|
||||
} ETableSearchFlags;
|
||||
|
||||
typedef struct {
|
||||
GtkObject base;
|
||||
|
||||
@ -50,7 +54,7 @@ typedef struct {
|
||||
/*
|
||||
* Signals
|
||||
*/
|
||||
gboolean (*search) (ETableSearch *ets, char *string /* utf8 */);
|
||||
gboolean (*search) (ETableSearch *ets, char *string /* utf8 */, ETableSearchFlags flags);
|
||||
void (*accept) (ETableSearch *ets);
|
||||
void (*cancelled) (ETableSearch *ets);
|
||||
} ETableSearchClass;
|
||||
|
@ -342,7 +342,7 @@ check_row (ETable *et, int model_row, int col, ETableSearchFunc search, char *st
|
||||
}
|
||||
|
||||
static gboolean
|
||||
et_search_search (ETableSearch *search, char *string, ETable *et)
|
||||
et_search_search (ETableSearch *search, char *string, ETableSearchFlags flags, ETable *et)
|
||||
{
|
||||
int cursor;
|
||||
int rows;
|
||||
@ -362,6 +362,9 @@ et_search_search (ETableSearch *search, char *string, ETable *et)
|
||||
"cursor_row", &cursor,
|
||||
NULL);
|
||||
|
||||
if ((flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST) && cursor < rows && cursor >= 0 && check_row (et, cursor, col, search_func, string))
|
||||
return TRUE;
|
||||
|
||||
cursor = e_sorter_model_to_sorted (E_SORTER (et->sorter), cursor);
|
||||
|
||||
for (i = cursor + 1; i < rows; i++) {
|
||||
@ -383,7 +386,7 @@ et_search_search (ETableSearch *search, char *string, ETable *et)
|
||||
cursor = e_sorter_sorted_to_model (E_SORTER (et->sorter), cursor);
|
||||
|
||||
/* Check if the cursor row is the only matching row. */
|
||||
return (cursor < rows && cursor >= 0 && check_row (et, cursor, col, search_func, string));
|
||||
return (!(flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST) && cursor < rows && cursor >= 0 && check_row (et, cursor, col, search_func, string));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -419,7 +419,7 @@ search_search_callback (ETreeModel *model, ETreePath path, gpointer data)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
et_search_search (ETableSearch *search, char *string, ETree *et)
|
||||
et_search_search (ETableSearch *search, char *string, ETableSearchFlags flags, ETree *et)
|
||||
{
|
||||
ETreePath cursor;
|
||||
ETreePath found;
|
||||
@ -436,11 +436,21 @@ et_search_search (ETableSearch *search, char *string, ETree *et)
|
||||
cursor = e_tree_get_cursor (et);
|
||||
cursor = e_tree_sorted_model_to_view_path (et->priv->sorted, cursor);
|
||||
|
||||
if (flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST) {
|
||||
const void *value;
|
||||
|
||||
value = e_tree_model_value_at (E_TREE_MODEL (et->priv->sorted), cursor, et->priv->current_search_col);
|
||||
|
||||
if (et->priv->current_search (value, string)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
found = e_tree_model_node_find (E_TREE_MODEL (et->priv->sorted), cursor, NULL, E_TREE_FIND_NEXT_FORWARD, search_search_callback, &cb_data);
|
||||
if (found == NULL)
|
||||
found = e_tree_model_node_find (E_TREE_MODEL (et->priv->sorted), NULL, cursor, E_TREE_FIND_NEXT_FORWARD, search_search_callback, &cb_data);
|
||||
|
||||
if (found) {
|
||||
if (found && found != cursor) {
|
||||
int model_row;
|
||||
|
||||
e_tree_table_adapter_show_node (et->priv->etta, found);
|
||||
@ -450,9 +460,14 @@ et_search_search (ETableSearch *search, char *string, ETree *et)
|
||||
|
||||
e_selection_model_select_as_key_press(E_SELECTION_MODEL (et->priv->selection), model_row, col, GDK_CONTROL_MASK);
|
||||
return TRUE;
|
||||
} else {
|
||||
} else if (!(flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST)) {
|
||||
const void *value;
|
||||
|
||||
value = e_tree_model_value_at (E_TREE_MODEL (et->priv->sorted), cursor, et->priv->current_search_col);
|
||||
|
||||
return et->priv->current_search (value, string);
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
Reference in New Issue
Block a user