diff --git a/ChangeLog b/ChangeLog index e587dd03..5a2022cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * doc/geany.docbook: Update Search section: escape sequences, Find All, Mark, Replace All. + * src/filetypes.c, src/filetypes.h, src/document.c: + Split filetypes_get_from_filename() into filetypes_detect_from_file() + and filetypes_detect_from_filename(). 2007-04-16 Enrico Tröger diff --git a/src/document.c b/src/document.c index d192b428..d7368db5 100644 --- a/src/document.c +++ b/src/document.c @@ -439,7 +439,7 @@ gint document_new_file(const gchar *filename, filetype *ft) //document_set_filetype(idx, (ft == NULL) ? filetypes[GEANY_FILETYPES_ALL] : ft); if (ft == NULL && filename != NULL) // guess the filetype from the filename if one is given - ft = filetypes_get_from_filename(idx); + ft = filetypes_detect_from_file(idx); document_set_filetype(idx, ft); // also clears taglist if (ft == NULL) filetypes[GEANY_FILETYPES_ALL]->style_func_ptr(doc_list[idx].sci); @@ -807,7 +807,7 @@ gint document_open_file(gint idx, const gchar *filename, gint pos, gboolean read g_signal_connect((GtkWidget*) doc_list[idx].sci, "sci-notify", G_CALLBACK(on_editor_notification), GINT_TO_POINTER(idx)); - use_ft = (ft != NULL) ? ft : filetypes_get_from_filename(idx); + use_ft = (ft != NULL) ? ft : filetypes_detect_from_file(idx); } else { // reloading @@ -1058,7 +1058,7 @@ gboolean document_save_file(gint idx, gboolean force) if (doc_list[idx].file_type == NULL || doc_list[idx].file_type->id == GEANY_FILETYPES_ALL) { - doc_list[idx].file_type = filetypes_get_from_filename(idx); + doc_list[idx].file_type = filetypes_detect_from_file(idx); filetypes_select_radio_item(doc_list[idx].file_type); } document_set_filetype(idx, doc_list[idx].file_type); diff --git a/src/filetypes.c b/src/filetypes.c index dd8bf425..1a706581 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -681,14 +681,10 @@ static filetype *find_shebang(gint idx) } -/* simple filetype selection based on the filename extension */ -filetype *filetypes_get_from_filename(gint idx) +/* Detect the filetype for document idx, checking for a shebang, then filename extension. */ +filetype *filetypes_detect_from_file(gint idx) { - GPatternSpec *pattern; filetype *ft; - const gchar *utf8_filename; - gchar *base_filename; - gint i, j; if (! DOC_IDX_VALID(idx)) return filetypes[GEANY_FILETYPES_ALL]; @@ -699,8 +695,18 @@ filetype *filetypes_get_from_filename(gint idx) if (doc_list[idx].file_name == NULL) return filetypes[GEANY_FILETYPES_ALL]; - else - utf8_filename = doc_list[idx].file_name; + + return filetypes_detect_from_filename(doc_list[idx].file_name); +} + + +/* Detect filetype based on the filename extension. + * utf8_filename can include the full path. */ +filetype *filetypes_detect_from_filename(const gchar *utf8_filename) +{ + GPatternSpec *pattern; + gchar *base_filename; + gint i, j; // to match against the basename of the file(because of Makefile*) base_filename = g_path_get_basename(utf8_filename); diff --git a/src/filetypes.h b/src/filetypes.h index a6c04817..076c6e0c 100644 --- a/src/filetypes.h +++ b/src/filetypes.h @@ -119,8 +119,12 @@ filetype *filetypes_get_from_uid(gint uid); * and create the filetype menu*/ void filetypes_init_types(); -/* simple filetype selection based on the filename extension */ -filetype *filetypes_get_from_filename(gint idx); +/* Detect the filetype for document idx, checking for a shebang, then filename extension. */ +filetype *filetypes_detect_from_file(gint idx); + +/* Detect filetype based on the filename extension. + * utf8_filename can include the full path. */ +filetype *filetypes_detect_from_filename(const gchar *utf8_filename); /* frees the array and all related pointers */ void filetypes_free_types();