Case-insensitive filenames on windows
This commit is contained in:
parent
bf11bca1fb
commit
c9dc774c41
@ -1260,6 +1260,25 @@ _moo_file_get_display_basename (GFile *file)
|
||||
return name;
|
||||
}
|
||||
|
||||
char *
|
||||
_moo_edit_normalize_filename_for_comparison (const char *filename)
|
||||
{
|
||||
moo_return_val_if_fail (filename != NULL, NULL);
|
||||
#ifdef __WIN32__
|
||||
/* XXX */
|
||||
char *tmp = g_utf8_normalize (filename, -1, G_NORMALIZE_ALL_COMPOSE);
|
||||
char *ret = g_utf8_strdown (tmp, -1);
|
||||
g_free (tmp);
|
||||
return ret;
|
||||
#else
|
||||
return g_strdup (filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *_moo_edit_normalize_uri_for_comparison (const char *uri)
|
||||
{
|
||||
return _moo_edit_normalize_filename_for_comparison (uri);
|
||||
}
|
||||
|
||||
void
|
||||
_moo_edit_set_file (MooEdit *edit,
|
||||
@ -1267,10 +1286,11 @@ _moo_edit_set_file (MooEdit *edit,
|
||||
const char *encoding)
|
||||
{
|
||||
GFile *tmp;
|
||||
char *tmp2, *tmp3, *tmp4;
|
||||
char *tmp2, *tmp3, *tmp4, *tmp5;
|
||||
|
||||
tmp = edit->priv->file;
|
||||
tmp2 = edit->priv->filename;
|
||||
tmp5 = edit->priv->norm_filename;
|
||||
tmp3 = edit->priv->display_filename;
|
||||
tmp4 = edit->priv->display_basename;
|
||||
|
||||
@ -1283,6 +1303,7 @@ _moo_edit_set_file (MooEdit *edit,
|
||||
|
||||
edit->priv->file = NULL;
|
||||
edit->priv->filename = NULL;
|
||||
edit->priv->norm_filename = NULL;
|
||||
|
||||
if (n == 1)
|
||||
edit->priv->display_filename = g_strdup (_("Untitled"));
|
||||
@ -1296,6 +1317,7 @@ _moo_edit_set_file (MooEdit *edit,
|
||||
remove_untitled (NULL, edit);
|
||||
edit->priv->file = g_file_dup (file);
|
||||
edit->priv->filename = g_file_get_path (file);
|
||||
edit->priv->norm_filename = _moo_edit_normalize_filename_for_comparison (edit->priv->filename);
|
||||
edit->priv->display_filename = _moo_file_get_display_name (file);
|
||||
edit->priv->display_basename = _moo_file_get_display_basename (file);
|
||||
}
|
||||
@ -1313,6 +1335,7 @@ _moo_edit_set_file (MooEdit *edit,
|
||||
g_free (tmp2);
|
||||
g_free (tmp3);
|
||||
g_free (tmp4);
|
||||
g_free (tmp5);
|
||||
}
|
||||
|
||||
|
||||
|
@ -118,6 +118,10 @@ GdkPixbuf *_moo_edit_get_icon (MooEdit *edit,
|
||||
GtkWidget *widget,
|
||||
GtkIconSize size);
|
||||
|
||||
char *_moo_edit_normalize_filename_for_comparison (const char *filename);
|
||||
char *_moo_edit_normalize_uri_for_comparison (const char *uri);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_EDIT_IMPL_H */
|
||||
|
@ -37,6 +37,7 @@ struct MooEditPrivate {
|
||||
*/
|
||||
GFile *file;
|
||||
char *filename;
|
||||
char *norm_filename;
|
||||
char *display_filename;
|
||||
char *display_basename;
|
||||
|
||||
|
@ -328,6 +328,7 @@ moo_edit_finalize (GObject *object)
|
||||
if (edit->priv->file)
|
||||
g_object_unref (edit->priv->file);
|
||||
g_free (edit->priv->filename);
|
||||
g_free (edit->priv->norm_filename);
|
||||
g_free (edit->priv->display_filename);
|
||||
g_free (edit->priv->display_basename);
|
||||
g_free (edit->priv->encoding);
|
||||
@ -687,6 +688,13 @@ moo_edit_get_filename (MooEdit *edit)
|
||||
return g_strdup (edit->priv->filename);
|
||||
}
|
||||
|
||||
char *
|
||||
moo_edit_get_norm_filename (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
||||
return g_strdup (edit->priv->norm_filename);
|
||||
}
|
||||
|
||||
const char *
|
||||
moo_edit_get_display_name (MooEdit *edit)
|
||||
{
|
||||
|
@ -75,6 +75,7 @@ GType moo_edit_file_info_get_type (void) G_GNUC_CONST;
|
||||
|
||||
char *moo_edit_get_uri (MooEdit *edit);
|
||||
char *moo_edit_get_filename (MooEdit *edit);
|
||||
char *moo_edit_get_norm_filename (MooEdit *edit);
|
||||
const char *moo_edit_get_display_name (MooEdit *edit);
|
||||
const char *moo_edit_get_display_basename (MooEdit *edit);
|
||||
|
||||
|
@ -101,7 +101,11 @@ _moo_edit_filter_new_regex (const char *string)
|
||||
|
||||
g_return_val_if_fail (string != NULL, NULL);
|
||||
|
||||
regex = g_regex_new (string, G_REGEX_OPTIMIZE, 0, &error);
|
||||
regex = g_regex_new (string, G_REGEX_OPTIMIZE
|
||||
#ifdef __WIN32__
|
||||
| G_REGEX_CASELESS
|
||||
#endif
|
||||
, 0, &error);
|
||||
|
||||
if (!regex)
|
||||
{
|
||||
|
@ -2263,7 +2263,7 @@ doc_list_find_filename (DocList *list,
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
char *tmp = moo_edit_get_filename (list->data);
|
||||
char *tmp = moo_edit_get_norm_filename (list->data);
|
||||
/* XXX */
|
||||
if (tmp && strcmp (tmp, filename) == 0)
|
||||
{
|
||||
@ -2280,15 +2280,17 @@ MooEdit *
|
||||
moo_editor_get_doc (MooEditor *editor,
|
||||
const char *filename)
|
||||
{
|
||||
char *freeme = NULL;
|
||||
char *freeme1 = NULL;
|
||||
char *freeme2 = NULL;
|
||||
MooEdit *doc = NULL;
|
||||
WindowList *l;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
|
||||
freeme = _moo_normalize_file_path (filename);
|
||||
filename = freeme;
|
||||
freeme1 = _moo_normalize_file_path (filename);
|
||||
freeme2 = _moo_edit_normalize_filename_for_comparison (freeme1);
|
||||
filename = freeme2;
|
||||
|
||||
if ((doc = doc_list_find_filename (editor->priv->windowless, filename)))
|
||||
goto out;
|
||||
@ -2303,7 +2305,8 @@ moo_editor_get_doc (MooEditor *editor,
|
||||
}
|
||||
|
||||
out:
|
||||
g_free (freeme);
|
||||
g_free (freeme2);
|
||||
g_free (freeme1);
|
||||
return doc;
|
||||
}
|
||||
|
||||
@ -2313,14 +2316,18 @@ doc_list_find_uri (DocList *list,
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
char *tmp = moo_edit_get_uri (list->data);
|
||||
char *freeme1 = moo_edit_get_uri (list->data);
|
||||
char *freeme2 = _moo_edit_normalize_uri_for_comparison (freeme1);
|
||||
const char *doc_uri = freeme2;
|
||||
/* XXX */
|
||||
if (tmp && strcmp (tmp, uri) == 0)
|
||||
if (doc_uri && strcmp (doc_uri, uri) == 0)
|
||||
{
|
||||
g_free (tmp);
|
||||
g_free (freeme2);
|
||||
g_free (freeme1);
|
||||
return list->data;
|
||||
}
|
||||
g_free (tmp);
|
||||
g_free (freeme2);
|
||||
g_free (freeme1);
|
||||
list = list->next;
|
||||
}
|
||||
return NULL;
|
||||
@ -2330,14 +2337,18 @@ MooEdit *
|
||||
moo_editor_get_doc_for_uri (MooEditor *editor,
|
||||
const char *uri)
|
||||
{
|
||||
MooEdit *doc;
|
||||
MooEdit *doc = NULL;
|
||||
WindowList *l;
|
||||
char *freeme = NULL;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
||||
g_return_val_if_fail (uri != NULL, NULL);
|
||||
|
||||
freeme = _moo_edit_normalize_uri_for_comparison (uri);
|
||||
uri = freeme;
|
||||
|
||||
if ((doc = doc_list_find_uri (editor->priv->windowless, uri)))
|
||||
return doc;
|
||||
goto out;
|
||||
|
||||
for (l = editor->priv->windows; l != NULL; l = l->next)
|
||||
{
|
||||
@ -2345,10 +2356,12 @@ moo_editor_get_doc_for_uri (MooEditor *editor,
|
||||
doc = doc_list_find_uri (docs, uri);
|
||||
doc_list_free_links (docs);
|
||||
if (doc)
|
||||
return doc;
|
||||
goto out;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
out:
|
||||
g_free (freeme);
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user