@@ -40,6 +40,7 @@ define(function main(require, exports, module) {
4040 Commands = require ( "command/Commands" ) ,
4141 AppInit = require ( "utils/AppInit" ) ,
4242 LiveDevelopment = require ( "LiveDevelopment/LiveDevelopment" ) ,
43+ MultiBrowserLiveDev = require ( "LiveDevelopment/LiveDevMultiBrowser" ) ,
4344 Inspector = require ( "LiveDevelopment/Inspector/Inspector" ) ,
4445 CommandManager = require ( "command/CommandManager" ) ,
4546 PreferencesManager = require ( "preferences/PreferencesManager" ) ,
@@ -50,9 +51,6 @@ define(function main(require, exports, module) {
5051 ExtensionUtils = require ( "utils/ExtensionUtils" ) ,
5152 StringUtils = require ( "utils/StringUtils" ) ;
5253
53- // expermiental multi-browser implementation
54- var MultiBrowserLiveDev = require ( "LiveDevelopment/LiveDevMultiBrowser" ) ;
55-
5654 var params = new UrlParams ( ) ;
5755 var config = {
5856 experimental : false , // enable experimental features
@@ -75,7 +73,41 @@ define(function main(require, exports, module) {
7573
7674 // current selected implementation (LiveDevelopment | LiveDevMultiBrowser)
7775 var LiveDevImpl ;
76+
77+ // "livedev.multibrowser" preference
78+ var PREF_MULTIBROWSER = "multibrowser" ;
79+ var prefs = PreferencesManager . getExtensionPrefs ( "livedev" ) ;
80+ var multiBrowserPref = prefs . definePreference ( PREF_MULTIBROWSER , "boolean" , false ) ;
81+
82+ /** Toggles or sets the preference **/
83+ function _togglePref ( key , value ) {
84+ var val ,
85+ oldPref = ! ! prefs . get ( key ) ;
7886
87+ if ( value === undefined ) {
88+ val = ! oldPref ;
89+ } else {
90+ val = ! ! value ;
91+ }
92+
93+ // update menu
94+ if ( val !== oldPref ) {
95+ prefs . set ( key , val ) ;
96+ }
97+
98+ return val ;
99+ }
100+
101+ /* Toggles or sets the "livedev.multibrowser" preference */
102+ function _toggleLivePreviewMultiBrowser ( value ) {
103+ var val = _togglePref ( PREF_MULTIBROWSER , value ) ;
104+
105+ CommandManager . get ( Commands . TOGGLE_LIVE_PREVIEW_MB_MODE ) . setChecked ( val ) ;
106+ // Issue #10217: multi-browser does not support user server, so disable
107+ // the setting if it is enabled.
108+ CommandManager . get ( Commands . FILE_PROJECT_SETTINGS ) . setEnabled ( ! val ) ;
109+ }
110+
79111 /** Load Live Development LESS Style */
80112 function _loadStyles ( ) {
81113 var lessText = require ( "text!LiveDevelopment/main.less" ) ,
@@ -215,10 +247,11 @@ define(function main(require, exports, module) {
215247 PreferencesManager . setViewState ( "livedev.highlight" , config . highlight ) ;
216248 }
217249
218- // sets the MultiBrowserLiveDev implementation if multibrowser = true,
219- // keeps default LiveDevelopment implementation based on CDT in other case.
220- // since UI status are slightly different btw implementations, it also set
221- // the corresponding style values.
250+ /**
251+ * Sets the MultiBrowserLiveDev implementation if multibrowser is truthy,
252+ * keeps default LiveDevelopment implementation based on CDT otherwise.
253+ * It also resets the listeners and UI elements.
254+ */
222255 function _setImplementation ( multibrowser ) {
223256 if ( multibrowser ) {
224257 // set implemenation
@@ -246,6 +279,11 @@ define(function main(require, exports, module) {
246279 { tooltip : Strings . LIVE_DEV_STATUS_TIP_SYNC_ERROR , style : "sync-error" }
247280 ] ;
248281 }
282+ // setup status changes listeners for new implementation
283+ _setupGoLiveButton ( ) ;
284+ _setupGoLiveMenu ( ) ;
285+ // toggle the menu
286+ _toggleLivePreviewMultiBrowser ( multibrowser ) ;
249287 }
250288
251289 /** Setup window references to useful LiveDevelopment modules */
@@ -261,7 +299,7 @@ define(function main(require, exports, module) {
261299 LiveDevelopment . reload ( ) ;
262300 }
263301 }
264-
302+
265303 /** Initialize LiveDevelopment */
266304 AppInit . appReady ( function ( ) {
267305 params . parse ( ) ;
@@ -274,13 +312,12 @@ define(function main(require, exports, module) {
274312 // It has to be initiated at this point in case of dynamically switching
275313 // by changing the preference value.
276314 MultiBrowserLiveDev . init ( config ) ;
277-
278- _loadStyles ( ) ;
279- _setupGoLiveButton ( ) ;
280- _setupGoLiveMenu ( ) ;
281315
316+ _loadStyles ( ) ;
282317 _updateHighlightCheckmark ( ) ;
283318
319+ _setImplementation ( prefs . get ( PREF_MULTIBROWSER ) ) ;
320+
284321 if ( config . debug ) {
285322 _setupDebugHelpers ( ) ;
286323 }
@@ -299,6 +336,25 @@ define(function main(require, exports, module) {
299336 LiveDevelopment . redrawHighlight ( ) ;
300337 }
301338 } ) ;
339+
340+ multiBrowserPref
341+ . on ( "change" , function ( ) {
342+ // Stop the current session if it is open and set implementation based on
343+ // the pref value. We could start the new implementation immediately, but
344+ // since the current document is potentially a user preferences file, Live
345+ // Preview will not locate the html file to serve.
346+ if ( LiveDevImpl && LiveDevImpl . status >= LiveDevImpl . STATUS_ACTIVE ) {
347+ LiveDevImpl . close ( )
348+ . done ( function ( ) {
349+ // status changes will now be listened by the new implementation
350+ LiveDevImpl . off ( "statusChange" ) ;
351+ _setImplementation ( prefs . get ( PREF_MULTIBROWSER ) ) ;
352+ } ) ;
353+ } else {
354+ _setImplementation ( prefs . get ( PREF_MULTIBROWSER ) ) ;
355+ }
356+ } ) ;
357+
302358 } ) ;
303359
304360 // init prefs
@@ -312,29 +368,15 @@ define(function main(require, exports, module) {
312368 "highlight" : "user livedev.highlight" ,
313369 "afterFirstLaunch" : "user livedev.afterFirstLaunch"
314370 } , true ) ;
315-
316- PreferencesManager . definePreference ( "livedev.multibrowser" , "boolean" , false )
317- . on ( "change" , function ( ) {
318- // stop the current session if it is open and set implementation based on
319- // the pref value. It could be automaticallty restarted but, since the preference file,
320- // is the document open in the editor, it will no launch a live document.
321- if ( LiveDevImpl && LiveDevImpl . status >= LiveDevImpl . STATUS_ACTIVE ) {
322- LiveDevImpl . close ( ) ;
323- // status changes will now be listen from the new implementation
324- LiveDevImpl . off ( 'statusChange' ) ;
325- }
326- _setImplementation ( PreferencesManager . get ( 'livedev.multibrowser' ) ) ;
327- // setup status changes listeners for new implementation
328- _setupGoLiveButton ( ) ;
329- _setupGoLiveMenu ( ) ;
330- } ) ;
331-
371+
332372 config . highlight = PreferencesManager . getViewState ( "livedev.highlight" ) ;
333373
334374 // init commands
335375 CommandManager . register ( Strings . CMD_LIVE_FILE_PREVIEW , Commands . FILE_LIVE_FILE_PREVIEW , _handleGoLiveCommand ) ;
336376 CommandManager . register ( Strings . CMD_LIVE_HIGHLIGHT , Commands . FILE_LIVE_HIGHLIGHT , _handlePreviewHighlightCommand ) ;
337377 CommandManager . register ( Strings . CMD_RELOAD_LIVE_PREVIEW , Commands . CMD_RELOAD_LIVE_PREVIEW , _handleReloadLivePreviewCommand ) ;
378+ CommandManager . register ( Strings . CMD_TOGGLE_LIVE_PREVIEW_MB_MODE , Commands . TOGGLE_LIVE_PREVIEW_MB_MODE , _toggleLivePreviewMultiBrowser ) ;
379+
338380 CommandManager . get ( Commands . FILE_LIVE_HIGHLIGHT ) . setEnabled ( false ) ;
339381
340382 // Export public functions
0 commit comments