<head>
</head>
-<body>
+<head>
<script language="JavaScript">
var locked;
var unlocked;
var goals;
var goalview;
var filename;
-var status;
+var logarea;
+var advanceButton;
+var retractButton;
+var cursorButton;
+var bottomButton;
function initialize()
{
goals = document.getElementById("goals");
goalview = document.getElementById("goalview");
filename = document.getElementById("filename");
- status = document.getElementById("status");
+ logarea = document.getElementById("logarea");
+ advanceButton = document.getElementById("advance");
+ retractButton = document.getElementById("retract");
+ cursorButton = document.getElementById("cursor");
+ bottomButton = document.getElementById("bottom");
+
+ // hide sequent view at start
+ hideSequent();
}
function debug(txt)
{
- var status = document.getElementById("status");
- status.innerHTML = txt + "\n" + status.innerHTML;
+ logarea.innerHTML = txt + "\n" + logarea.innerHTML;
}
function listhd(l)
function populate_goalarray(txt)
{
- debug("populate with '" + txt + "'");
- goalarray = new Array();
- metalist = listnil();
- var tmp_goallist = "";
- listiter (function(item)
- {
- debug ("item is '" + item + "'");
- tripletmap (function(a,ahtml,b) {
- debug ("found meta n. " + a);
- debug ("found goal\nBEGIN" + unescape(b) + "\nEND");
- goalarray[a] = unescape(b);
- tmp_goallist = " <A href=\"javascript:switch_goal(" + a + ")\">" + unescape(ahtml) + "</A>" + tmp_goallist;
- metalist = listcons(a,metalist);
- debug ("goalarray[\"" + a + "\"] = " + goalarray[a]);
- },item);
- }, txt);
- // metalist = listmap (p13,txt);
- document.getElementById("goals").innerHTML = tmp_goallist;
- debug("new metalist is '" + metalist + "'");
- if (is_nil(metalist)) {
- switch_goal();
- }
- else {
- switch_goal(listhd(metalist));
+ if (txt == "") {
+ try {
+ hideSequent();
+ } catch (err) { };
+ } else {
+ showSequent();
+ debug("populate with '" + txt + "'");
+ goalarray = new Array();
+ metalist = listnil();
+ var tmp_goallist = "";
+ listiter (function(item)
+ {
+ debug ("item is '" + item + "'");
+ tripletmap (function(a,ahtml,b) {
+ debug ("found meta n. " + a);
+ debug ("found goal\nBEGIN" + unescape(b) + "\nEND");
+ goalarray[a] = unescape(b);
+ tmp_goallist = " <A href=\"javascript:switch_goal(" + a + ")\">" + unescape(ahtml) + "</A>" + tmp_goallist;
+ metalist = listcons(a,metalist);
+ debug ("goalarray[\"" + a + "\"] = " + goalarray[a]);
+ },item);
+ }, txt);
+ // metalist = listmap (p13,txt);
+ goals.innerHTML = tmp_goallist;
+ debug("new metalist is '" + metalist + "'");
+ if (is_nil(metalist)) {
+ switch_goal();
+ }
+ else {
+ switch_goal(listhd(metalist));
+ }
}
}
function switch_goal(meta)
{
- goalview = document.getElementById("goalview");
if (typeof meta == "undefined") {
goalview.innerHTML = "";
}
function pause()
{
- var advanceButton = document.getElementById("advance");
- var retractButton = document.getElementById("retract");
advanceButton.disabled = true;
retractButton.disabled = true;
+ cursorButton.disabled = true;
+ bottomButton.disabled = true;
}
function resume()
{
- var advanceButton = document.getElementById("advance");
- var retractButton = document.getElementById("retract");
advanceButton.disabled = false;
retractButton.disabled = false;
+ cursorButton.disabled = false;
+ bottomButton.disabled = false;
}
-function advanceForm1()
+function advanceForm1(cb)
{
var req = null;
- unlocked = document.getElementById("unlocked");
- locked = document.getElementById("locked");
- goalview = document.getElementById("goalview");
pause();
if (window.XMLHttpRequest)
{
if(rs == 4)
{
+ var len;
if(stat == 200)
{
debug("advance: received response\nBEGIN\n" + req.responseText + "\nEND");
locked.innerHTML = locked.innerHTML + parsedtxt;
unlocked.innerHTML = unparsedtxt;
len1 = unlocked.innerHTML.length;
+ len2 = len0 - len1;
+ populate_goalarray(response[1]);
+ statements = listcons(len2,statements);
+ unlocked.scrollIntoView(true);
+ }
+ else
+ {
+ debug("advance error: returned status code " + req.status + " " + req.statusText + "\n" +
+ req.responseText);
+ len = 0;
+ }
+ resume();
+ if (cb) {
+ cb(len);
+ }
+ }
+ };
+ req.open("POST", "advance"); // + escape(unlocked.innerHTML), true);
+ req.send(unlocked.innerHTML.unescapeHTML());
+
+}
+
+function gotoBottom()
+{
+ var req = null;
+ pause();
+ if (window.XMLHttpRequest)
+ {
+ req = new XMLHttpRequest();
+ }
+ else if (window.ActiveXObject)
+ {
+ try {
+ req = new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e)
+ {
+ try {
+ req = new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (e) {}
+ }
+ }
+ req.onreadystatechange = function()
+ {
+
+ rs = req.readyState;
+ stat = req.status;
+ stxt = req.statusText;
+
+ if(rs == 4)
+ {
+ if(stat == 200)
+ {
+ debug("goto bottom: received response\nBEGIN\n" + req.responseText + "\nEND");
+ response = req.responseText.split("@");
+ len = parseInt(response[0]);
+ len0 = unlocked.innerHTML.length;
+ unescaped = unlocked.innerHTML.unescapeHTML();
+ parsedtxt = unescaped.substr(0,len);
+ unparsedtxt = unescaped.substr(len);
+ locked.innerHTML = locked.innerHTML + parsedtxt;
+ unlocked.innerHTML = unparsedtxt;
+ len1 = unlocked.innerHTML.length;
len = len0 - len1;
populate_goalarray(response[1]);
statements = listcons(len,statements);
}
else
{
- debug("advance error: returned status code " + req.status + " " + req.statusText + "\n" +
+ debug("goto bottom error: returned status code " + req.status + " " + req.statusText + "\n" +
req.responseText);
}
resume();
}
};
- req.open("POST", "advance"); // + escape(document.getElementById("unlocked").innerHTML), true);
+ req.open("POST", "bottom"); // + escape(unlocked.innerHTML), true);
req.send(unlocked.innerHTML.unescapeHTML());
}
+function gotoPos(offset)
+{
+ if (!offset) {
+ offset = getCursorPos();
+ }
+ if (offset > 0) {
+ advanceForm1(function(len) {
+ gotoPos(offset-len)
+ });
+ }
+
+}
+
function retract()
{
var req = null;
- unlocked = document.getElementById("unlocked");
- locked = document.getElementById("locked");
- goalview = document.getElementById("goalview");
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
resume();
}
};
- req.open("GET", "retract"); // + escape(document.getElementById("unlocked").innerHTML), true);
+ req.open("GET", "retract"); // + escape(unlocked.innerHTML), true);
req.send();
}
function openFile()
{
- unlocked = document.getElementById("unlocked");
- locked = document.getElementById("locked");
var req = null;
if (window.XMLHttpRequest)
{
}
}
};
- req.open("GET", "open?file=" + escape(document.getElementById("filename").value), true);
+ req.open("GET", "open?file=" + escape(filename.value), true);
req.send();
}
var goalcell;
function hideSequent() {
- goalcell = document.getElementById("goalcell");
goalcell.parentNode.removeChild(goalcell);
- document.getElementById("scriptcell").setAttribute("colspan","2");
+ scriptcell.setAttribute("colspan","2");
}
function showSequent() {
- document.getElementById("scriptcell").setAttribute("colspan","1");
- document.getElementById("workarea").appendChild(goalcell);
+ scriptcell.setAttribute("colspan","1");
+ workarea.appendChild(goalcell);
}
function removeElement(id) {
element.parentNode.removeChild(element);
}
+function getCursorPos() {
+ var cursorPos;
+ if (window.getSelection) {
+ var selObj = window.getSelection();
+ var selRange = selObj.getRangeAt(0);
+ //cursorPos = findNode(selObj.anchorNode.parentNode.childNodes, selObj.anchorNode) + selObj.anchorOffset;
+ cursorPos = findNode(unlocked.childNodes, selObj.anchorNode,0) + selObj.anchorOffset;
+ /* FIXME the following works wrong in Opera when the document is longer than 32767 chars */
+ return(cursorPos);
+ }
+ else if (document.selection) {
+ var range = document.selection.createRange();
+ var bookmark = range.getBookmark();
+ /* FIXME the following works wrong when the document is longer than 65535 chars */
+ cursorPos = bookmark.charCodeAt(2) - 11; /* Undocumented function [3] */
+ return(cursorPos);
+ }
+}
+
+function findNode(list, node, acc) {
+ for (var i = 0; i < list.length; i++) {
+ if (list[i] == node) {
+ // debug("success " + i);
+ return acc;
+ }
+ if (list[i].hasChildNodes()) {
+ try {
+ // debug("recursion on node " + i);
+ return (findNode(list[i].childNodes,node,acc))
+ }
+ catch (e) { /* debug("recursion failed"); */ }
+ }
+ sandbox = document.getElementById("sandbox");
+ dup = list[i].cloneNode(true);
+ sandbox.appendChild(dup);
+// debug("fail " + i + ": " + sandbox.innerHTML);
+ acc += sandbox.innerHTML.length;
+ sandbox.removeChild(dup);
+ }
+ throw "not found";
+}
+
+function test () {
+ debug("cursor test: " + unlocked.innerHTML.substr(0,getCursorPos()));
+}
</script>
+</head>
+<body onLoad="initialize();">
+<div id="sandbox" style="visibility:hidden;"></div>
<table style="table-layout: fixed; width:100%; height:100%; border-spacing: 0px; border-style: none;">
<tr>
<td style="padding: 0px; width:67%; border-style: none;">
<textarea id="unescape" style="display:none;"></textarea>
<p><INPUT type="BUTTON" value="advance" id="advance" ONCLICK="advanceForm1()">
- <INPUT type="BUTTON" value="go back" id="retract" ONCLICK="retract()">
+ <INPUT type="BUTTON" value="go back" id="retract" ONCLICK="retract()">
+ <INPUT type="BUTTON" value="go to cursor" id="cursor" ONCLICK="gotoPos()">
+ <INPUT type="BUTTON" value="bottom" id="bottom" ONCLICK="gotoBottom()">
<INPUT type="TEXT" id="filename" value=""><INPUT type="BUTTON" value="Open" ONCLICK="openFile()"></p>
<INPUT type="BUTTON" value="show sequent" id="showseq" ONCLICK="showSequent()">
<INPUT type="BUTTON" value="hide sequent" id="hideseq" ONCLICK="hideSequent()">
+ <INPUT type="BUTTON" value="selection test" id="hideseq" ONCLICK="test()">
+
</td>
-<td style="width:33%;"></td>
+<td style="width:33%; text-align:center;"><img src="icons/matita-text.png"></td>
</tr>
<tr id="workarea" style="height:80%;">
<td id="scriptcell" style="padding: 0px; border-style: none; padding: 0px;">
inside a PRE tag, a CR will be reflected in the document presentation)
-->
<div style="width:100%; height:100%; overflow:auto;">
- <pre>
- <div contentEditable="false" id="locked" style="background-color:#bfbfff; display:inline;"></div><div contentEditable="true" id="unlocked" style="display:inline">(* script lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo *)</div></pre></div>
+ <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) -->
</td>
<td id="goalcell" style="padding: 0px; width:33%; border-style: none;">
<div id="goals"></div>
<div contentEditable="true" style="border-style:solid; height:100%; width:100%; overflow:auto;">
- <pre id="goalview">lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo lungo </pre>
+ <pre id="goalview"></pre>
</div>
</td>
<tr style="height:15%">
<td colspan="2" style="padding: 0px; border-style: none;">
- <textarea id="status" style="width:100%; height:100%"></textarea>
+ <textarea id="logarea" style="width:100%; height:100%"></textarea>
</td>
</tr>
</table>