Renamed TextFuncs and its members; removed workaround for bug 314335

This commit is contained in:
Yevgen Muntyan 2013-05-12 22:03:13 -07:00
parent adfe739a1a
commit 577b5e40a8
3 changed files with 64 additions and 95 deletions

View File

@ -245,19 +245,7 @@ _moo_file_entry_completion_init (MooFileEntryCompletion *cmpl)
cmpl->priv->case_sensitive = CASE_SENSITIVE_DEFAULT; cmpl->priv->case_sensitive = CASE_SENSITIVE_DEFAULT;
cmpl->priv->visible_func = (MooFileVisibleFunc) completion_default_visible_func; cmpl->priv->visible_func = (MooFileVisibleFunc) completion_default_visible_func;
set_text_funcs(&cmpl->priv->text_funcs, cmpl->priv->case_sensitive);
if (cmpl->priv->case_sensitive)
{
cmpl->priv->text_funcs.file_equals_func = file_equals_func;
cmpl->priv->text_funcs.file_has_prefix_func = file_has_prefix_func;
cmpl->priv->text_funcs.normalize_func = normalize_func;
}
else
{
cmpl->priv->text_funcs.file_equals_func = case_file_equals_func;
cmpl->priv->text_funcs.file_has_prefix_func = case_file_has_prefix_func;
cmpl->priv->text_funcs.normalize_func = case_normalize_func;
}
model = _moo_folder_model_new (NULL); model = _moo_folder_model_new (NULL);
cmpl->priv->model = _moo_folder_filter_new (MOO_FOLDER_MODEL (model)); cmpl->priv->model = _moo_folder_filter_new (MOO_FOLDER_MODEL (model));
@ -748,20 +736,7 @@ completion_set_case_sensitive (MooFileEntryCompletion *cmpl,
if (case_sensitive != cmpl->priv->case_sensitive) if (case_sensitive != cmpl->priv->case_sensitive)
{ {
cmpl->priv->case_sensitive = case_sensitive; cmpl->priv->case_sensitive = case_sensitive;
set_text_funcs (&cmpl->priv->text_funcs, case_sensitive);
if (case_sensitive)
{
cmpl->priv->text_funcs.file_equals_func = file_equals_func;
cmpl->priv->text_funcs.file_has_prefix_func = file_has_prefix_func;
cmpl->priv->text_funcs.normalize_func = normalize_func;
}
else
{
cmpl->priv->text_funcs.file_equals_func = case_file_equals_func;
cmpl->priv->text_funcs.file_has_prefix_func = case_file_has_prefix_func;
cmpl->priv->text_funcs.normalize_func = case_normalize_func;
}
g_object_notify (G_OBJECT (cmpl), "case-sensitive"); g_object_notify (G_OBJECT (cmpl), "case-sensitive");
} }
} }
@ -1318,13 +1293,13 @@ completion_visible_func (GtkTreeModel *model,
} }
else if (cmpl->priv->visible_func (file, cmpl->priv->visible_func_data)) else if (cmpl->priv->visible_func (file, cmpl->priv->visible_func_data))
{ {
visible = cmpl->priv->text_funcs.file_has_prefix_func (file, visible = cmpl->priv->text_funcs.file_has_prefix (file,
cmpl->priv->display_basename, cmpl->priv->display_basename,
cmpl->priv->display_basename_len); cmpl->priv->display_basename_len);
} }
_moo_file_unref (file); _moo_file_unref (file);
return visible ? TRUE : FALSE; /* #314335 */ return visible;
} }

View File

