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