]> matita.cs.unibo.it Git - helm.git/commitdiff
Matitaweb: first attempt at web UI for disambiguation.
authorWilmer Ricciotti <ricciott@cs.unibo.it>
Mon, 24 Oct 2011 16:40:58 +0000 (16:40 +0000)
committerWilmer Ricciotti <ricciott@cs.unibo.it>
Mon, 24 Oct 2011 16:40:58 +0000 (16:40 +0000)
Also includes a rather radical change in the way the graphical layout is
handled.

matitaB/components/disambiguation/disambiguate.ml
matitaB/components/disambiguation/disambiguate.mli
matitaB/components/ng_disambiguation/grafiteDisambiguate.ml
matitaB/components/ng_disambiguation/grafiteDisambiguate.mli
matitaB/matita/index.html
matitaB/matita/matitadaemon.ml
matitaB/matita/matitaweb.css
matitaB/matita/matitaweb.js

index 5ce1386aeb0b16a9aca5a0f4abbde42270d3afe9..a65dd3e5f78b55a4825141f2a5a5003fe626576c 100644 (file)
@@ -31,9 +31,6 @@ open DisambiguateTypes
 
 module Ast = NotationPt
 
-(* the integer is an offset to be added to each location *)
-exception Ambiguous_input
-(* the integer is an offset to be added to each location *)
 exception NoWellTypedInterpretation of
  int *
  ((Stdpp.location list * string * string) list *
@@ -51,6 +48,7 @@ type 'a disambiguator_input = string * int * 'a
 type domain = domain_tree list
 and domain_tree = Node of Stdpp.location list * domain_item * domain
 
+(*
 let mono_uris_callback ~selection_mode ?ok
           ?(enable_button_for_non_vars = true) ~title ~msg ~id =
  if Helm_registry.get_opt_default Helm_registry.get_bool ~default:true
@@ -60,8 +58,8 @@ let mono_uris_callback ~selection_mode ?ok
  else
   raise Ambiguous_input
 
-let mono_interp_callback _ _ _ = raise Ambiguous_input
-let mono_disamb_callback _ = raise Ambiguous_input
+let mono_interp_callback _ _ _ = assert false
+let mono_disamb_callback _ = assert false
 
 let _choose_uris_callback = ref mono_uris_callback
 let _choose_interp_callback = ref mono_interp_callback
@@ -73,6 +71,8 @@ let set_choose_disamb_callback f = _choose_disamb_callback := f
 let interactive_user_uri_choice = !_choose_uris_callback
 let interactive_interpretation_choice interp = !_choose_interp_callback interp
 let interactive_ast_choice interp = !_choose_disamb_callback interp
+*)
+
 let input_or_locate_uri ~(title:string) ?id () = None
   (* Zack: I try to avoid using this callback. I therefore assume that
   * the presence of an identifier that can't be resolved via "locate"
@@ -730,12 +730,13 @@ let disambiguate_thing
     in
     match res with
     | [] -> raise (NoWellTypedInterpretation (0,[]))
+    (* XXX : the boolean seems not to play a role any longer *)
     | [t] -> res,false
-    | _ ->
-       let choices = List.map (fun (t,_,_,_,_) -> pp_thing t) res in
+    | _ -> res, true
+       (* let choices = List.map (fun (t,_,_,_,_) -> pp_thing t) res in
        let user_choice = interactive_ast_choice choices in
        [ List.nth res user_choice ], true
        (* let pp_thing (t,_,_,_,_,_) = prerr_endline ("interpretation: " ^ (pp_thing t)) in
-         List.iter pp_thing res; res,true *)
+         List.iter pp_thing res; res,true *) *)
 ;;
 
index bb20ff86635ca1ec53a6b218b610c7f36b97f2a7..2e6677d727f7996bf60b813363b78079c4c1b95f 100644 (file)
 
 (** {2 Disambiguation interface} *)
 
-(** raised when ambiguous input is found but not expected (e.g. in the batch
-  * compiler) *)
-exception Ambiguous_input
-
 (* the integer is an offset to be added to each location *)
 (* list of located error messages, each list is a tuple:
   * - environment in string form
@@ -58,6 +54,7 @@ type ('term,'metasenv,'subst,'graph) test_result =
 
 exception Try_again of string Lazy.t
 
+(*
 val set_choose_uris_callback:
   DisambiguateTypes.interactive_user_uri_choice_type -> unit
 
@@ -76,6 +73,7 @@ val mono_uris_callback: DisambiguateTypes.interactive_user_uri_choice_type
   * choose_interp_callback if not set otherwise with set_choose_interp_callback
   * above *)
 val mono_interp_callback: DisambiguateTypes.interactive_interpretation_choice_type
+*)
 
 val resolve : 
   env:'alias1 DisambiguateTypes.InterprEnv.t ->
index 9c7ea4768ceb4152cf35839d2cda60fcfb3f90a6..b1dc98a1e23e46cde8c3e265fed0061327a2af2b 100644 (file)
@@ -76,6 +76,9 @@ class virtual status uid =
   new_aliases,res
 ;;*)
 
