2222 */
2323
2424/*jslint regexp: true */
25- /*global less, path */
25+ /*global less, path, Phoenix */
2626
2727define ( function ( require , exports , module ) {
2828
@@ -36,6 +36,7 @@ define(function (require, exports, module) {
3636 ThemeSettings = require ( "view/ThemeSettings" ) ,
3737 ThemeView = require ( "view/ThemeView" ) ,
3838 PreferencesManager = require ( "preferences/PreferencesManager" ) ,
39+ UrlParams = require ( "utils/UrlParams" ) . UrlParams ,
3940 prefs = PreferencesManager . getExtensionPrefs ( "themes" ) ;
4041
4142 let loadedThemes = { } ,
@@ -192,6 +193,32 @@ define(function (require, exports, module) {
192193 }
193194
194195
196+ /**
197+ * Extension developers can load their custom themes using debug menu> load project as extension. in this case
198+ * a query strin param will ge specified with the dev extension path. we will always load that theme as default
199+ * as th user intent would be to develop the theme in that case.
200+ * @return {null|* }
201+ * @private
202+ */
203+ function _getCurrentlyLoadedDevTheme ( ) {
204+ const params = new UrlParams ( ) ;
205+ params . parse ( ) ;
206+ let devThemePaths = params . get ( "loadDevExtensionPath" ) ;
207+ if ( ! devThemePaths ) {
208+ return null ;
209+ }
210+ devThemePaths = devThemePaths . split ( "," ) ; // paths are a comma seperated list
211+ for ( let themeID of Object . keys ( loadedThemes ) ) {
212+ let themeFilePath = loadedThemes [ themeID ] . file . fullPath ;
213+ for ( let devThemePath of devThemePaths ) {
214+ if ( themeFilePath . startsWith ( devThemePath ) ) {
215+ return loadedThemes [ themeID ] ;
216+ }
217+ }
218+ }
219+ return null ;
220+ }
221+
195222 /**
196223 * Get current theme object that is loaded in the editor.
197224 *
@@ -201,6 +228,11 @@ define(function (require, exports, module) {
201228 let defaultTheme = isOSInDarkTheme ( ) ?
202229 ThemeSettings . DEFAULTS . darkTheme :
203230 ThemeSettings . DEFAULTS . lightTheme ;
231+ // check if a dev theme is loaded via query string parameter. If so that will be the current theme.
232+ let devTheme = _getCurrentlyLoadedDevTheme ( ) ;
233+ if ( devTheme ) {
234+ return devTheme ;
235+ }
204236 if ( ! currentTheme ) {
205237 currentTheme = loadedThemes [ prefs . get ( "theme" ) ] || loadedThemes [ defaultTheme ] ;
206238 }
@@ -220,6 +252,15 @@ define(function (require, exports, module) {
220252 }
221253
222254
255+ async function _applyThemeCSS ( lessContent , theme ) {
256+ const content = await window . jsPromise ( lessifyTheme ( lessContent . replace ( commentRegex , "" ) , theme ) ) ;
257+ const result = extractScrollbars ( content ) ;
258+ theme . scrollbar = result . scrollbar ;
259+ const cssContent = result . content ;
260+ $ ( "body" ) . toggleClass ( "dark" , theme . dark ) ;
261+ styleNode . text ( cssContent ) ;
262+ }
263+
223264 /**
224265 * @private
225266 * Process and load the current theme into the editor
@@ -232,17 +273,10 @@ define(function (require, exports, module) {
232273
233274 var pending = theme && FileUtils . readAsText ( theme . file )
234275 . then ( function ( lessContent ) {
235- return lessifyTheme ( lessContent . replace ( commentRegex , "" ) , theme ) ;
236- } )
237- . then ( function ( content ) {
238- var result = extractScrollbars ( content ) ;
239- theme . scrollbar = result . scrollbar ;
240- return result . content ;
241- } )
242- . then ( function ( cssContent ) {
243- $ ( "body" ) . toggleClass ( "dark" , theme . dark ) ;
244- styleNode . text ( cssContent ) ;
245- return theme ;
276+ const deferred = new $ . Deferred ( ) ;
277+ _applyThemeCSS ( lessContent , theme )
278+ . then ( deferred . resolve )
279+ . catch ( deferred . reject ) ;
246280 } ) ;
247281
248282 return $ . when ( pending ) ;
@@ -385,7 +419,11 @@ define(function (require, exports, module) {
385419 */
386420 function loadFile ( fileName , options ) {
387421 if ( fileName . startsWith ( "http://" ) || fileName . startsWith ( "https://" ) ) {
388- return _loadFileFromURL ( fileName , options ) ;
422+ if ( Phoenix . VFS . getPathForVirtualServingURL ( fileName ) ) {
423+ fileName = Phoenix . VFS . getPathForVirtualServingURL ( fileName ) ;
424+ } else {
425+ return _loadFileFromURL ( fileName , options ) ;
426+ }
389427 }
390428
391429 var deferred = new $ . Deferred ( ) ,
@@ -440,7 +478,7 @@ define(function (require, exports, module) {
440478 // listen to system dark/light theme changes
441479 console . log ( `System theme changed to ${ e . matches ? "dark" : "light" } mode` ) ;
442480 refresh ( true ) ;
443-
481+
444482 // Report os preference change also as a theme change
445483 exports . trigger ( EVENT_THEME_CHANGE , getCurrentTheme ( ) ) ;
446484 } ) ;
0 commit comments