Split filetypes_get_from_filename() into filetypes_detect_from_file()

and filetypes_detect_from_filename().


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1460 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Nick Treleaven 2007-04-18 12:12:51 +00:00
parent 3fe147c4f1
commit 14001ddc8f
4 changed files with 26 additions and 13 deletions

View File

@ -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 <enrico.troeger@uvena.de>

View File

@ -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);

View File

@ -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);

View File

@ -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();