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