Bug 369346, Bug 372139 - supports import of eclipsecolorthemes.org xml
diff --git a/bundles/org.eclipse.orion.client.core/web/orion/widgets/settings/SettingsContainer.js b/bundles/org.eclipse.orion.client.core/web/orion/widgets/settings/SettingsContainer.js
index 7898c7c..e41d2ed 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/widgets/settings/SettingsContainer.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/widgets/settings/SettingsContainer.js
@@ -175,6 +175,10 @@
 		

 			this.editorThemeWidget = new mThemeBuilder.ThemeBuilder({ commandService: this.commandService, preferences: this.preferences, themeData: editorTheme });

 			

+			var command = { name:'Import', tip:'Import a theme', id:0, callback: dojo.hitch( editorTheme, 'importTheme' ) };

+			

+			this.editorThemeWidget.addAdditionalCommand( command );

+			

 			dojo.empty(this.table);

 

 			var themeNode = dojo.create( 'div', null, this.table );

diff --git a/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/ThemeBuilder.js b/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/ThemeBuilder.js
index 3b77546..36bc3ce 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/ThemeBuilder.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/ThemeBuilder.js
@@ -169,7 +169,7 @@
 														'<span>OR HEX: </span>' + 

 														'<div id="colorstring"></div>' +

 														'<button style="margin-left:5px;height:17px;margin-top:0;" type="button" id="colorButton"}">ok</button>' + 

-													'</div>' +

+												'</div>' +

 											'</div>';

 		

 		var colornames = [["white", "seashell", "cornsilk", "lemonchiffon","lightyellow", "palegreen", "paleturquoise", "aliceblue", "lavender", "plum"],

@@ -210,9 +210,30 @@
 			} );

 		}

 		

-		

 		ThemeBuilder.prototype.initializeStorage = initializeStorage;

 		

+		function addAdditionalCommand( commandData ){

+		

+			var commitMessageParameters = new mCommands.ParametersDescription(

+			[new mCommands.CommandParameter('name', 'text', messages['Commit message:'], "", 4)], //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-1$ //$NON-NLS-0$

+			 {hasOptionalParameters: true});

+		

+			var command = new mCommands.Command({

+				name: commandData.name,

+				tooltip: commandData.tip,

+				parameters: commitMessageParameters,

+				id: commandData.id, //$NON-NLS-0$

+				callback: dojo.hitch(this, function(data){

+					commandData.callback(data);

+				})

+			});

+			

+			this.commandService.addCommand(command);

+			this.commandService.registerCommandContribution('themeCommands', commandData.id, 4); //$NON-NLS-1$ //$NON-NLS-0$

+		}

+		

+		ThemeBuilder.prototype.addAdditionalCommand = addAdditionalCommand;

+		

 		function validateHex(hexcode){

 		

 		     var regColorcode = /^(#)?([0-9a-fA-F]{3})([0-9a-fA-F]{3})?$/;

diff --git a/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/editor/ThemeData.js b/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/editor/ThemeData.js
index 3979182..41d24c8 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/editor/ThemeData.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/widgets/themes/editor/ThemeData.js
@@ -8,7 +8,7 @@
  * 

  * Contributors: Anton McConville - IBM Corporation - initial API and implementation

  ******************************************************************************/

-/*global dojo dijit widgets orion  window console define localStorage*/

+/*global dojo dijit widgets orion  window console define localStorage ActiveXObject DOMParser*/

 /*jslint browser:true*/

 

 define(['i18n!orion/settings/nls/messages', 'require', 'dojo', 'dijit', 'orion/util', 'orion/commands', 'orion/globalCommands', 'orion/PageUtil'], 

@@ -218,18 +218,80 @@
 			return dataset;

 		}

 		

+		function parseToXML ( text ) {

+		      try {

+		        var xml = null;

+		        

+		        if ( window.DOMParser ) {

+		

+		          var parser = new DOMParser();

+		          xml = parser.parseFromString( text, "text/xml" );

+		          

+		          var found = xml.getElementsByTagName( "parsererror" );

+		

+		          if ( !found || !found.length || !found[ 0 ].childNodes.length ) {

+		            return xml;

+		          }

+		

+		          return null;

+		        } else {

+		

+		          xml = new ActiveXObject( "Microsoft.XMLDOM" );

+		

+		          xml.async = false;

+		          xml.loadXML( text );

+		

+		          return xml;

+		        }

+		      } catch ( e ) {

+		        // suppress

+		      }

+		 }

+		 

+		ThemeData.prototype.parseToXML = parseToXML;

+		

+		function importTheme(data){

+			console.log( 'import theme' );

+			console.log( data );

+			

+			var body = data.parameters.valueFor("name");

+				

+			var xml = this.parseToXML( body );

+			

+			var newStyle = new StyleSet();

+			

+			newStyle.name = xml.getElementsByTagName("colorTheme")[0].attributes[1].value;;

+			newStyle.annotationRuler = xml.getElementsByTagName("background")[0].attributes[0].value; 

+			newStyle.background = xml.getElementsByTagName("background")[0].attributes[0].value;

+			newStyle.comment = xml.getElementsByTagName("singleLineComment")[0].attributes[0].value;

+			newStyle.keyword = xml.getElementsByTagName("keyword")[0].attributes[0].value;

+			newStyle.text = xml.getElementsByTagName("foreground")[0].attributes[0].value;

+			newStyle.string = xml.getElementsByTagName("string")[0].attributes[0].value;

+			newStyle.overviewRuler = xml.getElementsByTagName("background")[0].attributes[0].value;

+			newStyle.lineNumberOdd = xml.getElementsByTagName("lineNumber")[0].attributes[0].value;

+			newStyle.lineNumberEven = xml.getElementsByTagName("lineNumber")[0].attributes[0].value;

+			newStyle.lineNumber = xml.getElementsByTagName("lineNumber")[0].attributes[0].value;

+			newStyle.currentLine = xml.getElementsByTagName("selectionBackground")[0].attributes[0].value;

+			

+			data.items.styles.push( newStyle );

+			data.items.updateThemePicker( newStyle.name );

+			data.items.select( newStyle.name );

+		}

+		

+		ThemeData.prototype.importTheme = importTheme;

 		

 		function processSettings( settings, preferences ){

 		

 			console.log( settings );

 		

 			preferences.getPreferences('/settings', 2).then(function(prefs){ //$NON-NLS-0$

-

-				var subcategories = [];

 				

 				var font = {};		

 				font.label = 'Font';

-				font.data = [ { label:'Family', value: 'Sans Serif', ui:'Font' }, { label:'Size', value: '9pt', ui:'Font' }, { label:'Color', value: settings['text'].value }, { label:'Background', value: settings['background'].value } ];

+				font.data = [ { label:'Family', value: 'Sans Serif', ui:'Font' }, 

+							{ label:'Size', value: '9pt', ui:'Font' }, 

+							{ label:'Color', value: settings['text'].value }, 

+							{ label:'Background', value: settings['background'].value } ];

 				

 				var subcategories = [ { element: 'fontFamily', value: 'sans serif' },

 							          { element: 'fontSize', value: '9pt' },