+(* reports the first source of ambiguity and its possible interpretations *)
+exception Ambiguous_input of (Stdpp.location * GrafiteAst.alias_spec list)
+
 let dump_aliases out msg status =
    out (if msg = "" then "aliases dump:" else msg ^ ": aliases dump:");
    DisambiguateTypes.InterprEnv.iter (fun _ x -> out (GrafiteAstPp.pp_alias x))
@@ -107,15 +110,6 @@ let add_to_disambiguation_univ status new_aliases =
 
 exception BaseUriNotSetYet
 
-let singleton msg = function
-  | [x], _ -> x
-  | l, _   ->
-      let debug = 
-         Printf.sprintf "GrafiteDisambiguate.singleton (%s): %u interpretations"
-         msg (List.length l)
-      in
-      prerr_endline debug; assert false
-
 let __Implicit = "__Implicit__"
 let __Closed_Implicit = "__Closed_Implicit__"
 
@@ -297,11 +291,24 @@ let diff_obj loc o1 o2 = match o1,o2 with
  | _ -> assert false
 ;;
 
+(* this function, called on a list of choices that must
+ * be different, never fails and returns the location of
+ * the first ambiguity (and its possible interpretations) *)
+let rec find_diffs l =
+  let loc,_ = List.hd (List.hd l) in
+  let hds = List.map (fun x -> snd (List.hd x)) l in
+  let uniq_hds = HExtlib.list_uniq hds in
+
+  if List.length uniq_hds > 1
+    then loc, uniq_hds
+  else 
+    let tls = List.map List.tl l in
+    find_diffs tls
+;;
+
 let disambiguate_nterm status expty context metasenv subst thing
-= 
-  let newast, metasenv, subst, cic =
-    singleton "first"
-      (NCicDisambiguate.disambiguate_term
+=
+  let choices, _ = NCicDisambiguate.disambiguate_term
         status
         ~aliases:status#disambiguate_db.interpr
         ~expty 
@@ -310,16 +317,24 @@ let disambiguate_nterm status expty context metasenv subst thing
         ~mk_choice:(ncic_mk_choice status)
         ~mk_implicit ~fix_instance
         ~description_of_alias:GrafiteAst.description_of_alias
-        ~context ~metasenv ~subst thing)
+        ~context ~metasenv ~subst thing
   in
   let _,_,thing' = thing in
