@@ -25,7 +25,6 @@ import * as commonStorage from '../storage/common_storage';
2525import * as I18Next from "react-i18next" ;
2626import * as NewProjectNameModal from './NewProjectNameModal' ;
2727import * as NewModuleNameModal from './NewModuleNameModal' ;
28- import * as editor from '../editor/editor' ;
2928import type { MessageInstance } from 'antd/es/message/interface' ;
3029
3130import {
@@ -39,10 +38,10 @@ interface ModuleOutlineProps {
3938 initializeShownPythonToolboxCategories : ( ) => void ;
4039 storage : commonStorage . Storage | null ;
4140 messageApi : MessageInstance ;
42- blocksEditor : editor . Editor | null ;
4341 currentModule : commonStorage . Module | null ;
4442 setCurrentModule : ( module : commonStorage . Module | null ) => void ;
4543 saveBlocks : ( ) => Promise < boolean > ;
44+ areBlocksModified : ( ) => boolean ;
4645}
4746
4847export default function ModuleOutline ( props : ModuleOutlineProps ) {
@@ -259,32 +258,30 @@ export default function ModuleOutline(props: ModuleOutlineProps) {
259258 } ;
260259
261260 const checkIfBlocksWereModified = ( callback : ( ) => void ) => {
262- if ( props . blocksEditor ) {
263- if ( ! currentModulePath ) {
261+ if ( ! currentModulePath ) {
262+ callback ( ) ;
263+ return ;
264+ }
265+ if ( ! props . areBlocksModified ( ) ) {
266+ callback ( ) ;
267+ return ;
268+ }
269+
270+ // Show a bubble confirmation box to ask the user if they want to save the blocks.
271+ setPopconfirmTitle ( 'Blocks have been modified!' ) ;
272+ setPopconfirmDescription ( 'Press ok to save and continue' ) ;
273+ // Set the function to be executed if the user clicks 'ok'.
274+ afterPopconfirmOk . current = async ( ) => {
275+ setPopconfirmLoading ( true ) ;
276+ const success = await props . saveBlocks ( ) ;
277+ setOpenPopconfirm ( false ) ;
278+ setPopconfirmLoading ( false ) ;
279+ if ( success ) {
264280 callback ( ) ;
265- return ;
266281 }
267- if ( ! props . blocksEditor . isModified ( ) ) {
268- callback ( ) ;
269- return ;
270- }
271-
272- // Show a bubble confirmation box to ask the user if they want to save the blocks.
273- setPopconfirmTitle ( 'Blocks have been modified!' ) ;
274- setPopconfirmDescription ( 'Press ok to save and continue' ) ;
275- // Set the function to be executed if the user clicks 'ok'.
276- afterPopconfirmOk . current = async ( ) => {
277- setPopconfirmLoading ( true ) ;
278- const success = await props . saveBlocks ( ) ;
279- setOpenPopconfirm ( false ) ;
280- setPopconfirmLoading ( false ) ;
281- if ( success ) {
282- callback ( ) ;
283- }
284- } ;
285- setOpenPopconfirm ( true ) ;
286- }
287- } ;
282+ } ;
283+ setOpenPopconfirm ( true ) ;
284+ }
288285
289286 const handleNewModuleNameOk = async ( newModuleClassName : string ) => {
290287 if ( ! props . storage || ! props . currentModule ) {
0 commit comments