diff --git a/lib/ice-coder.js b/lib/ice-coder.js index c007d4a..5ef83c8 100644 --- a/lib/ice-coder.js +++ b/lib/ice-coder.js @@ -140,6 +140,16 @@ var ICEcoder = { if (top.ICEcoder.openSeconds % 300 == 0) { top.ICEcoder.filesFrame.contentWindow.frames['pingActive'].location.href = "lib/session-active-ping.php"; } + if (top.ICEcoder.openSeconds % 1 == 0) { + // Get new data + fetch('lib/indexer.php') + .then(function(response) { + // Convert to JSON + return response.json(); + }).then(function(data) { + top.ICEcoder.indexData = data; + }); + } },1000); // ICEcoder is ready to start using @@ -626,10 +636,56 @@ var ICEcoder = { }, // On mouse down - cMonMouseDown: function(thisCM,cMinstance) { + cMonMouseDown: function(thisCM,cMinstance,evt) { top.ICEcoder.mouseDownInCM = "editor"; }, + // On context menu + cMonContextMenu: function(thisCM,cMinstance,evt) { + // Set cursor + var currCoords = thisCM.coordsChar({left: evt.pageX, top: evt.pageY}); + thisCM.setCursor(currCoords); + + // If CTRL key down + if (evt.ctrlKey) { + setTimeout(function() { + // Get cM and word under mouse pointer + var cM = thisCM; + var word = (cM.getRange(cM.findWordAt(cM.getCursor()).anchor, cM.findWordAt(cM.getCursor()).head)); + + // Get result and number of results for word in functions and classes from index JSON object list + result = null; + numResults = 0; + for(i in top.ICEcoder.indexData.functions) { + if (i === word) { + result = top.ICEcoder.indexData.functions[i]; + numResults++; + } + }; + for(i in top.ICEcoder.indexData.classes) { + if (i === word) { + result = top.ICEcoder.indexData.classes[i]; + numResults++; + } + }; + + // If we have a single result, we can jump to where it's defined + if (numResults === 1) { + top.ICEcoder.openFile(result.fullPath.replace(top.docRoot,"")); + top.ICEcoder.goFindAfterOpenInt = setInterval(function(){ + if (top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1] == result.fullPath.replace(top.docRoot,"") && !top.ICEcoder.loadingFile) { + cM = top.ICEcoder.getcMInstance(); + cM.setSelection({line: result.range.from.line, ch: result.range.from.ch}, {line: result.range.to.line, ch: result.range.to.ch}); + clearInterval(top.ICEcoder.goFindAfterOpenInt); + } + },20); + } + + top.ICEcoder.mouseDownInCM = "editor"; + },0); + } + }, + // On drag over cMonDragOver: function(thisCM,evt,cMinstance) { top.ICEcoder.setDragCursor(evt,'editor'); @@ -660,6 +716,43 @@ var ICEcoder = { } }, + // Show Function & class params tooltip + functionClassParamsTooltip: function(e, area) { + if (top.ICEcoder.indexData) { + var i; + // Get cM instance, and the word under mouse pointer + var cM = top.ICEcoder.getcMInstance(); + var coordsChar = cM.coordsChar({left: top.ICEcoder.mouseX-top.ICEcoder.maxFilesW, top: top.ICEcoder.mouseY-72}); + var word = (cM.getRange(cM.findWordAt(coordsChar).anchor, cM.findWordAt(coordsChar).head)); + + // Get result and number of results for word in functions and classes from index JSON object list + var result = null; + var numResults = 0; + for(i in top.ICEcoder.indexData.functions) { + if (i === word) { + result = top.ICEcoder.indexData.functions[i]; + numResults++; + } + }; + for(i in top.ICEcoder.indexData.classes) { + if (i === word) { + result = top.ICEcoder.indexData.classes[i]; + numResults++; + } + }; + // If we have a single result, and that result is for another file we can display the tooltip + if (numResults === 1 && result.fullPath.replace(top.docRoot,"") !== top.ICEcoder.openFiles[top.ICEcoder.selectedTab-1]) { + get('tooltip').style.display = "block"; + get('tooltip').style.left = (top.ICEcoder.mouseX-top.ICEcoder.maxFilesW+10) + "px"; + get('tooltip').style.top = (top.ICEcoder.mouseY-30) + "px"; + get('tooltip').innerHTML = result.params; + // Else hide it + } else { + get('tooltip').style.display = "none"; + } + } + }, + // Update diffs shown to the user in each pane updateDiffs: function() { var cM, cMdiff, mainText, diffText, sm, opcodes, cMmarks, cMdiffMarks, amt, sDiffs;