@@ -56,6 +56,40 @@ var SupportedModes = {
5656 "text/x-web-textile" : "textile"
5757} ;
5858
59+ var contentTypes = {
60+ "js" : "application/javascript" ,
61+ "json" : "application/json" ,
62+ "css" : "text/css" ,
63+
64+ "xml" : "application/xml" ,
65+ "rdf" : "application/rdf+xml" ,
66+ "rss" : "application/rss+xml" ,
67+ "svg" : "image/svg+xml" ,
68+ "wsdl" : "application/wsdl+xml" ,
69+ "xslt" : "application/xslt+xml" ,
70+ "atom" : "application/atom+xml" ,
71+ "mathml" : "application/mathml+xml" ,
72+ "mml" : "application/mathml+xml" ,
73+
74+ "php" : "application/x-httpd-php" ,
75+ "html" : "text/html" ,
76+ "xhtml" : "application/xhtml+xml" ,
77+ "coffee" : "text/x-script.coffeescript" ,
78+ "py" : "text/x-script.python" ,
79+
80+ "ru" : "text/x-script.ruby" ,
81+ "gemspec" : "text/x-script.ruby" ,
82+ "rake" : "text/x-script.ruby" ,
83+ "rb" : "text/x-script.ruby" ,
84+
85+ "c" : "text/x-c" ,
86+ "cc" : "text/x-c" ,
87+ "cpp" : "text/x-c" ,
88+ "cxx" : "text/x-c" ,
89+ "h" : "text/x-c" ,
90+ "hh" : "text/x-c"
91+ } ;
92+
5993return ext . register ( "ext/code/code" , {
6094 name : "Code Editor" ,
6195 dev : "Ajax.org" ,
@@ -65,9 +99,20 @@ return ext.register("ext/code/code", {
6599
66100 nodes : [ ] ,
67101
68- getSyntax : function ( type ) {
69- var mime = type . split ( ";" ) [ 0 ] ;
70- return ( SupportedModes [ mime ] || "text" ) ;
102+ getSyntax : function ( node ) {
103+ if ( ! node ) return "" ;
104+ var customType = node . getAttribute ( "customtype" ) ;
105+ if ( ! customType )
106+ customType = contentTypes [ node . getAttribute ( "name" ) . split ( "." ) . pop ( ) ] ;
107+
108+ if ( customType ) {
109+ var mime = customType . split ( ";" ) [ 0 ] ;
110+
111+ return ( SupportedModes [ mime ] || "text" ) ;
112+ }
113+ else {
114+ return "text" ;
115+ }
71116 } ,
72117
73118 getSelection : function ( ) {
@@ -229,8 +274,13 @@ return ext.register("ext/code/code", {
229274
230275 mnuSyntax . onitemclick = function ( e ) {
231276 var file = ide . getActivePageModel ( ) ;
232- if ( file )
233- apf . xmldb . setAttribute ( file , "contenttype" , e . relatedNode . value ) ;
277+ if ( file ) {
278+ var value = e . relatedNode . value ;
279+ if ( value == "auto" )
280+ apf . xmldb . removeAttribute ( file , "customtype" , "" ) ;
281+ else
282+ apf . xmldb . setAttribute ( file , "customtype" , value ) ;
283+ }
234284 } ;
235285
236286 /*ide.addEventListener("clearfilecache", function(e){
@@ -277,4 +327,4 @@ return ext.register("ext/code/code", {
277327 }
278328} ) ;
279329
280- } ) ;
330+ } ) ;
0 commit comments