From: Stefano Zacchiroli Date: Thu, 30 Jun 2005 09:32:45 +0000 (+0000) Subject: better handling of script names X-Git-Tag: PRE_GETTER_STORAGE~104 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=ab0d1d5a50ad2e01bcf2e5e4a6ded8322a9da4b9;p=helm.git better handling of script names --- diff --git a/helm/matita/matitaScript.ml b/helm/matita/matitaScript.ml index 0d6bfedee..bd526212e 100644 --- a/helm/matita/matitaScript.ml +++ b/helm/matita/matitaScript.ml @@ -288,23 +288,31 @@ user_goal script s = eval_executable status mathviewer urichooser user_goal parsed_text script ex +let fresh_script_id = + let i = ref 0 in + fun () -> incr i; !i class script ~(buffer: GText.buffer) ~(init: MatitaTypes.status) ~(mathviewer: MatitaTypes.mathViewer) ~set_star ~urichooser () = -let std_filename = "unNamed.ma" in object (self) - val mutable filename = std_filename + val mutable filename = None + val scriptId = fresh_script_id () + method private getFilename = + match filename with Some f -> f | _ -> assert false + method private ppFilename = + match filename with Some f -> f | None -> sprintf ".unnamed%d.ma" scriptId initializer ignore(GMain.Timeout.add ~ms:30000 ~callback:(fun _ -> self#_saveToBackuptFile ();true)); + set_star self#ppFilename false; ignore(buffer#connect#modified_changed (fun _ -> if buffer#modified then - set_star filename true + set_star self#ppFilename true else - set_star filename false)); + set_star self#ppFilename false)); self#reset () val mutable statements = []; (** executed statements *) @@ -399,15 +407,15 @@ List.iter (fun s -> prerr_endline ("'" ^ s ^ "'")) new_statements; List.iter (fun o -> o status) observers method loadFromFile () = - buffer#set_text (MatitaMisc.input_file filename); + buffer#set_text (MatitaMisc.input_file self#getFilename); self#goto_top; buffer#set_modified false method assignFileName file = - filename <- file; + filename <- Some file; method saveToFile () = - let oc = open_out filename in + let oc = open_out self#getFilename in output_string oc (buffer#get_text ~start:buffer#start_iter ~stop:buffer#end_iter ()); close_out oc; @@ -416,7 +424,7 @@ List.iter (fun s -> prerr_endline ("'" ^ s ^ "'")) new_statements; method private _saveToBackuptFile () = if buffer#modified then begin - let f = filename ^ "~" in + let f = self#ppFilename ^ "~" in let oc = open_out f in output_string oc (buffer#get_text ~start:buffer#start_iter ~stop:buffer#end_iter ()); @@ -482,7 +490,8 @@ List.iter (fun s -> prerr_endline ("'" ^ s ^ "'")) new_statements; MatitaLog.debug ("history size: " ^ string_of_int (List.length history)); MatitaLog.debug (sprintf "%d statements:" (List.length statements)); List.iter MatitaLog.debug statements; - MatitaLog.debug ("Current file name: " ^ filename); + MatitaLog.debug ("Current file name: " ^ + (match filename with None -> "[ no name ]" | Some f -> f)); end diff --git a/helm/matita/matitaScript.mli b/helm/matita/matitaScript.mli index 6aea4ad1c..677006b71 100644 --- a/helm/matita/matitaScript.mli +++ b/helm/matita/matitaScript.mli @@ -62,6 +62,8 @@ object end + (** @param set_star callback used to set the modified symbol (usually a star + * "*") on the side of a script name *) val script: buffer:GText.buffer -> init:MatitaTypes.status ->