From fbfbf719113cb85cf49fd41d29570fe9ab47271e Mon Sep 17 00:00:00 2001 From: Wilmer Ricciotti Date: Wed, 22 Jun 2011 14:59:38 +0000 Subject: [PATCH] Opening scripts using the Library dialog (try 1). --- matitaB/matita/matitaFilesystem.ml | 30 +++++++++++++++++++----------- matitaB/matita/matitadaemon.ml | 5 ++++- matitaB/matita/matitaweb.css | 5 ++--- matitaB/matita/matitaweb.js | 15 +++++++++++++++ 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/matitaB/matita/matitaFilesystem.ml b/matitaB/matita/matitaFilesystem.ml index 32609b883..1ead03f90 100644 --- a/matitaB/matita/matitaFilesystem.ml +++ b/matitaB/matita/matitaFilesystem.ml @@ -62,40 +62,48 @@ let html_of_library uid = let i = ref 0 in let newid () = incr i; ("node" ^ string_of_int !i) in + let basedir = (Helm_registry.get "matita.rt_base_dir") ^ "/users/" ^ uid in + let branch text acc = let id = newid () in + let name = Filename.basename text in + let name = if name <> "." then name else "cic:/matita" in "\n" ^ "\n" ^ - text ^ "
\n" ^ + name ^ "
\n" ^ "\n" ^ acc ^ "\n" in - let leaf text link = + let leaf text = "\n" ^ - "" ^ text ^ "
" + "" ^ + (Filename.basename text) ^ "
" in let rec aux path = + let lpath filename = path ^ "/" ^ filename in + let gpath filename = basedir ^ "/" ^ path ^ "/" ^ filename in let dirlist = - List.filter (fun x -> String.sub x 0 1 = ".") (Array.to_list (Sys.readdir path)) in - let subdirs = List.filter (fun x -> Sys.is_directory (path ^ "/" ^ x)) dirlist in + List.filter (fun x -> String.sub x 0 1 = ".") + (Array.to_list (Sys.readdir (basedir ^ "/" ^ path))) in + let subdirs = List.filter (fun x -> Sys.is_directory (gpath x)) dirlist in let scripts = List.filter (fun x -> try let i = String.rindex x '.' in - not (Sys.is_directory (path ^ "/" ^ x)) && (String.sub x i 3 = ".ma") + let len = String.length x - i in + not (Sys.is_directory (gpath x)) && (String.sub x i len = ".ma") with Not_found | Invalid_argument _ -> false) dirlist in let subdirtags = - String.concat "\n" (List.map (fun x -> aux (path ^ "/" ^ x)) subdirs) in + String.concat "\n" (List.map (fun x -> aux (lpath x)) subdirs) in let scripttags = String.concat "\n" - (List.map (fun x -> leaf x (path ^ "/" ^ x)) scripts) + (List.map (fun x -> leaf (gpath x)) scripts) in - branch (Filename.basename path) (subdirtags ^ "\n" ^ scripttags) + branch path (subdirtags ^ "\n" ^ scripttags) in - let basedir = (Helm_registry.get "matita.rt_base_dir") ^ "/users/" ^ uid in - let res = aux basedir in + let res = aux "." in prerr_endline "BEGIN TREE";prerr_endline res;prerr_endline "END TREE"; res ;; diff --git a/matitaB/matita/matitadaemon.ml b/matitaB/matita/matitadaemon.ml index cd7d71dc9..92b1ce45c 100644 --- a/matitaB/matita/matitadaemon.ml +++ b/matitaB/matita/matitadaemon.ml @@ -5,6 +5,8 @@ module Stack = Continuationals.Stack let rt_path () = Helm_registry.get "matita.rt_base_dir" +let libdir uid = (rt_path ()) ^ "/users/" ^ uid + let utf8_length = Netconversion.ustring_length `Enc_utf8 let utf8_parsed_text s floc = @@ -167,11 +169,12 @@ let retrieve (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) = (try let sid = Uuidm.of_string (Netcgi.Cookie.value (env#cookie "session")) in let sid = HExtlib.unopt sid in + let uid = MatitaAuthentication.user_of_session sid in cgi # set_header ~cache:`No_cache ~content_type:"text/xml; charset=\"utf-8\"" (); - let filename = cgi # argument_value "file" in + let filename = libdir uid ^ "/" ^ (cgi # argument_value "file") in prerr_endline ("reading file " ^ filename); let body = Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () diff --git a/matitaB/matita/matitaweb.css b/matitaB/matita/matitaweb.css index f3f768bc2..5510ab677 100644 --- a/matitaB/matita/matitaweb.css +++ b/matitaB/matita/matitaweb.css @@ -24,8 +24,7 @@ div.scroll { display: block; margin-left: auto; margin-right: auto; - border: 1px; - border-style:solid; + border: 1px solid #ccc; height:470px; width:442px; overflow:auto; @@ -35,6 +34,6 @@ div.scroll { h2 { border: 0px; - padding: 0px; + padding: 1px; display: inline; } diff --git a/matitaB/matita/matitaweb.js b/matitaB/matita/matitaweb.js index 81995bb80..e785011b5 100644 --- a/matitaB/matita/matitaweb.js +++ b/matitaB/matita/matitaweb.js @@ -447,6 +447,21 @@ function openFile() callServer("open",processor,"file=" + escape(filename.value)); } +function retrieveFile(thefile) +{ + processor = function(xml) + { + if (is_defined(xml)) { + locked.innerHTML = ""; + unlocked.innerHTML = xml.documentElement.textContent; + } else { + debug("file open failed"); + } + }; + dialogBox.style.display = "none"; + callServer("open",processor,"file=" + escape(thefile); +} + function showLibrary() { var req = null; -- 2.39.2