Revision: 5329 http://geany.svn.sourceforge.net/geany/?rev=5329&view=rev Author: ntrel Date: 2010-10-26 16:02:30 +0000 (Tue, 26 Oct 2010)
Log Message: ----------- Add filetype mimetype field (patch by Colomban Wendling, thanks).
Modified Paths: -------------- trunk/ChangeLog trunk/src/filetypes.c trunk/src/filetypes.h trunk/src/ui_utils.c trunk/src/ui_utils.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-10-26 15:33:16 UTC (rev 5328) +++ trunk/ChangeLog 2010-10-26 16:02:30 UTC (rev 5329) @@ -9,6 +9,8 @@ * src/filetypes.c: Sort filetypes_by_title last instead of on insertion to prevent exponential time. + * src/ui_utils.h, src/filetypes.c, src/filetypes.h, src/ui_utils.c: + Add filetype mimetype field (patch by Colomban Wendling, thanks).
2010-10-25 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2010-10-26 15:33:16 UTC (rev 5328) +++ trunk/src/filetypes.c 2010-10-26 16:02:30 UTC (rev 5329) @@ -95,6 +95,7 @@ ft = filetypes[GEANY_FILETYPES_NONE]; ft->name = g_strdup(_("None")); ft->title = g_strdup(_("None")); + ft->mime_type = g_strdup("text/plain"); ft->group = GEANY_FILETYPE_GROUP_NONE;
#define C @@ -102,6 +103,7 @@ ft->lang = 0; ft->name = g_strdup("C"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-csrc"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define CPP @@ -109,6 +111,7 @@ ft->lang = 1; ft->name = g_strdup("C++"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-c++src"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define CS @@ -116,6 +119,7 @@ ft->lang = 25; ft->name = g_strdup("C#"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-csharp"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define VALA @@ -123,6 +127,7 @@ ft->lang = 33; ft->name = g_strdup("Vala"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-vala"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define D @@ -130,6 +135,7 @@ ft->lang = 17; ft->name = g_strdup("D"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-dsrc"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define JAVA @@ -137,6 +143,7 @@ ft->lang = 2; ft->name = g_strdup("Java"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-java"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define PAS /* to avoid warnings when building under Windows, the symbol PASCAL is there defined */ @@ -144,6 +151,7 @@ ft->lang = 4; ft->name = g_strdup("Pascal"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-pascal"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define ASM @@ -151,6 +159,7 @@ ft->lang = 9; ft->name = g_strdup("ASM"); ft->title = g_strdup_printf(_("%s source file"), "Assembler"); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define BASIC @@ -158,6 +167,7 @@ ft->lang = 26; ft->name = g_strdup("FreeBasic"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define FORTRAN @@ -165,6 +175,7 @@ ft->lang = 18; ft->name = g_strdup("Fortran"); ft->title = g_strdup_printf(_("%s source file"), "Fortran (F90)"); + ft->mime_type = g_strdup("text/x-fortran"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define F77 @@ -172,6 +183,7 @@ ft->lang = 30; ft->name = g_strdup("F77"); ft->title = g_strdup_printf(_("%s source file"), "Fortran (F77)"); + ft->mime_type = g_strdup("text/x-fortran"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define GLSL @@ -179,12 +191,14 @@ ft->lang = 31; ft->name = g_strdup("GLSL"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define CAML ft = filetypes[GEANY_FILETYPES_CAML]; ft->name = g_strdup("CAML"); ft->title = g_strdup_printf(_("%s source file"), "(O)Caml"); + ft->mime_type = g_strdup("text/x-ocaml"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define PERL @@ -192,6 +206,7 @@ ft->lang = 5; ft->name = g_strdup("Perl"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("application/x-perl"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define PHP @@ -199,6 +214,7 @@ ft->lang = 6; ft->name = g_strdup("PHP"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("application/x-php"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define JAVASCRIPT @@ -206,6 +222,7 @@ ft->lang = 23; ft->name = g_strdup("Javascript"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("application/javascript"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define PYTHON @@ -213,6 +230,7 @@ ft->lang = 7; ft->name = g_strdup("Python"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-python"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define RUBY @@ -220,6 +238,7 @@ ft->lang = 14; ft->name = g_strdup("Ruby"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("application/x-ruby"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define TCL @@ -227,6 +246,7 @@ ft->lang = 15; ft->name = g_strdup("Tcl"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-tcl"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define LUA @@ -234,6 +254,7 @@ ft->lang = 22; ft->name = g_strdup("Lua"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-lua"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define FERITE @@ -241,6 +262,7 @@ ft->lang = 19; ft->name = g_strdup("Ferite"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define HASKELL @@ -248,6 +270,7 @@ ft->lang = 24; ft->name = g_strdup("Haskell"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-haskell"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define MARKDOWN @@ -255,6 +278,7 @@ ft->lang = 36; ft->name = g_strdup("Markdown"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_MISC;
#define TXT2TAGS @@ -262,6 +286,7 @@ ft->lang = 37; ft->name = g_strdup("Txt2tags"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-txt2tags"); ft->group = GEANY_FILETYPE_GROUP_MISC;
#define ABC @@ -269,6 +294,7 @@ ft->lang = 38; ft->name = g_strdup("Abc"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_MISC;
#define SH @@ -276,6 +302,7 @@ ft->lang = 16; ft->name = g_strdup("Sh"); ft->title = g_strdup(_("Shell script file")); + ft->mime_type = g_strdup("application/x-shellscript"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define MAKE @@ -283,12 +310,14 @@ ft->lang = 3; ft->name = g_strdup("Make"); ft->title = g_strdup(_("Makefile")); + ft->mime_type = g_strdup("text/x-makefile"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define XML ft = filetypes[GEANY_FILETYPES_XML]; ft->name = g_strdup("XML"); ft->title = g_strdup(_("XML document")); + ft->mime_type = g_strdup("application/xml"); ft->group = GEANY_FILETYPE_GROUP_MARKUP;
#define DOCBOOK @@ -296,6 +325,7 @@ ft->lang = 12; ft->name = g_strdup("Docbook"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("application/docbook+xml"); ft->group = GEANY_FILETYPE_GROUP_MARKUP;
#define HTML @@ -303,6 +333,7 @@ ft->lang = 29; ft->name = g_strdup("HTML"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/html"); ft->group = GEANY_FILETYPE_GROUP_MARKUP;
#define CSS @@ -310,6 +341,7 @@ ft->lang = 13; ft->name = g_strdup("CSS"); ft->title = g_strdup(_("Cascading StyleSheet")); + ft->mime_type = g_strdup("text/css"); ft->group = GEANY_FILETYPE_GROUP_MARKUP; /* not really markup but fit quite well to HTML */
#define SQL @@ -317,6 +349,7 @@ ft->lang = 11; ft->name = g_strdup("SQL"); ft->title = g_strdup(_("SQL Dump file")); + ft->mime_type = g_strdup("text/x-sql"); ft->group = GEANY_FILETYPE_GROUP_MISC;
#define LATEX @@ -324,6 +357,7 @@ ft->lang = 8; ft->name = g_strdup("LaTeX"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-tex"); ft->group = GEANY_FILETYPE_GROUP_MISC;
#define VHDL @@ -331,6 +365,7 @@ ft->lang = 21; ft->name = g_strdup("VHDL"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-vhdl"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define VERILOG @@ -338,6 +373,7 @@ ft->lang = 39; ft->name = g_strdup("Verilog"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define DIFF @@ -345,18 +381,21 @@ ft->lang = 20; ft->name = g_strdup("Diff"); filetype_make_title(ft, TITLE_FILE); + ft->mime_type = g_strdup("text/x-patch"); ft->group = GEANY_FILETYPE_GROUP_MISC;
#define LISP ft = filetypes[GEANY_FILETYPES_LISP]; ft->name = g_strdup("Lisp"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define ERLANG ft = filetypes[GEANY_FILETYPES_ERLANG]; ft->name = g_strdup("Erlang"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-erlang"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define CONF @@ -364,12 +403,14 @@ ft->lang = 10; ft->name = g_strdup("Conf"); ft->title = g_strdup(_("Config file")); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_MISC;
#define PO ft = filetypes[GEANY_FILETYPES_PO]; ft->name = g_strdup("Po"); ft->title = g_strdup(_("Gettext translation file")); + ft->mime_type = g_strdup("text/x-gettext-translation"); ft->group = GEANY_FILETYPE_GROUP_MISC;
#define HAXE @@ -377,6 +418,7 @@ ft->lang = 27; ft->name = g_strdup("Haxe"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define ACTIONSCRIPT @@ -384,6 +426,7 @@ ft->lang = 34; ft->name = g_strdup("ActionScript"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("application/ecmascript"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define R @@ -391,6 +434,7 @@ ft->lang = 40; ft->name = g_strdup("R"); ft->title = g_strdup_printf(_("%s script file"), "R"); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define REST @@ -398,6 +442,7 @@ ft->lang = 28; ft->name = g_strdup("reStructuredText"); filetype_make_title(ft, TITLE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_MISC;
#define MATLAB @@ -405,18 +450,21 @@ ft->lang = 32; ft->name = g_strdup("Matlab/Octave"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-matlab"); ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
#define YAML ft = filetypes[GEANY_FILETYPES_YAML]; ft->name = g_strdup("YAML"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_MISC;
#define CMAKE ft = filetypes[GEANY_FILETYPES_CMAKE]; ft->name = g_strdup("CMake"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-cmake"); ft->group = GEANY_FILETYPE_GROUP_MISC;
#define NSIS @@ -424,18 +472,21 @@ ft->lang = 35; ft->name = g_strdup("NSIS"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_MISC;
#define ADA ft = filetypes[GEANY_FILETYPES_ADA]; ft->name = g_strdup("Ada"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/x-adasrc"); ft->group = GEANY_FILETYPE_GROUP_COMPILED;
#define FORTH ft = filetypes[GEANY_FILETYPES_FORTH]; ft->name = g_strdup("Forth"); filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->mime_type = g_strdup("text/plain"); /* FIXME */ ft->group = GEANY_FILETYPE_GROUP_SCRIPT; }
@@ -481,6 +532,9 @@
/* list will be sorted later */ filetypes_by_title = g_slist_prepend(filetypes_by_title, ft); + + if (ft->mime_type) + ft->icon = ui_get_mime_icon(ft->mime_type, GTK_ICON_SIZE_MENU); }
@@ -962,6 +1016,7 @@ g_free(ft->name); g_free(ft->title); g_free(ft->extension); + g_free(ft->mime_type); g_free(ft->comment_open); g_free(ft->comment_close); g_free(ft->context_action_cmd); @@ -969,6 +1024,8 @@ g_free(ft->ftdefcmds); g_free(ft->execcmds); set_error_regex(ft, NULL); + if (ft->icon) + g_object_unref(ft->icon);
g_strfreev(ft->pattern); g_free(ft->priv);
Modified: trunk/src/filetypes.h =================================================================== --- trunk/src/filetypes.h 2010-10-26 15:33:16 UTC (rev 5328) +++ trunk/src/filetypes.h 2010-10-26 16:02:30 UTC (rev 5329) @@ -129,6 +129,8 @@ GeanyFiletypeGroupID group; gchar *error_regex_string; GeanyFiletype *lexer_filetype; + gchar *mime_type; + GdkPixbuf *icon;
struct GeanyFiletypePrivate *priv; /* must be last, append fields before this item */ #ifdef GEANY_PRIVATE
Modified: trunk/src/ui_utils.c =================================================================== --- trunk/src/ui_utils.c 2010-10-26 15:33:16 UTC (rev 5328) +++ trunk/src/ui_utils.c 2010-10-26 16:02:30 UTC (rev 5329) @@ -2453,3 +2453,48 @@ g_signal_stop_emission_by_name(editable, "insert-text"); }
+ +/* gets the icon that applies to a particular MIME type */ +GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size) +{ + GdkPixbuf *icon = NULL; +#if defined(HAVE_GIO) && GLIB_CHECK_VERSION(2, 18, 0) + gchar *ctype; + GIcon *gicon; + GtkIconInfo *info; + GtkIconTheme *theme; + gint real_size; + + g_return_val_if_fail(gtk_icon_size_lookup(size, &real_size, NULL), NULL); + gtk_icon_size_lookup(size, &real_size, NULL); + + theme = gtk_icon_theme_get_default(); + ctype = g_content_type_from_mime_type(mime_type); + gicon = g_content_type_get_icon(ctype); + info = gtk_icon_theme_lookup_by_gicon(theme, gicon, real_size, 0); + g_object_unref(gicon); + g_free(ctype); + + if (info) + { + icon = gtk_icon_info_load_icon(info, NULL); + gtk_icon_info_free(info); + } +#else + const gchar *stock_id = GTK_STOCK_FILE; + GtkIconSet *icon_set; + + if (strstr(mime_type, "directory")) + stock_id = GTK_STOCK_DIRECTORY; + + icon_set = gtk_icon_factory_lookup_default(stock_id); + if (icon_set) + { + icon = gtk_icon_set_render_icon(icon_set, gtk_widget_get_default_style(), + gtk_widget_get_default_direction(), + GTK_STATE_NORMAL, size, NULL, NULL); + } +#endif + return icon; +} +
Modified: trunk/src/ui_utils.h =================================================================== --- trunk/src/ui_utils.h 2010-10-26 15:33:16 UTC (rev 5328) +++ trunk/src/ui_utils.h 2010-10-26 16:02:30 UTC (rev 5329) @@ -321,4 +321,6 @@
gint ui_get_gtk_settings_integer(const gchar *property_name, gint default_value);
+GdkPixbuf *ui_get_mime_icon(const gchar *mime_type, GtkIconSize size); + #endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.