From e89367d2ad0e194c547a4e84cac87b7a48b69600 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Fri, 4 Nov 2005 12:25:04 +0000 Subject: [PATCH] avoid losing work on CTRL-N --- helm/matita/matitaGui.ml | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/helm/matita/matitaGui.ml b/helm/matita/matitaGui.ml index d4157677f..589da7dcc 100644 --- a/helm/matita/matitaGui.ml +++ b/helm/matita/matitaGui.ml @@ -102,7 +102,7 @@ let ask_unsaved parent = MatitaGtkMisc.ask_confirmation ~parent ~title:"Unsaved work!" ~message:("Your work is unsaved!\n\n"^ - "Do you want to save the script before exiting?") + "Do you want to save the script before continuing?") () class gui () = @@ -605,34 +605,36 @@ class gui () = (s ())#saveToFile (); console#message ("'"^f^"' saved.\n"); in + let abandon_script () = + let status = (s ())#status in + if source_view#buffer#modified then + (match ask_unsaved main#toplevel with + | `YES -> saveScript () + | `NO -> () + | `CANCEL -> raise MatitaTypes.Cancel); + (match script_fname with + | None -> () + | Some fname -> ask_and_save_moo_if_needed main#toplevel fname status); + in let loadScript () = let script = s () in let status = script#status in try match self#chooseFile () with | Some f -> - if source_view#buffer#modified then - begin - match ask_unsaved main#toplevel with - | `YES -> saveScript () - | `NO -> () - | `CANCEL -> raise MatitaTypes.Cancel - end; - (match script_fname with - | None -> () - | Some fname -> - ask_and_save_moo_if_needed main#toplevel fname status); - script#reset (); - script#assignFileName f; - source_view#source_buffer#begin_not_undoable_action (); - script#loadFromFile f; - source_view#source_buffer#end_not_undoable_action (); - console#message ("'"^f^"' loaded.\n"); - self#_enableSaveTo f + abandon_script (); + script#reset (); + script#assignFileName f; + source_view#source_buffer#begin_not_undoable_action (); + script#loadFromFile f; + source_view#source_buffer#end_not_undoable_action (); + console#message ("'"^f^"' loaded.\n"); + self#_enableSaveTo f | None -> () with MatitaTypes.Cancel -> () in let newScript () = + abandon_script (); source_view#source_buffer#begin_not_undoable_action (); (s ())#reset (); (s ())#template (); -- 2.39.2