Commit 23db7761 authored by MARCHE Claude's avatar MARCHE Claude

detection whether session needs saving handled by the ITP server

fixes issue #147
parent dfa5a323
......@@ -559,6 +559,8 @@ let interpNotif (n: notification) =
TaskList.remove_node (string_of_int nid)
| Saved ->
PE.error_print_msg "Saved"
| Saving_needed _b ->
PE.error_print_msg "Saving_needed"
| Message m ->
begin
match m with
......
......@@ -102,16 +102,9 @@ module Protocol_why3ide = struct
end
(* True when session differs from the saved session *)
let session_needs_saving = ref false
let get_notified = Protocol_why3ide.get_notified
let send_request r =
(* If request changes the session then session needs saving *)
if modify_session r then
session_needs_saving := true;
Protocol_why3ide.send_request r
let send_request r = Protocol_why3ide.send_request r
(****************************************)
(* server instance on the GTK scheduler *)
......@@ -329,7 +322,10 @@ let files_need_saving () =
(* Ask if the user wants to save session before exit. Exit is then delayed until
the [Saved] notification is received *)
let exit_function_safe () =
if not !session_needs_saving && not (files_need_saving ()) then
send_request Check_need_saving_req
let exit_function_handler b =
if not b && not (files_need_saving ()) then
exit_function_unsafe ()
else
let answer =
......@@ -2412,11 +2408,11 @@ let treat_notification n =
complete_context_menu ();
Opt.iter select_iter goals_model#get_iter_first
| Saved ->
session_needs_saving := false;
print_message ~kind:1 ~notif_kind:"Saved action info"
"Session saved.";
if !quit_on_saved = true then
exit_function_safe ()
| Saving_needed b -> exit_function_handler b
| Message (msg) -> treat_message_notification msg
| Task (id, s, list_loc) ->
if is_selected_alone id then
......
......@@ -89,6 +89,8 @@ type notification =
next unproven node from this node *)
| Initialized of global_information
(* initial global data *)
| Saving_needed of bool
(* the session needs saving when argument is true *)
| Saved
(* the session was saved on disk *)
| Message of message_notification
......@@ -118,21 +120,11 @@ type ide_request =
| Unfocus_req
| Save_req
| Reload_req
| Check_need_saving_req
| Exit_req
| Interrupt_req
| Get_global_infos
(* Return true if the request modify the session *)
let modify_session (r: ide_request) =
match r with
| Command_req _ | Add_file_req _ | Remove_subtree _ | Copy_paste _
| Reload_req -> true
| Set_config_param _ | Set_prover_policy _ | Get_file_contents _
| Get_task _ | Save_file_req _ | Get_first_unproven_node _
| Unfocus_req | Save_req | Exit_req | Get_global_infos
| Interrupt_req -> false
(* Debugging functions *)
......@@ -155,6 +147,7 @@ let print_request fmt r =
| Unfocus_req -> fprintf fmt "unfocus"
| Save_req -> fprintf fmt "save"
| Reload_req -> fprintf fmt "reload"
| Check_need_saving_req -> fprintf fmt "check need saving"
| Exit_req -> fprintf fmt "exit"
| Interrupt_req -> fprintf fmt "interrupt"
| Get_global_infos -> fprintf fmt "get_global_infos"
......@@ -201,6 +194,7 @@ let print_notify fmt n =
| Remove _ni -> fprintf fmt "remove"
| Next_Unproven_Node_Id (ni, nj) -> fprintf fmt "next unproven node_id from %d is %d" ni nj
| Initialized _gi -> fprintf fmt "initialized"
| Saving_needed b -> fprintf fmt "saving needed=%b" b
| Saved -> fprintf fmt "saved"
| Message msg ->
print_msg fmt msg
......
......@@ -99,8 +99,10 @@ type notification =
next unproven node from this node *)
| Initialized of global_information
(** initial global data *)
| Saving_needed of bool
(** the session needs saving when argument is true *)
| Saved
(** the session was saved on disk *)
(** the session was just saved on disk *)
| Message of message_notification
(** an informative message, can be an error message *)
| Dead of string
......@@ -136,13 +138,11 @@ type ide_request =
| Unfocus_req
| Save_req
| Reload_req
| Check_need_saving_req
| Exit_req
| Interrupt_req
| Get_global_infos
(* Return true if the request modify the session *)
val modify_session: ide_request -> bool
val print_request: Format.formatter -> ide_request -> unit
val print_msg: Format.formatter -> message_notification -> unit
......
This diff is collapsed.
......@@ -137,6 +137,7 @@ let convert_notification_constructor n =
| Next_Unproven_Node_Id (_, _) -> String "Next_Unproven_Node_Id"
| Initialized _ -> String "Initialized"
| Saved -> String "Saved"
| Saving_needed _ -> String "Saving_needed"
| Message _ -> String "Message"
| Dead _ -> String "Dead"
| Task _ -> String "Task"
......@@ -169,6 +170,7 @@ let convert_request_constructor (r: ide_request) =
| Get_first_unproven_node _ -> String "Get_first_unproven_node"
| Unfocus_req -> String "Unfocus_req"
| Save_req -> String "Save_req"
| Check_need_saving_req -> String "Check_need_saving_req"
| Reload_req -> String "Reload_req"
| Exit_req -> String "Exit_req"
| Interrupt_req -> String "Interrupt_req"
......@@ -220,7 +222,8 @@ let print_request_to_json (r: ide_request): Json_base.json =
"node_ID2", Int to_id]
| Get_first_unproven_node id ->
convert_record ["ide_request", cc r;
"node_ID", Int id]
"node_ID", Int id]
| Check_need_saving_req
| Unfocus_req
| Save_req
| Reload_req
......@@ -384,9 +387,12 @@ let print_notification_to_json (n: notification): json =
"infos", convert_infos infos]
| Saved ->
convert_record ["notification", cc n]
| Saving_needed b ->
convert_record ["notification", cc n;
"need_saving", Bool b]
| Message m ->
convert_record ["notification", cc n;
"message", convert_message m]
"message", convert_message m]
| Dead s ->
convert_record ["notification", cc n;
"message", String s]
......
......@@ -250,6 +250,8 @@ let treat_notification fmt n =
fprintf fmt "Initialized@."
| Saved -> (* TODO *)
fprintf fmt "got a Saved notification not yet supported@."
| Saving_needed _b -> (* TODO *)
fprintf fmt "got a Saving_needed notification not yet supported@."
| Message (msg) -> treat_message_notification fmt msg
| Dead _s -> (* TODO *)
fprintf fmt "got a Dead notification not yet supported@."
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment