@@ -6,7 +6,7 @@ import Adw from "gi://Adw";
66import Vte from "gi://Vte" ;
77
88import * as xml from "./langs/xml/xml.js" ;
9- import { buildRuntimePath , languages } from "./util.js" ;
9+ import { buildRuntimePath , languages , quitOnLastWindowClose } from "./util.js" ;
1010import Document from "./Document.js" ;
1111import PanelUI from "./PanelUI.js" ;
1212import PanelCode from "./PanelCode.js" ;
@@ -508,18 +508,34 @@ async function setGtk4PreferDark(dark) {
508508 settings . save_to_file ( settings_path ) ;
509509}
510510
511+ function close ( window ) {
512+ quitOnLastWindowClose ( window ) ;
513+ window . destroy ( ) ;
514+ }
515+
511516async function onCloseSession ( { session, window } ) {
512517 if ( session . isProject ( ) ) {
513- window . destroy ( ) ;
514- return ;
518+ return close ( window ) ;
515519 }
516520
517521 if ( ! session . settings . get_boolean ( "edited" ) ) {
518522 await deleteSession ( session ) ;
519- window . destroy ( ) ;
520- return ;
523+ return close ( window ) ;
521524 }
522525
526+ const [ response , location ] = await promptSessionClose ( { window } ) ;
527+ if ( response === "cancel" ) return ;
528+
529+ if ( response === "discard" ) {
530+ await deleteSession ( session ) ;
531+ } else if ( response === "save" ) {
532+ await saveSessionAsProject ( session , location ) ;
533+ }
534+
535+ close ( window ) ;
536+ }
537+
538+ async function promptSessionClose ( { window } ) {
523539 const builder = Gtk . Builder . new_from_resource ( resource ) ;
524540 const dialog = builder . get_object ( "message_dialog_save_project" ) ;
525541
@@ -561,16 +577,8 @@ async function onCloseSession({ session, window }) {
561577 }
562578
563579 const response = await dialog . choose ( null ) ;
564- if ( response === "cancel" ) return ;
565-
566- if ( response === "discard" ) {
567- await deleteSession ( session ) ;
568- } else if ( response === "save" ) {
569- const destination = location . get_child_for_display_name (
570- row_project_name . text ,
571- ) ;
572- await saveSessionAsProject ( session , destination ) ;
573- }
574-
575- window . destroy ( ) ;
580+ return [
581+ response ,
582+ location ?. get_child_for_display_name ( row_project_name . text ) ,
583+ ] ;
576584}
0 commit comments