foreach_slist (elem, file_list) { GtkTreeIter iter; gchar **path_arr = elem->data; GIcon *icon = NULL; gchar *content_type = g_content_type_guess(path_arr[level], NULL, 0, NULL); if (content_type) { icon = g_content_type_get_icon(content_type); if (icon) { GtkIconInfo *icon_info; icon_info = gtk_icon_theme_lookup_by_gicon(gtk_icon_theme_get_default(), icon, 16, 0); if (!icon_info) { g_object_unref(icon); icon = NULL; } else gtk_icon_info_free(icon_info); } g_free(content_type); } if (patterns_match(header_patterns, path_arr[level])) { if (! icon) icon = g_icon_new_for_string("prjorg-header", NULL); gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0, FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, path_arr[level], FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1); } else if (patterns_match(source_patterns, path_arr[level])) { if (! icon) icon = g_icon_new_for_string("prjorg-source", NULL); gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0, FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, path_arr[level], FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1); } else { if (! icon) icon = g_icon_new_for_string("prjorg-file", NULL); gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0, FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, path_arr[level], FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1); } if (icon) g_object_unref(icon); }
/* path - absolute path in locale, returned list in locale */ static GSList *get_file_list(const gchar * path, GSList *patterns, GSList *ignored_dirs_patterns) { GSList *list = NULL; GDir *dir; dir = g_dir_open(path, 0, NULL); if (!dir) return NULL; while (TRUE) { const gchar *name; gchar *filename; name = g_dir_read_name(dir); if (!name) break; filename = g_build_filename(path, name, NULL); if (g_file_test(filename, G_FILE_TEST_IS_DIR)) { GSList *lst; if (patterns_match(ignored_dirs_patterns, name)) { g_free(filename); continue; } lst = get_file_list(filename, patterns, ignored_dirs_patterns); if (lst) list = g_slist_concat(list, lst); g_free(filename); } else if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { if (patterns_match(patterns, name)) list = g_slist_prepend(list, filename); else g_free(filename); } } g_dir_close(dir); return list; }
static gboolean try_swap_header_source(gchar *file_name, gboolean is_header, GSList *file_list, GSList *header_patterns, GSList *source_patterns) { gchar *name_pattern; gchar *base_name = NULL; GSList *elem; GPatternSpec *pattern; gboolean found = FALSE; name_pattern = g_path_get_basename(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); g_free(name_pattern); for (elem = file_list; elem != NULL; elem = g_slist_next(elem)) { gchar *full_name = elem->data; base_name = g_path_get_basename(full_name); if (g_pattern_match_string(pattern, base_name) && gprj_project_is_in_project(full_name)) { if ((is_header && patterns_match(source_patterns, base_name)) || (!is_header && patterns_match(header_patterns, base_name))) { open_file(full_name); found = TRUE; break; } } } g_free(base_name); g_pattern_spec_free(pattern); return found; }
static void on_swap_header_source(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) { GSList *header_patterns, *source_patterns; GeanyDocument *doc; gboolean known_type = TRUE; gboolean is_header; gchar *doc_basename; doc = document_get_current(); if (!g_prj || !geany_data->app->project || !doc || !doc->file_name) return; header_patterns = get_precompiled_patterns(g_prj->header_patterns); source_patterns = get_precompiled_patterns(g_prj->source_patterns); doc_basename = g_path_get_basename(doc->file_name); if (patterns_match(header_patterns, doc_basename)) is_header = TRUE; else if (patterns_match(source_patterns, doc_basename)) is_header = FALSE; else known_type = FALSE; if (known_type) { gboolean swapped; GSList *elem, *list = NULL; gint i; foreach_document(i) { gchar *filename; filename = document_index(i)->file_name; if (gprj_project_is_in_project(filename)) list = g_slist_prepend(list, filename); } swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); g_slist_free(list); list = NULL; if (!swapped) { gchar *doc_dir; doc_dir = g_path_get_dirname(doc->file_name); setptr(doc_dir, utils_get_locale_from_utf8(doc_dir)); list = utils_get_file_list(doc_dir, NULL, NULL); for (elem = list; elem != NULL; elem = g_slist_next(elem)) { gchar *full_name; full_name = g_build_filename(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); list = NULL; } if (!swapped) { g_hash_table_foreach(g_prj->file_tag_table, (GHFunc) get_project_file_list, &list); try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); g_slist_free(list); } } g_free(doc_basename); g_slist_foreach(header_patterns, (GFunc) g_pattern_spec_free, NULL); g_slist_free(header_patterns); g_slist_foreach(source_patterns, (GFunc) g_pattern_spec_free, NULL); g_slist_free(source_patterns); }