From 13e1b933e1e1a06bdbf61a269f30a96bb35d06ba Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Mon, 10 Jun 2013 09:49:54 +0100 Subject: [PATCH] Only action on fileName and dontAsk param We can only set the CaretLocType if we have a fileName to inspect, an edge case brought up by unit testing Extra param added to closeTab to allow us to not ask the user for close permission on unsaved files --- lib/ice-coder.js | 20 +++++++++++--------- lib/ice-coder.min.js | 12 ++++++------ 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/ice-coder.js b/lib/ice-coder.js index e7c9e09..a6f9db8 100644 --- a/lib/ice-coder.js +++ b/lib/ice-coder.js @@ -1204,13 +1204,15 @@ var ICEcoder = { else if (caretLocType=="Unknown") {caretLocType = "Content"}; fileName = ICEcoder.openFiles[ICEcoder.selectedTab-1]; - if (fileName.indexOf(".js")>0) {caretLocType="JavaScript"} - else if (fileName.indexOf(".coffee")>0) {caretLocType="CoffeeScript"} - else if (fileName.indexOf(".py")>0) {caretLocType="Python"} - else if (fileName.indexOf(".rb")>0) {caretLocType="Ruby"} - else if (fileName.indexOf(".css")>0) {caretLocType="CSS"} - else if (fileName.indexOf(".less")>0) {caretLocType="LESS"} - else if (fileName.indexOf(".md")>0) {caretLocType="Markdown"}; + if (fileName) { + if (fileName.indexOf(".js")>0) {caretLocType="JavaScript"} + else if (fileName.indexOf(".coffee")>0) {caretLocType="CoffeeScript"} + else if (fileName.indexOf(".py")>0) {caretLocType="Python"} + else if (fileName.indexOf(".rb")>0) {caretLocType="Ruby"} + else if (fileName.indexOf(".css")>0) {caretLocType="CSS"} + else if (fileName.indexOf(".less")>0) {caretLocType="LESS"} + else if (fileName.indexOf(".md")>0) {caretLocType="Markdown"}; + } ICEcoder.caretLocType = caretLocType; }, @@ -1880,12 +1882,12 @@ var ICEcoder = { }, // Close the tab upon request - closeTab: function(closeTabNum, dontSetPV) { + closeTab: function(closeTabNum, dontSetPV, dontAsk) { var cM, okToRemove, closeFileName; cM = ICEcoder.getcMInstance(); okToRemove = true; - if (ICEcoder.changedContent[closeTabNum-1]==1) { + if (!dontAsk && ICEcoder.changedContent[closeTabNum-1]==1) { okToRemove = top.ICEcoder.ask('You have made changes.\n\nAre you sure you want to close without saving?'); } diff --git a/lib/ice-coder.min.js b/lib/ice-coder.min.js index 5d7accf..1775847 100644 --- a/lib/ice-coder.min.js +++ b/lib/ice-coder.min.js @@ -52,11 +52,11 @@ ICEcoder.nestDisplay.innerHTML+="")}}},updateNestingIndicator:function(){var a,b,c;a=ICEcoder.getcMInstance();b=!0;c=ICEcoder.openFiles[ICEcoder.selectedTab-1];a&&(c&&-1==["js","coffee","css","less"].indexOf(c.split(".")[1]))&&(b="error"!=a.getTokenAt({line:a.lineCount(), ch:a.lineInfo(a.lineCount()-1).text.length}).className?!0:!1);ICEcoder.nestValid.style.background=b?"#0b0":"#f00";ICEcoder.nestValid.title=b?"Nesting OK":"Nesting Broken"},getCaretPosition:function(){var a,b,c,d;a=ICEcoder.getcMInstance();b=a.getValue();c=a.getCursor().line;a=a.getCursor().ch;for(var e=d=0;ea.lastIndexOf("\x3c/script>")&&"Unknown"==b?b="JavaScript":a.lastIndexOf("a.lastIndexOf("?>")&&"Unknown"==b?b="PHP":a.lastIndexOf("<%")>a.lastIndexOf("%>")&&"Unknown"==b?b="Ruby":a.lastIndexOf("<")>a.lastIndexOf(">")&&"Unknown"==b?b="HTML":"Unknown"==b&&(b="Content");a=ICEcoder.openFiles[ICEcoder.selectedTab-1];0c||19c||40c||36c||123=a||10<=a))&&top.ICEcoder.mouseX>parseInt(top.ICEcoder.files.style.width,10))top.ICEcoder.tabDragMouseX=top.ICEcoder.mouseX-parseInt(top.ICEcoder.files.style.width,10)-top.ICEcoder.tabDragMouseXStart,top.ICEcoder.tabDragMove();if(top.ICEcoder.ready&&(a=window.innerWidth?window.innerHeight:document.body.clientHeight,top.ICEcoder.mouseDown|| -(top.ICEcoder.draggingFilesW=!1),a=!ICEcoder.draggingTab&&(top.ICEcoder.mouseX>top.ICEcoder.filesW-7&&top.ICEcoder.mouseXa.lastIndexOf("\x3c/script>")&&"Unknown"==b?b="JavaScript":a.lastIndexOf("a.lastIndexOf("?>")&&"Unknown"==b?b="PHP":a.lastIndexOf("<%")>a.lastIndexOf("%>")&&"Unknown"==b?b="Ruby":a.lastIndexOf("<")>a.lastIndexOf(">")&&"Unknown"==b?b="HTML":"Unknown"==b&&(b="Content");(a=ICEcoder.openFiles[ICEcoder.selectedTab-1])&&(0c||19c||40c||36c||123=a||10<=a))&&top.ICEcoder.mouseX>parseInt(top.ICEcoder.files.style.width,10))top.ICEcoder.tabDragMouseX=top.ICEcoder.mouseX-parseInt(top.ICEcoder.files.style.width,10)-top.ICEcoder.tabDragMouseXStart,top.ICEcoder.tabDragMove();if(top.ICEcoder.ready&&(a=window.innerWidth?window.innerHeight:document.body.clientHeight, +top.ICEcoder.mouseDown||(top.ICEcoder.draggingFilesW=!1),a=!ICEcoder.draggingTab&&(top.ICEcoder.mouseX>top.ICEcoder.filesW-7&&top.ICEcoder.mouseXd.index+d[0].length;);(b=top.get("content").contentWindow.document.getElementById("cssColor"))&&b.parentNode.removeChild(b); top.ICEcoder.codeAssist&&"CSS"==top.ICEcoder.caretLocType&&(b=top.document.createElement("div"),b.id="cssColor",b.style.position="absolute",b.style.display="block",b.style.width=b.style.height="20px",b.style.zIndex="1000",b.style.background=d?d[0]:"",b.style.cursor="pointer",b.onclick=function(){top.ICEcoder.showColorPicker(d[0])},""==b.style.backgroundColor&&(b.style.display="none"),top.get("header").appendChild(b),a.addWidget(a.getCursor(),top.get("cssColor"),!0))},showColorPicker:function(a){top.get("blackMask").style.visibility= "visible";top.get("mediaContainer").innerHTML='



