X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=matitaB%2Fmatita%2Fmatitaweb.js;h=3b37fc76b0abf1537fc06203b5bda68274163b4a;hb=54f0752c831479f87d61afcdfdafd2a35edb4053;hp=d9bd38aa80e94dac072b197f10cb86b1d0555032;hpb=93ad0bc98a502397b5ba0334c0f7088da045fa2d;p=helm.git diff --git a/matitaB/matita/matitaweb.js b/matitaB/matita/matitaweb.js index d9bd38aa8..3b37fc76b 100644 --- a/matitaB/matita/matitaweb.js +++ b/matitaB/matita/matitaweb.js @@ -17,6 +17,22 @@ var dialogContent; var metasenv = ""; var lockedbackup = ""; +function text_of_html(h) +{ + if(document.all) { + return h.innerText; + } else { + return h.textContent; + } +} + +function unescape_html(s) +{ + u = document.getElementById("unescape"); + u.innerHTML = s; + return text_of_html(u) +} + function initialize() { if (readCookie("session") == null) { @@ -109,28 +125,25 @@ function suppressdefault(e,flag) return !flag; } -function restoreSelection(adjust) { +function restoreSelection(r) { unlocked.focus(); - if (savedRange != null) { + if (r != null) { if (window.getSelection)//non IE and there is already a selection { var s = window.getSelection(); if (s.rangeCount > 0) s.removeAllRanges(); - range = document.createRange(); - range.setStart(savedsc,savedso + adjust); - range.collapse(true); - s.addRange(range); + s.addRange(r); } else if (document.createRange)//non IE and no selection { - window.getSelection().addRange(savedRange); + window.getSelection().addRange(r); } else if (document.selection)//IE { - savedRange.select(); + r.select(); } } } @@ -151,16 +164,24 @@ function keypress(e) i = unlocked.innerHTML.lastIndexOf('\\',j); if (i >= 0) { match = unlocked.innerHTML.substring(i,j); - pre = unlocked.innerHTML.substring(0,i); - post = unlocked.innerHTML.substring(j); - - sym = lookup_tex(match); - if (typeof sym != "undefined") { - len1 = unlocked.innerText.length; - unlocked.innerHTML = pre + sym + post; - len2 = unlocked.innerText.length; - restoreSelection(len2 - len1); - return suppressdefault(e,true); + sym = unescape_html(lookup_tex(match)); + if (sym != "undefined") { + if (window.getSelection) { // non IE + savedRange.setStart(savedsc,savedso - (j-i)); + savedRange.deleteContents(); + savedRange.insertNode(document.createTextNode(sym)); + savedsc.parentNode.normalize(); + if (savedRange.collapsed) { // Mozilla + savedRange.setEnd(savedsc,savedRange.endOffset + sym.length); + } + savedRange.collapse(false); + } else { + savedRange.moveStart(i-j); + savedRange.text(sym); + savedRange.collapse(false); + } + restoreSelection(savedRange); + return suppressdefault(e,true); } else { // restoreSelection(0); @@ -173,13 +194,24 @@ function keypress(e) } } +var logtxt = ""; + function debug(txt) { // internet explorer (v.9) doesn't work with innerHTML // but google chrome's innerText is, in a sense, "write only" // what should we do? // logarea.innerText = txt + "\n" + logarea.innerText; - logarea.innerHTML = txt; // + "\n" + logarea.innerText; + logtxt = logtxt + "\n" + txt; +} + +function showLog() { + logWin = window.open( "", "Matita Log", + "width=600,height=450,status,scrollbars,resizable,screenX=20,screenY=40,left=20,top=40"); + logWin.document.write('Matita Log' + ''); + logWin.document.write(''); + logWin.document.close(); } function listhd(l) @@ -543,10 +575,18 @@ function gotoTop() debug("goto top failed"); } else - unlocked.innerHTML = locked.innerHTML + unlocked.innerHTML - locked.innerHTML = "" - hideSequent(); - unlocked.scrollIntoView(true); + statements = listnil(); + /* + lockedlen = locked.innerHTML.length - statementlen; + statement = locked.innerHTML.substr(lockedlen, statementlen); + locked.innerHTML = locked.innerHTML.substr(0,lockedlen); + unlocked.innerHTML = statement + unlocked.innerHTML; + */ + unlocked.innerHTML = lockedbackup + unlocked.innerHTML; + lockedbackup = ""; + locked.innerHTML = lockedbackup; + hideSequent(); + unlocked.scrollIntoView(true); } else { debug("goto top failed"); } @@ -665,9 +705,10 @@ function retrieveFile(thefile) callServer("open",processor,"file=" + escape(thefile)); } -function showLibrary(title,callback) +function showLibrary(title,callback,reloadDialog) { - var req = null; + var req = null; + dialogBox.reload = reloadDialog; // pause(); if (window.XMLHttpRequest) { @@ -696,7 +737,7 @@ function showLibrary(title,callback) if(stat == 200) { debug(req.responseText); - showDialog("

" + title + "

",req.responseText, callback); + showDialog("

" + title + "

",req.responseText, callback); } } }; @@ -739,7 +780,7 @@ function uploadOK() function openDialog() { callback = function (fname) { retrieveFile(fname); }; - showLibrary("Open file", callback); + showLibrary("Open file", callback, openDialog); } function saveDialog() @@ -751,7 +792,7 @@ function saveDialog() (unlocked.innerHTML.html_to_matita()).sescape(), false,saveDialog); }; - showLibrary("Save file as", callback); + showLibrary("Save file as", callback, saveDialog); } function newDialog() @@ -760,7 +801,7 @@ function newDialog() dialogBox.style.display = "none"; saveFile(fname,"","",false,newDialog,true); }; - showLibrary("Create new file", callback); + showLibrary("Create new file", callback, newDialog); } @@ -802,6 +843,30 @@ function saveFile(fname,lockedtxt,unlockedtxt,force,reloadDialog,reloadFile) else { debug("no file selected"); } } +function createDir() { + abortDialog(); + dirname = prompt("New directory name:\ncic:/matita/","newdir"); + if (dirname != null) { + if (dirname.substr(0,1) != "/") + dirname = "/" + dirname; + processor = function(xml) { + if (is_defined(xml)) { + if (xml.childNodes[0].textContent != "ok") { + alert("An error occurred :-("); + } + } else { + alert("An error occurred :-("); + } + dialogBox.reload(); + }; + pause(); + callServer("save",processor,"file=" + escape(dirname) + + "&locked=&unlocked=&force=false&dir=true"); + } else { + dialogBox.reload(); + } +} + function commitAll() { processor = function(xml) { @@ -816,6 +881,20 @@ function commitAll() callServer("commit",processor); } +function updateAll() +{ + processor = function(xml) { + if (is_defined(xml)) { + debug("update succeeded(?)"); + } else { + debug("update failed!"); + } + resume(); + }; + pause(); + callServer("update",processor); +} + var goalcell; function hideSequent() {