Finally fix case-insensitive file completion
This commit is contained in:
parent
3a71df37bc
commit
2d95b3ac9c
@ -248,14 +248,14 @@ _moo_file_entry_completion_init (MooFileEntryCompletion *cmpl)
|
||||
|
||||
if (cmpl->priv->case_sensitive)
|
||||
{
|
||||
cmpl->priv->text_funcs.strcmp_func = strcmp_func;
|
||||
cmpl->priv->text_funcs.strncmp_func = strncmp_func;
|
||||
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.strcmp_func = case_strcmp_func;
|
||||
cmpl->priv->text_funcs.strncmp_func = case_strncmp_func;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -751,14 +751,14 @@ completion_set_case_sensitive (MooFileEntryCompletion *cmpl,
|
||||
|
||||
if (case_sensitive)
|
||||
{
|
||||
cmpl->priv->text_funcs.strcmp_func = strcmp_func;
|
||||
cmpl->priv->text_funcs.strncmp_func = strncmp_func;
|
||||
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.strcmp_func = case_strcmp_func;
|
||||
cmpl->priv->text_funcs.strncmp_func = case_strncmp_func;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1318,8 +1318,9 @@ completion_visible_func (GtkTreeModel *model,
|
||||
}
|
||||
else if (cmpl->priv->visible_func (file, cmpl->priv->visible_func_data))
|
||||
{
|
||||
visible = !cmpl->priv->text_funcs.strncmp_func (cmpl->priv->display_basename, file,
|
||||
cmpl->priv->display_basename_len);
|
||||
visible = cmpl->priv->text_funcs.file_has_prefix_func (file,
|
||||
cmpl->priv->display_basename,
|
||||
cmpl->priv->display_basename_len);
|
||||
}
|
||||
|
||||
_moo_file_unref (file);
|
||||
|
@ -26,29 +26,29 @@
|
||||
|
||||
/* TODO: strncmp should accept char len, not byte len? */
|
||||
typedef struct {
|
||||
int (*strcmp_func) (const char *str,
|
||||
MooFile *file);
|
||||
int (*strncmp_func) (const char *str,
|
||||
MooFile *file,
|
||||
guint len);
|
||||
char* (*normalize_func) (const char *str,
|
||||
gssize len);
|
||||
gboolean (*file_equals_func) (MooFile *file,
|
||||
const char *str);
|
||||
gboolean (*file_has_prefix_func) (MooFile *file,
|
||||
const char *str,
|
||||
guint len);
|
||||
char* (*normalize_func) (const char *str,
|
||||
gssize len);
|
||||
} TextFuncs;
|
||||
|
||||
|
||||
static int
|
||||
strcmp_func (const char *str,
|
||||
MooFile *file)
|
||||
static gboolean
|
||||
file_equals_func (MooFile *file,
|
||||
const char *str)
|
||||
{
|
||||
return strcmp (str, _moo_file_display_name (file));
|
||||
return !strcmp (str, _moo_file_display_name (file));
|
||||
}
|
||||
|
||||
static int
|
||||
strncmp_func (const char *str,
|
||||
MooFile *file,
|
||||
guint len)
|
||||
static gboolean
|
||||
file_has_prefix_func (MooFile *file,
|
||||
const char *str,
|
||||
guint len)
|
||||
{
|
||||
return strncmp (str, _moo_file_display_name (file), len);
|
||||
return !strncmp (str, _moo_file_display_name (file), len);
|
||||
}
|
||||
|
||||
static char *
|
||||
@ -59,21 +59,6 @@ normalize_func (const char *str,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
case_strcmp_func (const char *str,
|
||||
MooFile *file)
|
||||
{
|
||||
return strcmp (str, _moo_file_case_display_name (file));
|
||||
}
|
||||
|
||||
static int
|
||||
case_strncmp_func (const char *str,
|
||||
MooFile *file,
|
||||
guint len)
|
||||
{
|
||||
return strncmp (str, _moo_file_case_display_name (file), len);
|
||||
}
|
||||
|
||||
static char *
|
||||
case_normalize_func (const char *str,
|
||||
gssize len)
|
||||
@ -84,6 +69,27 @@ case_normalize_func (const char *str,
|
||||
return res;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
case_file_equals_func (MooFile *file,
|
||||
const char *str)
|
||||
{
|
||||
char *temp = case_normalize_func (str, -1);
|
||||
gboolean ret = !strcmp (temp, _moo_file_case_display_name (file));
|
||||
g_free (temp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
case_file_has_prefix_func (MooFile *file,
|
||||
const char *str,
|
||||
guint len)
|
||||
{
|
||||
char *temp = case_normalize_func (str, len);
|
||||
gboolean ret = g_str_has_prefix (_moo_file_case_display_name (file), temp);
|
||||
g_free (temp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
model_find_next_match (GtkTreeModel *model,
|
||||
@ -111,10 +117,11 @@ model_find_next_match (GtkTreeModel *model,
|
||||
if (file)
|
||||
{
|
||||
if (exact_match)
|
||||
match = !funcs->strcmp_func (normalized_text, file);
|
||||
match = funcs->file_equals_func (file, normalized_text);
|
||||
else
|
||||
match = !funcs->strncmp_func (normalized_text, file,
|
||||
normalized_text_len);
|
||||
match = funcs->file_has_prefix_func (file,
|
||||
normalized_text,
|
||||
normalized_text_len);
|
||||
|
||||
_moo_file_unref (file);
|
||||
|
||||
|
@ -4809,7 +4809,7 @@ typeahead_tab_key (MooFileView *fileview)
|
||||
name = _moo_file_display_name (file);
|
||||
|
||||
#if 0
|
||||
if (!file || stuff->strcmp_func (stuff->matched_prefix->str, file))
|
||||
if (!file || !stuff->file_equals_func (file, stuff->matched_prefix->str))
|
||||
goto error;
|
||||
#endif
|
||||
|
||||
@ -4846,7 +4846,7 @@ typeahead_tab_key (MooFileView *fileview)
|
||||
goto error;
|
||||
|
||||
#if 0
|
||||
// if (stuff->strncmp_func (stuff->matched_prefix->str, file, stuff->matched_prefix->len))
|
||||
// if (!stuff->file_has_prefix_func (file, stuff->matched_prefix->str, stuff->matched_prefix->len))
|
||||
// goto error;
|
||||
#endif
|
||||
|
||||
@ -4898,14 +4898,14 @@ typeahead_create (MooFileView *fileview)
|
||||
|
||||
if (stuff->case_sensitive)
|
||||
{
|
||||
stuff->text_funcs.strcmp_func = strcmp_func;
|
||||
stuff->text_funcs.strncmp_func = strncmp_func;
|
||||
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.strcmp_func = case_strcmp_func;
|
||||
stuff->text_funcs.strncmp_func = case_strncmp_func;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -4939,14 +4939,14 @@ _moo_file_view_set_typeahead_case_sensitive (MooFileView *fileview,
|
||||
|
||||
if (case_sensitive)
|
||||
{
|
||||
stuff->text_funcs.strcmp_func = strcmp_func;
|
||||
stuff->text_funcs.strncmp_func = strncmp_func;
|
||||
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.strcmp_func = case_strcmp_func;
|
||||
stuff->text_funcs.strncmp_func = case_strncmp_func;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -2213,7 +2213,7 @@ moo_notebook_draw_label (MooNotebook *nb,
|
||||
&event->area,
|
||||
widget,
|
||||
DETAIL_TAB,
|
||||
x, y,
|
||||
x, y + 1,
|
||||
page->label->width,
|
||||
height,
|
||||
GTK_POS_BOTTOM);
|
||||
|
@ -253,4 +253,14 @@ G_END_DECLS
|
||||
|
||||
#endif /* G_OS_WIN32 */
|
||||
|
||||
G_INLINE_FUNC gboolean
|
||||
moo_os_win32 (void)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
return TRUE;
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* MOO_UTILS_MISC_H */
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "mooutils/mooi18n.h"
|
||||
#include "mooutils/moohelp.h"
|
||||
#include "mooutils/mooutils-fs.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "plugins/moofind-gxml.h"
|
||||
#include "plugins/moogrep-gxml.h"
|
||||
#include "moo-help-sections.h"
|
||||
@ -323,7 +324,7 @@ setup_file_combo (MooHistoryCombo *hist_combo)
|
||||
entry = MOO_COMBO (hist_combo)->entry;
|
||||
completion = g_object_new (MOO_TYPE_FILE_ENTRY_COMPLETION,
|
||||
"directories-only", TRUE,
|
||||
"case-sensitive", TRUE,
|
||||
"case-sensitive", !moo_os_win32 (),
|
||||
"show-hidden", FALSE,
|
||||
(const char*) NULL);
|
||||
_moo_file_entry_completion_set_entry (completion, GTK_ENTRY (entry));
|
||||
|
Loading…
x
Reference in New Issue
Block a user