@ -25,26 +25,26 @@
/* TODO: strncmp should accept char len, not byte len? */ /* TODO: strncmp should accept char len, not byte len? */
typedef struct { typedef struct TextFuncs {
gboolean (*file_equals_func) (MooFile *file, gboolean (*file_equals) (MooFile *file,
const char *str); const char *str);
gboolean (*file_has_prefix_func) (MooFile *file, gboolean (*file_has_prefix) (MooFile *file,
const char *str, const char *str,
guint len); guint len);
char* (*normalize_func) (const char *str, char* (*normalize) (const char *str,
gssize len); gssize len);
} TextFuncs; } TextFuncs;
static gboolean static gboolean
file_equals_func (MooFile *file, file_equals (MooFile *file,
const char *str) const char *str)
{ {
return !strcmp (str, _moo_file_display_name (file)); return !strcmp (str, _moo_file_display_name (file));
} }
static gboolean static gboolean
file_has_prefix_func (MooFile *file, file_has_prefix (MooFile *file,
const char *str, const char *str,
guint len) guint len)
{ {
@ -52,7 +52,7 @@ file_has_prefix_func (MooFile *file,
} }
static char * static char *
normalize_func (const char *str, normalize (const char *str,
gssize len) gssize len)
{ {
return g_utf8_normalize (str, len, G_NORMALIZE_ALL); return g_utf8_normalize (str, len, G_NORMALIZE_ALL);
@ -60,7 +60,7 @@ normalize_func (const char *str,
static char * static char *
case_normalize_func (const char *str, case_normalize (const char *str,
gssize len) gssize len)
{ {
char *norm = g_utf8_normalize (str, len, G_NORMALIZE_ALL); char *norm = g_utf8_normalize (str, len, G_NORMALIZE_ALL);
@ -70,27 +70,46 @@ case_normalize_func (const char *str,
} }
static gboolean static gboolean
case_file_equals_func (MooFile *file, case_file_equals (MooFile *file,
const char *str) const char *str)
{ {
char *temp = case_normalize_func (str, -1); char *temp = case_normalize (str, -1);
gboolean ret = !strcmp (temp, _moo_file_case_display_name (file)); gboolean ret = !strcmp (temp, _moo_file_case_display_name (file));
g_free (temp); g_free (temp);
return ret; return ret;
} }
static gboolean static gboolean
case_file_has_prefix_func (MooFile *file, case_file_has_prefix (MooFile *file,
const char *str, const char *str,
guint len) guint len)
{ {
char *temp = case_normalize_func (str, len); char *temp = case_normalize (str, len);
gboolean ret = g_str_has_prefix (_moo_file_case_display_name (file), temp); gboolean ret = g_str_has_prefix (_moo_file_case_display_name (file), temp);
g_free (temp); g_free (temp);
return ret; return ret;
} }
static void
set_text_funcs (TextFuncs *funcs,
gboolean case_sensitive)
{
if (case_sensitive)
{
funcs->file_equals = file_equals;
funcs->file_has_prefix = file_has_prefix;
funcs->normalize = normalize;
}
else
{
funcs->file_equals = case_file_equals;
funcs->file_has_prefix = case_file_has_prefix;
funcs->normalize = case_normalize;
}
}
static gboolean static gboolean
model_find_next_match (GtkTreeModel *model, model_find_next_match (GtkTreeModel *model,
GtkTreeIter *iter, GtkTreeIter *iter,
@ -104,7 +123,7 @@ model_find_next_match (GtkTreeModel *model,
g_return_val_if_fail (text != NULL, FALSE); g_return_val_if_fail (text != NULL, FALSE);
normalized_text = funcs->normalize_func (text, len); normalized_text = funcs->normalize (text, len);
normalized_text_len = strlen (normalized_text); normalized_text_len = strlen (normalized_text);
while (TRUE) while (TRUE)
@ -117,12 +136,11 @@ model_find_next_match (GtkTreeModel *model,
if (file) if (file)
{ {
if (exact_match) if (exact_match)
match = funcs->file_equals_func (file, normalized_text); match = funcs->file_equals (file, normalized_text);
else else
match = funcs->file_has_prefix_func (file, match = funcs->file_has_prefix (file,
normalized_text, normalized_text,
normalized_text_len); normalized_text_len);
_moo_file_unref (file); _moo_file_unref (file);
if (match) if (match)

View File

@ -4809,7 +4809,7 @@ typeahead_tab_key (MooFileView *fileview)
name = _moo_file_display_name (file); name = _moo_file_display_name (file);
#if 0 #if 0
if (!file || !stuff->file_equals_func (file, stuff->matched_prefix->str)) if (!file || !stuff->file_equals (file, stuff->matched_prefix->str))
goto error; goto error;
#endif #endif
@ -4846,7 +4846,7 @@ typeahead_tab_key (MooFileView *fileview)
goto error; goto error;
#if 0 #if 0
// if (!stuff->file_has_prefix_func (file, stuff->matched_prefix->str, stuff->matched_prefix->len)) // if (!stuff->file_has_prefix (file, stuff->matched_prefix->str, stuff->matched_prefix->len))
// goto error; // goto error;
#endif #endif
@ -4895,19 +4895,7 @@ typeahead_create (MooFileView *fileview)
stuff->fileview = fileview; stuff->fileview = fileview;
stuff->entry = fileview->priv->entry; stuff->entry = fileview->priv->entry;
stuff->case_sensitive = fileview->priv->typeahead_case_sensitive; stuff->case_sensitive = fileview->priv->typeahead_case_sensitive;
set_text_funcs (&stuff->text_funcs, stuff->case_sensitive);
if (stuff->case_sensitive)
{
stuff->text_funcs.file_equals_func = file_equals_func;
stuff->text_funcs.file_has_prefix_func = file_has_prefix_func;
stuff->text_funcs.normalize_func = normalize_func;
}
else
{
stuff->text_funcs.file_equals_func = case_file_equals_func;
stuff->text_funcs.file_has_prefix_func = case_file_has_prefix_func;
stuff->text_funcs.normalize_func = case_normalize_func;
}
fileview->priv->typeahead = stuff; fileview->priv->typeahead = stuff;
} }
@ -4936,19 +4924,7 @@ _moo_file_view_set_typeahead_case_sensitive (MooFileView *fileview,
fileview->priv->typeahead_case_sensitive = case_sensitive; fileview->priv->typeahead_case_sensitive = case_sensitive;
stuff->case_sensitive = case_sensitive; stuff->case_sensitive = case_sensitive;
set_text_funcs (&stuff->text_funcs, case_sensitive);
if (case_sensitive)
{
stuff->text_funcs.file_equals_func = file_equals_func;
stuff->text_funcs.file_has_prefix_func = file_has_prefix_func;
stuff->text_funcs.normalize_func = normalize_func;
}
else
{
stuff->text_funcs.file_equals_func = case_file_equals_func;
stuff->text_funcs.file_has_prefix_func = case_file_has_prefix_func;
stuff->text_funcs.normalize_func = case_normalize_func;
}
g_object_notify (G_OBJECT (fileview), "typeahead-case-sensitive"); g_object_notify (G_OBJECT (fileview), "typeahead-case-sensitive");
} }