@@ -1392,38 +1392,26 @@ class Activity {
13921392 * Switches between beginner/advanced mode
13931393 */
13941394 const doSwitchMode = ( activity ) => {
1395- activity . _doSwitchMode ( ) ;
1396- } ;
1397-
1398- /**
1399- * Switches between beginner and advanced modes.
1400- * Displays a message prompting browser refresh to apply mode change.
1401- * @private
1402- */
1403- this . _doSwitchMode = ( ) => {
1404- this . blocks . activeBlock = null ;
1405- const mode = this . storage . beginnerMode ;
1406-
1407- const MSGPrefix =
1408- "<a href='#' " +
1409- "onClick='window.location.reload()'" +
1410- "onMouseOver='this.style.opacity = 0.5'" +
1411- "onMouseOut='this.style.opacity = 1'>" ;
1412- const MSGSuffix = "</a>" ;
1413-
1414- if ( mode === null || mode === undefined || mode === "true" ) {
1415- this . textMsg (
1416- _ ( MSGPrefix + _ ( "Refresh your browser to change to advanced mode." ) + MSGSuffix )
1417- ) ;
1418- this . storage . setItem ( "beginnerMode" , false ) ;
1419- } else {
1420- this . textMsg (
1421- _ ( MSGPrefix + _ ( "Refresh your browser to change to beginner mode." ) + MSGSuffix )
1422- ) ;
1423- this . storage . setItem ( "beginnerMode" , true ) ;
1395+ // Update toolbar
1396+ activity . toolbar . renderSaveIcons (
1397+ activity . save . saveHTML . bind ( activity . save ) ,
1398+ doSVG ,
1399+ activity . save . saveSVG . bind ( activity . save ) ,
1400+ activity . save . savePNG . bind ( activity . save ) ,
1401+ activity . save . saveWAV . bind ( activity . save ) ,
1402+ activity . save . saveLilypond . bind ( activity . save ) ,
1403+ activity . save . saveAbc . bind ( activity . save ) ,
1404+ activity . save . saveMxml . bind ( activity . save ) ,
1405+ activity . save . saveBlockArtwork . bind ( activity . save )
1406+ ) ;
1407+
1408+ // Regenerate palettes
1409+ if ( activity . regeneratePalettes ) {
1410+ activity . regeneratePalettes ( ) ;
14241411 }
1425-
1426- this . refreshCanvas ( ) ;
1412+
1413+ // Force immediate canvas refresh
1414+ activity . refreshCanvas ( ) ;
14271415 } ;
14281416
14291417 /*
@@ -6401,12 +6389,9 @@ class Activity {
64016389 this . toolbar . renderPlanetIcon ( this . planet , doOpenSamples ) ;
64026390 this . toolbar . renderMenuIcon ( showHideAuxMenu ) ;
64036391 this . toolbar . renderHelpIcon ( showHelp ) ;
6404- this . toolbar . renderModeSelectIcon ( doSwitchMode ) ;
6392+ this . toolbar . renderModeSelectIcon ( doSwitchMode , doRecordButton , doAnalytics , doOpenPlugin , deletePlugin , setScroller ) ;
64056393 this . toolbar . renderRunSlowlyIcon ( doSlowButton ) ;
64066394 this . toolbar . renderRunStepIcon ( doStepButton ) ;
6407- this . toolbar . renderAdvancedIcons (
6408- doRecordButton , doAnalytics , doOpenPlugin , deletePlugin , setScroller
6409- ) ;
64106395 this . toolbar . renderMergeIcon ( _doMergeLoad ) ;
64116396 this . toolbar . renderRestoreIcon ( restoreTrash ) ;
64126397 if ( _THIS_IS_MUSIC_BLOCKS_ ) {
@@ -6962,6 +6947,105 @@ class Activity {
69626947 }
69636948 } ;
69646949 }
6950+
6951+ /**
6952+ * Saves the current state locally
6953+ * @returns {void }
6954+ */
6955+ saveLocally ( ) {
6956+ try {
6957+ localStorage . setItem ( 'beginnerMode' , this . beginnerMode . toString ( ) ) ;
6958+ } catch ( e ) {
6959+ console . error ( 'Error saving to localStorage:' , e ) ;
6960+ }
6961+ }
6962+
6963+ /**
6964+ * Regenerates all palettes based on current mode
6965+ * @returns {void }
6966+ */
6967+ regeneratePalettes ( ) {
6968+ try {
6969+ // Store current palette positions
6970+ const palettePositions = { } ;
6971+ if ( this . palettes && this . palettes . dict ) {
6972+ for ( const name in this . palettes . dict ) {
6973+ const palette = this . palettes . dict [ name ] ;
6974+ if ( palette && palette . container && typeof palette . container . x !== 'undefined' ) {
6975+ palettePositions [ name ] = {
6976+ x : palette . container . x ,
6977+ y : palette . container . y ,
6978+ visible : ! ! palette . visible
6979+ } ;
6980+ }
6981+ }
6982+ }
6983+
6984+ // Safely hide and clear existing palettes
6985+ if ( ! this . palettes ) {
6986+ console . warn ( 'Palettes object not initialized' ) ;
6987+ return ;
6988+ }
6989+
6990+ if ( typeof this . palettes . hide !== 'function' ) {
6991+ console . warn ( 'Palettes hide method not available' ) ;
6992+ } else {
6993+ this . palettes . hide ( ) ;
6994+ }
6995+
6996+ if ( typeof this . palettes . clear !== 'function' ) {
6997+ console . warn ( 'Palettes clear method not available' ) ;
6998+ // Fallback clear implementation
6999+ this . palettes . dict = { } ;
7000+ this . palettes . visible = false ;
7001+ this . palettes . activePalette = null ;
7002+ this . palettes . paletteObject = null ;
7003+ } else {
7004+ this . palettes . clear ( ) ;
7005+ }
7006+
7007+ // Reinitialize palettes
7008+ initPalettes ( this . palettes ) ;
7009+
7010+ // Reinitialize blocks
7011+ if ( this . blocks ) {
7012+ initBasicProtoBlocks ( this ) ;
7013+ }
7014+
7015+ // Restore palette positions
7016+ if ( this . palettes && this . palettes . dict ) {
7017+ for ( const name in palettePositions ) {
7018+ const palette = this . palettes . dict [ name ] ;
7019+ const pos = palettePositions [ name ] ;
7020+
7021+ if ( palette && palette . container && pos ) {
7022+ palette . container . x = pos . x ;
7023+ palette . container . y = pos . y ;
7024+
7025+ if ( pos . visible ) {
7026+ palette . showMenu ( true ) ;
7027+ }
7028+ }
7029+ }
7030+ }
7031+
7032+ // Update the palette display
7033+ if ( this . palettes && typeof this . palettes . updatePalettes === 'function' ) {
7034+ this . palettes . updatePalettes ( ) ;
7035+ }
7036+
7037+ // Update blocks
7038+ if ( this . blocks && typeof this . blocks . updateBlockPositions === 'function' ) {
7039+ this . blocks . updateBlockPositions ( ) ;
7040+ }
7041+
7042+ this . refreshCanvas ( ) ;
7043+
7044+ } catch ( e ) {
7045+ console . error ( 'Error regenerating palettes:' , e ) ;
7046+ this . errorMsg ( _ ( 'Error regenerating palettes. Please refresh the page.' ) ) ;
7047+ }
7048+ }
69657049}
69667050
69677051const activity = new Activity ( ) ;
0 commit comments