'; @@ -87,7 +87,7 @@ ICEcoder.setLayout();ICEcoder.thisFileFolderType="file";ICEcoder.thisFileFolderL top.ICEcoder.selectedTab-1?top.ICEcoder.selectedTab-1:top.ICEcoder.openFiles.length,"noFocus")},renameTab:function(a,b){var c;top.ICEcoder.openFiles[a-1]=b;c=top.ICEcoder.openFiles[a-1];top.get("tab"+a).innerHTML='
'+ c.slice(c.lastIndexOf("/")).replace(/\//,"");top.get("tab"+a).title="/"+top.ICEcoder.openFiles[a-1].replace(/\//,"")},redoTabHighlight:function(a){for(var b,c,d=1;d<=ICEcoder.changedContent.length;d++){document.getElementById("tab"+d).childNodes[0]&&(document.getElementById("tab"+d).childNodes[0].childNodes[0].style.backgroundColor=1==ICEcoder.changedContent[d-1]?"#b00":"transparent");b=d==a?top.ICEcoder.tabFGselected:top.ICEcoder.tabFGnormalTab;if("undefined"!=typeof top.ICEcoder.openFiles[d-1]&& "/[NEW]"!=top.ICEcoder.openFiles[d-1]&&(c=top.ICEcoder.filesFrame.contentWindow.document.getElementById(top.ICEcoder.openFiles[d-1].replace(/\//g,"|"))))c.style.backgroundColor=d==a?top.ICEcoder.tabBGcurrent:top.ICEcoder.tabBGopen,c.style.color=d==a?top.ICEcoder.tabFGcurrent:top.ICEcoder.tabFGopenFile;document.getElementById("tab"+d).style.color=b;document.getElementById("tab"+d).style.background=d==a?top.ICEcoder.tabBGcurrent:top.ICEcoder.tabBGopen}top.ICEcoder.fMIconVis("fMSave",1==ICEcoder.changedContent[a- -1]?1:0.3)},closeTab:function(a,b){var c;ICEcoder.getcMInstance();c=!0;1==ICEcoder.changedContent[a-1]&&(c=top.ICEcoder.ask("You have made changes.\n\nAre you sure you want to close without saving?"));if(c){c=top.ICEcoder.openFiles[a-1];for(var d=a;d