mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-04 15:54:00 +01:00
Combo moveLine function & code condensing
moveLine(dir) func added as combo of moveLineUp and moveLineDown funcs Move initialising vars to start of func Used indexOf to check array for shortURL instead of for loop in 2 places Improving/removing a few comments Condensed code to now check if selectedFiles is empty or contains right clicked file and also condensed code to use indexOf on array instead of for loop Don't need foundFile because of this condensing Using ICEcoder ref for filesFrame and also showing dropdown higher up (next to mouse pointer/inline with file/folder name)
This commit is contained in:
80
lib/coder.js
80
lib/coder.js
@@ -204,12 +204,12 @@ var ICEcoder = {
|
||||
|
||||
// CTRL+up arrow (Move line up)
|
||||
} else if(key==38 && top.ICEcoder.ctrlKeyDown==true && area=="content") {
|
||||
top.ICEcoder.moveLineUp();
|
||||
top.ICEcoder.moveLine('up');
|
||||
return false;
|
||||
|
||||
// CTRL+down arrow (Move line down)
|
||||
} else if(key==40 && top.ICEcoder.ctrlKeyDown==true && area=="content") {
|
||||
top.ICEcoder.moveLineDown();
|
||||
top.ICEcoder.moveLine('down');
|
||||
return false;
|
||||
|
||||
// CTRL+numeric plus (New tab)
|
||||
@@ -717,6 +717,8 @@ var ICEcoder = {
|
||||
|
||||
// Open a file on demand
|
||||
openFile: function(fileLink) {
|
||||
var shortURL, canOpenFile;
|
||||
|
||||
if (fileLink) {
|
||||
top.ICEcoder.thisFileFolderLink=fileLink;
|
||||
top.ICEcoder.thisFileFolderType="file";
|
||||
@@ -724,26 +726,21 @@ var ICEcoder = {
|
||||
if (top.ICEcoder.isOpen(top.ICEcoder.thisFileFolderLink)!==false) {
|
||||
top.ICEcoder.switchTab(top.ICEcoder.isOpen(top.ICEcoder.thisFileFolderLink)+1);
|
||||
} else if (top.ICEcoder.thisFileFolderLink!="" && top.ICEcoder.thisFileFolderType=="file") {
|
||||
var shortURL, canOpenFile;
|
||||
|
||||
// work out a shortened URL for the file
|
||||
shortURL = top.ICEcoder.thisFileFolderLink.replace(/\|/g,"/");
|
||||
|
||||
// No reason why we can't open a file (so far)
|
||||
canOpenFile = true;
|
||||
// Limit to 10 files open at a time
|
||||
if (top.ICEcoder.openFiles.length<10) {
|
||||
// check if we've already got it in our array
|
||||
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
|
||||
if (top.ICEcoder.openFiles[i]==shortURL && shortURL!="/[NEW]") {
|
||||
// we have, so don't bother opening again
|
||||
canOpenFile = false;
|
||||
// instead, switch to that tab
|
||||
top.ICEcoder.switchTab(i+1);
|
||||
}
|
||||
if (top.ICEcoder.openFiles.indexOf(shortURL)>-1 && shortURL!="/[NEW]") {
|
||||
// we have, so instead, switch to that tab
|
||||
canOpenFile = false;
|
||||
top.ICEcoder.switchTab(i+1);
|
||||
}
|
||||
} else {
|
||||
// show a message because we have 10 files open
|
||||
// show a message because we have 10 files open
|
||||
top.ICEcoder.message('Sorry, you can only have 10 files open at a time!');
|
||||
canOpenFile = false;
|
||||
}
|
||||
@@ -753,7 +750,6 @@ var ICEcoder = {
|
||||
top.ICEcoder.shortURL = shortURL;
|
||||
|
||||
if (shortURL!="/[NEW]") {
|
||||
// replace forward slashes with pipes so it get be placed in a querystring
|
||||
top.ICEcoder.thisFileFolderLink = top.ICEcoder.thisFileFolderLink.replace(/\//g,"|");
|
||||
top.ICEcoder.serverQueue("add","lib/file-control.php?action=load&file="+top.ICEcoder.thisFileFolderLink);
|
||||
top.ICEcoder.serverMessage('<b>Opening File</b><br>'+top.ICEcoder.shortURL);
|
||||
@@ -770,7 +766,6 @@ var ICEcoder = {
|
||||
var saveType;
|
||||
|
||||
saveType = saveAs ? "saveAs" : "save";
|
||||
|
||||
top.ICEcoder.serverQueue("add","lib/file-control.php?action=save&file="+ICEcoder.openFiles[ICEcoder.selectedTab-1].replace(top.iceRoot,"").replace(/\//g,"|")+"&fileMDT="+ICEcoder.openFileMDTs[ICEcoder.selectedTab-1]+"&saveType="+saveType);
|
||||
top.ICEcoder.serverMessage('<b>Saving</b><br>'+ICEcoder.openFiles[ICEcoder.selectedTab-1].replace(top.iceRoot,""));
|
||||
},
|
||||
@@ -789,13 +784,11 @@ var ICEcoder = {
|
||||
newName = top.ICEcoder.getInput('Please enter the new name for',shortURL);
|
||||
}
|
||||
if (newName) {
|
||||
for (var i=0;i<top.ICEcoder.openFiles.length;i++) {
|
||||
if(top.ICEcoder.openFiles[i]==shortURL.replace(/\|/g,"/")) {
|
||||
// rename array item and the tab
|
||||
top.ICEcoder.openFiles[i] = newName;
|
||||
closeTabLink = '<a nohref onClick="top.ICEcoder.files.contentWindow.closeTab('+(i+1)+')"><img src="images/nav-close.gif" id="closeTabButton'+(i+1)+'" class="closeTab" onMouseOver="prevBG=this.style.backgroundColor;this.style.backgroundColor=\'#333\'" onMouseOut="this.style.backgroundColor=prevBG"></a>';
|
||||
top.document.getElementById('tab'+(i+1)).innerHTML = top.ICEcoder.openFiles[i] + " " + closeTabLink;
|
||||
}
|
||||
if(top.ICEcoder.openFiles.indexOf(shortURL.replace(/\|/g,"/"))>-1) {
|
||||
// rename array item and the tab
|
||||
top.ICEcoder.openFiles[i] = newName;
|
||||
closeTabLink = '<a nohref onClick="top.ICEcoder.files.contentWindow.closeTab('+(i+1)+')"><img src="images/nav-close.gif" id="closeTabButton'+(i+1)+'" class="closeTab" onMouseOver="prevBG=this.style.backgroundColor;this.style.backgroundColor=\'#333\'" onMouseOut="this.style.backgroundColor=prevBG"></a>';
|
||||
top.document.getElementById('tab'+(i+1)).innerHTML = top.ICEcoder.openFiles[i] + " " + closeTabLink;
|
||||
}
|
||||
top.ICEcoder.serverQueue("add","lib/file-control.php?action=rename&file="+newName+"&oldFileName="+oldName.replace(/\|/g,"/"));
|
||||
top.ICEcoder.serverMessage('<b>Renaming to</b><br>'+newName);
|
||||
@@ -823,15 +816,12 @@ var ICEcoder = {
|
||||
|
||||
// Show menu on right clicking in file manager
|
||||
showMenu: function() {
|
||||
var menuType, folderMenuItems, foundFile;
|
||||
var menuType, folderMenuItems;
|
||||
|
||||
if (top.ICEcoder.selectedFiles.length == 0) {top.ICEcoder.selectFileFolder()};
|
||||
|
||||
foundFile=false;
|
||||
for (var i=0;i<=top.ICEcoder.selectedFiles.length-1;i++) {
|
||||
if (top.ICEcoder.rightClickedFile==top.ICEcoder.selectedFiles[i].replace(/\|/g,"/")) {foundFile=true};
|
||||
if ( top.ICEcoder.selectedFiles.length == 0 ||
|
||||
top.ICEcoder.selectedFiles.indexOf(top.ICEcoder.rightClickedFile.replace(/\//g,"|")) == -1) {
|
||||
top.ICEcoder.selectFileFolder();
|
||||
}
|
||||
if (!foundFile) {top.ICEcoder.selectFileFolder()};
|
||||
|
||||
if ("undefined" != typeof top.ICEcoder.thisFileFolderLink && top.ICEcoder.thisFileFolderLink!="") {
|
||||
menuType = top.ICEcoder.selectedFiles[0].indexOf(".")>-1 ? "file" : "folder";
|
||||
@@ -840,7 +830,7 @@ var ICEcoder = {
|
||||
singleFileMenuItems.style.display = top.ICEcoder.selectedFiles.length > 1 ? "none" : "block";
|
||||
document.getElementById('fileMenu').style.display = "inline-block";
|
||||
document.getElementById('fileMenu').style.left = (top.ICEcoder.mouseX+20) + "px";
|
||||
document.getElementById('fileMenu').style.top = (top.ICEcoder.mouseY-top.document.getElementById('filesFrame').contentWindow.document.body.scrollTop+10) + "px";
|
||||
document.getElementById('fileMenu').style.top = (top.ICEcoder.mouseY-top.ICEcoder.filesFrame.contentWindow.document.body.scrollTop-10) + "px";
|
||||
}
|
||||
return false;
|
||||
},
|
||||
@@ -850,31 +840,19 @@ var ICEcoder = {
|
||||
elem.style.visibility = doVis=="show" ? 'visible' : 'hidden';
|
||||
},
|
||||
|
||||
// Move current line upwards
|
||||
moveLineUp: function() {
|
||||
var cM, line, prevLine;
|
||||
// Move current line up/down
|
||||
moveLine: function(dir) {
|
||||
var cM, line, swapLineNo, swapLine;
|
||||
|
||||
cM = top.ICEcoder.getcMInstance();
|
||||
line = cM.getCursor().line;
|
||||
if (line>0) {
|
||||
prevLine = cM.getLine(line-1);
|
||||
cM.setLine(line-1,cM.getLine(line));
|
||||
cM.setLine(line,prevLine);
|
||||
ICEcoder.highlightLine(line-1);
|
||||
}
|
||||
},
|
||||
|
||||
// Move current line downwards
|
||||
moveLineDown: function() {
|
||||
var cM, line, nextLine;
|
||||
|
||||
cM = top.ICEcoder.getcMInstance();
|
||||
line = cM.getCursor().line;
|
||||
if (line<cM.lineCount()-1) {
|
||||
nextLine = cM.getLine(line+1);
|
||||
cM.setLine(line+1,cM.getLine(line));
|
||||
cM.setLine(line,nextLine);
|
||||
ICEcoder.highlightLine(line+1);
|
||||
if (dir=="up" && line>0) {swapLineNo = line-1}
|
||||
if (dir=="down" && line<cM.lineCount()-1) {swapLineNo = line+1}
|
||||
if (!isNaN(swapLineNo)) {
|
||||
swapLine = cM.getLine(swapLineNo);
|
||||
cM.setLine(swapLineNo,cM.getLine(line));
|
||||
cM.setLine(line,swapLine);
|
||||
ICEcoder.highlightLine(swapLineNo);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user