22 var CodeEditor = CodeEditor || {};
24 if (typeof DesktopContent ==
'undefined')
25 throw(
'ERROR: DesktopContent is undefined! Must include DesktopWindowContentCode.js before CodeEditor.js');
28 CodeEditor.MENU_PRIMARY_COLOR =
"rgb(220, 187, 165)";
29 CodeEditor.MENU_SECONDARY_COLOR =
"rgb(130, 51, 51)";
42 function htmlOpen(tag,attObj,innerHTML,doCloseTag)
45 var attKeys = Object.keys(attObj);
46 str +=
"<" + tag +
" ";
47 for(var i=0;i<attKeys.length;++i)
48 str +=
" " + attKeys[i] +
"='" +
49 attObj[attKeys[i]] +
"' ";
51 if(innerHTML) str += innerHTML;
53 str +=
"</" + tag +
">";
59 function htmlClearDiv()
61 return "<div id='clearDiv'></div>";
68 if (!Element.prototype.scrollIntoViewIfNeeded) {
69 Element.prototype.scrollIntoViewIfNeeded =
function (centerIfNeeded) {
70 centerIfNeeded = arguments.length === 0 ?
true : !!centerIfNeeded;
72 var parent = this.parentNode,
73 tdParent = parent.parentNode,
74 editorParent = parent.parentNode.parentNode.parentNode.parentNode.parentNode,
75 parentComputedStyle = window.getComputedStyle(parent, null),
76 parentBorderTopWidth = parseInt(parentComputedStyle.getPropertyValue(
'border-top-width')),
77 parentBorderLeftWidth = parseInt(parentComputedStyle.getPropertyValue(
'border-left-width')),
78 overTop = this.offsetTop - tdParent.offsetTop < editorParent.scrollTop,
79 overBottom = (
this.offsetTop - tdParent.offsetTop +
this.clientHeight - parentBorderTopWidth) > (editorParent.scrollTop + editorParent.clientHeight),
80 overLeft = this.offsetLeft - tdParent.offsetLeft < editorParent.scrollLeft,
81 overRight = (
this.offsetLeft + tdParent.offsetLeft +
this.clientWidth - parentBorderLeftWidth) > (editorParent.scrollLeft + editorParent.clientWidth),
82 alignWithTop = overTop && !overBottom;
84 if ((overTop || overBottom) && centerIfNeeded) {
85 editorParent.scrollTop = this.offsetTop - tdParent.offsetTop - editorParent.clientHeight / 2 - parentBorderTopWidth + this.clientHeight / 2;
89 if ((overLeft || overRight) && centerIfNeeded) {
90 editorParent.scrollLeft = this.offsetLeft + tdParent.offsetLeft - editorParent.clientWidth / 2 - parentBorderLeftWidth + this.clientWidth / 2;
94 if ((overTop || overBottom || overLeft || overRight) && !centerIfNeeded) {
95 this.scrollIntoView(alignWithTop);
103 CodeEditor.showTooltip =
function(alwaysShow)
105 DesktopContent.tooltip(
106 (alwaysShow?
"ALWAYS":
"Code Editor"),
107 "Welcome to the Code Editor user interface. "+
108 "Edit your code, save it, and compile!\n\n" +
109 "Hover your mouse over the icons and buttons to see what they do. " +
110 "If you hover your mouse over the filename additional icons will appear for changing the filename, downloading, uploading, undo, and redo. The buttons in the top corners are described below followed by hot-keys:\n\n" +
112 "<b>Open a file:</b>\n<INDENT>Use the folder icon in the top-left to navigate to a code file to edit.</INDENT>\n" +
113 "<b>Toggle view:</b>\n<INDENT>Use the split-pane icon in the top-right to toggle another code editor in the same window.</INDENT>\n" +
114 "<b>Save:</b>\n<INDENT>Use the save icon in the top-left to save your changes.</INDENT>\n" +
115 "<b>Compile:</b>\n<INDENT>Use the Incremmental Build or Clean Build icons in the top-right.</INDENT>\n" +
117 "<b>Global Hot Keys:</b>\n<INDENT>" +
119 "<table border=0 cellspacing=0 cellpadding=0 style='border: 1px solid grey;'>" +
120 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> " +
121 "Ctrl + B </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Incremental Build</td></tr>" +
122 "<tr><td style='white-space: nowrap; padding:5px;'> " +
123 "Ctrl + N </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Clean Build</td></tr>" +
124 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> " +
125 "Ctrl + 2 </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Toggle Split-View Mode (single, dual-vertical, dual-horizontal)</td></tr>" +
126 "</table></INDENT>\n" +
129 "<b>Editor Pane Hot Keys:</b>\n<INDENT>" +
131 "<table border=0 cellspacing=0 cellpadding=0 style='border: 1px solid grey;'>" +
133 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> " +
134 "Ctrl + S </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Save File</td></tr>" +
136 "<tr><td style='white-space: nowrap; padding:5px;'> " +
137 "Ctrl + D </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Toggle Directory Navigation</td></tr>" +
139 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> " +
140 "Ctrl + F </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Find & Replace</td></tr>" +
142 "<tr><td style='white-space: nowrap; padding:5px;'> " +
143 "Ctrl + U </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Undo Text Editing</td></tr>" +
145 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> " +
146 "Shift + Ctrl + U </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Redo Text Editing</td></tr>" +
148 "<tr><td style='white-space: nowrap; padding:5px;'> " +
149 "Ctrl + L or G </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Goto Line Number</td></tr>" +
151 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> " +
152 "Ctrl + 1 </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Switch to Related File (associated .h or .cc)</td></tr>" +
154 "<tr><td style='white-space: nowrap; padding:5px;'> " +
155 "Ctrl + 0 </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Reload Current File from Server</td></tr>" +
157 "</table></INDENT>\n" +
160 "<b>Selected-Text Hot Keys:</b>\n<INDENT>" +
162 "<table border=0 cellspacing=0 cellpadding=0 style='border: 1px solid grey;'>" +
163 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> TAB</td><td style='padding:5px'> ==> </td><td style='padding:5px'> Add leading TAB character to all highlighted lines.</td></tr>" +
164 "<tr><td style='white-space: nowrap; padding:5px;'> Shift + TAB </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Remove leading TAB character from all highlighted lines.</td></tr>" +
165 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> Ctrl + T or Y </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Add TAB character at starting cursor position of all highlighted line (i.e. Block Tab effect).</td></tr>" +
166 "<tr><td style='white-space: nowrap; padding:5px;'> Shift + Ctrl + T or Y</td><td style='padding:5px'> ==> </td><td style='padding:5px'> Remove TAB character from starting cursor position of all highlighted line (i.e. reverse Block Tab effect).</td></tr>" +
167 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> Ctrl + / </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Add leading comment character(s) to all highlighted lines.</td></tr>" +
168 "<tr><td style='white-space: nowrap; padding:5px;'> Shift + Ctrl + / </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Remove leading comment character(s) to all highlighted lines.</td></tr>" +
169 "<tr style='background-color: rgb(106, 102, 119);'><td style='white-space: nowrap; padding:5px;'> Ctrl + I </td><td style='padding:5px'> ==> </td><td style='padding:5px'> Auto-indent all highlighted lines.</td></tr>" +
170 "</table></INDENT>\n" +
181 CodeEditor.create =
function() {
185 CodeEditor.showTooltip();
249 var _WINDOW_MIN_SZ = 525;
251 var _ALLOWED_FILE_EXTENSIONS = [];
253 var _needEventListeners =
true;
256 var _navMode = [0,0];
257 var _filePath = [
"",
""];
258 var _fileExtension = [
"",
""];
259 var _fileLastSave = [0,0];
260 var _fileWasModified = [
false,
false];
261 var _numberOfLines = [0,0];
263 var _eel = [undefined,undefined];
265 var _updateTimerHandle = 0;
266 var _updateHandlerTargetPane = [
false,
false];
267 var _commandKeyDown =
false;
268 var _lastPageUpDownLine = -1;
269 var _startPageUpDownLine = -1;
270 var _startPageUpDownNodeIndex = -1;
271 var _startPageUpDownPos = -1;
273 var _fileNameMouseMoveTimerHandle = 0;
274 var _fileNameEditing = [
false,
false];
275 var _fileUploadString;
277 var _activePaneIsPrimary = 1;
279 var _undoStackLatestIndex = [-1,-1];
280 var _undoStack_MAX_SIZE = 10;
281 var _undoStack = [[],[]];
283 var _fileHistoryStack = {};
285 var _findAndReplaceCursorInContent = [undefined,undefined];
287 var _fileStringHoverEl = 0;
288 var _fileStringHoverTimeout = 0;
290 var _UPDATE_DECOR_TIMEOUT = 2000;
297 CodeEditor.editor =
this;
298 Debug.log(
"CodeEditor.editor constructed");
301 this.lastFileNameHistorySelectIndex = -1;
302 this.findAndReplaceFind = [
"",
""];
303 this.findAndReplaceReplace = [
"",
""];
304 this.findAndReplaceScope = [0,0];
305 this.findAndReplaceDirection = [0,0];
306 this.findAndReplaceCaseSensitive = [0,0];
307 this.findAndReplaceWholeWord = [1,1];
308 this.findAndReplaceLastButton = [-1,-1];
312 Debug.log(
"CodeEditor.editor initialized");
319 Debug.log(
"Code Editor init ");
322 var parameterStartFile = [
328 DesktopContent.getParameter(0,
"startFilePrimary"),
329 DesktopContent.getParameter(0,
"startFileSecondary")
331 var parameterGotoLine = [
332 DesktopContent.getParameter(0,
"gotoLinePrimary"),
333 DesktopContent.getParameter(0,
"gotoLineSecondary")
335 var parameterOpenDirectory = [
336 DesktopContent.getParameter(0,
"openDirectoryPrimary"),
337 DesktopContent.getParameter(0,
"openDirectorySecondary")
339 if(parameterOpenDirectory[0] === undefined)
340 parameterOpenDirectory[0] =
"/";
341 if(parameterOpenDirectory[1] === undefined)
342 parameterOpenDirectory[1] =
"/";
344 var parameterViewMode = DesktopContent.getParameter(0,
"startViewMode");
345 if(parameterViewMode !== undefined)
347 _viewMode = parameterViewMode|0;
349 console.log(
"parameterStartFile",parameterStartFile);
350 console.log(
"parameterGotoLine",parameterGotoLine);
351 console.log(
"parameterViewMode",parameterViewMode);
352 console.log(
"parameterOpenDirectory",parameterOpenDirectory);
361 if(_needEventListeners)
363 window.addEventListener(
"resize",redrawWindow);
364 _needEventListeners =
false;
369 DesktopContent.XMLHttpRequest(
"Request?RequestType=codeEditor" +
370 "&option=getAllowedExtensions"
374 console.log(
"getAllowedExtensions",req);
376 _ALLOWED_FILE_EXTENSIONS = DesktopContent.getXMLValue(req,
"AllowedExtensions");
377 console.log(
"_ALLOWED_FILE_EXTENSIONS",_ALLOWED_FILE_EXTENSIONS);
378 _ALLOWED_FILE_EXTENSIONS = _ALLOWED_FILE_EXTENSIONS.split(
',');
379 console.log(
"_ALLOWED_FILE_EXTENSIONS",_ALLOWED_FILE_EXTENSIONS);
381 DesktopContent.XMLHttpRequest(
"Request?RequestType=codeEditor" +
382 "&option=getDirectoryContent" +
392 CodeEditor.editor.handleDirectoryContent(1 , req);
393 CodeEditor.editor.handleDirectoryContent(0 , req);
397 if(parameterStartFile[0] && parameterStartFile[0] !=
"")
398 fileSplit = parameterStartFile[0].split(
'.');
402 if(fileSplit.length == 2)
403 CodeEditor.editor.openFile(
408 parameterGotoLine[0 ] );
411 CodeEditor.editor.openDirectory(
413 parameterOpenDirectory[0]
420 if(parameterStartFile[1] && parameterStartFile[1] !=
"")
421 fileSplit = parameterStartFile[1].split(
'.');
423 if(fileSplit.length == 2)
424 CodeEditor.editor.openFile(
429 parameterGotoLine[1 ] );
433 CodeEditor.editor.openDirectory(
435 parameterOpenDirectory[1]
441 _activePaneIsPrimary = 1;
451 function createElements()
453 Debug.log(
"createElements");
463 var cel,el,al,sl,str;
465 cel = document.getElementById(
"content");
468 cel = document.createElement(
"div");
469 cel.setAttribute(
"id",
"content");
480 for(forPrimary=1;forPrimary >= 0;--forPrimary)
482 el = document.createElement(
"div");
483 el.setAttribute(
"class",
"editorPane");
484 el.setAttribute(
"id",
"editorPane" + forPrimary);
487 str += createTextEditor(forPrimary);
488 str += createDirectoryNav(forPrimary);
489 str += localCreatePaneControls(forPrimary);
496 function localCreatePaneControls(forPrimary)
504 str += htmlOpen(
"div",
506 "class":
"controlsPane",
510 str += htmlOpen(
"div",
512 "id":
"directoryNavToggle",
513 "class":
"controlsButton",
514 "style":
"float:left",
515 "onclick":
"CodeEditor.editor.toggleDirectoryNav(" + forPrimary +
");",
516 "title":
"Open a file... (Ctrl + D)",
519 str += htmlOpen(
"div",
521 "id":
"directoryNavToggleTop",
524 str += htmlOpen(
"div",
526 "id":
"directoryNavToggleBottom",
533 str += htmlOpen(
"div",
536 "class":
"controlsButton",
537 "style":
"float:left;",
538 "onclick":
"CodeEditor.editor.saveFile(" + forPrimary +
");",
539 "title":
"Click to Save the File (Ctrl + S)\nUndo changes (Ctrl + U)\nRedo changes (Shift + Ctrl + U)",
542 str += htmlOpen(
"div",
547 str += htmlOpen(
"div",
549 "id":
"saveFileMainTop",
552 str += htmlOpen(
"div",
554 "id":
"saveFileMainBottom",
569 el = document.createElement(
"div");
570 el.setAttribute(
"class",
"controlsPane");
577 str += htmlOpen(
"div",
580 "class":
"controlsButton",
581 "style":
"float:right",
582 "onclick":
"CodeEditor.editor.toggleView();",
583 "title":
"Toggle Verical/Horizontal Split-view (Ctrl + W)",
587 str += htmlOpen(
"div",
589 "id":
"viewToggleRight",
592 str += htmlOpen(
"div",
594 "id":
"viewToggleLeftTop",
597 str += htmlOpen(
"div",
599 "id":
"viewToggleLeftBottom",
606 str += htmlOpen(
"div",
608 "id":
"incrementalBuild",
609 "class":
"controlsButton",
610 "style":
"float:right",
611 "onclick":
"CodeEditor.editor.build(0 /*cleanBuild*/);",
612 "title":
"Incremental Build... (Ctrl + B)",
616 str += htmlOpen(
"div",
618 "style":
"margin:11px 0 0 13px;",
624 str += htmlOpen(
"div",
627 "class":
"controlsButton",
628 "style":
"float:right",
629 "onclick":
"CodeEditor.editor.build(1 /*cleanBuild*/);",
630 "title":
"Clean Build... (Ctrl + N)",
634 str += htmlOpen(
"div",
636 "style":
"margin:10px 0 0 13px;",
642 str += htmlOpen(
"div",
645 "class":
"controlsButton",
646 "style":
"float:right",
647 "onclick":
"CodeEditor.showTooltip(1 /*alwaysShow*/);",
648 "title":
"Click for help, short-cuts, etc.",
652 str += htmlOpen(
"div",
654 "style":
"margin:12px 0 0 13px;",
665 document.body.appendChild(cel);
666 _eel = [document.getElementById(
"editableBox" + 0),
667 document.getElementById(
"editableBox" + 1)];
675 _eel[i].addEventListener(
"input",
680 var forPrimary = this.
id[this.
id.length-1]|0;
681 forPrimary = forPrimary?1:0;
683 Debug.log(
"input forPrimary=" + forPrimary);
685 _fileWasModified[forPrimary] =
true;
686 CodeEditor.editor.updateLastSave(forPrimary);
688 CodeEditor.editor.startUpdateHandling(forPrimary);
692 _eel[i].addEventListener(
"keydown",
695 if(e.keyCode == 91 || e.keyCode == 93 ||
697 _commandKeyDown =
true;
699 var forPrimary =
this.id[
this.id.length-1]|0;
700 forPrimary = forPrimary?1:0;
703 CodeEditor.editor.keyDownHandler(e,forPrimary);
707 _eel[i].addEventListener(
"keyup",
710 if(e.keyCode == 91 || e.keyCode == 93 ||
712 _commandKeyDown =
false;
715 _eel[i].addEventListener(
"click",
721 Debug.log(
"Special mouse click handling");
731 _eel[i].addEventListener(
"dblclick",
735 var forPrimary = this.
id[this.
id.length-1]|0;
736 forPrimary = forPrimary?1:0;
738 Debug.log(
"dblclick handler for editor" + forPrimary);
741 CodeEditor.editor.doubleClickHandler(forPrimary);
744 _eel[i].addEventListener(
"contextmenu",
750 Debug.log(
"Special context menu handling");
759 _eel[i].addEventListener(
"mousedown",
764 Debug.log(
"Special mouse down handling");
771 CodeEditor.editor.stopUpdateHandling(e);
773 var forPrimary = this.
id[this.
id.length-1]|0;
774 forPrimary = forPrimary?1:0;
776 Debug.log(
"mousedown handler for editor" + forPrimary +
" " + e.which);
779 if(_activePaneIsPrimary != forPrimary)
780 CodeEditor.editor.updateDualView(!forPrimary);
782 _activePaneIsPrimary = forPrimary;
787 _eel[i].addEventListener(
"mouseup",
790 var forPrimary = this.
id[this.
id.length-1]|0;
791 forPrimary = forPrimary?1:0;
793 Debug.log(
"mouseup handler for editor" + forPrimary);
797 Debug.log(
"Special mouse up handling");
804 CodeEditor.editor.startUpdateHandling(forPrimary);
809 box = document.getElementById(
"editorPane" + i);
810 box.addEventListener(
"click",
813 var forPrimary = this.
id[this.
id.length-1]|0;
814 forPrimary = forPrimary?1:0;
816 Debug.log(
"click handler for pane" + forPrimary);
820 if(_activePaneIsPrimary != forPrimary)
821 CodeEditor.editor.updateDualView(!forPrimary);
823 _activePaneIsPrimary = forPrimary;
826 CodeEditor.editor.showFindAndReplaceSelection(forPrimary);
829 var el = document.getElementById(
"textEditorBody" + forPrimary);
830 var scrollLeft = el.scrollLeft;
831 var scrollTop = el.scrollTop;
833 _eel[forPrimary].focus();
835 el.scrollLeft = scrollLeft;
836 el.scrollTop = scrollTop;
845 box.addEventListener(
"keydown",
848 if(e.keyCode == 91 || e.keyCode == 93 ||
850 _commandKeyDown =
true;
852 var forPrimary = _activePaneIsPrimary;
853 Debug.log(
"keydown handler for body" + forPrimary);
854 CodeEditor.editor.keyDownHandler(e,forPrimary,
true );
857 box.addEventListener(
"keyup",
860 if(e.keyCode == 91 || e.keyCode == 93 ||
862 _commandKeyDown =
false;
864 box.addEventListener(
"mouseover",
868 if(_fileStringHoverEl.parentNode)
870 Debug.log(
"body removing string hover");
871 window.clearTimeout(_fileStringHoverTimeout);
872 _fileStringHoverTimeout = window.setTimeout(
875 Debug.log(
"body removed string hover");
878 _fileStringHoverEl.parentNode.removeChild(_fileStringHoverEl);
891 function createTextEditor(forPrimary)
893 forPrimary = forPrimary?1:0;
895 Debug.log(
"createTextEditor forPrimary=" + forPrimary);
899 str += htmlOpen(
"div",
901 "class":
"textEditor",
902 "id":
"textEditor" + forPrimary,
903 "style":
"overflow:hidden;",
912 str += htmlOpen(
"div",
914 "class":
"textEditorHeader",
915 "id":
"textEditorHeader" + forPrimary,
919 str += htmlOpen(
"div",
921 "class":
"textEditorBody",
922 "id":
"textEditorBody" + forPrimary,
925 str +=
"<table class='editableBoxTable' style='margin-bottom:200px'>" +
926 "<tr><td valign='top'>";
927 str += htmlOpen(
"div",
929 "class":
"editableBoxLeftMargin",
930 "id":
"editableBoxLeftMargin" + forPrimary,
932 str +=
"</td><td valign='top'>";
933 str += htmlOpen(
"div",
935 "class":
"editableBox",
936 "id":
"editableBox" + forPrimary,
937 "contenteditable":
"true",
938 "autocomplete":
"off",
940 "autocapitalize":
"off",
941 "spellcheck":
"false",
943 str +=
"</td></tr></table>";
954 function createDirectoryNav(forPrimary)
956 forPrimary = forPrimary?1:0;
958 Debug.log(
"createDirectoryNav forPrimary=" + forPrimary);
962 str += htmlOpen(
"div",
964 "class":
"directoryNav",
965 "id":
"directoryNav" + forPrimary,
975 function redrawWindow()
980 var w = window.innerWidth | 0;
981 var h = window.innerHeight | 0;
983 if(w < _WINDOW_MIN_SZ)
985 if(h < _WINDOW_MIN_SZ)
988 Debug.log(
"redrawWindow to " + w +
" - " + h);
990 var eps = document.getElementsByClassName(
"editorPane");
991 var epHdrs = document.getElementsByClassName(
"textEditorHeader");
992 var epBdys = document.getElementsByClassName(
"textEditorBody");
993 var dns = document.getElementsByClassName(
"directoryNav");
997 eps[0].style.position =
"absolute";
998 eps[1].style.position =
"absolute";
1000 var DIR_NAV_MARGIN = 50;
1001 var EDITOR_MARGIN = 20;
1002 var EDITOR_HDR_H = 56;
1007 rect = [{
"left":0,
"top":0,
"w":w,
"h":h},
1012 rect = [{
"left":0,
"top":0,
"w":((w/2)|0),
"h":h},
1013 {
"left":((w/2)|0),
"top":0,
"w":(w-((w/2)|0)),
"h":h}];
1018 rect = [{
"left":0,
"top":0,
"h":((h/2)|0),
"w":w},
1019 {
"top":((h/2)|0),
"left":0,
"h":(h-((h/2)|0)),
"w":w}];
1023 Debug.log(
"Invalid view mode encountered: " + _viewMode);
1027 for(var i=0;i<2;++i)
1031 eps[i].style.display =
"none";
1035 dns[i].style.left = (DIR_NAV_MARGIN) +
"px";
1036 dns[i].style.top = (DIR_NAV_MARGIN) +
"px";
1037 dns[i].style.width = (rect[i].w - 2*DIR_NAV_MARGIN) +
"px";
1038 dns[i].style.height = (rect[i].h - 2*DIR_NAV_MARGIN) +
"px";
1040 eps[i].style.left = rect[i].left +
"px";
1041 eps[i].style.top = rect[i].top +
"px";
1042 eps[i].style.height = rect[i].h +
"px";
1043 eps[i].style.width = rect[i].w +
"px";
1045 epHdrs[i].style.left = EDITOR_MARGIN +
"px";
1046 epHdrs[i].style.top = (DIR_NAV_MARGIN - 2*EDITOR_MARGIN) +
"px";
1047 epHdrs[i].style.height = (EDITOR_HDR_H + 2*EDITOR_MARGIN) +
"px";
1048 epHdrs[i].style.width = (rect[i].w - 2*EDITOR_MARGIN) +
"px";
1051 epBdys[i].style.left = 0 +
"px";
1052 epBdys[i].style.top = (DIR_NAV_MARGIN + EDITOR_HDR_H) +
"px";
1053 epBdys[i].style.height = (rect[i].h - DIR_NAV_MARGIN - EDITOR_HDR_H) +
"px";
1054 epBdys[i].style.width = (rect[i].w - 0) +
"px";
1056 eps[i].style.display =
"block";
1065 this.toggleView =
function(v)
1070 _viewMode = (_viewMode+1)%3;
1071 Debug.log(
"toggleView _viewMode=" + _viewMode);
1078 this.toggleDirectoryNav =
function(forPrimary, v)
1080 forPrimary = forPrimary?1:0;
1081 _activePaneIsPrimary = forPrimary;
1083 Debug.log(
"toggleDirectoryNav forPrimary=" + forPrimary);
1086 _navMode[forPrimary] = v?1:0;
1088 _navMode[forPrimary] = _navMode[forPrimary]?0:1;
1089 Debug.log(
"toggleDirectoryNav _navMode=" + _navMode[forPrimary]);
1091 var el = document.getElementById(
"directoryNav" + forPrimary);
1092 var wasHidden = el.style.display ==
"none";
1094 _navMode[forPrimary]?
"block":
"none";
1096 if(_navMode[forPrimary] && wasHidden)
1098 var paths = document.getElementById(
"directoryNav" +
1099 forPrimary).getElementsByClassName(
"dirNavPath");
1100 var buildPath =
"/";
1101 for(var i=1;i<paths.length;++i)
1102 buildPath += (i>1?
"/":
"") + paths[i].textContent;
1103 Debug.log(
"refresh " + buildPath);
1105 CodeEditor.editor.openDirectory(forPrimary,buildPath);
1112 this.saveFile =
function(forPrimary, quiet)
1114 forPrimary = forPrimary?1:0;
1116 Debug.log(
"saveFile forPrimary=" + forPrimary);
1118 Debug.log(
"saveFile _filePath=" + _filePath[forPrimary]);
1119 Debug.log(
"saveFile _fileExtension=" + _fileExtension[forPrimary]);
1121 if(_filePath[forPrimary] ==
"")
1123 Debug.log(
"Error, can not save to empty file name!",
1124 Debug.HIGH_PRIORITY);
1130 DesktopContent.popUpVerification(
1131 "Are you sure you want to save...<br>" +
1132 _filePath[forPrimary] +
"." + _fileExtension[forPrimary] +
"?",
1134 undefined,undefined,undefined,
1135 undefined,undefined,
1143 function localDoIt()
1147 var textObj = {
"text":
1148 _eel[forPrimary].innerText,
1155 textObj.text = textObj.text.replace(/%C2%A0%C2%A0/g,
"%20%20").replace(/%C2%A0/g,
1156 "%20").replace(/%C2/g,
"%20").replace(/%A0/g,
"%20");
1160 DesktopContent.XMLHttpRequest(
"Request?RequestType=codeEditor" +
1161 "&option=saveFileContent" +
1162 "&path=" + _filePath[forPrimary] +
1163 "&ext=" + _fileExtension[forPrimary]
1164 ,
"content=" + encodeURIComponent(textObj.text) ,
1167 Debug.log(
"Successfully saved " +
1168 _filePath[forPrimary] +
"." +
1169 _fileExtension[forPrimary],quiet?Debug.LOW_PRIORITY:Debug.INFO_PRIORITY);
1171 _fileWasModified[forPrimary] =
false;
1172 textObj.time = Date.now();
1173 _fileLastSave[forPrimary] = textObj.time;
1176 CodeEditor.editor.updateLastSave(forPrimary);
1178 if(_filePath[0] == _filePath[1] &&
1179 _fileExtension[0] == _fileExtension[1])
1181 CodeEditor.editor.updateDualView(forPrimary);
1183 CodeEditor.editor.updateFileSnapshot(!forPrimary,
1189 CodeEditor.editor.updateFileSnapshot(forPrimary,
1201 this.build =
function(cleanBuild)
1203 cleanBuild = cleanBuild?1:0;
1205 Debug.log(
"build cleanBuild=" + cleanBuild);
1209 DesktopContent.popUpVerification(
1210 "Are you sure you want to do a clean build?!",
1218 function localDoIt()
1220 DesktopContent.XMLHttpRequest(
"Request?RequestType=codeEditor" +
1222 "&clean=" + (cleanBuild?1:0)
1226 Debug.log(
"Build was launched! Check " +
1227 "<a onclick='DesktopContent.openNewBrowserTab(" +
1229 "title='Click to open the Console web app in a new browser tab.'>" +
1230 "console</a> for result!", Debug.INFO_PRIORITY);
1240 this.undo =
function(forPrimary,redo)
1242 DesktopContent.showLoading(localDoIt);
1245 function localDoIt()
1247 forPrimary = forPrimary?1:0;
1249 Debug.log(
"undo() forPrimary=" + forPrimary +
" redo=" + redo);
1250 console.log(
"undo stack index",_undoStackLatestIndex[forPrimary]);
1251 console.log(
"undo stack length",_undoStack[forPrimary].length);
1253 console.log(
"undo stack",_undoStack[forPrimary]);
1255 var el = _eel[forPrimary];
1258 CodeEditor.editor.updateFileSnapshot(forPrimary,
1259 {
"text":el.textContent,
1263 var newIndex = _undoStackLatestIndex[forPrimary];
1264 newIndex += redo?1:-1;
1265 if(newIndex >= _undoStack_MAX_SIZE)
1267 else if(newIndex < 0)
1268 newIndex = _undoStack[forPrimary].length-1;
1270 console.log(
"new stack index",newIndex);
1274 _undoStack[forPrimary][newIndex][1] >=
1275 _undoStack[forPrimary][_undoStackLatestIndex[forPrimary]][1])
1277 Debug.log(
"Reached end of undo history...",Debug.WARN_PRIORITY);
1281 (newIndex >= _undoStack[forPrimary].length ||
1282 _undoStack[forPrimary][newIndex][1] <=
1283 _undoStack[forPrimary][_undoStackLatestIndex[forPrimary]][1]))
1285 Debug.log(
"Reached end of redo history...",Debug.WARN_PRIORITY);
1290 _undoStackLatestIndex[forPrimary] = newIndex;
1291 console.log(
"result stack index",newIndex);
1293 var cursor = CodeEditor.editor.getCursor(el);
1296 _undoStack[forPrimary][_undoStackLatestIndex[forPrimary]][0];
1297 _fileWasModified[forPrimary] =
true;
1299 CodeEditor.editor.updateDecorations(forPrimary,
1303 CodeEditor.editor.setCursor(el,cursor,
true );
1310 this.handleDirectoryContent =
function(forPrimary,req)
1312 forPrimary = forPrimary?1:0;
1314 Debug.log(
"handleDirectoryContent forPrimary=" + forPrimary);
1317 var path = DesktopContent.getXMLValue(req,
"path");
1318 if(path ==
"/") path =
"";
1320 var specials = req.responseXML.getElementsByTagName(
"special");
1321 var dirs = req.responseXML.getElementsByTagName(
"directory");
1322 var files = req.responseXML.getElementsByTagName(
"file");
1323 var specialFiles = req.responseXML.getElementsByTagName(
"specialFile");
1325 Debug.log(
"handleDirectoryContent path=" + path);
1326 console.log(dirs);console.log(files);
1331 str += htmlOpen(
"div",
1333 "style":
"margin:20px;" +
1334 "white-space: nowrap;",
1340 var pathSplit = path.split(
'/');
1344 str +=
"Path: <a class='dirNavPath' onclick='CodeEditor.editor.openDirectory(" +
1345 forPrimary +
",\"" +
1352 for(i=0;i<pathSplit.length;++i)
1354 pathSplitName = pathSplit[i].trim();
1355 if(pathSplitName ==
"")
continue;
1356 Debug.log(
"pathSplitName " + pathSplitName);
1358 buildPath +=
"/" + pathSplitName;
1361 str +=
"<a class='dirNavPath' onclick='CodeEditor.editor.openDirectory(" +
1362 forPrimary +
",\"" +
1364 ")' title='Open folder: \nsrcs" + buildPath +
1366 pathSplitName +
"</a>";
1372 str += htmlOpen(
"a",
1374 "title":
"Open folder in the other editor pane of the split-view: \n" +
1376 "onclick":
"CodeEditor.editor.openDirectory(" +
1377 (!forPrimary) +
",\"" +
1380 "<img class='dirNavFileNewWindowImgNewPane' " +
1381 "src='/WebPath/images/windowContentImages/CodeEditor-openInOtherPane.png'>"
1385 str += htmlOpen(
"a",
1387 "title":
"Open folder in a new browser tab: \n" +
1389 "onclick":
"DesktopContent.openNewBrowserTab(" +
1390 "\"Code Editor\",\"\"," +
1391 "\"/WebPath/html/CodeEditor.html?openDirectoryPrimary=" +
1392 buildPath +
"\",0 /*unique*/);' ",
1394 "<img class='dirNavFileNewWindowImgNewWindow' " +
1395 "src='/WebPath/images/windowContentImages/CodeEditor-openInNewWindow.png'>"
1404 for(i=0;i<specials.length;++i)
1406 name = specials[i].getAttribute(
'value');
1409 str += htmlOpen(
"a",
1411 "title":
"Open folder in a new browser tab: \n" +
1412 "srcs" + path +
"/" + name,
1413 "onclick":
"DesktopContent.openNewBrowserTab(" +
1414 "\"Code Editor\",\"\"," +
1415 "\"/WebPath/html/CodeEditor.html?openDirectoryPrimary=" +
1416 path +
"/" + name +
"\",0 /*unique*/);' ",
1418 "<img class='dirNavFileNewWindowImgNewWindow' " +
1419 "src='/WebPath/images/windowContentImages/CodeEditor-openInNewWindow.png'>"
1423 str += htmlOpen(
"a",
1425 "title":
"Open folder in the other editor pane of the split-view: \n" +
1426 "srcs" + path +
"/" + name,
1427 "onclick":
"CodeEditor.editor.openDirectory(" +
1428 (!forPrimary) +
",\"" +
1429 path +
"/" + name +
"\");",
1431 "<img class='dirNavFileNewWindowImgNewPane' " +
1432 "src='/WebPath/images/windowContentImages/CodeEditor-openInOtherPane.png'>"
1436 str +=
"<a class='dirNavSpecial' onclick='CodeEditor.editor.openDirectory(" +
1437 forPrimary +
",\"" +
1438 path +
"/" + name +
"\"" +
1439 ")' title='Open folder: \nsrcs" + path +
"/" + name +
"' >" +
1449 if(specialFiles.length)
1452 str +=
"<tr><th>" + path.substr(1,path.length-2) +
" Files</th><th style='padding-left:20px'>Repository</th></tr>";
1454 for(i=0;i<specialFiles.length;++i)
1456 name = specialFiles[i].getAttribute(
'value');
1461 str += htmlOpen(
"a",
1463 "title":
"Open file in a new browser tab: \n" +
1465 "onclick":
"DesktopContent.openNewBrowserTab(" +
1466 "\"Code Editor\",\"\"," +
1467 "\"/WebPath/html/CodeEditor.html?startFilePrimary=" +
1468 name +
"\",0 /*unique*/);' ",
1470 "<img class='dirNavFileNewWindowImgNewWindow' " +
1471 "src='/WebPath/images/windowContentImages/CodeEditor-openInNewWindow.png'>"
1475 str += htmlOpen(
"a",
1477 "title":
"Open file in the other editor pane of the split-view: \n" +
1479 "onclick":
"CodeEditor.editor.openFile(" +
1480 (!forPrimary) +
",\"" +
1482 name.substr(name.indexOf(
'.')+1) +
"\"" +
1485 "<img class='dirNavFileNewWindowImgNewPane' " +
1486 "src='/WebPath/images/windowContentImages/CodeEditor-openInOtherPane.png'>"
1490 str +=
"<a class='dirNavFile' onclick='CodeEditor.editor.openFile(" +
1491 forPrimary +
",\"" +
1493 name.substr(name.indexOf(
'.')+1) +
"\"" +
1494 ")' title='Open file: \nsrcs" + name +
"' >";
1495 nameSplit = name.split(
'/');
1496 str += nameSplit[nameSplit.length-1] +
"</a>";
1500 str +=
"</td><td style='padding-left:20px'>" + nameSplit[1] +
"</td></tr>";
1503 if(specialFiles.length)
1509 for(i=0;i<dirs.length;++i)
1511 name = dirs[i].getAttribute(
'value');
1514 str += htmlOpen(
"a",
1516 "title":
"Open file in a new browser tab: \n" +
1517 "srcs" + path +
"/" + name,
1518 "onclick":
"DesktopContent.openNewBrowserTab(" +
1519 "\"Code Editor\",\"\"," +
1520 "\"/WebPath/html/CodeEditor.html?openDirectoryPrimary=" +
1521 path +
"/" + name +
"\",0 /*unique*/);' ",
1523 "<img class='dirNavFileNewWindowImgNewWindow' " +
1524 "src='/WebPath/images/windowContentImages/CodeEditor-openInNewWindow.png'>"
1528 str += htmlOpen(
"a",
1530 "title":
"Open folder in the other editor pane of the split-view: \n" +
1531 "srcs" + path +
"/" + name,
1532 "onclick":
"CodeEditor.editor.openDirectory(" +
1533 (!forPrimary) +
",\"" +
1534 path +
"/" + name +
"\");",
1536 "<img class='dirNavFileNewWindowImgNewPane' " +
1537 "src='/WebPath/images/windowContentImages/CodeEditor-openInOtherPane.png'>"
1541 str +=
"<a class='dirNavFolder' onclick='CodeEditor.editor.openDirectory(" +
1542 forPrimary +
",\"" +
1543 path +
"/" + name +
"\"" +
1544 ")' title='Open folder: \nsrcs" + path +
"/" + name +
"' >" +
1553 for(i=0;i<files.length;++i)
1555 name = files[i].getAttribute(
'value');
1558 str += htmlOpen(
"a",
1560 "title":
"Open file in a new browser tab: \n" +
1561 "srcs" + path +
"/" + name,
1562 "onclick":
"DesktopContent.openNewBrowserTab(" +
1563 "\"Code Editor\",\"\"," +
1564 "\"/WebPath/html/CodeEditor.html?startFilePrimary=" +
1565 path +
"/" + name +
"\",0 /*unique*/);' ",
1567 "<img class='dirNavFileNewWindowImgNewWindow' " +
1568 "src='/WebPath/images/windowContentImages/CodeEditor-openInNewWindow.png'>"
1572 str += htmlOpen(
"a",
1574 "title":
"Open file in the other editor pane of the split-view: \n" +
1575 "srcs" + path +
"/" + name,
1576 "onclick":
"CodeEditor.editor.openFile(" +
1577 (!forPrimary) +
",\"" +
1578 path +
"/" + name +
"\", \"" +
1579 name.substr(name.indexOf(
'.')+1) +
"\"" +
1582 "<img class='dirNavFileNewWindowImgNewPane' " +
1583 "src='/WebPath/images/windowContentImages/CodeEditor-openInOtherPane.png'>"
1588 str +=
"<a class='dirNavFile' onclick='CodeEditor.editor.openFile(" +
1589 forPrimary +
",\"" +
1590 path +
"/" + name +
"\", \"" +
1591 name.substr(name.indexOf(
'.')+1) +
"\"" +
1592 ")' title='Open file: \nsrcs" + path +
"/" + name +
"' >" +
1601 document.getElementById(
"directoryNav" + forPrimary).innerHTML = str;
1607 this.openDirectory =
function(forPrimary,path)
1609 forPrimary = forPrimary?1:0;
1611 if(!path || path ==
"") path =
"/";
1612 Debug.log(
"openDirectory forPrimary=" + forPrimary +
1616 DesktopContent.XMLHttpRequest(
"Request?RequestType=codeEditor" +
1617 "&option=getDirectoryContent" +
1622 CodeEditor.editor.handleDirectoryContent(forPrimary, req);
1623 CodeEditor.editor.toggleDirectoryNav(forPrimary,1 );
1631 this.openRelatedFile =
function(forPrimary)
1633 Debug.log(
"openRelatedFile forPrimary=" + forPrimary +
1634 " path=" + _filePath[forPrimary]);
1636 var relatedPath = _filePath[forPrimary];
1637 var relatedExtension = _fileExtension[forPrimary];
1640 var altExtensions = [];
1642 if(relatedExtension ==
"html")
1644 relatedExtension =
"js";
1645 var i = relatedPath.indexOf(
"/html/");
1648 altPaths.push(relatedPath.substr(0,i) +
"/css/" +
1649 relatedPath.substr(i + (
"/html/").length));
1650 altExtensions.push(
"css");
1652 relatedPath = relatedPath.substr(0,i) +
"/js/" +
1653 relatedPath.substr(i + (
"/html/").length);
1657 altPaths.push(relatedPath);
1658 altExtensions.push(
"css");
1661 CodeEditor.editor.openFile(forPrimary,relatedPath,relatedExtension,
1662 undefined , undefined,
1663 altPaths , altExtensions);
1666 else if(relatedExtension[0] ==
"h")
1668 relatedExtension =
"cc";
1670 var i = relatedPath.indexOf(
"/FEInterfaces/");
1672 altPaths.push(relatedPath);
1673 altExtensions.push(
"cc");
1674 altPaths.push(relatedPath);
1675 altExtensions.push(
"cpp");
1676 altPaths.push(relatedPath);
1677 altExtensions.push(
"CC");
1678 altPaths.push(relatedPath);
1679 altExtensions.push(
"cxx");
1680 altPaths.push(relatedPath);
1681 altExtensions.push(
"c");
1682 altPaths.push(relatedPath);
1683 altExtensions.push(
"C");
1685 relatedPath +=
"_interface";
1686 CodeEditor.editor.openFile(forPrimary,relatedPath,relatedExtension,
1687 undefined , undefined,
1688 altPaths , altExtensions);
1691 else if(relatedExtension ==
"css")
1693 relatedExtension =
"js";
1694 var i = relatedPath.indexOf(
"/css/");
1698 altPaths.push(relatedPath.substr(0,i) +
"/html/" +
1699 relatedPath.substr(i + (
"/css/").length));
1700 altExtensions.push(
"html");
1702 relatedPath = relatedPath.substr(0,i) +
"/js/" +
1703 relatedPath.substr(i + (
"/css/").length);
1707 altPaths.push(relatedPath);
1708 altExtensions.push(
"html");
1711 CodeEditor.editor.openFile(forPrimary,relatedPath,relatedExtension,
1712 undefined , undefined,
1713 altPaths , altExtensions);
1716 else if(relatedExtension[0] ==
'c' ||
1717 relatedExtension[0] ==
'C')
1719 relatedExtension =
"h";
1721 altPaths.push(relatedPath);
1722 altExtensions.push(
"h");
1724 var i = relatedPath.indexOf(
"_interface");
1725 if(i > 0 && i == relatedPath.length-(
"_interface").length)
1726 relatedPath = relatedPath.substr(0,i);
1728 altPaths.push(relatedPath);
1729 altExtensions.push(
"hh");
1730 altPaths.push(relatedPath);
1731 altExtensions.push(
"hpp");
1732 altPaths.push(relatedPath);
1733 altExtensions.push(
"hxx");
1734 altPaths.push(relatedPath);
1735 altExtensions.push(
"H");
1737 CodeEditor.editor.openFile(forPrimary,relatedPath,relatedExtension,
1738 undefined , undefined,
1739 altPaths , altExtensions);
1742 else if(relatedExtension ==
"js")
1744 relatedExtension =
"css";
1745 var i = relatedPath.indexOf(
"/js/");
1749 altPaths.push(relatedPath.substr(0,i) +
"/html/" +
1750 relatedPath.substr(i + (
"/js/").length));
1751 altExtensions.push(
"html");
1753 relatedPath = relatedPath.substr(0,i) +
"/css/" +
1754 relatedPath.substr(i + (
"/js/").length);
1758 altPaths.push(relatedPath);
1759 altExtensions.push(
"html");
1762 CodeEditor.editor.openFile(forPrimary,relatedPath,relatedExtension,
1763 undefined , undefined,
1764 altPaths , altExtensions);
1768 Debug.log(
"Giving up on attempt to open a related file for " +
1769 relatedPath +
"." + relatedExtension +
1770 "... no known related file.", Debug.HIGH_PRIORITY);
1781 this.openFile =
function(forPrimary,path,extension,doConfirm,gotoLine,
1782 altPaths,altExtensions,propagateErr)
1784 forPrimary = forPrimary?1:0;
1786 Debug.log(
"openFile forPrimary=" + forPrimary +
1788 var i = path.indexOf(
'.');
1790 path = path.substr(0,i);
1792 if(!propagateErr) propagateErr =
"";
1796 DesktopContent.popUpVerification(
1797 "Do you want to reload the file from the server (and discard your changes)?",
1805 var keys = Object.keys(_fileHistoryStack);
1806 var filename = path +
"." + extension;
1807 for(i;i<keys.length;++i)
1808 if(filename == keys[i])
1810 Debug.log(
"Found " + filename +
" in file history.");
1815 fileObj.path = path;
1816 fileObj.extension = extension;
1817 fileObj.text = _fileHistoryStack[filename][0];
1818 fileObj.fileWasModified = _fileHistoryStack[filename][2];
1819 fileObj.fileLastSave = _fileHistoryStack[filename][3];
1821 console.log(
"fileObj",fileObj);
1823 CodeEditor.editor.handleFileContent(forPrimary,0,fileObj);
1825 CodeEditor.editor.toggleDirectoryNav(forPrimary,
false );
1828 if(!forPrimary && _viewMode == 0)
1829 CodeEditor.editor.toggleView();
1837 function localDoIt()
1839 CodeEditor.editor.toggleDirectoryNav(forPrimary,
false );
1841 DesktopContent.XMLHttpRequest(
"Request?RequestType=codeEditor" +
1842 "&option=getFileContent" +
1849 var err = DesktopContent.getXMLValue(req,
"Error");
1852 if(altPaths && altPaths.length &&
1853 altExtensions && altExtensions.length)
1856 CodeEditor.editor.openFile(forPrimary,
1857 altPaths.splice(0,1)[0],
1858 altExtensions.splice(0,1)[0],
1859 undefined , undefined,
1860 altPaths , altExtensions,
1861 propagateErr + err );
1864 Debug.log(propagateErr + err,Debug.HIGH_PRIORITY);
1873 CodeEditor.editor.toggleDirectoryNav(forPrimary,0 );
1874 CodeEditor.editor.handleFileContent(forPrimary, req);
1877 if(!forPrimary && _viewMode == 0)
1878 CodeEditor.editor.toggleView();
1880 if(gotoLine !== undefined)
1881 CodeEditor.editor.gotoLine(forPrimary,gotoLine);
1885 Debug.log(
"Ignoring error handling file open: " + e);
1887 console.log(DesktopContent._loadBox.style.display);
1897 this.getLine =
function(forPrimary)
1899 Debug.log(
"getLine() forPrimary=" + forPrimary);
1902 var el = _eel[forPrimary];
1903 var cursor = CodeEditor.editor.getCursor(el);
1905 if(cursor.startNodeIndex === undefined)
1907 Debug.log(
"No cursor, so defaulting to top");
1913 for(n=0; n<el.childNodes.length; ++n)
1915 node = el.childNodes[n];
1916 val = node.textContent;
1919 for(i=0;i<val.length;++i)
1922 if(!cursor.focusAtEnd &&
1923 n == cursor.startNodeIndex &&
1924 i == cursor.startPos)
1926 else if(cursor.focusAtEnd &&
1927 n == cursor.endNodeIndex &&
1936 if(!cursor.focusAtEnd &&
1937 n == cursor.startNodeIndex)
1939 Debug.log(
"Found cursor at line " + cursor.line);
1942 else if(cursor.focusAtEnd &&
1943 n == cursor.endNodeIndex)
1945 Debug.log(
"Found cursor at line " + cursor.line);
1955 this.gotoLine =
function(forPrimary,line,selectionCursor,topOfView)
1958 if(line < 1) line = 1;
1959 if(line > _numberOfLines[forPrimary])
1960 line = _numberOfLines[forPrimary];
1961 console.log(
"Goto line number ",line,selectionCursor);
1964 window.location.href =
"#" + forPrimary +
"L" + line;
1970 var el = _eel[forPrimary];
1977 "startNodeIndex": 0,
1986 cursor.endNodeIndex = selectionCursor.startNodeIndex;
1987 cursor.endPos = selectionCursor.startPos;
1988 cursor.focusAtEnd = selectionCursor.focusAtEnd;
1990 CodeEditor.editor.setCursor(el,cursor,
true );
1995 var i,n,node,el,val;
1998 var newLine =
false;
2002 for(n=0; n<el.childNodes.length; ++n)
2004 node = el.childNodes[n];
2005 val = node.textContent;
2008 for(i=0;i<val.length;++i)
2017 if(line == lineCount)
2020 Debug.log(
"Found line " + line);
2038 "startNodeIndex":lastNode,
2040 "endNodeIndex":lastNode,
2048 cursor.focusAtEnd = selectionCursor.focusAtEnd;
2050 if(lastNode < selectionCursor.startNodeIndex ||
2051 ( lastNode == selectionCursor.startNodeIndex &&
2052 lastPos < selectionCursor.startPos))
2054 cursor.endNodeIndex = selectionCursor.startNodeIndex;
2055 cursor.endPos = selectionCursor.startPos;
2059 cursor.startNodeIndex = selectionCursor.startNodeIndex;
2060 cursor.startPos = selectionCursor.startPos;
2064 CodeEditor.editor.setCursor(el,cursor,
2070 CodeEditor.editor.setCursor(el,cursor,
true );
2082 this.handleFileContent =
function(forPrimary,req,fileObj)
2084 forPrimary = forPrimary?1:0;
2086 Debug.log(
"handleFileContent forPrimary=" + forPrimary);
2092 var fileWasModified, fileLastSave;
2096 path = DesktopContent.getXMLValue(req,
"path");
2097 extension = DesktopContent.getXMLValue(req,
"ext");
2098 text = DesktopContent.getXMLValue(req,
"content");
2099 fileWasModified =
false;
2104 path = fileObj.path;
2105 extension = fileObj.extension;
2106 text = fileObj.text;
2107 fileWasModified = fileObj.fileWasModified;
2108 fileLastSave = fileObj.fileLastSave;
2113 text = text.replace(
new RegExp(
2114 String.fromCharCode(160),
'g'),
' ');
2118 _filePath[forPrimary] = path;
2119 _fileExtension[forPrimary] = extension;
2120 _fileWasModified[forPrimary] = fileWasModified;
2121 _fileLastSave[forPrimary] = fileLastSave;
2123 _undoStack[forPrimary] = [];
2124 _undoStackLatestIndex[forPrimary] = -1;
2126 var el = _eel[forPrimary];
2129 DesktopContent.showLoading(
function()
2133 el.textContent = text;
2134 CodeEditor.editor.displayFileHeader(forPrimary);
2137 { Debug.log(
"Ignoring error: " + e); }
2144 this.setCursor =
function(el,inCursor,scrollIntoView)
2146 if(inCursor.startNodeIndex !== undefined)
2150 "startNodeIndex": inCursor.startNodeIndex,
2151 "startPos": inCursor.startPos,
2152 "endNodeIndex": inCursor.endNodeIndex,
2153 "endPos": inCursor.endPos,
2154 "focusAtEnd": inCursor.focusAtEnd,
2158 var scrollEndIntoView = cursor.focusAtEnd?
true:
false;
2162 console.log(
"set cursor",cursor,
"scrollIntoView=",scrollIntoView,
2163 "scrollEndIntoView=",scrollEndIntoView);
2165 var range = document.createRange();
2167 var firstEl = el.childNodes[cursor.startNodeIndex];
2171 var secondEl = el.childNodes[cursor.endNodeIndex];
2177 Debug.log(
"scrollIntoView");
2186 Debug.log(
"inserting scroll 2nd element");
2190 var val = secondEl.textContent;
2191 var newNode1 = document.createTextNode(
2192 val.substr(0,cursor.endPos));
2194 el.insertBefore(newNode1,secondEl);
2196 var newNode = document.createElement(
"label");
2197 newNode.textContent = val[cursor.endPos];
2198 el.insertBefore(newNode,secondEl);
2200 secondEl.textContent = val.substr(cursor.endPos+1);
2202 newNode.scrollIntoViewIfNeeded();
2204 el.removeChild(newNode);
2205 el.removeChild(newNode1);
2206 secondEl.textContent = val;
2210 Debug.log(
"Failed to scroll to inserted 2nd element: " + e);
2213 secondEl.scrollIntoViewIfNeeded();
2217 Debug.log(
"Failed to scroll 2nd element: " + e);
2222 Debug.log(
"inserting scroll 1st element");
2227 if(!scrollEndIntoView)
2230 firstEl = el.childNodes[cursor.startNodeIndex];
2231 var val = firstEl.textContent;
2232 var newNode1 = document.createTextNode(
2233 val.substr(0,cursor.startPos));
2235 el.insertBefore(newNode1,firstEl);
2237 var newNode = document.createElement(
"label");
2238 newNode.textContent = val[cursor.startPos];
2239 el.insertBefore(newNode,firstEl);
2241 firstEl.textContent = val.substr(cursor.startPos+1);
2243 newNode.scrollIntoViewIfNeeded();
2246 el.removeChild(newNode);
2247 el.removeChild(newNode1);
2248 firstEl.textContent = val;
2251 Debug.log(
"scrollEndIntoView only");
2255 Debug.log(
"Failed to scroll to inserted 1st element: " + e);
2258 firstEl.scrollIntoViewIfNeeded();
2262 Debug.log(
"Failed to scroll 1st element: " + e);
2271 if(firstEl.firstChild)
2272 firstEl = firstEl.firstChild;
2273 if(secondEl.firstChild)
2274 secondEl = secondEl.firstChild;
2276 range.setStart(firstEl,
2278 range.setEnd(secondEl,
2282 var selection = window.getSelection();
2283 selection.removeAllRanges();
2284 selection.addRange(range);
2287 if(scrollEndIntoView)
2288 selection.extend(secondEl,cursor.endPos);
2300 console.log(
"set cursor err:",err);
2307 this.createCursorFromContentPosition =
function(el,startPos,endPos)
2311 "startNodeIndex":undefined,
2312 "startPos":undefined,
2313 "endNodeIndex":undefined,
2324 for(i=0;i<el.childNodes.length;++i)
2326 sum += el.childNodes[i].textContent.length;
2328 if(cursor.startNodeIndex === undefined &&
2329 startPos >= oldSum &&
2333 cursor.startNodeIndex = i;
2334 cursor.startPos = startPos - oldSum;
2336 if(endPos >= oldSum &&
2340 cursor.endNodeIndex = i;
2341 cursor.endPos = endPos - oldSum;
2348 console.log(
"createCursorFromContentPosition:",cursor);
2353 console.log(
"get cursor err:",err);
2361 this.getCursor =
function(el)
2365 "startNodeIndex":undefined,
2366 "startPos":undefined,
2367 "endNodeIndex":undefined,
2369 "startPosInContent":undefined,
2370 "endPosInContent":undefined,
2371 "focusAtEnd":undefined
2377 var selection = window.getSelection();
2378 var range = selection.getRangeAt(0);
2379 var focusNode = selection.focusNode;
2380 var extentNode = selection.extentNode;
2382 cursor.startPos = range.startOffset;
2383 cursor.endPos = range.endOffset;
2386 for(i=0;i<el.childNodes.length;++i)
2388 if(cursor.startNodeIndex === undefined &&
2390 el.childNodes[i] == range.startContainer ||
2391 el.childNodes[i] == range.startContainer.parentNode ||
2392 el.childNodes[i] == range.startContainer.parentNode.parentNode ||
2393 el.childNodes[i] == range.startContainer.parentNode.parentNode.parentNode) )
2395 cursor.startNodeIndex = i;
2396 cursor.startPosInContent = sum + cursor.startPos;
2398 if(focusNode == range.startContainer ||
2399 extentNode == range.startContainer)
2400 cursor.focusAtEnd =
false;
2403 if(el.childNodes[i] == range.endContainer ||
2404 el.childNodes[i] == range.endContainer.parentNode ||
2405 el.childNodes[i] == range.endContainer.parentNode.parentNode ||
2406 el.childNodes[i] == range.startContainer.parentNode.parentNode.parentNode)
2408 cursor.endNodeIndex = i;
2409 cursor.endPosInContent = sum + cursor.endPos;
2411 if(cursor.focusAtEnd == undefined &&
2412 (focusNode == range.endContainer ||
2413 extentNode == range.endContainer))
2414 cursor.focusAtEnd =
true;
2419 sum += el.childNodes[i].textContent.length;
2428 console.log(
"get cursor err:",err);
2436 var _DECORATION_RED =
"rgb(202, 52, 52)";
2437 var _DECORATION_BLUE =
"rgb(64, 86, 206)";
2438 var _DECORATION_GREEN =
"rgb(33, 175, 60)";
2439 var _DECORATION_BLACK =
"rgb(5, 5, 5)";
2440 var _DECORATION_GRAY =
"rgb(162, 179, 158)";
2441 var _DECORATIONS = {
2443 "ADD_SUBDIRECTORY" : _DECORATION_RED,
2444 "include_directories" : _DECORATION_RED,
2445 "simple_plugin" : _DECORATION_RED,
2446 "set" : _DECORATION_RED,
2447 "install_headers" : _DECORATION_RED,
2448 "install_source" : _DECORATION_RED,
2449 "enable_testing" : _DECORATION_RED,
2450 "CMAKE_MINIMUM_REQUIRED": _DECORATION_RED,
2451 "include" : _DECORATION_RED,
2452 "create_doxygen_documentation": _DECORATION_RED,
2455 "#define" : _DECORATION_RED,
2456 "#undef" : _DECORATION_RED,
2457 "#include" : _DECORATION_RED,
2458 "#ifndef" : _DECORATION_RED,
2459 "#else" : _DECORATION_RED,
2460 "#endif" : _DECORATION_RED,
2461 "using" : _DECORATION_RED,
2462 "namespace" : _DECORATION_RED,
2463 "class" : _DECORATION_RED,
2464 "public" : _DECORATION_RED,
2465 "private" : _DECORATION_RED,
2466 "protected" : _DECORATION_RED,
2467 "static" : _DECORATION_RED,
2468 "virtual" : _DECORATION_RED,
2469 "override" : _DECORATION_RED,
2470 "const" : _DECORATION_RED,
2471 "void" : _DECORATION_RED,
2472 "bool" : _DECORATION_RED,
2473 "unsigned" : _DECORATION_RED,
2474 "int" : _DECORATION_RED,
2475 "uint64_t" : _DECORATION_RED,
2476 "uint32_t" : _DECORATION_RED,
2477 "uint16_t" : _DECORATION_RED,
2478 "uint8_t" : _DECORATION_RED,
2479 "long" : _DECORATION_RED,
2480 "float" : _DECORATION_RED,
2481 "double" : _DECORATION_RED,
2482 "return" : _DECORATION_RED,
2483 "char" : _DECORATION_RED,
2484 "if" : _DECORATION_RED,
2485 "else" : _DECORATION_RED,
2486 "for" : _DECORATION_RED,
2487 "while" : _DECORATION_RED,
2488 "do" : _DECORATION_RED,
2489 "switch" : _DECORATION_RED,
2490 "case" : _DECORATION_RED,
2491 "default" : _DECORATION_RED,
2492 "try" : _DECORATION_RED,
2493 "catch" : _DECORATION_RED,
2494 "this" : _DECORATION_RED,
2495 "true" : _DECORATION_RED,
2496 "false" : _DECORATION_RED,
2500 "std" : _DECORATION_GREEN,
2501 "ots" : _DECORATION_GREEN,
2502 "string" : _DECORATION_GREEN,
2503 "set" : _DECORATION_GREEN,
2504 "vector" : _DECORATION_GREEN,
2505 "pair" : _DECORATION_GREEN,
2506 "get" : _DECORATION_GREEN,
2507 "map" : _DECORATION_GREEN,
2508 "endl" : _DECORATION_GREEN,
2509 "runtime_error" : _DECORATION_GREEN,
2510 "memcpy" : _DECORATION_GREEN,
2511 "cout" : _DECORATION_GREEN,
2514 "this" : _DECORATION_RED,
2515 "var" : _DECORATION_RED,
2516 "return" : _DECORATION_RED,
2517 "function" : _DECORATION_RED,
2518 "if" : _DECORATION_RED,
2519 "else" : _DECORATION_RED,
2520 "for" : _DECORATION_RED,
2521 "while" : _DECORATION_RED,
2522 "do" : _DECORATION_RED,
2523 "switch" : _DECORATION_RED,
2524 "case" : _DECORATION_RED,
2525 "default" : _DECORATION_RED,
2526 "try" : _DECORATION_RED,
2527 "catch" : _DECORATION_RED,
2528 "new" : _DECORATION_RED,
2529 "instanceof" : _DECORATION_RED,
2530 "true" : _DECORATION_RED,
2531 "false" : _DECORATION_RED,
2533 "Debug" : _DECORATION_GREEN,
2534 "DesktopContent" : _DECORATION_GREEN,
2535 "HIGH_PRIORITY" : _DECORATION_GREEN,
2536 "WARN_PRIORITY" : _DECORATION_GREEN,
2537 "INFO_PRIORITY" : _DECORATION_GREEN,
2538 "LOW_PRIORITY" : _DECORATION_GREEN,
2540 "Math" : _DECORATION_GREEN,
2541 "String" : _DECORATION_GREEN,
2542 "window" : _DECORATION_GREEN,
2543 "document" : _DECORATION_GREEN,
2544 "textContent" : _DECORATION_GREEN,
2545 "innerHTML" : _DECORATION_GREEN,
2548 "if" : _DECORATION_RED,
2549 "then" : _DECORATION_RED,
2550 "else" : _DECORATION_RED,
2551 "fi" : _DECORATION_RED,
2552 "for" : _DECORATION_RED,
2553 "in" : _DECORATION_RED,
2554 "while" : _DECORATION_RED,
2555 "do" : _DECORATION_RED,
2556 "done" : _DECORATION_RED,
2557 "switch" : _DECORATION_RED,
2558 "case" : _DECORATION_RED,
2559 "default" : _DECORATION_RED,
2560 "export" : _DECORATION_RED,
2562 "echo" : _DECORATION_GREEN,
2563 "cd" : _DECORATION_GREEN,
2564 "cp" : _DECORATION_GREEN,
2565 "rm" : _DECORATION_GREEN,
2566 "cat" : _DECORATION_GREEN,
2567 "wget" : _DECORATION_GREEN,
2568 "chmod" : _DECORATION_GREEN,
2569 "sleep" : _DECORATION_GREEN,
2572 this.updateDecorations =
function(forPrimary,forceDisplayComplete,forceDecorations)
2574 forPrimary = forPrimary?1:0;
2576 Debug.log(
"updateDecorations forPrimary=" + forPrimary +
" forceDisplayComplete=" + forceDisplayComplete);
2578 var el = _eel[forPrimary];
2579 var elTextObj = {
"text":el.textContent,
"time":Date.now()};
2580 var wasSnapshot = CodeEditor.editor.updateFileSnapshot(forPrimary,
2583 if(wasSnapshot || forceDisplayComplete)
2584 CodeEditor.editor.updateOutline(forPrimary,elTextObj);
2586 if(!forceDecorations && !wasSnapshot)
2588 Debug.log(
"unchanged, skipping decorations");
2598 var cursor = CodeEditor.editor.getCursor(el);
2602 CodeEditor.editor.updateLastSave(forPrimary);
2606 var decor, fontWeight;
2608 var commentString =
"#";
2609 if(_fileExtension[forPrimary][0] ==
'c' ||
2610 _fileExtension[forPrimary][0] ==
'C' ||
2611 _fileExtension[forPrimary][0] ==
'h' ||
2612 _fileExtension[forPrimary][0] ==
'j')
2613 commentString =
"//";
2615 var fileDecorType =
"txt";
2616 if( _fileExtension[forPrimary] ==
'html' ||
2617 _fileExtension[forPrimary] ==
'js')
2618 fileDecorType =
"js";
2619 else if(_fileExtension[forPrimary][0] ==
'c' ||
2620 _fileExtension[forPrimary][0] ==
'C' ||
2621 _fileExtension[forPrimary][0] ==
'h' ||
2622 _fileExtension[forPrimary][0] ==
'j')
2623 fileDecorType =
"c++";
2624 else if(_fileExtension[forPrimary] ==
'sh' ||
2625 _fileExtension[forPrimary] ==
'py')
2626 fileDecorType =
"sh";
2631 var startOfWord = -1;
2632 var startOfString = -1;
2633 var stringQuoteChar;
2635 var startOfComment = -1;
2636 var firstSpecialStringStartHandling =
true;
2637 var firstSpecialStringEndHandling =
true;
2638 var endPositionCache;
2649 function localInsertLabel(startPos, isQuote)
2653 newNode = document.createTextNode(val.substr(0,startPos));
2654 el.insertBefore(newNode,node);
2656 newNode = document.createElement(
"label");
2657 newNode.style.fontWeight = fontWeight;
2658 newNode.style.color = decor;
2659 newNode.textContent = specialString;
2661 el.insertBefore(newNode,node);
2665 var str = newNode.textContent;
2666 str = str.substr(str.indexOf(
'.')+1);
2669 if(str.length > 0 && str.length <= 4 &&
2679 Debug.log(
"is quote " + str);
2681 newNode.onmouseover =
function(e)
2683 window.clearTimeout(_fileStringHoverTimeout);
2685 var x = this.offsetWidth + this.offsetLeft + 64;
2686 var y = this.offsetTop;
2687 e.stopPropagation();
2690 if(_fileStringHoverEl.parentNode)
2692 _fileStringHoverEl.parentNode.removeChild(_fileStringHoverEl);
2697 _fileStringHoverEl = document.createElement(
"div");
2698 _fileStringHoverEl.setAttribute(
"id",
"fileStringHoverEl");
2699 _fileStringHoverEl.setAttribute(
"contentEditable",
"false");
2700 _fileStringHoverEl.onmouseover =
function(e)
2702 window.clearTimeout(_fileStringHoverTimeout);
2703 e.stopPropagation();
2707 _fileStringHoverEl.style.display =
'none';
2710 var name = this.textContent;
2713 name = name.substr(1,name.length-2);
2714 var nameArr = name.split(
'/');
2715 if(nameArr.length == 0)
2717 Debug.log(
"empty name array, error! name = " + name);
2720 else if(nameArr.length > 1 && nameArr[0] ==
"" &&
2721 nameArr[1] ==
"WebPath")
2723 name =
"/otsdaq_utilities/WebGUI" +
2724 name.substr((
"/WebPath").length);
2726 else if(nameArr[0] !=
"")
2729 var i = nameArr[0].indexOf(
'-');
2733 if(nameArr[0] !=
"otsdaq-core")
2735 nameArr[0] = nameArr[0].substr(0,i) +
'_'
2736 + nameArr[0].substr(i+1);
2739 nameArr[0] =
"otsdaq";
2741 name =
"/" + nameArr[0] +
"/" + name;
2745 Debug.log(
"Confused by name array, error! name = " + name);
2751 Debug.log(
"name " + name);
2755 str += htmlOpen(
"a",
2757 "title":
"Open file in this editor pane: \n" +
2759 "onclick":
"CodeEditor.editor.openFile(" +
2760 (forPrimary) +
",\"" +
2762 name.substr(name.indexOf(
'.')+1) +
"\"" +
2766 "style='float: left; padding: 1px 0 1px 6px;'>" +
2768 "style='border:1px solid rgb(99, 98, 98); border-radius: 2px; width: 9px;" +
2769 "height: 9px; '></div></div>"
2772 str += htmlOpen(
"a",
2774 "title":
"Open file in the other editor pane of the split-view: \n" +
2776 "onclick":
"CodeEditor.editor.openFile(" +
2777 (!forPrimary) +
",\"" +
2779 name.substr(name.indexOf(
'.')+1) +
"\"" +
2783 "style='float: left; padding: 0;'>" +
2784 "<img class='dirNavFileNewWindowImgNewPane' " +
2785 "src='/WebPath/images/windowContentImages/CodeEditor-openInOtherPane.png'></div>"
2788 str += htmlOpen(
"a",
2790 "title":
"Open file in a new browser tab: \n" +
2792 "onclick":
"DesktopContent.openNewBrowserTab(" +
2793 "\"Code Editor\",\"\"," +
2794 "\"/WebPath/html/CodeEditor.html?startFilePrimary=" +
2795 name +
"\",0 /*unique*/);' ",
2798 "style='float: left; padding: 0 6px 0 0;'>" +
2799 "<img class='dirNavFileNewWindowImgNewWindow' " +
2800 "src='/WebPath/images/windowContentImages/CodeEditor-openInNewWindow.png'></div>"
2803 _fileStringHoverEl.innerHTML = str;
2805 this.parentNode.appendChild(_fileStringHoverEl);
2808 _fileStringHoverEl.style.left = x +
"px";
2809 _fileStringHoverEl.style.top = y +
"px";
2811 _fileStringHoverEl.style.display =
'block';
2818 node.textContent = val.substr(i);
2822 if(cursor.startNodeIndex !== undefined)
2824 if(n < cursor.startNodeIndex)
2827 cursor.startNodeIndex += 2;
2828 cursor.endNodeIndex += 2;
2835 if(n == cursor.startNodeIndex)
2838 if(cursor.startPos < startPos)
2843 else if(cursor.startPos < i)
2846 ++cursor.startNodeIndex;
2847 cursor.startPos -= startPos;
2852 cursor.startNodeIndex += 2;
2853 if(val[cursor.startPos-1] ==
'\r') --cursor.startPos;
2854 cursor.startPos -= i;
2859 if(n == cursor.endNodeIndex)
2862 if(cursor.endPos < startPos)
2867 else if(cursor.endPos < i)
2870 ++cursor.endNodeIndex;
2871 cursor.endPos -= startPos;
2876 cursor.endNodeIndex += 2;
2877 if(val[cursor.endPos-1] ==
'\r') --cursor.endPos;
2882 else if(n < cursor.endNodeIndex)
2884 cursor.endNodeIndex += 2;
2894 for(n=0;!done && n<el.childNodes.length;++n)
2896 node = el.childNodes[n];
2897 val = node.textContent;
2899 if(node.nodeName ==
"LABEL" ||
2900 node.nodeName ==
"FONT" ||
2901 node.nodeName ==
"SPAN" ||
2902 node.nodeName ==
"PRE")
2907 if((_DECORATIONS[fileDecorType][val] === undefined &&
2908 (val[0] != commentString[0] ||
2909 val.indexOf(
'\n') >= 0) &&
2912 (n+1 >= cursor.startNodeIndex && n-1 <= cursor.endNodeIndex))
2917 newNode = document.createTextNode(val);
2918 el.insertBefore(newNode,node);
2919 el.removeChild(node);
2928 else if(node.nodeName ==
"DIV" ||
2929 node.nodeName ==
"BR")
2933 eatVal = node.innerHTML;
2937 if(node.nodeName ==
"DIV")
2941 specialString = el.childNodes[n-1].textContent;
2942 if(specialString[specialString.length-1] ==
'\n')
2946 if(eatVal.indexOf(
"<br>") == 0 ||
2958 newNode = document.createTextNode(val);
2959 el.insertBefore(newNode,node);
2960 el.removeChild(node);
2963 if(n == cursor.startNodeIndex)
2964 cursor.startPos += i;
2965 if(n == cursor.endNodeIndex)
2972 else if(node.nodeName ==
"#text")
2975 el.childNodes[n-1].nodeName ==
"#text")
2983 if(n + 1 < el.childNodes.length &&
2984 el.childNodes[n+1].nodeName ==
"#text")
2991 if(cursor.startNodeIndex !== undefined)
2993 if(n+1 < cursor.startNodeIndex)
2996 cursor.startNodeIndex -= 1;
2997 cursor.endNodeIndex -= 1;
3004 if(n+1 == cursor.startNodeIndex)
3007 --cursor.startNodeIndex;
3008 cursor.startPos += val.length;
3012 if(n+1 == cursor.endNodeIndex)
3015 --cursor.endNodeIndex;
3016 cursor.endPos += val.length;
3018 else if(n+1 < cursor.endNodeIndex)
3021 --cursor.endNodeIndex;
3027 newNode = el.childNodes[n+1];
3028 val += newNode.textContent;
3029 newNode.textContent = val;
3030 el.removeChild(node);
3038 for(i=0;i<val.length;++i)
3045 if(startOfComment == -1 && (
3046 startOfString != -1 ||
3047 (prevChar !=
'\\' && val[i] ==
'"') ||
3048 (prevChar !=
'\\' && val[i] ==
"'")
3051 if(startOfString == -1 &&
3052 (val[i] ==
'"' || val[i] ==
"'"))
3055 stringQuoteChar = val[i];
3057 firstSpecialStringStartHandling =
true;
3058 firstSpecialStringEndHandling =
true;
3060 else if(prevChar !=
'\\' && val[i] == stringQuoteChar)
3063 specialString = val.substr(startOfString,i-startOfString);
3066 decor = _DECORATION_BLUE;
3067 fontWeight =
"normal";
3068 localInsertLabel(startOfString,
true );
3074 else if(startOfString == -1 && (
3075 startOfComment != -1 ||
3076 (i+commentString.length-1 < val.length &&
3077 val.substr(i,commentString.length) ==
3080 if(startOfComment == -1 && val[i] == commentString[0])
3083 firstSpecialStringStartHandling =
true;
3084 firstSpecialStringEndHandling =
true;
3086 else if(val[i] ==
'\n')
3089 specialString = val.substr(startOfComment,i-startOfComment);
3092 decor = _DECORATION_GRAY;
3093 fontWeight =
"normal";
3094 localInsertLabel(startOfComment);
3095 startOfComment = -1;
3101 (val[i] >=
'a' && val[i] <=
'z') ||
3102 (val[i] >=
'A' && val[i] <=
'Z') ||
3103 (val[i] >=
'0' && val[i] <=
'9') ||
3104 (val[i] ==
'_' || val[i] ==
'-') ||
3107 if(startOfWord == -1)
3111 else if(startOfWord != -1)
3113 specialString = val.substr(startOfWord,i-startOfWord);
3114 decor = _DECORATIONS[fileDecorType][specialString];
3120 fontWeight =
"bold";
3121 localInsertLabel(startOfWord);
3131 if(prevChar ==
'\\' && val[i] ==
'\\')
3134 if(escapeCount%2 == 0)
3152 if(startOfString != -1 || startOfComment != -1)
3154 console.log(
"In string/comment crossing Nodes!");
3157 closedString =
false;
3158 for(++n;n<el.childNodes.length;++n)
3160 eatNode = el.childNodes[n];
3161 eatVal = eatNode.textContent;
3165 if(cursor.startNodeIndex !== undefined)
3167 if(firstSpecialStringStartHandling)
3168 firstSpecialStringStartHandling =
false;
3170 if(firstSpecialStringEndHandling)
3174 endPositionCache = cursor.endPos;
3175 firstSpecialStringEndHandling =
false;
3178 if(n < cursor.startNodeIndex)
3181 cursor.startNodeIndex -= 1;
3182 cursor.endNodeIndex -= 1;
3189 if(n == cursor.startNodeIndex)
3192 --cursor.startNodeIndex;
3193 cursor.startPos += val.length;
3197 if(n == cursor.endNodeIndex)
3200 --cursor.endNodeIndex;
3201 cursor.endPos += val.length;
3203 else if(n < cursor.endNodeIndex)
3206 --cursor.endNodeIndex;
3282 el.removeChild(eatNode);
3287 for(i;i<val.length;++i)
3290 if(startOfString != -1 &&
3291 (prevChar !=
'\\' && val[i] ==
'"'))
3293 Debug.log(
"Closing node crossed string.");
3296 specialString = val.substr(startOfString,i-startOfString);
3299 decor = _DECORATION_BLUE;
3300 fontWeight =
"normal";
3301 localInsertLabel(startOfString,
true );
3303 closedString =
true;
3308 if(startOfComment != -1 && val[i] ==
'\n')
3310 Debug.log(
"Closing node crossed comment.");
3314 specialString = val.substr(startOfComment,i-startOfComment);
3317 decor = _DECORATION_GRAY;
3318 fontWeight =
"normal";
3319 localInsertLabel(startOfComment);
3320 startOfComment = -1;
3322 closedString =
true;
3328 if(prevChar ==
'\\' && val[i] ==
'\\')
3331 if(escapeCount%2 == 0)
3344 if(closedString)
break;
3348 if(!closedString && startOfString != -1)
3350 Debug.log(
"String is never closed!");
3351 specialString = val.substr(startOfString,i-startOfString);
3354 decor = _DECORATION_BLUE;
3356 localInsertLabel(startOfString,
true );
3359 if(!closedString && startOfComment != -1)
3361 Debug.log(
"Comment is never closed!");
3362 specialString = val.substr(startOfComment,i-startOfComment);
3365 decor = _DECORATION_GRAY;
3367 localInsertLabel(startOfComment);
3368 startOfComment = -1;
3371 if(n < cursor.endNodeIndex)
3375 firstSpecialStringEndHandling =
true;
3376 cursor.endPos = endPositionCache;
3385 console.log(
"unknown node.nodeName",node.nodeName);
3386 throw(
"node error!");
3391 CodeEditor.editor.setCursor(el,cursor);
3393 CodeEditor.editor.updateDualView(forPrimary);
3399 this.autoIndent =
function(forPrimary, cursor)
3401 if(!cursor || cursor.startNodeIndex === undefined)
3403 Debug.log(
"Invalid text selection for auto-indent. Please select text in the text editor.",
3404 Debug.HIGH_PRIORITY);
3407 forPrimary = forPrimary?1:0;
3409 Debug.log(
"autoIndent " + forPrimary);
3411 DesktopContent.showLoading(localDoIt);
3420 function localDoIt()
3430 var el = _eel[forPrimary];
3436 for(n=cursor.startNodeIndex;n>=0; --n)
3438 node = el.childNodes[n];
3439 val = node.textContent;
3441 for(i=(n==cursor.startNodeIndex?cursor.startPos-1:
3442 val.length-1); i>=0; --i)
3455 console.log(
"at leading newline - n",n,
"i",i);
3461 cursor.startNodeIndex = n;
3462 cursor.startPos = i;
3470 for(n=0; n<el.childNodes.length; ++n)
3472 val = el.childNodes[n].textContent;
3473 if(n < cursor.startNodeIndex)
3475 else if(n == cursor.startNodeIndex)
3477 preText += val.substr(0,cursor.startPos);
3479 if(n < cursor.endNodeIndex)
3480 text += val.substr(cursor.startPos);
3483 text += val.substr(cursor.startPos,
3484 cursor.endPos-cursor.startPos);
3485 postText += val.substr(cursor.endPos);
3488 else if(n < cursor.endNodeIndex)
3490 else if(n == cursor.endNodeIndex)
3492 text += val.substr(0,cursor.endPos);
3493 postText += val.substr(cursor.endPos);
3503 var fileExtension = _fileExtension[forPrimary];
3514 for(i=0;i<text.length;++i)
3517 else if(text[i] ==
'\t')
3518 x += _TAB_SIZE - (x+_TAB_SIZE)%_TAB_SIZE;
3521 Debug.log(
"Whitespace size =" + x +
" tabs=" + ((x/_TAB_SIZE)|0));
3525 for(n=0;n<((x/_TAB_SIZE)|0);++n)
3534 var lastChar,firstChar;
3535 var prevLastChar,prevFirstChar;
3537 var inCmdTabStr =
"";
3538 var nextInCmdTabStr =
"";
3539 var isCmdTabStr =
"";
3540 var nextIsCmdTabStr =
"";
3545 var firstColonCommand =
false;
3546 var lastColonCommand =
false;
3547 var foundDoubleQuote,foundSingleQuote;
3548 var tradeInCmdStack = [];
3549 var tradeIsCmdStack = [];
3559 foundComment =
false;
3560 foundDoubleQuote =
false;
3561 foundSingleQuote =
false;
3563 for(n=i+1;n<text.length;++n)
3571 if(!foundSingleQuote && text[n] ==
'"')
3572 foundDoubleQuote = !foundDoubleQuote;
3573 else if(!foundDoubleQuote && text[n] ==
"'")
3574 foundSingleQuote = !foundSingleQuote;
3575 else if(text[n] ==
'/' && n+1 < text.length &&
3578 foundComment =
true;
3582 if(foundDoubleQuote || foundSingleQuote)
3585 if(text[n] !=
' ' && text[n] !=
'\t')
3589 firstChar = text[n];
3594 inCmdTabStr +=
'\t';
3595 else if(text[n] ==
')')
3596 inCmdTabStr = inCmdTabStr.substr(0, inCmdTabStr.length-1);
3597 else if(inCmdTabStr.length == 0 &&
3602 firstColonCommand =
false;
3603 lastColonCommand =
false;
3608 nextTabStr = tabStr;
3611 if(firstChar ==
'}')
3613 nextIsCmdTabStr =
"";
3616 if(tradeInCmdStack.length &&
3617 tradeInCmdStack[tradeInCmdStack.length-1][0] ==
3621 inCmdTabStr = tradeInCmdStack.pop()[1];
3622 nextInCmdTabStr = inCmdTabStr;
3623 isCmdTabStr = tradeIsCmdStack.pop();
3624 tabStr = tabStr.substr(0,tabStr.length-1);
3629 firstColonCommand =
false;
3631 tabStr = tabStr.substr(0,tabStr.length-1);
3632 nextTabStr = tabStr;
3634 else if(lastChar ==
':' &&
3635 (firstChar ==
'p' ||
3639 nextIsCmdTabStr =
"";
3643 firstColonCommand =
false;
3644 lastColonCommand =
false;
3645 nextTabStr = tabStr.substr(0,tabStr.length-1);
3647 else if(firstChar ==
':')
3650 nextIsCmdTabStr =
"";
3652 firstColonCommand =
true;
3654 else if(firstChar ==
'#' ||
3658 if(lastColonCommand)
3659 tabStr = tabStr.substr(0,tabStr.length-1);
3663 if(nextInCmdTabStr.length != 0 ||
3664 nextIsCmdTabStr.length != 1 ||
3665 prevLastChar !=
',')
3668 nextIsCmdTabStr =
"";
3672 else if(!firstColonCommand &&
3673 !lastColonCommand &&
3679 else if(lastColonCommand &&
3680 prevLastChar ==
',' &&
3681 inCmdTabStr.length == 0)
3684 lastColonCommand =
false;
3685 tabStr = tabStr.substr(0,tabStr.length-1);
3687 nextIsCmdTabStr =
"\t";
3690 firstColonCommand =
false;
3697 firstColonCommand =
false;
3698 lastColonCommand =
false;
3702 "firstChar = " + firstChar +
3703 "lastChar = " + lastChar +
3704 "prevFirstChar = " + prevFirstChar +
3705 "prevLastChar = " + prevLastChar +
3709 inCmdTabStr.length +
3711 isCmdTabStr.length +
3715 nextInCmdTabStr.length +
3717 nextIsCmdTabStr.length +
3719 tradeInCmdStack.length +
3720 " " + firstColonCommand +
3721 " " + lastColonCommand);
3725 newText += nextTabStr + nextInCmdTabStr + nextIsCmdTabStr;
3727 newText += text.substr(i+1,n-(i+1)).trimLeft();
3736 if(inCmdTabStr.length)
3740 tradeInCmdStack.push([tabStr.length,inCmdTabStr]);
3741 tradeIsCmdStack.push(isCmdTabStr);
3757 nextInCmdTabStr = inCmdTabStr;
3758 nextIsCmdTabStr = isCmdTabStr;
3761 prevLastChar = lastChar;
3763 prevFirstChar = firstChar;
3767 }
while(i+1<text.length);
3771 if(text[i] ==
'\n') newText +=
'\n';
3777 Debug.log(
"Unknown operation to auto-indent file with extension " +
3778 fileExtension,Debug.HIGH_PRIORITY);
3783 el.textContent = preText + newText + postText;
3785 _fileWasModified[forPrimary] =
true;
3787 CodeEditor.editor.updateDecorations(forPrimary,
3796 this.updateDualView =
function(forPrimary)
3798 forPrimary = forPrimary?1:0;
3800 Debug.log(
"updateDualView " + forPrimary);
3804 if(_filePath[0] == _filePath[1] &&
3805 _fileExtension[0] == _fileExtension[1])
3807 var val,node, newNode;
3808 var el = _eel[forPrimary];
3810 Debug.log(
"Update dual view");
3812 _fileLastSave[(!forPrimary)?1:0] = _fileLastSave[forPrimary];
3813 _fileWasModified[(!forPrimary)?1:0] = _fileWasModified[forPrimary];
3814 CodeEditor.editor.updateLastSave(!forPrimary);
3818 var elAlt = _eel[(!forPrimary)?1:0];
3819 elAlt.innerHTML =
"";
3820 for(i=0;i<el.childNodes.length;++i)
3822 node = el.childNodes[i];
3823 val = node.textContent;
3824 if(node.nodeName ==
"LABEL")
3826 newNode = document.createElement(
"label");
3827 newNode.style.fontWeight = node.style.fontWeight;
3828 newNode.style.color = node.style.color;
3829 newNode.textContent = val;
3831 else if(node.nodeName ==
"#text")
3833 newNode = document.createTextNode(val);
3836 Debug.log(
"Skipping unknown node " + node.nodeName);
3837 elAlt.appendChild(newNode);
3846 this.updateOutline =
function(forPrimary,elTextObj)
3848 forPrimary = forPrimary?1:0;
3850 Debug.log(
"updateOutline " + forPrimary);
3858 var localNewLineCount;
3860 var newLineCount = 0;
3862 outline.push([1,
"Top"]);
3866 var isCcSource = _fileExtension[forPrimary][0] ==
'c' ||
3867 _fileExtension[forPrimary][0] ==
'C';
3868 var isJsSource = _fileExtension[forPrimary] ==
"js" ||
3869 _fileExtension[forPrimary] ==
"html";
3871 var indicatorIndex = 0;
3873 if(isCcSource) indicator =
"::";
3874 if(isJsSource) indicator =
"function";
3876 for(i=0;i<elTextObj.text.length;++i)
3878 if(elTextObj.text[i] ==
'\n')
3886 if(elTextObj.text[i] == indicator[indicatorIndex])
3889 if(indicatorIndex == indicator.length)
3896 str = localHandleCcOutline();
3898 str = localHandleJsOutline();
3903 outline.push([newLineCount+1,
3916 Debug.log(
"Number of lines " + newLineCount);
3917 console.log(
"Done with outline", outline);
3921 for(i=0;i<newLineCount;++i)
3923 str +=
"<a name='" + forPrimary +
"L" + (i+1) +
"'></a>";
3927 document.getElementById(
"editableBoxLeftMargin" + forPrimary).innerHTML = str;
3929 _numberOfLines[forPrimary] = newLineCount;
3932 if(!isCcSource && !isJsSource)
3935 i = (newLineCount/2)|0;
3938 outline.push([i,
"Middle"]);
3941 outline.push([newLineCount,
"Bottom"]);
3947 str +=
"<table><td>"
3950 str += htmlOpen(
"select",
3952 "class":
"textEditorOutlineSelect",
3953 "id":
"textEditorOutlineSelect" + forPrimary,
3954 "style":
"text-align-last: center; width: 100%;",
3955 "title":
"Jump to a section of code.",
3957 "CodeEditor.editor.handleOutlineSelect(" + forPrimary +
");",
3959 "CodeEditor.editor.stopUpdateHandling(event);",
3961 str +=
"<option value='0'>Jump to a Line Number (Ctrl + L)</option>";
3964 for(i=0;i<outline.length;++i)
3966 str +=
"<option value='" + (outline[i][0]-2) +
"'>";
3967 text =
"#" + outline[i][0];
3971 found = (outline[i][1].indexOf(
"local") == 0);
3973 for(j=text.length;j<(found?20:12);++j)
3975 str += outline[i][1];
3979 str +=
"</td></table>";
3983 document.getElementById(
"textEditorOutline" + forPrimary).innerHTML = str;
3987 Debug.log(
"Ignoring missing outline element. Assuming header not shown.");
3993 function localHandleCcOutline()
3995 if(startCi && i < startCi)
4009 for(j=i+2;j<elTextObj.text.length;++j)
4011 if(elTextObj.text[j] ==
';' ||
4012 elTextObj.text[j] ==
'+' ||
4013 elTextObj.text[j] ==
'"' ||
4014 elTextObj.text[j] ==
"'")
4018 if(elTextObj.text[j] ==
'(')
4021 else if(startCi < 0)
4023 if(elTextObj.text[j] ==
'{')
4033 if(endi < 0 || startCi < 0)
4042 if(elTextObj.text[j] ==
')')
4056 return elTextObj.text.substr(starti+2,endi-starti-2).replace(/\s+/g,
'');
4062 function localHandleJsOutline()
4064 if(elTextObj.text[i + 1] ==
'(')
4071 for(j=i-1-(
"function").length;j>=0;--j)
4073 if(elTextObj.text[j] ==
'=')
4079 else if(!(elTextObj.text[j] ==
' ' || elTextObj.text[j] ==
'\t' ||
4080 (elTextObj.text[j] ==
'=' && !found)))
4089 if(elTextObj.text[j] ==
' ' || elTextObj.text[j] ==
'\t' ||
4090 elTextObj.text[j] ==
'\n')
4093 return elTextObj.text.substr(j+1,k-j-1).trim();
4103 for(j=i+2;j<elTextObj.text.length;++j)
4105 if(elTextObj.text[j] ==
'\n')
4107 else if(elTextObj.text[j] ==
'(')
4110 return elTextObj.text.substr(i+2,j-(i+2)).trim();
4122 this.handleOutlineSelect =
function(forPrimary)
4124 forPrimary = forPrimary?1:0;
4126 Debug.log(
"handleOutlineSelect() " + forPrimary);
4128 var val = document.getElementById(
"textEditorOutlineSelect" + forPrimary).value | 0;
4129 if(val < 1) val = 1;
4130 console.log(
"line val",val);
4132 CodeEditor.editor.gotoLine(forPrimary,val,
4141 this.keyDownHandler =
function(e,forPrimary,shortcutsOnly)
4143 forPrimary = forPrimary?1:0;
4145 var keyCode = e.keyCode;
4147 CodeEditor.editor.stopUpdateHandling();
4162 CodeEditor.editor.startUpdateHandling(forPrimary);
4164 var el = _eel[forPrimary];
4166 var cursorSelection =
false;
4172 cursor = CodeEditor.editor.getCursor(el);
4174 cursorSelection = (cursor.startNodeIndex !== undefined &&
4175 (cursor.startNodeIndex != cursor.endNodeIndex ||
4176 cursor.startPos != cursor.endPos));
4178 if(!cursorSelection)
4179 _lastPageUpDownLine = -1;
4182 function localInsertCharacter(c)
4184 Debug.log(
"Inserting character... " + c);
4197 if(cursor.endNodeIndex > cursor.startNodeIndex)
4200 val = el.childNodes[cursor.endNodeIndex].textContent;
4201 val = val.substr(cursor.endPos);
4202 el.childNodes[cursor.endNodeIndex].textContent = val;
4203 --cursor.endNodeIndex;
4204 while(cursor.endNodeIndex > cursor.startNodeIndex)
4207 el.removeChild(el.childNodes[cursor.endNodeIndex]);
4208 --cursor.endNodeIndex;
4211 cursor.endPos = el.childNodes[cursor.startNodeIndex].textContent.length;
4214 var whiteSpaceString =
"";
4215 var postWhiteSpaceString =
"";
4216 var text = el.childNodes[cursor.startNodeIndex].textContent;
4217 var preCharString = text.substr(0,cursor.startPos);
4218 var cursorPosDelta = 0;
4229 for(n=cursor.startNodeIndex;n>=0; --n)
4231 node = el.childNodes[n];
4232 val = node.textContent;
4234 for(i=(n==cursor.startNodeIndex?cursor.startPos-1:
4235 val.length-1); i>=0; --i)
4243 else if(firstChar ==
'' &&
4244 val[i] !=
'\t' && val[i] !=
' ')
4251 console.log(
"at leading newline - n",n,
"i",i,
"firstChar",firstChar);
4258 for(n; n<el.childNodes.length; ++n)
4260 node = el.childNodes[n];
4261 val = node.textContent;
4263 for(i;i<val.length;++i)
4266 if((val[i] !=
'\t' && val[i] !=
' ') ||
4267 (n == cursor.startNodeIndex &&
4268 i >= cursor.startPos))
4274 whiteSpaceString += val[i];
4277 if(found || n == cursor.startNodeIndex)
break;
4282 if(firstChar ==
'{')
4284 postWhiteSpaceString +=
"\n" + whiteSpaceString +
"}";
4285 whiteSpaceString +=
'\t';
4286 postWhiteSpaceString += text.substr(cursor.endPos);
4290 val = text.substr(cursor.endPos);
4291 i = val.indexOf(
'\n');
4295 postWhiteSpaceString += val.substr(0,
4297 postWhiteSpaceString += val.substr(i);
4300 postWhiteSpaceString += val.trimLeft();
4311 var foundFirstNewLine =
false;
4315 for(n=cursor.startNodeIndex;n>=0; --n)
4317 node = el.childNodes[n];
4318 val = node.textContent;
4320 for(i=(n==cursor.startNodeIndex?cursor.startPos-1:
4321 val.length-1); i>=0; --i)
4330 Debug.log(
"Found matching bracket n=" + n +
4337 else if(val[i] ==
'}')
4339 else if(!foundFirstNewLine &&
4342 foundFirstNewLine =
true;
4344 Debug.log(
"pre-deleted white space preCharString=" +
4345 preCharString.length +
" " + preCharString);
4350 for(nn;nn<el.childNodes.length;++nn)
4352 if(nn < cursor.startNodeIndex)
4355 el.childNodes[nn].textContent =
"";
4357 else if(nn == cursor.startNodeIndex)
4360 preCharString = el.childNodes[nn].textContent.substr(
4367 Debug.log(
"deleted white space preCharString=" +
4368 preCharString.length +
" " + preCharString);
4370 else if(!foundFirstNewLine && val[i] !=
' ' &&
4373 Debug.log(
"Found character between } and new line, so doing nothing.");
4382 console.log(
"at closing bracket - n",n,
"i",i);
4385 preCharString = preCharString.trimRight();
4389 var matchingWhiteSpace =
"";
4391 var firstTime =
true;
4395 node = el.childNodes[n];
4396 val = node.textContent;
4399 val.length-1); i>=0; --i)
4407 else if(val[i] ==
' ' ||
4409 matchingWhiteSpace += val[i];
4411 matchingWhiteSpace =
"";
4420 preCharString += matchingWhiteSpace;
4421 Debug.log(
"matching white space preCharString=" +
4422 preCharString.length +
" " + preCharString);
4424 postWhiteSpaceString += text.substr(cursor.endPos);
4428 postWhiteSpaceString += text.substr(cursor.endPos);
4430 val = preCharString + c +
4432 postWhiteSpaceString;
4434 el.childNodes[cursor.startNodeIndex].textContent = val;
4437 console.log(
"cursorPosDelta",cursorPosDelta);
4439 cursor.startPos = c.length + preCharString.length + whiteSpaceString.length;
4440 cursor.endNodeIndex = cursor.startNodeIndex;
4441 cursor.endPos = cursor.startPos;
4443 console.log(
"cursor after newline",cursor);
4445 CodeEditor.editor.setCursor(el,cursor,
true );
4447 _fileWasModified[forPrimary] =
true;
4462 localInsertCharacter(
'\n');
4468 else if(keyCode == 36)
4482 var lastNonWhitespacePos = cursor.startPos;
4483 var lastNonWhitespaceNodeIndex = cursor.startNodeIndex;
4484 var lastPos = cursor.startPos;
4485 var lastNodeIndex = cursor.startNodeIndex;
4488 for(n=cursor.startNodeIndex; n>=0; --n)
4490 node = el.childNodes[n];
4491 val = node.textContent;
4493 for(i=(n==cursor.startNodeIndex?
4494 cursor.startPos-1:val.length-1);i>=0;--i)
4501 else if(!(val[i] ==
' ' ||
4504 lastNonWhitespacePos = i;
4505 lastNonWhitespaceNodeIndex = n;
4513 console.log(
"lastNonWhitespacePos",lastNonWhitespacePos);
4514 console.log(
"lastNonWhitespaceNodeIndex",lastNonWhitespaceNodeIndex);
4516 if(lastNonWhitespacePos == cursor.startPos &&
4517 lastNonWhitespaceNodeIndex == cursor.startNodeIndex)
4520 lastNonWhitespacePos = lastPos;
4521 lastNonWhitespaceNodeIndex = lastNodeIndex;
4525 if(lastNonWhitespacePos == lastPos &&
4526 lastNonWhitespaceNodeIndex == lastNodeIndex)
4527 document.getElementById(
"textEditorBody" + forPrimary).scrollLeft = 0;
4529 cursor.startNodeIndex = lastNonWhitespaceNodeIndex
4530 cursor.startPos = lastNonWhitespacePos;
4534 cursor.endNodeIndex = cursor.startNodeIndex;
4535 cursor.endPos = cursor.startPos;
4539 CodeEditor.editor.setCursor(el,cursor,
true );
4543 else if(keyCode == 35)
4559 var wantNext =
false;
4560 var lastNonWhitespacePos = cursor.startPos;
4561 var lastNonWhitespaceNodeIndex = cursor.startNodeIndex;
4564 for(n=cursor.startNodeIndex; n<el.childNodes.length; ++n)
4566 node = el.childNodes[n];
4567 val = node.textContent;
4569 for(i=(n==cursor.startNodeIndex?
4570 cursor.startPos:0);i<val.length;++i)
4574 lastNonWhitespacePos = i;
4575 lastNonWhitespaceNodeIndex = n;
4583 else if(!(val[i] ==
' ' ||
4591 console.log(
"lastNonWhitespacePos",lastNonWhitespacePos);
4592 console.log(
"lastNonWhitespaceNodeIndex",lastNonWhitespaceNodeIndex);
4594 if(lastNonWhitespacePos == cursor.startPos &&
4595 lastNonWhitespaceNodeIndex == cursor.startNodeIndex)
4598 lastNonWhitespacePos = i;
4599 lastNonWhitespaceNodeIndex = n;
4602 cursor.endNodeIndex = lastNonWhitespaceNodeIndex
4603 cursor.endPos = lastNonWhitespacePos;
4607 cursor.startNodeIndex = cursor.endNodeIndex;
4608 cursor.startPos = cursor.endPos;
4612 CodeEditor.editor.setCursor(el,cursor,
true );
4623 e.stopPropagation();
4632 var gotoLineCursor = {};
4635 if(_lastPageUpDownLine == -1)
4637 var cursorWithLine = CodeEditor.editor.getLine(forPrimary);
4639 _startPageUpDownNodeIndex = cursorWithLine.startNodeIndex;
4640 _startPageUpDownPos = cursorWithLine.startPos;
4642 _startPageUpDownLine = cursorWithLine.line;
4643 _lastPageUpDownLine = _startPageUpDownLine;
4646 gotoLineCursor.startNodeIndex = _startPageUpDownNodeIndex;
4647 gotoLineCursor.startPos = _startPageUpDownPos;
4650 _lastPageUpDownLine -= N;
4651 gotoLineCursor.focusAtEnd = (_lastPageUpDownLine > _startPageUpDownLine);
4653 Debug.log(
"Page up to line " + _lastPageUpDownLine +
" dir=" +
4654 gotoLineCursor.focusAtEnd);
4656 _lastPageUpDownLine = CodeEditor.editor.gotoLine(forPrimary,_lastPageUpDownLine,
4657 e.shiftKey?gotoLineCursor:undefined);
4661 else if(keyCode == 34)
4665 e.stopPropagation();
4674 var gotoLineCursor = {};
4677 if(_lastPageUpDownLine == -1)
4679 var cursorWithLine = CodeEditor.editor.getLine(forPrimary);
4681 _startPageUpDownNodeIndex = cursorWithLine.startNodeIndex;
4682 _startPageUpDownPos = cursorWithLine.startPos;
4684 _startPageUpDownLine = cursorWithLine.line;
4685 _lastPageUpDownLine = _startPageUpDownLine;
4688 gotoLineCursor.startNodeIndex = _startPageUpDownNodeIndex;
4689 gotoLineCursor.startPos = _startPageUpDownPos;
4692 _lastPageUpDownLine += N;
4693 gotoLineCursor.focusAtEnd = (_lastPageUpDownLine > _startPageUpDownLine);
4695 Debug.log(
"Page down to line " + _lastPageUpDownLine +
" dir=" +
4696 gotoLineCursor.focusAtEnd);
4698 _lastPageUpDownLine = CodeEditor.editor.gotoLine(forPrimary,_lastPageUpDownLine,
4699 e.shiftKey?gotoLineCursor:undefined);
4703 else if(keyCode == 13)
4709 if(CodeEditor.editor.findAndReplaceLastButton[forPrimary] > 0)
4712 e.stopPropagation();
4714 Debug.log(
"Launch find and replace action " +
4715 CodeEditor.editor.findAndReplaceLastButton[forPrimary]);
4716 CodeEditor.editor.doFindAndReplaceAction(forPrimary,
4717 CodeEditor.editor.findAndReplaceLastButton[forPrimary]);
4721 else if(keyCode == 27)
4727 if(CodeEditor.editor.findAndReplaceLastButton[forPrimary] > 0)
4730 e.stopPropagation();
4733 CodeEditor.editor.displayFileHeader(forPrimary);
4746 CodeEditor.editor.saveFile(forPrimary,
true );
4750 else if(keyCode == 68)
4752 CodeEditor.editor.toggleDirectoryNav(forPrimary);
4756 else if(keyCode == 66)
4758 CodeEditor.editor.build();
4762 else if(keyCode == 70)
4764 CodeEditor.editor.showFindAndReplace(forPrimary);
4768 else if(keyCode == 73)
4770 CodeEditor.editor.autoIndent(forPrimary, cursor);
4774 else if(keyCode == 78)
4776 CodeEditor.editor.build(
true );
4780 else if(keyCode == 48)
4782 CodeEditor.editor.openFile(forPrimary,
4783 _filePath[forPrimary],
4784 _fileExtension[forPrimary],
4789 else if(keyCode == 50)
4791 CodeEditor.editor.toggleView();
4795 else if(keyCode == 85)
4797 CodeEditor.editor.undo(forPrimary, e.shiftKey );
4801 else if(keyCode == 76 ||
4804 DesktopContent.popUpVerification(
4805 "Goto line number: ",
4809 Debug.log(
"Going to line... " + line);
4810 CodeEditor.editor.gotoLine(forPrimary,line);
4823 else if(keyCode == 49)
4825 CodeEditor.editor.openRelatedFile(forPrimary);
4836 var rectangularTAB =
false;
4837 var blockCOMMENT =
false;
4848 rectangularTAB =
true;
4852 else if(keyCode == 191)
4854 blockCOMMENT =
true;
4865 if(keyCode == TABKEY || rectangularTAB ||
4868 _fileWasModified[forPrimary] =
true;
4869 CodeEditor.editor.updateLastSave(forPrimary);
4881 Debug.log(
"special key selected lines " + cursor.startNodeIndex +
" - " +
4882 cursor.endNodeIndex);
4889 Debug.log(
"Rectangular TAB");
4904 for(n=cursor.startNodeIndex;n>=0; --n)
4906 node = el.childNodes[n];
4907 val = node.textContent;
4909 for(i=(n==cursor.startNodeIndex?cursor.startPos-1:
4910 val.length-1); i>=0; --i)
4922 console.log(
"at leading newline - n",n,
"i",i);
4926 for(n; n<el.childNodes.length; ++n)
4928 node = el.childNodes[n];
4929 val = node.textContent;
4931 for(i;i<val.length;++i)
4934 if(n == cursor.startNodeIndex &&
4935 i == cursor.startPos)
4940 var prelength = val.length;
4944 if(i-1 >= 0 && val[i-1] ==
'\t')
4945 node.textContent = val.substr(0,i-1) + val.substr(i);
4949 node.textContent = val.substr(0,i) +
"\t" + val.substr(i);
4955 cursor.startPos += node.textContent.length - prelength;
4961 x += _TAB_SIZE - (x+_TAB_SIZE)%_TAB_SIZE;
4977 for(n=cursor.startNodeIndex; n<el.childNodes.length; ++n)
4979 node = el.childNodes[n];
4980 val = node.textContent;
4982 for(i=(n==cursor.startNodeIndex?cursor.startPos:
4983 0);i<val.length;++i)
4998 if(i-1 < val.length && val[i-1] ==
'\t')
5000 val = val.substr(0,i-1) + val.substr(i);
5001 node.textContent = val;
5006 val = val.substr(0,i) +
"\t" + val.substr(i);
5007 node.textContent = val;
5014 xcnt += _TAB_SIZE - (xcnt+_TAB_SIZE)%_TAB_SIZE;
5020 if(n == cursor.endNodeIndex)
5027 CodeEditor.editor.setCursor(el,cursor,
true );
5072 var specialStr =
'\t';
5075 if(_fileExtension[forPrimary][0] ==
'c' ||
5076 _fileExtension[forPrimary][0] ==
'C' ||
5077 _fileExtension[forPrimary][0] ==
'h' ||
5078 _fileExtension[forPrimary][0] ==
'H' ||
5079 _fileExtension[forPrimary][0] ==
'j')
5085 for(n=cursor.startNodeIndex; n>=0; --n)
5087 node = el.childNodes[n];
5088 val = node.textContent;
5090 for(i=(n==cursor.startNodeIndex?cursor.startPos-1:
5091 val.length-1); i>=0; --i)
5107 var prevCharIsNewLine =
false;
5108 var lookForNewLineIndex;
5110 for(; n<el.childNodes.length &&
5111 n <= cursor.endNodeIndex; ++n)
5113 node = el.childNodes[n];
5114 val = node.textContent;
5116 lookForNewLineIndex = 0;
5117 for(;i<val.length;++i)
5119 if(n == cursor.endNodeIndex && i >= cursor.endPos)
5126 if(val[i] ==
'\n' ||
5127 (i == 0 && prevCharIsNewLine))
5129 if(i == 0 && prevCharIsNewLine) --i;
5133 var didDelete =
false;
5134 if(i + specialStr.length < val.length &&
5138 (j=val.indexOf(specialStr,i+1)) == i+1 ||
5141 (k=val.indexOf(
'\n',i+1)) < 0 ||
5146 val.substr(i+1,j-(i+1)).trim().length == 0
5152 val = val.substr(0,j) +
5153 val.substr(j+specialStr.length);
5154 node.textContent = val;
5156 lookForNewLineIndex = j+specialStr.length;
5158 else if(specialStr ==
'\t')
5161 if((specialStr =
" ") &&
5162 i + specialStr.length < val.length &&
5163 val.indexOf(specialStr,i+1) == i+1)
5165 val = val.substr(0,i+1) +
5166 val.substr(i+1+specialStr.length);
5167 node.textContent = val;
5170 else if((specialStr =
" ") &&
5171 i + specialStr.length < val.length &&
5172 val.indexOf(specialStr,i+1) == i+1)
5174 val = val.substr(0,i+1) +
5175 val.substr(i+1+specialStr.length);
5176 node.textContent = val;
5179 else if((specialStr =
" ") &&
5180 i + specialStr.length < val.length &&
5181 val.indexOf(specialStr,i+1) == i+1)
5183 val = val.substr(0,i+1) +
5184 val.substr(i+1+specialStr.length);
5185 node.textContent = val;
5188 else if((specialStr =
" ") &&
5189 i + specialStr.length < val.length &&
5190 val.indexOf(specialStr,i+1) == i+1)
5192 val = val.substr(0,i+1) +
5193 val.substr(i+1+specialStr.length);
5194 node.textContent = val;
5205 if(n == cursor.startNodeIndex &&
5206 i < cursor.startPos)
5208 cursor.startPos -= specialStr.length;
5210 if(n == cursor.endNodeIndex &&
5213 cursor.endPos -= specialStr.length;
5218 if(n == cursor.endNodeIndex &&
5219 cursor.endPos >= val.length)
5221 ++cursor.endNodeIndex;
5240 val = val.substr(0,i+1) + specialStr + val.substr(i+1);
5241 node.textContent = val;
5244 if(i == -1 && prevCharIsNewLine) ++i;
5254 j = val.lastIndexOf(
'\n');
5255 if(j >= lookForNewLineIndex &&
5257 j == val[val.length-1] ||
5258 val.substr(j+1).trim().length == 0
5260 prevCharIsNewLine =
true;
5261 else if(j < 0 && prevCharIsNewLine &&
5262 val.trim().length == 0)
5263 prevCharIsNewLine =
true;
5265 prevCharIsNewLine =
false;
5268 prevCharIsNewLine = (val.length &&
5269 val[val.length-1] ==
'\n');
5273 CodeEditor.editor.setCursor(el,cursor,
true );
5303 else if(!blockCOMMENT)
5307 if(cursor.startNodeIndex !== undefined)
5312 i = cursor.startPos;
5313 node = el.childNodes[cursor.startNodeIndex];
5314 val = node.textContent;
5318 if(val[i-1] ==
'\t')
5320 node.textContent = val.substr(0,i-1) + val.substr(i);
5323 var range = document.createRange();
5324 range.setStart(node,i-1);
5325 range.setEnd(node,i-1);
5327 var selection = window.getSelection();
5328 selection.removeAllRanges();
5329 selection.addRange(range);
5339 Debug.log(
"No cursor for reverse tab.");
5342 document.execCommand(
'insertHTML',
false,
'	');
5348 else if(cursorSelection)
5350 Debug.log(
"cursorSelection handling for speed-up");
5360 console.log(
"cursorSelection char",keyCode,c);
5362 if(e.key.length > 1)
5364 if( keyCode != 46 &&
5371 e.stopPropagation();
5372 localInsertCharacter(c);
5378 if(localInsertCharacter(c))
5382 e.stopPropagation();
5392 this.updateLastSave =
function(forPrimary)
5394 forPrimary = forPrimary?1:0;
5396 var el = document.getElementById(
"textEditorLastSave" + forPrimary);
5399 Debug.log(
"updateLastSave() forPrimary=" + forPrimary);
5401 if(_fileWasModified[forPrimary])
5402 str +=
"<label style='color:red'>Unsaved changes!</label> ";
5404 str +=
"Unmodified. ";
5406 if(_fileLastSave[forPrimary])
5408 var now =
new Date();
5409 var d =
new Date(_fileLastSave[forPrimary]);
5410 var tstr = d.toLocaleTimeString();
5411 tstr = tstr.substring(0,tstr.lastIndexOf(
' ')) +
5412 (tstr[tstr.length-2]==
'A'?
"am":
"pm");
5414 var diff = ((now.getTime() - d.getTime())/1000)|0;
5418 diffStr =
"(just now) ";
5420 diffStr =
"(5 seconds ago) ";
5422 diffStr =
"(15 seconds ago) ";
5424 diffStr =
"(30 seconds ago) ";
5426 diffStr =
"(45 seconds ago) ";
5428 diffStr =
"(one minute ago) ";
5429 else if(diff < 15*60)
5430 diffStr =
"(" + ((diff/60)|0) +
" minutes ago) ";
5431 else if(diff < 20*60)
5432 diffStr =
"(15 minutes ago) ";
5433 else if(diff < 40*60)
5434 diffStr =
"(30 minutes ago) ";
5435 else if(diff < 50*60)
5436 diffStr =
"(45 minutes ago) ";
5437 else if(diff < 90*60)
5438 diffStr =
"(an hour ago) ";
5440 diffStr =
"(" + (Math.round(diff/60/60)) +
" hours ago) ";
5443 str +=
"Last save was " + diffStr + tstr;
5450 this.handleFileNameMouseMove =
function(forPrimary,doNotStartTimer)
5452 forPrimary = forPrimary?1:0;
5456 if(_fileNameEditing[forPrimary])
return;
5458 var el = document.getElementById(
"fileButtonContainerShowHide" + forPrimary);
5459 el.style.display =
"block";
5461 window.clearTimeout(_fileNameMouseMoveTimerHandle);
5463 if(doNotStartTimer)
return;
5465 _fileNameMouseMoveTimerHandle = window.setTimeout(
5468 el.style.display =
"none";
5476 this.startEditFileName =
function(forPrimary)
5478 forPrimary = forPrimary?1:0;
5480 if(_fileNameEditing[forPrimary])
return;
5481 _fileNameEditing[forPrimary] =
true;
5484 document.getElementById(
"fileButtonContainerShowHide" + forPrimary).style.display =
"none";
5487 console.log(
"startEditFileName " + forPrimary);
5489 var el = document.getElementById(
"fileNameDiv" + forPrimary);
5491 var keys = Object.keys(_fileHistoryStack);
5492 var initVal = keys[document.getElementById(
"fileNameHistorySelect" +
5493 forPrimary).value|0].trim();
5495 var _OK_CANCEL_DIALOG_STR =
"";
5497 _OK_CANCEL_DIALOG_STR +=
"<div title='' style='padding:5px;background-color:#eeeeee;border:1px solid #555555;position:relative;z-index:2000;" +
5498 "width:105px;height:20px;margin: 4px -122px -32px -120px; font-size: 16px; white-space:nowrap; text-align:center;'>";
5499 _OK_CANCEL_DIALOG_STR +=
"<a class='popUpOkCancel' onclick='" +
5500 "CodeEditor.editor.editCellOK(" + forPrimary +
5501 "); event.stopPropagation();' onmouseup='event.stopPropagation();' title='Accept Changes' style='color:green'>" +
5502 "<b style='color:green;font-size: 16px;'>OK</b></a> | " +
5503 "<a class='popUpOkCancel' onclick='" +
5504 "CodeEditor.editor.editCellCancel(" + forPrimary +
5505 "); event.stopPropagation();' onmouseup='event.stopPropagation();' title='Discard Changes' style='color:red'>" +
5506 "<b style='color:red;font-size: 16px;'>Cancel</b></a>";
5507 _OK_CANCEL_DIALOG_STR +=
"</div>";
5511 str += htmlOpen(
"input",
5514 "style":
"text-align:center;margin:-4px -2px -4px -1px;width:90%;" +
5515 " height:" + (el.offsetHeight>20?el.offsetHeight:20) +
"px",
5517 "onclick":
"event.stopPropagation();",
5526 str += _OK_CANCEL_DIALOG_STR;
5531 el = el.getElementsByTagName(
"input")[0];
5532 var startPos = initVal.lastIndexOf(
'/')+1;
5533 var endPos = initVal.lastIndexOf(
'.');
5534 if(endPos < 0) endPos = initVal.length;
5535 el.setSelectionRange(startPos, endPos);
5542 this.editCellOK =
function(forPrimary)
5544 forPrimary = forPrimary?1:0;
5546 var val = document.getElementById(
"fileNameDiv" + forPrimary).getElementsByTagName(
"input")[0].value;
5547 console.log(
"editCellOK " + forPrimary +
" = " + val);
5548 _fileNameEditing[forPrimary] =
false;
5550 var extPos = val.lastIndexOf(
'.');
5554 _filePath[forPrimary] = val.substr(0,extPos);
5555 _fileExtension[forPrimary] = extPos > 0?val.substr(extPos+1):
"";
5570 _fileWasModified[forPrimary] =
true;
5571 _fileLastSave[forPrimary] = 0;
5572 CodeEditor.editor.updateLastSave(forPrimary);
5583 _fileHistoryStack[_filePath[forPrimary] +
"." +
5584 _fileExtension[forPrimary]] = [
5585 _eel[forPrimary].textContent,
5587 _fileWasModified[forPrimary],
5588 _fileLastSave[forPrimary]];
5589 console.log(
"_fileHistoryStack",_fileHistoryStack);
5591 CodeEditor.editor.updateFileHistoryDropdowns();
5597 this.editCellCancel =
function(forPrimary)
5599 forPrimary = forPrimary?1:0;
5601 Debug.log(
"editCellCancel " + forPrimary);
5602 _fileNameEditing[forPrimary] =
false;
5605 CodeEditor.editor.updateFileHistoryDropdowns(forPrimary);
5614 this.updateFileHistoryDropdowns =
function(forPrimarySelect)
5616 Debug.log(
"updateFileHistoryDropdowns forPrimarySelect=" + forPrimarySelect);
5623 var keys = Object.keys(_fileHistoryStack);
5626 for(var forPrimary=0;forPrimary<2;++forPrimary)
5628 if(forPrimarySelect !== undefined &&
5629 forPrimarySelect != forPrimary)
continue;
5631 currentFile = _filePath[forPrimary] +
"." + _fileExtension[forPrimary];
5633 str += htmlOpen(
"select",
5635 "class":
"fileNameHistorySelect",
5636 "id":
"fileNameHistorySelect" + forPrimary,
5637 "style":
"width:100%;" +
5638 "text-align-last: center;",
5639 "title":
"The current file is\n" + currentFile,
5641 "CodeEditor.editor.handleFileNameHistorySelect(" +
5643 "onclick":
"CodeEditor.editor.stopUpdateHandling(event);",
5644 "onfocus":
"CodeEditor.editor.lastFileNameHistorySelectIndex = this.value;" +
5646 "onblur":
"this.value = CodeEditor.editor.lastFileNameHistorySelectIndex;",
5651 for(i=0;i<keys.length;++i)
5655 str +=
"<option value='" + i +
"' ";
5656 if(currentFile == keys[i])
5659 if(_fileHistoryStack[keys[i]][2])
5660 str +=
"*MODIFIED* ";
5669 el = document.getElementById(
"fileNameDiv" + forPrimary);
5674 Debug.log(
"Ignoring error since file forPrimary=" +
5675 forPrimary +
" is probably not opened: " +
5685 this.handleFileNameHistorySelect =
function(forPrimary)
5687 forPrimary = forPrimary?1:0;
5689 var selectedFileIndex = document.getElementById(
"fileNameHistorySelect" + forPrimary).value | 0;
5690 Debug.log(
"updateFileHistoryDropdowns " + forPrimary +
5691 "selected=" + selectedFileIndex);
5693 var keys = Object.keys(_fileHistoryStack);
5694 var selectedFileName = keys[selectedFileIndex];
5696 Debug.log(
"selectedFileName " + selectedFileName);
5702 var fileArr = selectedFileName.split(
'.');
5705 if(fileArr[0] == _filePath[forPrimary] &&
5706 fileArr[1] == _fileExtension[forPrimary])
5708 CodeEditor.editor.openFile(forPrimary,
5709 _filePath[forPrimary],
5710 _fileExtension[forPrimary],
5715 fileObj.path = fileArr[0];
5716 fileObj.extension = fileArr[1];
5717 fileObj.text = _fileHistoryStack[selectedFileName][0];
5718 fileObj.fileWasModified = _fileHistoryStack[selectedFileName][2];
5719 fileObj.fileLastSave = _fileHistoryStack[selectedFileName][3];
5721 console.log(
"fileObj",fileObj);
5723 CodeEditor.editor.handleFileContent(forPrimary,0,fileObj);
5730 this.showFindAndReplace =
function(forPrimary)
5732 forPrimary = forPrimary?1:0;
5733 _activePaneIsPrimary = forPrimary;
5735 Debug.log(
"showFindAndReplace forPrimary=" + forPrimary +
" activePane=" + _activePaneIsPrimary);
5737 CodeEditor.editor.findAndReplaceLastButton[forPrimary] = 1;
5740 var el = _eel[forPrimary];
5741 var cursor = _findAndReplaceCursorInContent[forPrimary] =
5742 CodeEditor.editor.getCursor(el);
5745 el = document.getElementById(
"textEditorHeader" + forPrimary);
5750 str +=
"<table style='margin-top: 2px;'>";
5754 str +=
"<tr><td style='text-align:right'>";
5757 str += htmlOpen(
"input",
5760 "id":
"findAndReplaceFind" + forPrimary,
5761 "style":
"text-align:left; width:90%;" +
5762 " height:" + (20) +
"px",
5763 "value": CodeEditor.editor.findAndReplaceFind[forPrimary],
5764 "onclick":
"event.stopPropagation();",
5765 "onchange":
"CodeEditor.editor.findAndReplaceFind[" +
5766 forPrimary +
"] = this.value;" +
5767 "CodeEditor.editor.showFindAndReplaceSelection(" +
5774 str += htmlOpen(
"select",
5776 "id":
"findAndReplaceScope" + forPrimary,
5777 "style":
"width:100%;" +
5778 "text-align-last: center;",
5779 "title":
"Choose the scope for Replace All",
5780 "onclick":
"event.stopPropagation();" ,
5781 "onchange":
"CodeEditor.editor.findAndReplaceScope[" +
5782 forPrimary +
"] = this.value;" +
5783 "CodeEditor.editor.showFindAndReplaceSelection(" +
5787 str +=
"<option value='0'>All Lines</option>";
5788 str +=
"<option value='1' " + (CodeEditor.editor.findAndReplaceScope[forPrimary] ==
5789 1?
"selected":
"") +
">Selected Lines</option>";
5795 str += htmlOpen(
"input",
5798 "id":
"findAndReplaceCaseSensitive" + forPrimary,
5799 "title":
"Toggle case sensitive search",
5800 "onclick":
"event.stopPropagation();",
5801 "style":
"margin-left:10px;",
5802 "onchange":
"CodeEditor.editor.findAndReplaceCaseSensitive[" +
5803 forPrimary +
"] = this.checked;" +
5804 "CodeEditor.editor.showFindAndReplaceSelection(" +
5810 "title":
"Toggle case sensitive search",
5811 "style":
"margin-left:5px;",
5812 "onclick":
"event.stopPropagation();" +
5813 "var el = document.getElementById(\"findAndReplaceCaseSensitive" +
5814 forPrimary +
"\"); el.checked = !el.checked;" +
5815 "CodeEditor.editor.findAndReplaceCaseSensitive[" +
5816 forPrimary +
"] = el.checked;" +
5817 "CodeEditor.editor.showFindAndReplaceSelection(" +
5821 "Case sensitive" ,
true
5824 str +=
"</td></tr>";
5827 str +=
"<tr><td style='text-align:right'>";
5828 str +=
"Replace with:";
5830 str += htmlOpen(
"input",
5833 "id":
"findAndReplaceReplace" + forPrimary,
5834 "style":
"text-align:left; width:90%;" +
5835 " height:" + (20) +
"px",
5836 "value": CodeEditor.editor.findAndReplaceReplace[forPrimary],
5837 "onclick":
"event.stopPropagation();",
5838 "onchange":
"CodeEditor.editor.findAndReplaceReplace[" +
5839 forPrimary +
"] = this.value; " +
5840 "CodeEditor.editor.showFindAndReplaceSelection(" +
5847 str += htmlOpen(
"select",
5849 "id":
"findAndReplaceDirection" + forPrimary,
5850 "style":
"width:100%;" +
5851 "text-align-last: center;",
5852 "title":
"Choose the search direction for the Find & Replace",
5853 "onclick":
"event.stopPropagation();",
5854 "onchange":
"CodeEditor.editor.findAndReplaceDirection[" +
5855 forPrimary +
"] = this.value;" +
5856 "CodeEditor.editor.showFindAndReplaceSelection(" +
5860 str +=
"<option value='0'>Search Forward</option>";
5861 str +=
"<option value='1' " + (CodeEditor.editor.findAndReplaceDirection[forPrimary] ==
5863 ">Search Backward</option>";
5869 str += htmlOpen(
"input",
5872 "id":
"findAndReplaceWholeWord" + forPrimary,
5873 "title":
"Toggle whole word search",
5874 "onclick":
"event.stopPropagation();",
5875 "style":
"margin-left:10px;",
5876 "onchange":
"CodeEditor.editor.findAndReplaceWholeWord[" +
5877 forPrimary +
"] = this.checked;" +
5878 "CodeEditor.editor.showFindAndReplaceSelection(" +
5884 "style":
"margin-left:5px;",
5885 "title":
"Toggle whole word search",
5886 "onclick":
"event.stopPropagation();" +
5887 "var el = document.getElementById(\"findAndReplaceWholeWord" +
5888 forPrimary +
"\"); el.checked = !el.checked;" +
5889 "CodeEditor.editor.findAndReplaceWholeWord[" +
5890 forPrimary +
"] = el.checked;" +
5891 "CodeEditor.editor.showFindAndReplaceSelection(" +
5897 str +=
"</td></tr>";
5901 str +=
"<tr><td colspan='4' style='text-align:center'>";
5902 str += htmlOpen(
"div",
5904 "id":
"findAndReplaceWrapped" + forPrimary,
5905 "style":
"text-align:right; margin: 4px; width:115px;" +
5906 "color: red; float: left;",
5908 str +=
"<div style='float:left;'>";
5909 str += htmlOpen(
"input",
5914 "style":
"text-align:center; margin: 4px;" ,
5915 "onclick":
"event.stopPropagation();" +
5916 "CodeEditor.editor.doFindAndReplaceAction(" + forPrimary +
",1)",
5919 str += htmlOpen(
"input",
5924 "style":
"text-align:center; margin: 4px;" ,
5925 "onclick":
"event.stopPropagation();" +
5926 "CodeEditor.editor.doFindAndReplaceAction(" + forPrimary +
",2)",
5929 str += htmlOpen(
"input",
5932 "value":
"Replace & Find",
5934 "style":
"text-align:center; margin: 4px;" ,
5935 "onclick":
"event.stopPropagation();" +
5936 "CodeEditor.editor.doFindAndReplaceAction(" + forPrimary +
",3)",
5939 str += htmlOpen(
"input",
5942 "value":
"Replace All",
5944 "style":
"text-align:center; margin: 4px;" ,
5945 "onclick":
"event.stopPropagation();" +
5946 "CodeEditor.editor.doFindAndReplaceAction(" + forPrimary +
",4)",
5949 str += htmlOpen(
"input",
5953 "title":
"Close find and replace controls.",
5954 "style":
"text-align:center; margin: 4px;" ,
5956 "onclick":
"event.stopPropagation();" +
5957 "CodeEditor.editor.displayFileHeader(" + forPrimary +
")",
5961 str +=
"</td></tr>";
5968 el = document.getElementById(
"findAndReplaceFind" + forPrimary);
5969 el.setSelectionRange(0, el.value.length);
5972 el = document.getElementById(
"findAndReplaceCaseSensitive" + forPrimary);
5973 el.checked = CodeEditor.editor.findAndReplaceCaseSensitive[forPrimary];
5975 el = document.getElementById(
"findAndReplaceWholeWord" + forPrimary);
5976 el.checked = CodeEditor.editor.findAndReplaceWholeWord[forPrimary];
5983 this.showFindAndReplaceSelection =
function(forPrimary)
5985 forPrimary = forPrimary?1:0;
5986 Debug.log(
"showFindAndReplaceSelection forPrimary=" + forPrimary);
5988 var el = _eel[forPrimary];
5989 var cursor = CodeEditor.editor.getCursor(el);
5991 if(cursor.startPosInContent !== undefined)
5992 CodeEditor.editor.setCursor(el,
5996 CodeEditor.editor.findAndReplaceLastButton[forPrimary] > 0 &&
5997 _findAndReplaceCursorInContent[forPrimary] !== undefined)
5998 CodeEditor.editor.setCursor(el,
5999 _findAndReplaceCursorInContent[forPrimary],
6012 this.doFindAndReplaceAction =
function(forPrimary,action)
6014 forPrimary = forPrimary?1:0;
6015 action = action | 0;
6017 CodeEditor.editor.findAndReplaceLastButton[forPrimary] = action;
6019 var find = document.getElementById(
"findAndReplaceFind" + forPrimary).value;
6020 var originalFind = find;
6021 if(!find || find ==
"")
6023 Debug.log(
"Illegal empty string to find.", Debug.HIGH_PRIORITY);
6026 var replace = CodeEditor.editor.findAndReplaceReplace[forPrimary];
6027 var scope = CodeEditor.editor.findAndReplaceScope[forPrimary]|0;
6028 var direction = CodeEditor.editor.findAndReplaceDirection[forPrimary]|0;
6031 var caseSensitive = CodeEditor.editor.findAndReplaceCaseSensitive[forPrimary]?1:0;
6032 var wholeWord = CodeEditor.editor.findAndReplaceWholeWord[forPrimary]?1:0;
6034 Debug.log(
"doFindAndReplaceAction forPrimary=" + forPrimary +
6035 " action=" + action +
6037 " replace=" + replace +
6039 " direction=" + direction +
6040 " caseSensitive=" + caseSensitive +
6041 " wholeWord=" + wholeWord);
6052 var el = _eel[forPrimary];
6053 var originalText = el.textContent;
6056 text = originalText;
6059 text = originalText.toLowerCase();
6060 find = find.toLowerCase();
6063 var i = direction?text.length:-1;
6064 var j = text.length-1;
6066 var cursor = CodeEditor.editor.getCursor(el);
6069 if(cursor.startPosInContent !== undefined &&
6071 document.getElementById(
"findAndReplaceWrapped" + forPrimary).textContent ==
""))
6072 i = cursor.startPosInContent;
6073 else if(_findAndReplaceCursorInContent[forPrimary] !== undefined &&
6074 _findAndReplaceCursorInContent[forPrimary].startPosInContent !== undefined &&
6075 _findAndReplaceCursorInContent[forPrimary].startPosInContent >= 0 &&
6077 document.getElementById(
"findAndReplaceWrapped" + forPrimary).textContent ==
""))
6079 i = _findAndReplaceCursorInContent[forPrimary].startPosInContent;
6082 CodeEditor.editor.setCursor(el,
6083 _findAndReplaceCursorInContent[forPrimary],
6088 document.getElementById(
"findAndReplaceWrapped" + forPrimary).innerHTML =
"";
6090 Debug.log(
"Starting position: " + i);
6094 if(cursor.endPosInContent !== undefined)
6095 j = cursor.endPosInContent;
6096 else if(_findAndReplaceCursorInContent[forPrimary] !== undefined &&
6097 _findAndReplaceCursorInContent[forPrimary].endPosInContent != undefined &&
6098 _findAndReplaceCursorInContent[forPrimary].endPosInContent >= 0)
6099 j = _findAndReplaceCursorInContent[forPrimary].endPosInContent;
6101 Debug.log(
"Ending position: " + j);
6103 else if(action == 4)
6106 var replaceCount = 0;
6119 if(i > 0 && i + find.length <= text.length)
6125 Debug.log(
"Replacing");
6130 originalText.substr(0,i) +
6132 originalText.substr(i+find.length);
6136 text = originalText;
6138 text = originalText.toLowerCase();
6145 Debug.log(
"Unrecognized action! " + action, Debug.HIGH_PRIORITY);
6159 i = text.indexOf(find,i+1);
6160 else if(direction == 1)
6161 i = text.lastIndexOf(find,i-1);
6167 (text[i-1] >=
'a' && text[i-1] <=
'z') ||
6168 (text[i-1] >=
'A' && text[i-1] <=
'Z') ||
6169 (text[i-1] >=
'0' && text[i-1] <=
'9') ||
6176 else if(i>0 && i+find.length<text.length && (
6177 (text[i+find.length] >=
'a' && text[i+find.length] <=
'z') ||
6178 (text[i+find.length] >=
'A' && text[i+find.length] <=
'Z') ||
6179 (text[i+find.length] >=
'0' && text[i+find.length] <=
'9') ||
6180 text[i+find.length] ==
'_'
6200 if(i + find.length < j)
6208 document.getElementById(
"findAndReplaceWrapped" + forPrimary).innerHTML =
"Reached end";
6218 Debug.log(
"Unrecognized action! " + action, Debug.HIGH_PRIORITY);
6236 el.textContent = originalText;
6237 CodeEditor.editor.updateDecorations(forPrimary);
6242 _findAndReplaceCursorInContent[forPrimary] =
6243 CodeEditor.editor.createCursorFromContentPosition(el,
6244 i, i + find.length);
6245 CodeEditor.editor.setCursor(
6247 _findAndReplaceCursorInContent[forPrimary],
6256 _findAndReplaceCursorInContent[forPrimary] =
6257 CodeEditor.editor.createCursorFromContentPosition(el,
6259 CodeEditor.editor.setCursor(
6261 _findAndReplaceCursorInContent[forPrimary],
6266 Debug.log(
"Unrecognized action! " + action, Debug.HIGH_PRIORITY);
6274 document.getElementById(
"findAndReplaceWrapped" + forPrimary).innerHTML =
6275 replaceCount +
" Replaced";
6282 this.displayFileHeader =
function(forPrimary)
6284 forPrimary = forPrimary?1:0;
6286 var forceDisplayComplete =
false;
6287 if(CodeEditor.editor.findAndReplaceLastButton[forPrimary] != -1)
6289 CodeEditor.editor.findAndReplaceLastButton[forPrimary] = -1;
6290 forceDisplayComplete =
true;
6293 Debug.log(
"displayFileHeader forPrimary=" + forPrimary);
6296 var el = document.getElementById(
"textEditorHeader" + forPrimary);
6299 var path = _filePath[forPrimary];
6300 var extension = _fileExtension[forPrimary];
6307 str += htmlOpen(
"div",
6310 "CodeEditor.editor.handleFileNameMouseMove(" + forPrimary +
");",
6315 str += htmlOpen(
"div",
6317 "class":
"fileButtonContainer",
6318 "id":
"fileButtonContainer" + forPrimary,
6321 str += htmlOpen(
"div",
6323 "class":
"fileButtonContainerShowHide",
6324 "id":
"fileButtonContainerShowHide" + forPrimary,
6326 "event.stopPropagation(); " +
6327 "CodeEditor.editor.handleFileNameMouseMove(" + forPrimary +
6328 ",1 /*doNotStartTimer*/);",
6331 str += htmlOpen(
"div",
6333 "class":
"fileButton",
6334 "id":
"fileRenameButton" + forPrimary,
6335 "title":
"Change the filename\n" + path +
"." + extension,
6337 "event.stopPropagation(); " +
6338 "CodeEditor.editor.startEditFileName(" + forPrimary +
");",
6340 str += htmlOpen(
"div",
6342 "class":
"fileButton",
6343 "id":
"fileDownloadButton" + forPrimary,
6344 "title":
"Download the file content from\n" + path +
"." + extension,
6346 "event.stopPropagation(); " +
6347 "CodeEditor.editor.download(" + forPrimary +
");",
6350 "<div class='fileDownloadButtonBgChild' style='display: block; margin-left: 0px; margin-top: 1px; height:7px; width: 6px; background-color: rgb(202, 204, 210);'></div>" +
6351 "<div class='fileDownloadButtonBorderChild' style='display: block; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid rgb(202, 204, 210);'></div>" +
6352 "<div class='fileDownloadButtonBgChild' style='position: relative; top: 2px; width: 12px; height: 2px; display: block; background-color: rgb(202, 204, 210);'></div>"
6354 str += htmlOpen(
"div",
6356 "class":
"fileButton",
6357 "id":
"fileUploadButton" + forPrimary,
6358 "title":
"Upload file content to\n" + path +
"." + extension,
6360 "event.stopPropagation(); " +
6361 "CodeEditor.editor.upload(" + forPrimary +
");",
6364 "<div class='fileDownloadButtonBorderChild' style='display: block; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 8px solid rgb(202, 204, 210);'></div>" +
6365 "<div class='fileDownloadButtonBgChild' style='display: block; margin-left: 0px; height:7px; width: 6px; background-color: rgb(202, 204, 210);'></div>" +
6366 "<div class='fileDownloadButtonBgChild' style='position: relative; top: 3px; width: 12px; height: 2px; display: block; background-color: rgb(202, 204, 210);'></div>"
6368 str += htmlOpen(
"div",
6370 "class":
"fileButton fileUndoButton",
6371 "id":
"fileUndoButton" + forPrimary,
6372 "title":
"Undo to rewind to last recorded checkpoint for\n" + path +
"." + extension,
6373 "style":
"color: rgb(202, 204, 210);" +
6374 "padding: 0 5px 0;" +
6375 "font-size: 17px;" +
6376 "font-weight: bold;",
6378 "event.stopPropagation(); " +
6379 "CodeEditor.editor.undo(" + forPrimary +
");",
6384 str += htmlOpen(
"div",
6386 "class":
"fileButton fileUndoButton",
6387 "id":
"fileRedoButton" + forPrimary,
6388 "title":
"Redo to fast-forward to last recorded checkpoint for\n" + path +
"." + extension,
6389 "style":
"color: rgb(202, 204, 210);" +
6390 "padding: 0 5px 0;" +
6391 "font-size: 17px;" +
6392 "font-weight: bold;",
6394 "event.stopPropagation(); " +
6395 "CodeEditor.editor.undo(" + forPrimary +
",1 /*redo*/);",
6406 str += htmlClearDiv();
6409 str +=
"<table><tr><td>";
6411 str += htmlOpen(
"a",
6413 "title":
"Open file in a new browser tab: \n" +
6414 "srcs" + path +
"." + extension,
6415 "onclick":
"DesktopContent.openNewBrowserTab(" +
6416 "\"Code Editor\",\"\"," +
6417 "\"/WebPath/html/CodeEditor.html?startFilePrimary=" +
6418 path +
"." + extension +
"\",0 /*unique*/);' ",
6420 "<img class='dirNavFileNewWindowImgNewWindow' " +
6421 "src='/WebPath/images/windowContentImages/CodeEditor-openInNewWindow.png'>"
6425 str += htmlOpen(
"a",
6427 "title":
"Open file in the other editor pane of the split-view: \n" +
6428 "srcs" + path +
"." + extension,
6429 "onclick":
"CodeEditor.editor.openFile(" +
6430 (!forPrimary) +
",\"" +
6435 "<img class='dirNavFileNewWindowImgNewPane' " +
6436 "src='/WebPath/images/windowContentImages/CodeEditor-openInOtherPane.png'>"
6441 str += htmlOpen(
"div",
6443 "class":
"fileNameDiv",
6444 "id":
"fileNameDiv" + forPrimary,
6445 "style":
"margin: 0 5px 0 5px",
6447 str +=
"<a onclick='CodeEditor.editor.openFile(" + forPrimary +
6448 ",\"" + path +
"\",\"" + extension +
"\",true /*doConfirm*/);' " +
6449 "title='Click to reload \n" + path +
"." + extension +
"' " +
6451 path +
"." + extension +
"</a>";
6454 str +=
"</td></tr></table>";
6458 str += htmlClearDiv();
6461 str +=
"<div class='textEditorLastSave' id='textEditorLastSave" +
6462 forPrimary +
"'>Unmodified</div>";
6464 str += htmlClearDiv();
6466 str +=
"<div class='textEditorOutline' id='textEditorOutline" +
6467 forPrimary +
"'>Outline:</div>";
6471 CodeEditor.editor.updateDecorations(forPrimary,forceDisplayComplete);
6472 CodeEditor.editor.updateFileHistoryDropdowns();
6482 this.updateFileSnapshot =
function(forPrimary,textObj , ignoreTimeDelta)
6484 forPrimary = forPrimary?1:0;
6486 Debug.log(
"updateFileSnapshot forPrimary=" + forPrimary);
6489 var addSnapshot =
false;
6491 if(_undoStackLatestIndex[forPrimary] != -1)
6495 if((ignoreTimeDelta ||
6496 2*1000 < textObj.time - _undoStack[forPrimary][_undoStackLatestIndex[forPrimary]][1]) &&
6497 _undoStack[forPrimary][_undoStackLatestIndex[forPrimary]][0] != textObj.text)
6506 ++_undoStackLatestIndex[forPrimary];
6507 if(_undoStackLatestIndex[forPrimary] >= _undoStack_MAX_SIZE)
6508 _undoStackLatestIndex[forPrimary] = 0;
6510 _undoStack[forPrimary][_undoStackLatestIndex[forPrimary]] =
6514 console.log(
"snapshot added to stack",_undoStack[forPrimary]);
6522 _fileHistoryStack[_filePath[forPrimary] +
"." +
6523 _fileExtension[forPrimary]] = [
6526 _fileWasModified[forPrimary],
6527 _fileLastSave[forPrimary]];
6528 console.log(
"_fileHistoryStack",_fileHistoryStack);
6530 CodeEditor.editor.updateFileHistoryDropdowns();
6540 this.startUpdateHandling =
function(forPrimary)
6542 _updateHandlerTargetPane[forPrimary] =
true;
6544 window.clearTimeout(_updateTimerHandle);
6545 _updateTimerHandle = window.setTimeout(
6546 CodeEditor.editor.updateTimeoutHandler,
6547 _UPDATE_DECOR_TIMEOUT );
6554 this.stopUpdateHandling =
function(event)
6556 if(event)
event.stopPropagation();
6557 window.clearTimeout(_updateTimerHandle);
6563 this.updateTimeoutHandler =
function()
6565 if(_updateHandlerTargetPane[0])
6567 CodeEditor.editor.updateDecorations(0 );
6568 _updateHandlerTargetPane[0] =
false;
6570 if(_updateHandlerTargetPane[1])
6572 CodeEditor.editor.updateDecorations(1 );
6573 _updateHandlerTargetPane[1] =
false;
6580 this.doubleClickHandler =
function(forPrimary)
6582 forPrimary = forPrimary?1:0;
6584 Debug.log(
"doubleClickHandler forPrimary=" + forPrimary);
6590 var el = _eel[forPrimary];
6591 var cursor = CodeEditor.editor.getCursor(el);
6593 if(!cursor || cursor.startNodeIndex === undefined)
6596 var n = cursor.startNodeIndex;
6597 var c = el.childNodes[n].textContent[
6602 if(c !=
'{' && c !=
'}')
6604 if(cursor.startPos == 0)
6610 }
while(n >= 0 && el.childNodes[n].textContent.length);
6613 c = el.childNodes[n].textContent[
6614 el.childNodes[n].textContent.length-1];
6617 c = el.childNodes[n].textContent[
6624 Debug.log(
"character before cursor " + c);
6626 if(c !=
'{' && c !=
'}')
return;
6630 var foundDoubleQuote =
false;
6631 var foundSingleQuote =
false;
6632 var foundComment =
false;
6637 cursor.endNodeIndex = -1;
6644 var openCountSave = openCount;
6645 var prelimFound =
false;
6649 node = el.childNodes[n];
6650 val = node.textContent;
6651 for(i=(n==cursor.startNodeIndex?cursor.startPos-1:
6652 val.length-1); i>=0; --i)
6654 if(cursor.endNodeIndex == -1)
6656 cursor.endNodeIndex = n;
6662 foundSingleQuote =
false;
6663 foundDoubleQuote =
false;
6664 openCountSave = openCount;
6668 Debug.log(
"confirmed found open count match ni " + n +
" " + i);
6674 if(!foundSingleQuote && val[i] ==
'"')
6675 foundDoubleQuote = !foundDoubleQuote;
6676 else if(!foundDoubleQuote && val[i] ==
"'")
6677 foundSingleQuote = !foundSingleQuote;
6678 else if(val[i]==
'/' && i-1 >= 0 &&
6682 openCount = openCountSave;
6684 prelimFound =
false;
6690 if(foundDoubleQuote || foundSingleQuote ||
6696 else if(val[i] ==
'{')
6702 Debug.log(
"found open count match ni " + n +
" " + i);
6709 cursor.startNodeIndex = n;
6710 cursor.startPos = i;
6721 i = cursor.startPos;
6722 for(n=cursor.startNodeIndex;n<el.childNodes.length; ++n)
6724 node = el.childNodes[n];
6725 val = node.textContent;
6727 for(; i<val.length; ++i)
6731 foundSingleQuote =
false;
6732 foundDoubleQuote =
false;
6733 foundComment =
false;
6739 if(!foundSingleQuote && val[i] ==
'"')
6740 foundDoubleQuote = !foundDoubleQuote;
6741 else if(!foundDoubleQuote && val[i] ==
"'")
6742 foundSingleQuote = !foundSingleQuote;
6743 else if(val[i]==
'/' && i+1 < val.length &&
6746 foundComment =
true;
6750 if(foundDoubleQuote || foundSingleQuote)
6755 else if(val[i] ==
'}')
6761 Debug.log(
"found open count match ni " + n +
" " + i);
6766 cursor.endNodeIndex = n;
6778 CodeEditor.editor.setCursor(el,cursor);
6785 this.download =
function(forPrimary)
6787 forPrimary = forPrimary?1:0;
6789 Debug.log(
"download forPrimary=" + forPrimary);
6791 var dataStr =
"data:text/plain;charset=utf-8," +
6792 encodeURIComponent(_eel[forPrimary].textContent);
6794 var filename = _filePath[forPrimary];
6795 var i = filename.lastIndexOf(
'/');
6797 filename = filename.substr(i+1);
6798 filename +=
"." + _fileExtension[forPrimary];
6800 Debug.log(
"Downloading to filename " + filename);
6802 var link = document.createElement(
"a");
6803 link.setAttribute(
"href", dataStr);
6804 link.setAttribute(
"style",
"display:none");
6805 link.setAttribute(
"download", filename);
6806 document.body.appendChild(link);
6810 link.parentNode.removeChild(link);
6816 this.upload =
function(forPrimary)
6818 forPrimary = forPrimary?1:0;
6820 Debug.log(
"upload forPrimary=" + forPrimary);
6822 _fileUploadString =
"";
6826 var el = document.getElementById(
"popUpDialog");
6829 el = document.createElement(
"div");
6830 el.setAttribute(
"id",
"popUpDialog");
6832 el.style.display =
"none";
6837 DesktopContent.setPopUpPosition(el,w ,h );
6839 var str =
"<a id='" +
6841 "-header' onclick='var el = document.getElementById(" +
6842 "\"popUpDialog\"); if(el) el.parentNode.removeChild(el); return false;'>Cancel</a><br><br>";
6844 str +=
"<div id='popUpDialog-div'>";
6846 str +=
"Please choose the file to upload which has the text content to place in the open source file:<br><br>" +
6847 _filePath[forPrimary] +
"." + _fileExtension[forPrimary] +
6852 str +=
"<input type='file' id='popUpDialog-fileUpload' " +
6854 for(var i=0;i<_ALLOWED_FILE_EXTENSIONS.length;++i)
6855 str += (i?
", ":
"") +
"." + _ALLOWED_FILE_EXTENSIONS[i];
6856 str +=
"' enctype='multipart/form-data' />";
6859 var onmouseupJS =
"";
6860 onmouseupJS +=
"document.getElementById(\"popUpDialog-submitButton\").disabled = true;";
6861 onmouseupJS +=
"CodeEditor.editor.uploadTextFromFile(" + forPrimary +
");";
6863 str +=
"<input id='popUpDialog-submitButton' disabled type='button' onmouseup='" +
6864 onmouseupJS +
"' " +
6865 "value='Upload File' title='" +
6866 "Upload the chosen file text content to\n" +
6867 _filePath[forPrimary] +
"." + _fileExtension[forPrimary] +
6871 document.body.appendChild(el);
6872 el.style.display =
"block";
6874 document.getElementById(
'popUpDialog-fileUpload').addEventListener(
6875 'change',
function(evt) {
6876 var files = evt.target.files;
6877 var file = files[0];
6878 var reader =
new FileReader();
6879 reader.onload =
function() {
6881 _fileUploadString = this.result;
6882 Debug.log(
"_fileUploadString = " + _fileUploadString);
6883 document.getElementById(
'popUpDialog-submitButton').disabled =
false;
6885 reader.readAsText(file);
6891 this.uploadTextFromFile =
function(forPrimary)
6893 forPrimary = forPrimary?1:0;
6895 Debug.log(
"uploadTextFromFile forPrimary=" + forPrimary);
6898 document.getElementById(
'popUpDialog-submitButton').disabled =
false;
6900 Debug.log(
"uploadTextFromFile _fileUploadString = " + _fileUploadString);
6904 DesktopContent.showLoading(
function()
6910 _fileUploadString = _fileUploadString.replace(
new RegExp(
6911 String.fromCharCode(160),
'g'),
' ');
6912 _fileUploadString =
"hi";
6913 var el = _eel[forPrimary];
6914 el.textContent = _fileUploadString;
6915 CodeEditor.editor.displayFileHeader(forPrimary);
6919 Debug.log(
"There was an error uploading the text: " + e,
6920 Debug.HIGH_PRIORITY);
6923 Debug.log(
"Source upload complete! (You can use undo to go back) ",
6924 Debug.INFO_PRIORITY);
6927 var el = document.getElementById(
"popUpDialog");
6928 if(el) el.parentNode.removeChild(el);