-  let diff = diff_term Stdpp.dummy_loc thing' newast in
-  let status = add_to_interpr status diff 
-  in
-   metasenv, subst, status, cic
+  match choices with
+  | [newast, metasenv, subst, cic] -> 
+      let diff = diff_term Stdpp.dummy_loc thing' newast in
+      let status = add_to_interpr status diff 
+      in
+      metasenv, subst, status, cic
+  | [] -> assert false
+  | _ -> 
+      let diffs = 
+        List.map (fun (ast,_,_,_) -> 
+          diff_term Stdpp.dummy_loc thing' ast) choices 
+      in
+      raise (Ambiguous_input (find_diffs diffs))
 ;;
 
-
 type pattern = 
   NotationPt.term Disambiguate.disambiguator_input option * 
   (string * NCic.term) list * NCic.term option
@@ -367,7 +382,7 @@ let disambiguate_just disambiguate_term context metasenv =
        metasenv, `Auto params
 ;;
       
-let disambiguate_nobj status ?baseuri (text,prefix_len,obj) =
+let disambiguate_nobj status ?baseuri (text,prefix_len,obj as obj') =
   let uri =
    let baseuri = 
      match baseuri with Some x -> x | None -> raise BaseUriNotSetYet
@@ -381,9 +396,8 @@ let disambiguate_nobj status ?baseuri (text,prefix_len,obj) =
    in
      NUri.uri_of_string (baseuri ^ "/" ^ name)
   in
-  let ast, _, _, cic =
-   singleton "third"
-    (NCicDisambiguate.disambiguate_obj
+
+  let choices, _ = NCicDisambiguate.disambiguate_obj
       status
       ~lookup_in_library:(nlookup_in_library status)
       ~description_of_alias:GrafiteAst.description_of_alias
@@ -391,11 +405,21 @@ let disambiguate_nobj status ?baseuri (text,prefix_len,obj) =
       ~mk_implicit ~fix_instance ~uri
       ~aliases:status#disambiguate_db.interpr
       ~universe:(status#disambiguate_db.multi_aliases) 
-      (text,prefix_len,obj)) in
-  let diff = diff_obj Stdpp.dummy_loc obj ast in
-  let status = add_to_interpr status diff
+      obj'
   in
-   status, cic
+  match choices with
+  | [ast, _, _, cic] -> 
+      let diff = diff_obj Stdpp.dummy_loc obj ast in
+      let status = add_to_interpr status diff
+      in
+      status, cic
+  | [] -> assert false
+  | _ -> 
+      let diffs = 
+        List.map (fun (ast,_,_,_) -> 
+          diff_obj Stdpp.dummy_loc obj ast) choices 
+      in
+      raise (Ambiguous_input (find_diffs diffs))
 ;;
 
 let disambiguate_cic_appl_pattern status args =
index e71c25b828101f2a9e83198a431f3ee21439cff9..c9735dbf9d576c295ca208a9b1ee137cd0d50a39 100644 (file)
@@ -65,6 +65,9 @@ val aliases_for_objs:
 (* args: print function, message (may be empty), status *) 
 val dump_aliases: (string -> unit) -> string -> #status -> unit
 
+(* reports the first source of ambiguity and its possible interpretations *)
+exception Ambiguous_input of (Stdpp.location * GrafiteAst.alias_spec list)
+
 exception BaseUriNotSetYet
 
 val disambiguate_nterm :
index d3fe3491f263e0e34314fe5ff35496d329c5e4b9..80f49ece416a748bc209e770b5cd0296259f9141 100644 (file)
@@ -3,6 +3,7 @@
 <head>
 <script type="text/javascript" src="utf8MacroTable.js"></script>
 <script type="text/javascript" src="matitaweb.js"></script>
+<script type="text/javascript" src="layout.js"></script>
 <link rel="stylesheet" type="text/css" href="matitaweb.css"/>
 
 <link href="treeview/xmlTree.css" type="text/css" rel="stylesheet"/>
 
 </head>
 
-<body onLoad="initialize();">
+<body onLoad="initialize();" onResize="resize();">
 <textarea id="unescape" style="display:none;"></textarea>
-<div id="sandbox" style="visibility:hidden;"></div>
+<div id="sandbox" style="display:none;"></div>
 
-<div class="matitaapparea">
+<div class="matitaapparea" id="matitaapparea">
 
-<div class="titlebar">
+<div class="titlebar" id="titlebar">
   <div class="mainTitle"><H2 id="matitaTitle">Matita - &lt;&lt;Filename&gt;&gt;</H2></div>
   <div class="mainRight" id="matitaLogout"><A id="hlogout" href="/logout.html">Log out</A></div>
 </div>
 
 
-<div class="toparea">
+<div class="toparea" id="toparea">
 <div class="navibar">
            <A href="javascript:advanceForm1()"><IMG class="topimg" src="icons/advance.png" 
                                                     id="advance" alt="Advance" 
   <pre><div contentEditable="false" id="locked" style="background-color:#bfbfff; display:inline;"></div><div contentEditable="true" id="unlocked" style="display:inline">(* script *)</div></pre></div>
   <!-- the script (end) --> 
 </div>
-<div class="goalarea" id="goalcell">
+<div class="sidearea" id="sidearea">
+ <div class="framed" id="disambcell"></div>
+ <div class="framed" id="goalcell">
   <div id="goals"></div>
-  <div contentEditable="true" style="border-style:solid; height:95%; width:100%; overflow:auto;">
+  <div class="context">
   <pre id="goalview"></pre>
   </div>
+ </div>
 </div>
 </div>
 
@@ -92,7 +96,7 @@
 
 <div class="dialog" id="dialogBox" style="display: none;">
   <div class="diaTitle" id="dialogTitle"></div>
-  <div class="diaClose" id="dialogClose"><H2><A id="butClose" href="javascript:abortDialog()">X</A></H2></div>
+  <div class="diaClose" id="dialogClose"><H2><A class="butClose" href="javascript:abortDialog('dialogBox')">X</A></H2></div>
   <INPUT type="button" id="dialogNewdir" value="Create dir..." ONCLICK="createDir()" style="width:150px"><br/>
   <div class="scroll" id="dialogContent"></div>
   <INPUT class="diaFile" type="text" id="dialogFilename">
 
 <div class="upload" id="uploadBox" style="display: none;">
   <div class="dialogTitle" id="uploadTitle"></div>
-  <div class="diaClose" id="uploadClose"><H2><A id="but1Close" href="javascript:abortUpload()">X</A></H2></div>
+  <div class="diaClose" id="uploadClose"><H2><A class="butClose" href="javascript:abortDialog('uploadBox')">X</A></H2></div>
   <INPUT class="diaFile" type="file" id="uploadFilename">
   <INPUT type="button" id="uploadSelect" value="OK" ONCLICK="uploadOK()" style="width:70px">
 </div>
 
  </body>
- </html> 
+</html> 
index c2a586120227bd3fcbc11b2aa7103b039c8580f1..9fc2b1bbcf05b30e9cc327f39ba847dc0d29b5d4 100644 (file)
@@ -2,6 +2,7 @@ open Printf;;
 open Http_types;;
 
 exception Emphasized_error of string
+exception Ambiguous of string
 
 module Stack = Continuationals.Stack
 
@@ -362,15 +363,33 @@ let advance0 sid text =
       let marked = Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false 
       () (html_of_matita marked) in
       raise (Emphasized_error marked) 
-    | GrafiteDisambiguate.Ambiguous_input (loc,choices) -> 
-        let strchoices = 
-          String.concat "\n" (List.map
-            GrafiteAst.description_of_alias choices)
-        in
-        let x,y = HExtlib.loc_of_floc loc in
-        prerr_endline (Printf.sprintf
-          "@@@ Ambiguous input at (%d,%d). Possible choices:\n\n%s\n\n@@@ End."
+    | GrafiteDisambiguate.Ambiguous_input (loc,choices) ->
+      let x,y = HExtlib.loc_of_floc loc in
+      let choice_of_alias = function
+       | GrafiteAst.Ident_alias (_,uri) -> uri, None, uri
+       | GrafiteAst.Number_alias (None,desc)
+       | GrafiteAst.Symbol_alias (_,None,desc) -> "cic:/fakeuri.def(1)", Some desc, desc
+       | GrafiteAst.Number_alias (Some uri,desc)
+       | GrafiteAst.Symbol_alias (_,Some uri,desc) -> uri, Some desc, desc
+      in
+      let tag_of_choice (uri,title,desc) =
+        match title with
+        | None -> Printf.sprintf "<choice href=\"%s\">%s</choice>"
+            uri 
+            (Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () desc)
+        | Some t -> Printf.sprintf "<choice href=\"%s\" title=\"%s\">%s</choice>"
+            uri 
+            (Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () t)
+            (Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false () desc)
+      in
+      let strchoices = 
+        String.concat "\n" 
+          (List.map (fun x -> tag_of_choice (choice_of_alias x)) choices)
+      in
+      prerr_endline (Printf.sprintf
+        "@@@ Ambiguous input at (%d,%d). Possible choices:\n\n%s\n\n@@@ End."
           x y strchoices);
+      (*
       let pre = Netconversion.ustring_sub `Enc_utf8  0 x text in
       let err = Netconversion.ustring_sub `Enc_utf8  x (y-x) text in
       let post = Netconversion.ustring_sub `Enc_utf8 y 
@@ -381,7 +400,10 @@ let advance0 sid text =
        pre ^ "\005span class=\"error\" title=\"" ^ title ^ "\"\006" ^ err ^ "\005/span\006" ^ post in
       let marked = Netencoding.Html.encode ~in_enc:`Enc_utf8 ~prefer_name:false 
       () (html_of_matita marked) in
-      raise (Emphasized_error marked) 
+      *)
+      let strchoices = Printf.sprintf
+        "<ambiguity start=\"%d\" stop=\"%d\">%s</ambiguity>" x y strchoices
+      in raise (Ambiguous strchoices) 
    (* | End_of_file -> ...          *)
   in
   let stringbuf = Ulexing.from_utf8_string new_statements in
@@ -655,7 +677,14 @@ let advance (cgi : Netcgi1_compat.Netcgi_types.cgi_activation) =
    with
   | Emphasized_error text ->
 (* | MultiPassDisambiguator.DisambiguationError (offset,errorll) -> *)
-    let body = "<response><error>" ^ text ^ "</error> </response>" in 
+    let body = "<response><error>" ^ text ^ "</error></response>" in 
+    cgi # set_header 
+      ~cache:`No_cache 
+      ~content_type:"text/xml; charset=\"utf-8\""
+      ();
+    cgi#out_channel#output_string body
+  | Ambiguous text ->
+    let body = "<response>" ^ text ^ "</response>" in 
     cgi # set_header 
       ~cache:`No_cache 
       ~content_type:"text/xml; charset=\"utf-8\""
index 9f0da288466c0a307ab58a8a0b59960cd1c87fd8..fbc7d22ed8e7ffd064a61251dd172a59b7d581ab 100644 (file)
@@ -1,3 +1,16 @@
+body {
+       border:0px;
+       padding:0px;
+       margin:0px;
+}
+
+div#matitaapparea {
+       border:0px;
+       padding:0px;
+       margin:0px;
+       position:fixed;
+}
+
 div.upload {
        position:absolute;
        top: 50%;
@@ -13,9 +26,8 @@ div.upload {
 
 div.titlebar {
        display: block;
-       margin-left: auto;
-       margin-right: auto;
-       margin-bottom: 4px;
+       margin:0px;
+       border:0px;
        width:100%;
        height: 32px;
        background-color: #007fff;
@@ -86,7 +98,8 @@ a#hlogout {
   color: inherit;
   font-weight: bold;
 }
-a#butClose {
+
+a.butClose {
   color: inherit;
 }
 
@@ -120,6 +133,7 @@ div.matitaapparea {
 
 div.toparea {
        display: block;
+       padding:4px;
        margin-left: auto;
        margin-right: auto;
        height:64px; 
@@ -138,8 +152,11 @@ div.bottomarea {
 
 div.workarea {
        display: block;
-       margin-left: auto;
-       margin-right: auto;
+       border:0px;
+       padding:0px;
+       margin:0px;
+       /*margin-left: auto;
+       margin-right: auto;*/
        height:84%; 
        width:100%; 
 }
@@ -179,19 +196,25 @@ img.topimg {
 
 div.scriptarea {
        display: inline-block;
-       margin-left: auto;
-       margin-right: auto;
+       border:0px;
+       padding:0px;
+       margin:0px;
+/*     margin-left: auto;
+       margin-right: auto;*/
        height:100%; 
-       width:67%%;
+       width:67%;
         min-width:67%;
         max-width:67%;
         float:left;
 }
 
-div.goalarea {
+div.sidearea {
        display: inline-block;
-       margin-left: auto;
-       margin-right: auto;
+       border:0px;
+       padding:0px;
+       margin:0px;
+       /*margin-left: auto;
+       margin-right: auto;*/
        height:100%; 
        width:33%;
         min-width:33%;
@@ -199,6 +222,14 @@ div.goalarea {
         float:right;
 }
 
+div.framed { 
+       border: 2px solid DarkGray;
+}
+
+div.context {
+       overflow: auto;
+}
+
 span.activegoal {
        color: red;
        font-weight: bold;
index ccb2f37445fabf8e38332df2fc714e9d5fffbf6e..890b34ec0b8cef0982f5b703e35ce8470130b30d 100644 (file)
@@ -16,6 +16,7 @@ var dialogTitle;
 var dialogContent;
 var metasenv = "";
 var lockedbackup = "";
+var matita;
 
 function text_of_html(h)
 {
@@ -48,11 +49,17 @@ function initialize()
   if (readCookie("session") == null) {
     window.location = "/login.html"
   } else {
+    body = document.body;
+    titlebar = document.getElementById("titlebar");
     matitaTitle = document.getElementById("matitaTitle");
+    apparea = document.getElementById("matitaapparea");
     locked = document.getElementById("locked");
     unlocked = document.getElementById("unlocked");
+    toparea = document.getElementById("toparea");
     workarea = document.getElementById("workarea");
     scriptcell = document.getElementById("scriptcell");
+    sidearea = document.getElementById("sidearea");
+    disambcell = document.getElementById("disambcell");
     goalcell = document.getElementById("goalcell");
     goals = document.getElementById("goals");
     goalview = document.getElementById("goalview");
@@ -63,13 +70,18 @@ function initialize()
     cursorButton = document.getElementById("cursor");
     bottomButton = document.getElementById("bottom");
     dialogBox = document.getElementById("dialogBox");
+    uploadBox = document.getElementById("uploadBox");
     dialogTitle = document.getElementById("dialogTitle");
     dialogContent = document.getElementById("dialogContent");
 
-    changeFile("test.ma");
-  
+    matita = new Object();
+    matita.disambMode = matita.proofMode = false;
+
     // hide sequent view at start
-    hideSequent();
+    initializeLayout();
+    updateSide();
+
+    changeFile("test.ma");
 
     // initialize keyboard events in the unlocked script
     init_keyboard(unlocked);
@@ -535,28 +547,87 @@ function advanceForm1()
 {
        processor = function(xml) {
                if (is_defined(xml)) {
-                        parsed = xml.getElementsByTagName("parsed")[0];
+                        var parsed = xml.getElementsByTagName("parsed")[0];
+                       var ambiguity = xml.getElementsByTagName("ambiguity")[0];
                         if (is_defined(parsed)) {
                        // debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
-                           len = parseInt(parsed.getAttribute("length"));
+                           var len = parseInt(parsed.getAttribute("length"));
                            // len0 = unlocked.innerHTML.length;
-                           unescaped = unlocked.innerHTML.html_to_matita();
-                           parsedtxt = parsed.childNodes[0].nodeValue;
+                           var unescaped = unlocked.innerHTML.html_to_matita();
+                           var parsedtxt = parsed.childNodes[0].nodeValue;
                            //parsedtxt = unescaped.substr(0,len); 
-                           unparsedtxt = unescaped.substr(len);
+                           var unparsedtxt = unescaped.substr(len);
                            lockedbackup += parsedtxt;
                            locked.innerHTML = lockedbackup;
                            unlocked.innerHTML = unparsedtxt.matita_to_html();
                            // len1 = unlocked.innerHTML.length;
                            // len2 = len0 - len1;
-                           len2 = parsedtxt.length;
-                           metasenv = xml.getElementsByTagName("meta");
+                           var len2 = parsedtxt.length;
+                           var metasenv = xml.getElementsByTagName("meta");
                            populate_goalarray(metasenv);
                            statements = listcons(len2,statements);
                            unlocked.scrollIntoView(true);
                        }
+                       else if (is_defined(ambiguity)) {
+                           var start = parseInt(ambiguity.getAttribute("start"));
+                           var stop = parseInt(ambiguity.getAttribute("stop"));
+                           var choices = xml.getElementsByTagName("choice");
+
+                           matita.ambiguityStart = start;
+                           matita.ambiguityStop = stop;
+                           matita.unlockedbackup = unlocked.innerHTML;
+                           matita.interpretations = [];
+                       
+                           var unlockedtxt = unlocked.innerHTML;
+                           var pre = unlockedtxt.substring(0,start);
+                           var mid = unlockedtxt.substring(start,stop);
+                           var post = unlockedtxt.substring(stop);
+                           unlocked.innerHTML = pre + 
+                                   "<span class=\"error\" title=\"disambiguation error\">" +
+                                   mid + "</span>" + post;
+
+                           var title = "<H3>Ambiguous input</H3>";
+                           disambcell.innerHTML = title;
+                           for (i = 0;i < choices.length;i++) {
+                               matita.interpretations[i] = new Object();
+
+                               var href = choices[i].getAttribute("href");
+                               var title = choices[i].getAttribute("title");
+                               var desc = choices[i].childNodes[0].nodeValue;
+
+                               matita.interpretations[i].href = href;
+                               matita.interpretations[i].title = title;
+                               matita.interpretations[i].desc = desc;
+                               
+                               var choice = document.createElement("input");
+                               choice.setAttribute("type","radio");
+                               choice.setAttribute("name","interpr");
+                               choice.setAttribute("href",href);
+                               choice.setAttribute("title",title);
+                               if (i == 0) choice.setAttribute("checked","");
+                               
+                               disambcell.appendChild(choice);
+                               disambcell.appendChild(document.createTextNode(desc));
+                               disambcell.appendChild(document.createElement("br"));
+                           }
+
+                           var okbutton = document.createElement("input");
+                           okbutton.setAttribute("type","button");
+                           okbutton.setAttribute("value","OK");
+                           okbutton.setAttribute("onclick","do_disambiguate()");
+                           var cancelbutton = document.createElement("input");
+                           cancelbutton.setAttribute("type","button");
+                           cancelbutton.setAttribute("value","Cancel");
+                           cancelbutton.setAttribute("onclick","void(0)");
+
+                           disambcell.appendChild(okbutton);
+                           disambcell.appendChild(cancelbutton);
+
+                           matita.disambMode = true;
+                           updateSide();
+                       }
                        else {
-                            error = xml.getElementsByTagName("error")[0]; 
+                            var error = xml.getElementsByTagName("error")[0]; 
                            unlocked.innerHTML = error.childNodes[0].nodeValue;
                            // debug(xml.childNodes[0].nodeValue);
                        }
@@ -944,17 +1015,13 @@ function updateAll()
 var goalcell;
 
 function hideSequent() {
-  goalcell.style.display = "none";
-  scriptcell.style.width = "100%";
-  scriptcell.style.minWidth = "100%";
-  scriptcell.style.maxWidth = "100%";
+       matita.proofMode = false;
+       updateSide();
 }
 
 function showSequent() {
-  scriptcell.style.width = "67%";
-  scriptcell.style.minWidth = "67%";
-  scriptcell.style.maxWidth = "67%";
-  goalcell.style.display = "inline-block";
+       matita.proofMode = true;
+       updateSide();
 }
 
 function showDialog(title,content,callback) {
@@ -964,12 +1031,13 @@ function showDialog(title,content,callback) {
   dialogBox.style.display = "block";
 }
 
-function abortDialog() {
-  dialogBox.style.display = "none";
+function showDisamb(content) {
+  disambContent.innerHTML = content;
+  disambBox.style.display = "block";
 }
 
-function abortUpload() {
-  uploadBox.style.display = "none";
+function abortDialog(dialog) {
+  dialogBox.style.display = "none";
 }
 
 function removeElement(id) {
@@ -1028,6 +1096,39 @@ function test () {
   debug("cursor test: " + unlocked.innerHTML.substr(0,getCursorPos()));
 }
 
+function get_checked_index(name) {
+       var radios = document.getElementsByName(name);
+       for (i = 0; i < radios.length; i++) {
+           if (radios[i].checked) {
+                   return i;
+           }
+       }
+       return null;
+}
+
+function do_disambiguate() {
+       var i = get_checked_index("interpr");
+       if (i != null) {
+           var pre = matita.unlockedbackup.substring(0,matita.ambiguityStart);
+           var mid = matita.unlockedbackup.substring(matita.ambiguityStart,matita.ambiguityStop);
+           var post = matita.unlockedbackup.substring(matita.ambiguityStop);
+
+           var href = matita.interpretations[i].href;
+           var title = matita.interpretations[i].title;
+
+           if (is_defined(title)) {
+                mid = "<A href=\"" + href + "\" title=\"" + title + "\">" + mid + "</A>";
+           } else {
+                mid = "<A href=\"" + href + "\">" + mid + "</A>";
+           }
+
+           unlocked.innerHTML = pre + mid + post;
+
+           matita.disambMode = false;
+           updateSide();
+       }
+}
+
 function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');