Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Tue, 30 Jun 2015 11:18:16 UTC Commit: bbbb769a3e7aa8cc00d76dde45fb21506efc5616 https://github.com/geany/geany-plugins/commit/bbbb769a3e7aa8cc00d76dde45fb21...
Log Message: ----------- projectorganizer: fix (?) locale/utf8-ness
Hopefully fix all (?) utf8/locale issues. Not really tested because I realized I don't know how to properly test this...
Also fix some memory leaks on the way.
Modified Paths: -------------- projectorganizer/src/prjorg-menu.c projectorganizer/src/prjorg-project.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-utils.c projectorganizer/src/prjorg-utils.h
Modified: projectorganizer/src/prjorg-menu.c 88 lines changed, 51 insertions(+), 37 deletions(-) =================================================================== @@ -50,14 +50,14 @@ enum static GtkWidget *s_fif_item, *s_ff_item, *s_ft_item, *s_shs_item, *s_sep_item, *s_context_osf_item, *s_context_sep_item;
-static gboolean try_swap_header_source(gchar *file_name, gboolean is_header, GSList *file_list, GSList *header_patterns, GSList *source_patterns) +static gboolean try_swap_header_source(gchar *utf8_file_name, gboolean is_header, GSList *file_list, GSList *header_patterns, GSList *source_patterns) { gchar *name_pattern; GSList *elem; GPatternSpec *pattern; gboolean found = FALSE;
- name_pattern = g_path_get_basename(file_name); + name_pattern = g_path_get_basename(utf8_file_name); SETPTR(name_pattern, utils_remove_ext_from_filename(name_pattern)); SETPTR(name_pattern, g_strconcat(name_pattern, ".*", NULL)); pattern = g_pattern_spec_new(name_pattern); @@ -132,24 +132,26 @@ static void on_swap_header_source(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_U
if (!swapped) { - gchar *doc_dir; + gchar *utf8_doc_dir; + gchar *locale_doc_dir;
- doc_dir = g_path_get_dirname(doc->file_name); - SETPTR(doc_dir, utils_get_locale_from_utf8(doc_dir)); + utf8_doc_dir = g_path_get_dirname(doc->file_name); + locale_doc_dir = utils_get_locale_from_utf8(utf8_doc_dir);
- list = utils_get_file_list(doc_dir, NULL, NULL); + list = utils_get_file_list(locale_doc_dir, NULL, NULL); foreach_list (elem, list) { gchar *full_name;
- full_name = g_build_filename(doc_dir, elem->data, NULL); + full_name = g_build_filename(locale_doc_dir, elem->data, NULL); SETPTR(full_name, utils_get_utf8_from_locale(full_name)); SETPTR(elem->data, full_name); } swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); g_slist_foreach(list, (GFunc) g_free, NULL); g_slist_free(list); - g_free(doc_dir); + g_free(utf8_doc_dir); + g_free(locale_doc_dir); list = NULL; }
@@ -185,7 +187,12 @@ static void on_swap_header_source(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_U static void on_find_in_project(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) { if (geany_data->app->project) - search_show_find_in_files_dialog(get_project_base_path()); + { + gchar *utf8_base_path = get_project_base_path(); + + search_show_find_in_files_dialog(utf8_base_path); + g_free(utf8_base_path); + } }
@@ -227,22 +234,21 @@ static gboolean kb_callback(guint key_id) static void on_open_selected_file(GtkMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current(); - gchar *sel = NULL; - gchar *filename = NULL; - gchar *path = NULL; + gchar *utf8_sel, *locale_sel; + gchar *filename = NULL; /* locale */
g_return_if_fail(doc != NULL);
- sel = get_selection(); + utf8_sel = get_selection();
- if (!sel) + if (!utf8_sel) return;
- SETPTR(sel, utils_get_locale_from_utf8(sel)); + locale_sel = utils_get_locale_from_utf8(utf8_sel);
- if (g_path_is_absolute(sel)) + if (g_path_is_absolute(locale_sel)) { - filename = g_strdup(sel); + filename = g_strdup(locale_sel); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { g_free(filename); @@ -252,44 +258,47 @@ static void on_open_selected_file(GtkMenuItem *menuitem, gpointer user_data)
if (!filename) { + gchar *locale_path = NULL; + if (doc->file_name) { - path = g_path_get_dirname(doc->file_name); - SETPTR(path, utils_get_locale_from_utf8(path)); + locale_path = g_path_get_dirname(doc->file_name); + SETPTR(locale_path, utils_get_locale_from_utf8(locale_path)); }
- if (!path) - path = g_get_current_dir(); + if (!locale_path) + locale_path = g_get_current_dir();
- filename = g_build_path(G_DIR_SEPARATOR_S, path, sel, NULL); + filename = g_build_path(G_DIR_SEPARATOR_S, locale_path, locale_sel, NULL); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { g_free(filename); filename = NULL; }
- g_free(path); + g_free(locale_path); }
if (!filename && geany_data->app->project != NULL) { + gchar *utf8_path; gchar **pathv; gint i;
- path = g_strdup(""); - pathv = g_strsplit_set(sel, "/\", -1); + utf8_path = g_strdup(""); + pathv = g_strsplit_set(utf8_sel, "/\", -1); for (i = g_strv_length(pathv) - 1; i >= 0; i--) { if (g_strcmp0(pathv[i], "..") == 0) break; - SETPTR(path, g_build_filename(G_DIR_SEPARATOR_S, pathv[i], path, NULL)); + SETPTR(utf8_path, g_build_filename(G_DIR_SEPARATOR_S, pathv[i], utf8_path, NULL)); } g_strfreev(pathv);
- if (g_strcmp0(path, "") != 0) + if (g_strcmp0(utf8_path, "") != 0) { GSList *elem; - gchar *found_path = NULL; + const gchar *found_path = NULL;
foreach_slist (elem, prj_org->roots) { @@ -301,9 +310,9 @@ static void on_open_selected_file(GtkMenuItem *menuitem, gpointer user_data) while (g_hash_table_iter_next(&iter, &key, &value)) { gchar *file_name = key; - gchar *pos = g_strrstr(file_name, path); + gchar *pos = g_strrstr(file_name, utf8_path); - if (pos && (pos - file_name + strlen(path) == strlen(file_name))) + if (pos && (pos - file_name + strlen(utf8_path) == strlen(file_name))) { found_path = file_name; break; @@ -316,8 +325,7 @@ static void on_open_selected_file(GtkMenuItem *menuitem, gpointer user_data)
if (found_path) { - filename = g_strdup(found_path); - SETPTR(filename, utils_get_locale_from_utf8(filename)); + filename = utils_get_locale_from_utf8(found_path); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { g_free(filename); @@ -325,13 +333,13 @@ static void on_open_selected_file(GtkMenuItem *menuitem, gpointer user_data) } } } - g_free(path); + g_free(utf8_path); }
#ifdef G_OS_UNIX if (!filename) { - filename = g_build_path(G_DIR_SEPARATOR_S, "/usr/local/include", sel, NULL); + filename = g_build_path(G_DIR_SEPARATOR_S, "/usr/local/include", locale_sel, NULL); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { g_free(filename); @@ -341,7 +349,7 @@ static void on_open_selected_file(GtkMenuItem *menuitem, gpointer user_data)
if (!filename) { - filename = g_build_path(G_DIR_SEPARATOR_S, "/usr/include", sel, NULL); + filename = g_build_path(G_DIR_SEPARATOR_S, "/usr/include", locale_sel, NULL); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { g_free(filename); @@ -351,10 +359,16 @@ static void on_open_selected_file(GtkMenuItem *menuitem, gpointer user_data) #endif
if (filename) - open_file(filename); + { + gchar *utf8_filename = utils_get_utf8_from_locale(filename); + + open_file(utf8_filename); + g_free(utf8_filename); + }
g_free(filename); - g_free(sel); + g_free(utf8_sel); + g_free(locale_sel); }
Modified: projectorganizer/src/prjorg-project.c 192 lines changed, 112 insertions(+), 80 deletions(-) =================================================================== @@ -70,64 +70,76 @@ static void collect_source_files(gchar *filename, TMSourceFile *sf, gpointer use
/* path - absolute path in locale, returned list in locale */ -static GSList *get_file_list(const gchar * path, GSList *patterns, GSList *ignored_dirs_patterns, GSList *ignored_file_patterns) +static GSList *get_file_list(const gchar *utf8_path, GSList *patterns, GSList *ignored_dirs_patterns, GSList *ignored_file_patterns) { GSList *list = NULL; GDir *dir; + gchar *locale_path = utils_get_locale_from_utf8(utf8_path);
- dir = g_dir_open(path, 0, NULL); + dir = g_dir_open(locale_path, 0, NULL); if (!dir) + { + g_free(locale_path); return NULL; + }
while (TRUE) { - const gchar *name; - gchar *filename; + const gchar *locale_name; + gchar *locale_filename, *utf8_filename, *utf8_name;
- name = g_dir_read_name(dir); - if (!name) + locale_name = g_dir_read_name(dir); + if (!locale_name) break;
- filename = g_build_filename(path, name, NULL); + utf8_name = utils_get_utf8_from_locale(locale_name); + locale_filename = g_build_filename(locale_path, locale_name, NULL); + utf8_filename = utils_get_utf8_from_locale(locale_filename);
- if (g_file_test(filename, G_FILE_TEST_IS_DIR)) + if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR)) { GSList *lst; - gchar *parent_realpath, *child_realpath, *relative; + gchar *relative, *locale_parent_realpath, *locale_child_realpath, + *utf8_parent_realpath, *utf8_child_realpath;
/* symlink cycle avoidance - test if directory within parent directory */ - parent_realpath = tm_get_real_path(path); - child_realpath = tm_get_real_path(filename); - relative = get_relative_path(parent_realpath, child_realpath); - g_free(parent_realpath); - g_free(child_realpath); + locale_parent_realpath = tm_get_real_path(locale_path); + locale_child_realpath = tm_get_real_path(locale_filename); + utf8_parent_realpath = utils_get_utf8_from_locale(locale_parent_realpath); + utf8_child_realpath = utils_get_utf8_from_locale(locale_child_realpath);
- if (!relative) - continue; + relative = get_relative_path(utf8_parent_realpath, utf8_child_realpath);
- g_free(relative); + g_free(locale_parent_realpath); + g_free(locale_child_realpath); + g_free(utf8_parent_realpath); + g_free(utf8_child_realpath);
- if (patterns_match(ignored_dirs_patterns, name)) + if (relative) { - g_free(filename); - continue; + g_free(relative); + + if (!patterns_match(ignored_dirs_patterns, utf8_name)) + { + lst = get_file_list(utf8_filename, patterns, ignored_dirs_patterns, ignored_file_patterns); + if (lst) + list = g_slist_concat(list, lst); + } } - - lst = get_file_list(filename, patterns, ignored_dirs_patterns, ignored_file_patterns); - if (lst) - list = g_slist_concat(list, lst); - g_free(filename); } - else if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) + else if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR)) { - if (patterns_match(patterns, name) && !patterns_match(ignored_file_patterns, name)) - list = g_slist_prepend(list, filename); - else - g_free(filename); + if (patterns_match(patterns, utf8_name) && !patterns_match(ignored_file_patterns, utf8_name)) + list = g_slist_prepend(list, g_strdup(utf8_filename)); } + + g_free(utf8_filename); + g_free(locale_filename); + g_free(utf8_name); }
g_dir_close(dir); + g_free(locale_path);
return list; } @@ -165,12 +177,11 @@ static gint prjorg_project_rescan_root(PrjOrgRoot *root) foreach_slist(elem, lst) { - char *path = g_strdup(elem->data); + char *path = elem->data;
if (path) { - SETPTR(path, utils_get_utf8_from_locale(path)); - g_hash_table_insert(root->file_table, path, NULL); + g_hash_table_insert(root->file_table, g_strdup(path), NULL); filenum++; } } @@ -191,7 +202,7 @@ static gint prjorg_project_rescan_root(PrjOrgRoot *root) static gboolean match_basename(gconstpointer pft, gconstpointer user_data) { const GeanyFiletype *ft = pft; - const gchar *base_filename = user_data; + const gchar *utf8_base_filename = user_data; gint j; gboolean ret = FALSE;
@@ -202,7 +213,7 @@ static gboolean match_basename(gconstpointer pft, gconstpointer user_data) { GPatternSpec *pattern = g_pattern_spec_new(ft->pattern[j]);
- if (g_pattern_match_string(pattern, base_filename)) + if (g_pattern_match_string(pattern, utf8_base_filename)) { ret = TRUE; g_pattern_spec_free(pattern); @@ -220,36 +231,44 @@ static gboolean match_basename(gconstpointer pft, gconstpointer user_data) * extension and only if this fails, look at the shebang */ static GeanyFiletype *filetypes_detect(const gchar *utf8_filename) { - guint i; struct stat s; - gchar *base_filename; GeanyFiletype *ft = NULL; + gchar *locale_filename;
- if (g_stat(utf8_filename, &s) != 0 || s.st_size > 10*1024*1024) - return filetypes[GEANY_FILETYPES_NONE]; + locale_filename = utils_get_locale_from_utf8(utf8_filename); + if (g_stat(locale_filename, &s) != 0 || s.st_size > 10*1024*1024) + ft = filetypes[GEANY_FILETYPES_NONE]; + else + { + guint i; + gchar *utf8_base_filename;
- /* to match against the basename of the file (because of Makefile*) */ - base_filename = g_path_get_basename(utf8_filename); + /* to match against the basename of the file (because of Makefile*) */ + utf8_base_filename = g_path_get_basename(utf8_filename); #ifdef G_OS_WIN32 - /* use lower case basename */ - SETPTR(base_filename, g_utf8_strdown(base_filename, -1)); + /* use lower case basename */ + SETPTR(utf8_base_filename, g_utf8_strdown(utf8_base_filename, -1)); #endif
- for (i = 0; i < geany_data->filetypes_array->len; i++) - { - GeanyFiletype *ftype = filetypes[i]; - - if (match_basename(ftype, base_filename)) + for (i = 0; i < geany_data->filetypes_array->len; i++) { - ft = ftype; - break; + GeanyFiletype *ftype = filetypes[i]; + + if (match_basename(ftype, utf8_base_filename)) + { + ft = ftype; + break; + } } + + if (ft == NULL) + ft = filetypes_detect_from_file(utf8_filename); + + g_free(utf8_base_filename); } - - if (ft == NULL) - ft = filetypes_detect_from_file(utf8_filename);
- g_free(base_filename); + g_free(locale_filename); + return ft; }
@@ -267,13 +286,15 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data) while (g_hash_table_iter_next(&iter, &key, &value)) { TMSourceFile *sf; - gchar *path = key; + gchar *utf8_path = key; + gchar *locale_path = utils_get_locale_from_utf8(utf8_path); - sf = tm_source_file_new(path, filetypes_detect(path)->name); - if (sf && !document_find_by_filename(path)) + sf = tm_source_file_new(locale_path, filetypes_detect(utf8_path)->name); + if (sf && !document_find_by_filename(utf8_path)) g_ptr_array_add(source_files, sf); - g_hash_table_insert(file_table, g_strdup(path), sf); + g_hash_table_insert(file_table, g_strdup(utf8_path), sf); + g_free(locale_path); } g_hash_table_destroy(root->file_table); root->file_table = file_table; @@ -361,10 +382,10 @@ void prjorg_project_save(GKeyFile * key_file) }
-static PrjOrgRoot *create_root(const gchar *base_dir) +static PrjOrgRoot *create_root(const gchar *utf8_base_dir) { PrjOrgRoot *root = (PrjOrgRoot *) g_new0(PrjOrgRoot, 1); - root->base_dir = g_strdup(base_dir); + root->base_dir = g_strdup(utf8_base_dir); root->file_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GFreeFunc)tm_source_file_free); return root; } @@ -387,21 +408,28 @@ static void close_root(PrjOrgRoot *root, gpointer user_data)
static gint root_comparator(PrjOrgRoot *a, PrjOrgRoot *b) { - gchar *a_realpath, *b_realpath; + gchar *a_realpath, *b_realpath, *a_locale_base_dir, *b_locale_base_dir; gint res;
- a_realpath = tm_get_real_path(a->base_dir); - b_realpath = tm_get_real_path(b->base_dir); + a_locale_base_dir = utils_get_locale_from_utf8(a->base_dir); + b_locale_base_dir = utils_get_locale_from_utf8(b->base_dir); + a_realpath = tm_get_real_path(a_locale_base_dir); + b_realpath = tm_get_real_path(b_locale_base_dir); + res = g_strcmp0(a_realpath, b_realpath); + g_free(a_realpath); g_free(b_realpath); + g_free(a_locale_base_dir); + g_free(b_locale_base_dir); + return res; }
-void prjorg_project_add_external_dir(const gchar *dirname) +void prjorg_project_add_external_dir(const gchar *utf8_dirname) { - PrjOrgRoot *new_root = create_root(dirname); + PrjOrgRoot *new_root = create_root(utf8_dirname); if (g_slist_find_custom (prj_org->roots, new_root, (GCompareFunc)root_comparator) != NULL) { close_root(new_root, NULL); @@ -417,9 +445,9 @@ void prjorg_project_add_external_dir(const gchar *dirname) }
-void prjorg_project_remove_external_dir(const gchar *dirname) +void prjorg_project_remove_external_dir(const gchar *utf8_dirname) { - PrjOrgRoot *test_root = create_root(dirname); + PrjOrgRoot *test_root = create_root(utf8_dirname); GSList *found = g_slist_find_custom (prj_org->roots, test_root, (GCompareFunc)root_comparator); if (found != NULL) { @@ -438,6 +466,7 @@ void prjorg_project_open(GKeyFile * key_file) gchar **source_patterns, **header_patterns, **ignored_dirs_patterns, **ignored_file_patterns, **external_dirs, **dir_ptr, *last_name; gint generate_tag_prefs; GSList *elem, *ext_list = NULL; + gchar *utf8_base_path;
if (prj_org != NULL) prjorg_project_close(); @@ -476,8 +505,11 @@ void prjorg_project_open(GKeyFile * key_file) last_name = elem->data; } g_slist_free(ext_list); + /* the project directory is always first */ - prj_org->roots = g_slist_prepend(prj_org->roots, create_root(get_project_base_path())); + utf8_base_path = get_project_base_path(); + prj_org->roots = g_slist_prepend(prj_org->roots, create_root(utf8_base_path)); + g_free(utf8_base_path);
update_project( source_patterns, @@ -650,17 +682,17 @@ void prjorg_project_close(void) }
-gboolean prjorg_project_is_in_project(const gchar * filename) +gboolean prjorg_project_is_in_project(const gchar *utf8_filename) { GSList *elem; - if (!filename || !prj_org || !geany_data->app->project || !prj_org->roots) + if (!utf8_filename || !prj_org || !geany_data->app->project || !prj_org->roots) return FALSE; foreach_slist (elem, prj_org->roots) { PrjOrgRoot *root = elem->data; - if (g_hash_table_lookup_extended (root->file_table, filename, NULL, NULL)) + if (g_hash_table_lookup_extended (root->file_table, utf8_filename, NULL, NULL)) return TRUE; }
@@ -678,14 +710,14 @@ static gboolean add_tm_idle(gpointer foo) foreach_slist (elem2, s_idle_add_funcs) { GSList *elem; - gchar *fname = elem2->data; + gchar *utf8_fname = elem2->data; foreach_slist (elem, prj_org->roots) { PrjOrgRoot *root = elem->data; - TMSourceFile *sf = g_hash_table_lookup(root->file_table, fname); + TMSourceFile *sf = g_hash_table_lookup(root->file_table, utf8_fname); - if (sf != NULL && !document_find_by_filename(fname)) + if (sf != NULL && !document_find_by_filename(utf8_fname)) { tm_workspace_add_source_file(sf); break; /* single file representation in TM is enough */ @@ -706,12 +738,12 @@ static gboolean add_tm_idle(gpointer foo) * Additional problem: The tag removal in Geany happens after this function is called. * To be sure, perform on idle after this happens (even though from my knowledge of TM * this shouldn't probably matter). */ -void prjorg_project_add_single_tm_file(gchar *filename) +void prjorg_project_add_single_tm_file(gchar *utf8_filename) { if (s_idle_add_funcs == NULL) plugin_idle_add(geany_plugin, (GSourceFunc)add_tm_idle, NULL); - s_idle_add_funcs = g_slist_prepend(s_idle_add_funcs, g_strdup(filename)); + s_idle_add_funcs = g_slist_prepend(s_idle_add_funcs, g_strdup(utf8_filename)); }
@@ -725,12 +757,12 @@ static gboolean remove_tm_idle(gpointer foo) foreach_slist (elem2, s_idle_remove_funcs) { GSList *elem; - gchar *fname = elem2->data; + gchar *utf8_fname = elem2->data;
foreach_slist (elem, prj_org->roots) { PrjOrgRoot *root = elem->data; - TMSourceFile *sf = g_hash_table_lookup(root->file_table, fname); + TMSourceFile *sf = g_hash_table_lookup(root->file_table, utf8_fname); if (sf != NULL) tm_workspace_remove_source_file(sf); @@ -755,10 +787,10 @@ static gboolean remove_tm_idle(gpointer foo) * when this function is called and if we remove the TmSourceFile now, line * number for the searched tag won't be found. For this reason delay the tag * TmSourceFile removal until idle */ -void prjorg_project_remove_single_tm_file(gchar *filename) +void prjorg_project_remove_single_tm_file(gchar *utf8_filename) { if (s_idle_remove_funcs == NULL) plugin_idle_add(geany_plugin, (GSourceFunc)remove_tm_idle, NULL); - s_idle_remove_funcs = g_slist_prepend(s_idle_remove_funcs, g_strdup(filename)); + s_idle_remove_funcs = g_slist_prepend(s_idle_remove_funcs, g_strdup(utf8_filename)); }
Modified: projectorganizer/src/prjorg-project.h 10 lines changed, 5 insertions(+), 5 deletions(-) =================================================================== @@ -55,12 +55,12 @@ void prjorg_project_save(GKeyFile * key_file); void prjorg_project_read_properties_tab(void); void prjorg_project_rescan(void);
-void prjorg_project_add_external_dir(const gchar *dirname); -void prjorg_project_remove_external_dir(const gchar *dirname); +void prjorg_project_add_external_dir(const gchar *utf8_dirname); +void prjorg_project_remove_external_dir(const gchar *utf8_dirname);
-void prjorg_project_add_single_tm_file(gchar *filename); -void prjorg_project_remove_single_tm_file(gchar *filename); +void prjorg_project_add_single_tm_file(gchar *utf8_filename); +void prjorg_project_remove_single_tm_file(gchar *utf8_filename);
-gboolean prjorg_project_is_in_project(const gchar * filename); +gboolean prjorg_project_is_in_project(const gchar *utf8_filename);
#endif
Modified: projectorganizer/src/prjorg-sidebar.c 151 lines changed, 89 insertions(+), 62 deletions(-) =================================================================== @@ -102,7 +102,7 @@ static struct } s_popup_menu;
-static gint show_dialog_find_file(gchar *path, gchar **pattern, gboolean *case_sensitive, gboolean *full_path) +static gint show_dialog_find_file(gchar *utf8_path, gchar **pattern, gboolean *case_sensitive, gboolean *is_full_path) { gint res; GtkWidget *entry; @@ -164,8 +164,8 @@ static gint show_dialog_find_file(gchar *path, gchar **pattern, gboolean *case_s gtk_widget_show_all(vbox); }
- if (path) - gtk_label_set_text(GTK_LABEL(s_fif_dialog.dir_label), path); + if (utf8_path) + gtk_label_set_text(GTK_LABEL(s_fif_dialog.dir_label), utf8_path); else gtk_label_set_text(GTK_LABEL(s_fif_dialog.dir_label), _("project or external directory")); entry = gtk_bin_get_child(GTK_BIN(s_fif_dialog.combo)); @@ -184,7 +184,7 @@ static gint show_dialog_find_file(gchar *path, gchar **pattern, gboolean *case_s str = gtk_entry_get_text(GTK_ENTRY(entry)); *pattern = g_strconcat("*", str, "*", NULL); *case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s_fif_dialog.case_sensitive)); - *full_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s_fif_dialog.full_path)); + *is_full_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s_fif_dialog.full_path)); ui_combo_box_add_to_history(GTK_COMBO_BOX_TEXT(s_fif_dialog.combo), str, 0); }
@@ -210,6 +210,7 @@ static gboolean topmost_selected(GtkTreeModel *model, GtkTreeIter *iter, gboolea }
+/* utf8 */ static gchar *build_path(GtkTreeIter *iter) { GtkTreeIter node; @@ -219,7 +220,7 @@ static gchar *build_path(GtkTreeIter *iter) gchar *name;
if (!iter) - return g_strdup(get_project_base_path()); + return get_project_base_path();
node = *iter; model = GTK_TREE_MODEL(s_file_store); @@ -237,7 +238,12 @@ static gchar *build_path(GtkTreeIter *iter) }
if (topmost_selected(model, &node, TRUE)) - SETPTR(path, g_build_filename(get_project_base_path(), path, NULL)); + { + gchar *utf8_base_path = get_project_base_path(); + + SETPTR(path, g_build_filename(utf8_base_path, path, NULL)); + g_free(utf8_base_path); + } else { gtk_tree_model_get(model, &node, FILEVIEW_COLUMN_NAME, &name, -1); @@ -285,26 +291,33 @@ static void on_follow_active(GtkToggleToolButton *button, G_GNUC_UNUSED gpointer
static void on_add_external(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) { + gchar *utf8_base_path = get_project_base_path(); + gchar *locale_path = utils_get_locale_from_utf8(utf8_base_path); GtkWidget *dialog;
dialog = gtk_file_chooser_dialog_new(_("Add External Directory"), GTK_WINDOW(geany->main_widgets->window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, _("_Cancel"), GTK_RESPONSE_CANCEL, _("Add"), GTK_RESPONSE_ACCEPT, NULL); - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), get_project_base_path()); + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + gchar *locale_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + gchar *utf8_filename = utils_get_utf8_from_locale(locale_filename); - prjorg_project_add_external_dir(filename); + prjorg_project_add_external_dir(utf8_filename); prjorg_sidebar_update(TRUE); project_write_config(); - g_free (filename); + g_free(utf8_filename); + g_free(locale_filename); }
gtk_widget_destroy(dialog); + + g_free(utf8_base_path); + g_free(locale_path); }
@@ -348,37 +361,41 @@ static void find_file_recursive(GtkTreeIter *iter, gboolean case_sensitive, gboo } else { - gchar *name; + gchar *utf8_name;
if (iter == NULL) return;
if (full_path) { - gchar *path; + gchar *utf8_path, *utf8_base_path;
- path = build_path(iter); - name = get_relative_path(get_project_base_path(), path); - g_free(path); + utf8_path = build_path(iter); + utf8_base_path = get_project_base_path(); + utf8_name = get_relative_path(utf8_base_path, utf8_path); + g_free(utf8_path); + g_free(utf8_base_path); } else - gtk_tree_model_get(GTK_TREE_MODEL(model), iter, FILEVIEW_COLUMN_NAME, &name, -1); + gtk_tree_model_get(GTK_TREE_MODEL(model), iter, FILEVIEW_COLUMN_NAME, &utf8_name, -1);
if (!case_sensitive) - SETPTR(name, g_utf8_strdown(name, -1)); + SETPTR(utf8_name, g_utf8_strdown(utf8_name, -1));
- if (g_pattern_match_string(pattern, name)) + if (g_pattern_match_string(pattern, utf8_name)) { - gchar *path, *rel_path; + gchar *utf8_base_path = get_project_base_path(); + gchar *utf8_path, *rel_path;
- path = build_path(iter); - rel_path = get_relative_path(get_project_base_path(), path); - msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s", rel_path ? rel_path : path); - g_free(path); + utf8_path = build_path(iter); + rel_path = get_relative_path(utf8_base_path, utf8_path); + msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s", rel_path ? rel_path : utf8_path); + g_free(utf8_path); g_free(rel_path); + g_free(utf8_base_path); }
- g_free(name); + g_free(utf8_name); } }
@@ -386,13 +403,13 @@ static void find_file_recursive(GtkTreeIter *iter, gboolean case_sensitive, gboo static void find_file(GtkTreeIter *iter) { gchar *pattern_str = NULL; - gboolean case_sensitive, full_path; - gchar *path; + gboolean case_sensitive, is_full_path; + gchar *utf8_path = build_path(iter);
- path = build_path(iter); - - if (show_dialog_find_file(iter ? path : NULL, &pattern_str, &case_sensitive, &full_path) == GTK_RESPONSE_ACCEPT) + if (show_dialog_find_file(iter ? utf8_path : NULL, &pattern_str, &case_sensitive, &is_full_path) == GTK_RESPONSE_ACCEPT) { + gchar *utf8_base_path = get_project_base_path(); + gchar *locale_base_path = utils_get_locale_from_utf8(utf8_base_path); GPatternSpec *pattern;
if (!case_sensitive) @@ -401,13 +418,15 @@ static void find_file(GtkTreeIter *iter) pattern = g_pattern_spec_new(pattern_str);
msgwin_clear_tab(MSG_MESSAGE); - msgwin_set_messages_dir(get_project_base_path()); - find_file_recursive(iter, case_sensitive, full_path, pattern); + msgwin_set_messages_dir(locale_base_path); + find_file_recursive(iter, case_sensitive, is_full_path, pattern); msgwin_switch_tab(MSG_MESSAGE, TRUE); + g_free(utf8_base_path); + g_free(locale_base_path); }
g_free(pattern_str); - g_free(path); + g_free(utf8_path); }
@@ -521,7 +540,7 @@ static const char *tm_tag_type_name(const TMTag *tag)
static gboolean match(TMTag *tag, const gchar *name, gboolean declaration, gboolean case_sensitive, - MatchType match_type, GPatternSpec *pspec, gchar *path) + MatchType match_type, GPatternSpec *pspec, gchar *utf8_path) { const gint forward_types = tm_tag_prototype_t | tm_tag_externvar_t; gboolean matches = FALSE; @@ -554,21 +573,25 @@ static gboolean match(TMTag *tag, const gchar *name, gboolean declaration, gbool g_free(name_case); } - if (matches && path) + if (matches && utf8_path) { + gchar *utf8_file_name = utils_get_utf8_from_locale(tag->file->file_name); gchar *relpath; - relpath = get_relative_path(path, tag->file->file_name); + relpath = get_relative_path(utf8_path, utf8_file_name); matches = relpath != NULL; g_free(relpath); + g_free(utf8_file_name); } return matches; }
-static void find_tags(const gchar *name, gboolean declaration, gboolean case_sensitive, MatchType match_type, gchar *path) +static void find_tags(const gchar *name, gboolean declaration, gboolean case_sensitive, MatchType match_type, gchar *utf8_path) { + gchar *utf8_base_path = get_project_base_path(); + gchar *locale_base_path = utils_get_locale_from_utf8(utf8_base_path); GPtrArray *tags_array = geany_data->app->tm_workspace->tags_array; guint i; gchar *name_case; @@ -581,44 +604,48 @@ static void find_tags(const gchar *name, gboolean declaration, gboolean case_sen pspec = g_pattern_spec_new(name_case);
- msgwin_set_messages_dir(get_project_base_path()); + msgwin_set_messages_dir(locale_base_path); msgwin_clear_tab(MSG_MESSAGE); for (i = 0; i < tags_array->len; i++) /* TODO: binary search */ { TMTag *tag = tags_array->pdata[i];
- if (match(tag, name_case, declaration, case_sensitive, match_type, pspec, path)) + if (match(tag, name_case, declaration, case_sensitive, match_type, pspec, utf8_path)) { gchar *scopestr = tag->scope ? g_strconcat(tag->scope, "::", NULL) : g_strdup(""); + gchar *utf8_fname = utils_get_utf8_from_locale(tag->file->file_name); gchar *relpath; - relpath = get_relative_path(get_project_base_path(), tag->file->file_name); + relpath = get_relative_path(utf8_base_path, utf8_fname); msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s:%lu:\n\t[%s]\t %s%s%s", relpath, tag->line, tm_tag_type_name(tag), scopestr, tag->name, tag->arglist ? tag->arglist : ""); g_free(scopestr); g_free(relpath); + g_free(utf8_fname); } } msgwin_switch_tab(MSG_MESSAGE, TRUE); g_free(name_case); g_free(pspec); + g_free(utf8_base_path); + g_free(locale_base_path); }
static void find_tag(GtkTreeIter *iter) { gchar *selection; - gchar *path; + gchar *utf8_path; GtkWidget *entry;
create_dialog_find_tag();
entry = gtk_bin_get_child(GTK_BIN(s_ft_dialog.combo));
- path = build_path(iter); + utf8_path = build_path(iter); if (iter) - gtk_label_set_text(GTK_LABEL(s_ft_dialog.dir_label), path); + gtk_label_set_text(GTK_LABEL(s_ft_dialog.dir_label), utf8_path); else gtk_label_set_text(GTK_LABEL(s_ft_dialog.dir_label), _("project or external directory"));
@@ -642,10 +669,10 @@ static void find_tag(GtkTreeIter *iter)
ui_combo_box_add_to_history(GTK_COMBO_BOX_TEXT(s_ft_dialog.combo), name, 0);
- find_tags(name, declaration, case_sensitive, match_type, iter?path:NULL); + find_tags(name, declaration, case_sensitive, match_type, iter ? utf8_path : NULL); } - g_free(path); + g_free(utf8_path); gtk_widget_hide(s_ft_dialog.widget); }
@@ -727,7 +754,7 @@ static void on_open_clicked(void) } else { - gchar *name; + gchar *utf8_path; GIcon *icon;
gtk_tree_model_get(model, &iter, FILEVIEW_COLUMN_ICON, &icon, -1); @@ -738,9 +765,9 @@ static void on_open_clicked(void) return; }
- name = build_path(&iter); - open_file(name); - g_free(name); + utf8_path = build_path(&iter); + open_file(utf8_path); + g_free(utf8_path); g_object_unref(icon); } } @@ -822,7 +849,7 @@ static void on_find_in_files(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED GtkTreeSelection *treesel; GtkTreeIter iter, parent; GtkTreeModel *model; - gchar *path; + gchar *utf8_path;
treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view));
@@ -832,15 +859,15 @@ static void on_find_in_files(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED if (!gtk_tree_model_iter_has_child(model, &iter)) { if (gtk_tree_model_iter_parent(model, &parent, &iter)) - path = build_path(&parent); + utf8_path = build_path(&parent); else - path = build_path(NULL); + utf8_path = build_path(NULL); } else - path = build_path(&iter); + utf8_path = build_path(&iter);
- search_show_find_in_files_dialog(path); - g_free(path); + search_show_find_in_files_dialog(utf8_path); + g_free(utf8_path); }
@@ -1132,7 +1159,7 @@ static gboolean find_in_tree(GtkTreeIter *parent, gchar **path_split, gint level static gboolean follow_editor_on_idle(gpointer foo) { GtkTreeIter root_iter, found_iter; - gchar *path = NULL; + gchar *utf8_path = NULL; gchar **path_split; GeanyDocument *doc; GSList *elem; @@ -1149,20 +1176,20 @@ static gboolean follow_editor_on_idle(gpointer foo) { PrjOrgRoot *root = elem->data; - path = get_relative_path(root->base_dir, doc->file_name); - if (path) + utf8_path = get_relative_path(root->base_dir, doc->file_name); + if (utf8_path) break; - g_free(path); - path = NULL; + g_free(utf8_path); + utf8_path = NULL; if (!gtk_tree_model_iter_next(model, &root_iter)) break; } - if (!path) + if (!utf8_path) return FALSE;
- path_split = g_strsplit_set(path, "/\", 0); + path_split = g_strsplit_set(utf8_path, "/\", 0);
if (find_in_tree(&root_iter, path_split, 0, &found_iter)) { @@ -1180,7 +1207,7 @@ static gboolean follow_editor_on_idle(gpointer foo) gtk_tree_path_free(tree_path); } - g_free(path); + g_free(utf8_path); g_strfreev(path_split); return FALSE;
Modified: projectorganizer/src/prjorg-utils.c 21 lines changed, 15 insertions(+), 6 deletions(-) =================================================================== @@ -27,20 +27,28 @@ extern GeanyData *geany_data; extern GeanyFunctions *geany_functions;
-gchar *get_relative_path(const gchar *parent, const gchar *descendant) +/* utf8 */ +gchar *get_relative_path(const gchar *utf8_parent, const gchar *utf8_descendant) { GFile *gf_parent, *gf_descendant; - gchar *ret; + gchar *locale_parent, *locale_descendant; + gchar *locale_ret, *utf8_ret;
- gf_parent = g_file_new_for_path(parent); - gf_descendant = g_file_new_for_path(descendant); + locale_parent = utils_get_locale_from_utf8(utf8_parent); + locale_descendant = utils_get_locale_from_utf8(utf8_descendant); + gf_parent = g_file_new_for_path(locale_parent); + gf_descendant = g_file_new_for_path(locale_descendant);
- ret = g_file_get_relative_path(gf_parent, gf_descendant); + locale_ret = g_file_get_relative_path(gf_parent, gf_descendant); + utf8_ret = utils_get_utf8_from_locale(locale_ret);
g_object_unref(gf_parent); g_object_unref(gf_descendant); + g_free(locale_parent); + g_free(locale_descendant); + g_free(locale_ret);
- return ret; + return utf8_ret; }
@@ -118,6 +126,7 @@ gchar *get_selection(void) }
+/* utf8 */ gchar *get_project_base_path(void) { GeanyProject *project = geany_data->app->project;
Modified: projectorganizer/src/prjorg-utils.h 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -19,7 +19,7 @@ #ifndef __PRJORG_UTILS_H__ #define __PRJORG_UTILS_H__
-gchar *get_relative_path(const gchar *parent, const gchar *descendant); +gchar *get_relative_path(const gchar *utf8_parent, const gchar *utf8_descendant);
gboolean patterns_match(GSList *patterns, const gchar *str); GSList *get_precompiled_patterns(gchar **patterns);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).