]> matita.cs.unibo.it Git - helm.git/commitdiff
Matitaweb: first attempt at "Save as".
authorWilmer Ricciotti <ricciott@cs.unibo.it>
Thu, 8 Sep 2011 14:11:12 +0000 (14:11 +0000)
committerWilmer Ricciotti <ricciott@cs.unibo.it>
Thu, 8 Sep 2011 14:11:12 +0000 (14:11 +0000)
matitaB/matita/matitadaemon.ml
matitaB/matita/matitaweb.js

index 61b2dc5479a311eddd69c2b7c831fdee11647b3f..a07e7e16039489d962b2b318890d1fb21960e133 100644 (file)
@@ -351,6 +351,8 @@ let logout (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
   cgi#out_channel#commit_work()
 ;;
 
+exception File_already_exists;;
+
 let save (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
   let cgi = Netcgi1_compat.Netcgi_types.of_compat_activation cgi in
   let env = cgi#environment in
@@ -363,7 +365,12 @@ let save (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
     let locked = cgi#argument_value "locked" in
     let unlocked = cgi#argument_value "unlocked" in
     let filename = libdir uid ^ "/" ^ (cgi # argument_value "file") in
+    let force = bool_of_string (cgi#argument_value "force") in
     prerr_endline ("Matita will save the file for user " ^ uid);
+
+    if ((not force) && (Sys.file_exists filename)) then 
+      raise File_already_exists;
+
     let oc = open_out filename in
     output_string oc (locked ^ unlocked);
     close_out oc;
@@ -382,7 +389,9 @@ let save (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
       ();
     cgi#out_channel#output_string "<response>ok</response>"
   with
-  | Not_found _ -> 
+  | File_already_exists ->
+      cgi#out_channel#output_string "<response>cancelled</response>"
+  | Sys_error _ -> 
     cgi # set_header
       ~status:`Internal_server_error
       ~cache:`No_cache 
index c0b9458425ccde715e620507f978bb74b9de3b1b..221ef90b56f3c6361d5338d48c71d5a89548498e 100644 (file)
@@ -644,7 +644,7 @@ function retrieveFile(thefile)
        callServer("open",processor,"file=" + escape(thefile)); 
 }
 
-function showLibrary()
+function showLibrary(title,callback)
 { 
        var req = null; 
         // pause();
@@ -675,7 +675,7 @@ function showLibrary()
                        if(stat == 200)
                        {
                          debug(req.responseText);
-                         showDialog("<H2>Library</H2>",req.responseText);
+                         showDialog("<H2>" + title + "</H2>",req.responseText, callback);
                        } 
                } 
        };
@@ -685,21 +685,44 @@ function showLibrary()
   
 }
 
-function saveFile()
+function openDialog()
+{  
+       callback = function (fname) { retrieveFile(fname); };
+       showLibrary("Open file", callback);
+}
+
+function saveDialog()
+{  
+       callback = function (fname) { saveFile(fname,false); };
+       showLibrary("Save file as", callback);
+}
+
+function saveFile(fname,force)
 {
+        if (!is_defined(fname) {
+            fname = current_fname;
+        }
        processor = function(xml) {
                if (is_defined(xml)) {
+                 if (xml.childNodes[0].textContent != "ok") {
+                    if (confirm("File already exists. Do you want to proceed anyway?")) {
+                       saveFile(fname,true);
+                   } else {
+                      saveDialog();
+                   }
+                 } else
                        debug("file saved!");
                } else {
                        debug("save file failed");
                }
                resume();
        };
-       if (is_defined(current_fname)) {
+       if (is_defined(fname)) {
           pause();
-          callServer("save",processor,"file=" + escape(current_fname) + 
+          callServer("save",processor,"file=" + escape(fname) + 
                                    "&locked=" + (locked.innerHTML.html_to_matita()).sescape() +
-                                   "&unlocked=" + (unlocked.innerHTML.html_to_matita()).sescape());
+                                   "&unlocked=" + (unlocked.innerHTML.html_to_matita()).sescape() +
+                                   "&force=" + force);
        }
        else { debug("no file selected"); }
 }
@@ -730,10 +753,11 @@ function showSequent() {
   workarea.appendChild(goalcell);
 }
 
-function showDialog(title,content) {
+function showDialog(title,content,callback) {
   dialogTitle.innerHTML = title;
   dialogContent.innerHTML = content;
   dialogBox.style.display = "block";
+  dialogBox.callback = callback;
 }
 
 function removeElement(id) {