Alterations to work with dynamic CM instances

Various functions updates to work with dynamically generated CM instances
New variables added to track the CM instance refs & next avail number
CTRL+G now focuses on go to line box
A few lines of now useless code removed
This commit is contained in:
Matt Pass
2012-02-09 07:53:59 +00:00
parent 3202cfe0dd
commit 82c350444a

View File

@@ -15,6 +15,8 @@ var ICEcoder = {
delKeyDown: false, // Indicates if DEL keydown
canSwitchTabs: true, // Stops switching of tabs when trying to close
openFiles: [], // Array of open file URLs
cMInstances: [], // List of CodeMirror instance no's
nextcMInstance: 1, // Next available CodeMirror instance no
selectedFiles: [], // Array of selected files
findMode: false, // States if we're in find/replace mode
lockedNav: false, // Nav is locked or not
@@ -34,7 +36,6 @@ var ICEcoder = {
// Set layout & the nest location
ICEcoder.setLayout();
ICEcoder.getNestLocation('yes');
},
// Set out our layout according to the browser size
@@ -196,6 +197,11 @@ var ICEcoder = {
top.document.getElementById('find').focus();
return false;
// CTRL+G (Go to Line)
} else if(key==71 && top.ICEcoder.ctrlKeyDown==true) {
top.document.getElementById('goToLineNo').focus();
return false;
// CTRL+S (Save)
} else if(key==83 && top.ICEcoder.ctrlKeyDown==true) {
top.ICEcoder.saveFile();
@@ -261,9 +267,9 @@ var ICEcoder = {
// Switch mode
ICEcoder.switchMode();
// Set all 10 cM instances to be hidden, then make our selected instance visable
for (var i=1;i<=10;i++) {
ICEcoder.content.contentWindow['cM'+i].setOption('theme','icecoder hidden');
// Set all cM instances to be hidden, then make our selected instance visable
for (var i=0;i<ICEcoder.cMInstances.length;i++) {
ICEcoder.content.contentWindow['cM'+ICEcoder.cMInstances[i]].setOption('theme','icecoder hidden');
}
cM.setOption('theme','icecoder visible');
@@ -288,14 +294,21 @@ var ICEcoder = {
newTab: function() {
var cM;
ICEcoder.cMInstances.push(ICEcoder.nextcMInstance);
ICEcoder.selectedTab = ICEcoder.cMInstances.length;
ICEcoder.content.contentWindow.createNewCMInstance(ICEcoder.nextcMInstance);
ICEcoder.thisFileFolderType='file';
ICEcoder.thisFileFolderLink=shortURLStarts+'/[NEW]';
ICEcoder.openFile();
cM = ICEcoder.getcMInstance('new');
cM.setValue('');
cM.clearHistory();
ICEcoder.switchTab(ICEcoder.openFiles.length);
ICEcoder.content.style.visibility='visible';
cM.setLineClass(ICEcoder['cMActiveLine'+ICEcoder.selectedTab], null);
ICEcoder['cMActiveLine'+ICEcoder.selectedTab] = cM.setLineClass(0, "cm-s-activeLine");
ICEcoder.nextcMInstance++;
},
// Create a new tab for a file
@@ -413,6 +426,7 @@ var ICEcoder = {
// Close the tab upon request
closeTab: function(closeTabNum) {
var cM, okToRemove;
cM = ICEcoder.getcMInstance();
@@ -422,7 +436,7 @@ var ICEcoder = {
}
if (okToRemove) {
// recursively copy over all tab data from the tab to the right, if there is one
// recursively copy over all tabs & data from the tab to the right, if there is one
for (var i=closeTabNum;i<ICEcoder.openFiles.length;i++) {
ICEcoder.tD.getElementById('tab'+i).innerHTML = ICEcoder.tD.getElementById('tab'+(i+1)).innerHTML;
ICEcoder.openFiles[i-1] = ICEcoder.openFiles[i];
@@ -431,7 +445,12 @@ var ICEcoder = {
ICEcoder.tD.getElementById('tab'+i).innerHTML = ICEcoder.tD.getElementById('tab'+i).innerHTML.replace(("closeTab("+(i+1)+")"),"closeTab("+i+")");
}
// clear the rightmost tab (or only one left in a 1 tab scenario)
// hide the instance we're closing by setting the hide class, clear the value & remove from the array
ICEcoder.content.contentWindow['cM'+top.ICEcoder.cMInstances[closeTabNum-1]].setOption('theme','icecoder hidden');
ICEcoder.content.contentWindow['cM'+top.ICEcoder.cMInstances[closeTabNum-1]].setValue('');
top.ICEcoder.cMInstances.splice(closeTabNum-1,1);
// clear the rightmost tab (or only one left in a 1 tab scenario) & remove from the array
ICEcoder.tD.getElementById('tab'+ICEcoder.openFiles.length).style.display = "none";
ICEcoder.tD.getElementById('tab'+ICEcoder.openFiles.length).innerHTML = "";
ICEcoder.openFiles.pop();
@@ -440,12 +459,8 @@ var ICEcoder = {
ICEcoder.openFiles.length>0 ? ICEcoder.selectedTab-=1 : ICEcoder.selectedTab = 0;
if (ICEcoder.openFiles.length>0 && ICEcoder.selectedTab==0) {ICEcoder.selectedTab=1};
// clear & hide the code textarea if we have no tabs open
// hide the content area if we have no tabs open
if (ICEcoder.openFiles.length==0) {
// clear the value & HTML of the code textarea and also hide it
cM = ICEcoder.getcMInstance();
cM.setValue('');
cM.clearHistory();
ICEcoder.tD.getElementById('content').style.visibility = "hidden";
} else {
// Switch the mode & the tab
@@ -826,11 +841,11 @@ var ICEcoder = {
var cM;
if (newTab=="new") {
cM = top.ICEcoder.content.contentWindow['cM'+ICEcoder.openFiles.length];
cM = top.ICEcoder.content.contentWindow['cM'+ICEcoder.cMInstances[ICEcoder.selectedTab-1]];
} else if (ICEcoder.openFiles.length==0) {
cM = top.ICEcoder.content.contentWindow['cM1'];
} else {
cM = top.ICEcoder.content.contentWindow['cM'+ICEcoder.selectedTab];
cM = top.ICEcoder.content.contentWindow['cM'+ICEcoder.cMInstances[ICEcoder.selectedTab-1]];
}
return cM;
},