@@ -270,6 +270,64 @@ define(function (require, exports, module) {
270270 } ) ;
271271 }
272272
273+ /**
274+ *
275+ * @param file FileSystem.getFileForPath object
276+ * @param options
277+ * @private
278+ */
279+ function _loadThemeFromFile ( file , options ) {
280+ var currentThemeName = prefs . get ( "theme" ) ;
281+ var theme = new Theme ( file , options ) ;
282+ loadedThemes [ theme . name ] = theme ;
283+ ThemeSettings . _setThemes ( loadedThemes ) ;
284+
285+ // For themes that are loaded after ThemeManager has been loaded,
286+ // we should check if it's the current theme. If it is, then we just
287+ // load it.
288+ if ( currentThemeName === theme . name ) {
289+ refresh ( true ) ;
290+ }
291+ }
292+
293+ /**
294+ * Loads a theme from a url.
295+ *
296+ * @param {string } url is the full hhtp/https url of the theme file
297+ * @param {Object } options is an optional parameter to specify metadata
298+ * for the theme.
299+ * @return {$.Promise } promise object resolved with the theme to be loaded from fileName
300+ */
301+ function _loadFileFromURL ( url , options ) {
302+ var deferred = new $ . Deferred ( ) ;
303+
304+ var themeName = options . name || options . theme . title ;
305+ var fileName = options . theme . file ;
306+ var themePath = path . normalize ( brackets . app . getApplicationSupportDirectory ( ) + "/extensions/user/" +
307+ themeName + '_' + fileName ) ;
308+ var file = FileSystem . getFileForPath ( themePath ) ;
309+
310+ file . exists ( function ( err , exists ) {
311+ var theme ;
312+
313+ if ( exists ) {
314+ _loadThemeFromFile ( file , options ) ;
315+ deferred . resolve ( theme ) ;
316+ return ;
317+ }
318+ $ . get ( url ) . done ( function ( themeContent ) {
319+ // Write theme to file
320+ FileUtils . writeText ( file , themeContent ) . then ( function ( ) {
321+ _loadThemeFromFile ( file , options ) ;
322+ deferred . resolve ( theme ) ;
323+ } , deferred . reject ) ;
324+ } ) . fail ( function ( err ) {
325+ deferred . reject ( err ) ;
326+ } ) ;
327+ } ) ;
328+
329+ return deferred . promise ( ) ;
330+ }
273331
274332 /**
275333 * Loads a theme from a file.
@@ -280,6 +338,10 @@ define(function (require, exports, module) {
280338 * @return {$.Promise } promise object resolved with the theme to be loaded from fileName
281339 */
282340 function loadFile ( fileName , options ) {
341+ if ( fileName . startsWith ( "http://" ) || fileName . startsWith ( "https://" ) ) {
342+ return _loadFileFromURL ( fileName , options ) ;
343+ }
344+
283345 var deferred = new $ . Deferred ( ) ,
284346 file = FileSystem . getFileForPath ( fileName ) ,
285347 currentThemeName = prefs . get ( "theme" ) ;
0 commit comments