Commit 7eb3b18276e82d92265b52d149b3abf86c6bcf45
1 parent
76c2e18c
fix bug
Showing
5 changed files
with
514 additions
and
68 deletions
src/ide.html
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | |
| 17 | 17 | <script src="js/jquery-1.7.1.js"></script> |
| 18 | 18 | <script src="js/bootstrap.js"></script> |
| 19 | + <script src="js/codemirror.js"></script> | |
| 19 | 20 | <script type="text/javascript" src="js/zTree_v3-3.5.27/js/jquery.ztree.core.js"></script> |
| 20 | 21 | <script src="js/gxb-ide.js"></script> |
| 21 | 22 | |
| ... | ... | @@ -26,29 +27,34 @@ |
| 26 | 27 | </style> |
| 27 | 28 | <script> |
| 28 | 29 | $(function(){ |
| 29 | - var ide = new GxbIde(); | |
| 30 | + | |
| 31 | + var ide = new GxbIde({ | |
| 32 | + el: "#folder", | |
| 33 | + languageid: 10 | |
| 34 | + }); | |
| 30 | 35 | console.log(ide); |
| 31 | 36 | |
| 32 | - $.ajax({ | |
| 33 | - type: "GET", | |
| 34 | - url: "js/tree.json", | |
| 35 | - dataType: "json", | |
| 36 | - contentType: "application/json", | |
| 37 | - success: function(res) { | |
| 38 | - console.log(res); | |
| 37 | + // ide.RecordIde.Dir.init(); | |
| 38 | + // $.ajax({ | |
| 39 | + // type: "GET", | |
| 40 | + // url: "js/lang.json", | |
| 41 | + // dataType: "json", | |
| 42 | + // contentType: "application/json", | |
| 43 | + // success: function(res) { | |
| 44 | + // console.log(res); | |
| 39 | 45 | |
| 40 | - treeData = res.tree; | |
| 41 | - var folder = $("#folder"); | |
| 42 | - ide.RecordIde.Dir.buildTree(folder, treeData); | |
| 46 | + // treeData = res.lang.java; | |
| 47 | + // var folder = $("#folder"); | |
| 48 | + // ide.RecordIde.Dir.buildTree(folder, treeData); | |
| 43 | 49 | |
| 44 | - // treeObj = $.fn.zTree.init($("#folder"), ZTREE.config, treeData); | |
| 50 | + // // treeObj = $.fn.zTree.init($("#folder"), ZTREE.config, treeData); | |
| 45 | 51 | |
| 46 | - }, | |
| 47 | - error: function(XMLHttpRequest, textStatus, errorThrown) { | |
| 48 | - console.log('Ajax tree.json error'); | |
| 49 | - console.log(XMLHttpRequest); | |
| 50 | - } | |
| 51 | - }); | |
| 52 | + // }, | |
| 53 | + // error: function(XMLHttpRequest, textStatus, errorThrown) { | |
| 54 | + // console.log('Ajax lang.json error'); | |
| 55 | + // console.log(XMLHttpRequest); | |
| 56 | + // } | |
| 57 | + // }); | |
| 52 | 58 | console.log(ide); |
| 53 | 59 | |
| 54 | 60 | }) | ... | ... |
src/js/gb.js
| ... | ... | @@ -546,7 +546,7 @@ $(function() { |
| 546 | 546 | treeData = playTreePathData.tree; |
| 547 | 547 | treeObj = $.fn.zTree.init($("#folder"), ZTREE.config, treeData); |
| 548 | 548 | |
| 549 | - GBCodePlayBack.recordinit(treeData); | |
| 549 | + GBCodePlayBack.recordinit(); | |
| 550 | 550 | |
| 551 | 551 | $('#app').show(); |
| 552 | 552 | }else{ |
| ... | ... | @@ -587,7 +587,7 @@ $(function() { |
| 587 | 587 | |
| 588 | 588 | treeObj = $.fn.zTree.init($("#folder"), ZTREE.config, treeData); |
| 589 | 589 | |
| 590 | - GBCodePlayBack.recordinit(treeData); | |
| 590 | + GBCodePlayBack.recordinit(); | |
| 591 | 591 | |
| 592 | 592 | }, |
| 593 | 593 | error: function(XMLHttpRequest, textStatus, errorThrown) { |
| ... | ... | @@ -2670,6 +2670,7 @@ $(function() { |
| 2670 | 2670 | if(!_datalist.length){ |
| 2671 | 2671 | return false; |
| 2672 | 2672 | } |
| 2673 | + | |
| 2673 | 2674 | |
| 2674 | 2675 | setHtmlButton(_languageid, 'JAVA'); |
| 2675 | 2676 | ... | ... |
src/js/gxb-ide.js
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | ;(function(window){ |
| 3 | 3 | |
| 4 | 4 | GxbIde = function(){ |
| 5 | - // this.init.apply(this, arguments); | |
| 5 | + this.init.apply(this, arguments); | |
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | // 储存一个树结构和编辑器的对应关系 |
| ... | ... | @@ -12,71 +12,378 @@ |
| 12 | 12 | fileList, // 有值的文件数据结构 |
| 13 | 13 | treeObj; // 获取ztree对象 |
| 14 | 14 | |
| 15 | - var config = { | |
| 16 | - edit: { | |
| 17 | - enable: true | |
| 18 | - // editNameSelectAll: true | |
| 15 | + var isReplayPage = false; // initJavaPage 判断输出 | |
| 16 | + | |
| 17 | + var treeFoo = { | |
| 18 | + beforeClick: function (treeId, treeNode){ | |
| 19 | + console.log('点击了 ' + treeNode.name); | |
| 20 | + console.log(treeNode); | |
| 21 | + // 判断是否点击了文件夹 | |
| 22 | + if (treeNode.isParent) { | |
| 23 | + return false; | |
| 24 | + } | |
| 25 | + treeObj.expandNode(treeNode); | |
| 26 | + | |
| 27 | + // if (GBCodePlayBack.isRecordPlay == 1) { | |
| 28 | + // GBCodePlayBack.check_tree_time = new Date().getTime(); // 获取焦点的时间 | |
| 29 | + // var recordobj = { | |
| 30 | + // intervaltime: GBCodePlayBack.check_tree_time - GBCodePlayBack.record_startime, | |
| 31 | + // editor: 'tab', | |
| 32 | + // changeobj: { | |
| 33 | + // from: { | |
| 34 | + // ch: 0, | |
| 35 | + // line: 0, | |
| 36 | + // }, | |
| 37 | + // text: '', | |
| 38 | + // to: { | |
| 39 | + // ch: 0, | |
| 40 | + // line: 0, | |
| 41 | + // } | |
| 42 | + // }, | |
| 43 | + // treefile: treeNode, | |
| 44 | + // trigger: 0, | |
| 45 | + // playTime: 0 | |
| 46 | + // }; | |
| 47 | + // GBCodePlayBack.records.push(recordobj); | |
| 48 | + // console.log(GBCodePlayBack.records); | |
| 49 | + // GBCodePlayBack.record_startime = GBCodePlayBack.check_tree_time; | |
| 50 | + // } | |
| 51 | + | |
| 52 | + // 处理显示目录树对应的编辑器目录 | |
| 53 | + Dir.showEdite({'treeNode': treeNode}); | |
| 19 | 54 | }, |
| 20 | - view: { | |
| 21 | - addHoverDom: addHoverDom, | |
| 22 | - removeHoverDom: removeHoverDom, | |
| 23 | - selectedMulti: false, | |
| 24 | - showLine: false | |
| 55 | + beforeDrag: function (treeId, treeNodes) { | |
| 56 | + return false; | |
| 25 | 57 | }, |
| 26 | - data: { | |
| 27 | - simpleData: { | |
| 28 | - enable: true | |
| 29 | - } | |
| 58 | + beforeEditName: function (treeId, treeNode) { | |
| 59 | + treeObj.selectNode(treeNode); | |
| 60 | + setTimeout(function() { | |
| 61 | + treeObj.editName(treeNode); | |
| 62 | + }, 0); | |
| 63 | + return false; | |
| 30 | 64 | }, |
| 31 | - callback: { | |
| 32 | - beforeClick: beforeClick | |
| 33 | - } | |
| 34 | - }; | |
| 65 | + renameAlert: function (str, treeNode){ | |
| 66 | + setTimeout(function() { | |
| 67 | + treeObj.cancelEditName(); | |
| 68 | + alert(str); | |
| 69 | + }, 0); | |
| 35 | 70 | |
| 36 | - function beforeClick(treeId, treeNodes) { | |
| 37 | - console.log('567890') | |
| 38 | - console.log('点击了 ' + treeNodes.name); | |
| 39 | - console.log('点击了 ' + treeNodes.isParent); | |
| 71 | + // 这样写有bug 造成 编辑框死去焦点 获取焦点 死循环 | |
| 72 | + // 优化体验再次进入编辑状态 | |
| 73 | + // setTimeout(function() { | |
| 74 | + // treeObj.selectNode(treeNode); | |
| 75 | + // treeObj.editName(treeNode); | |
| 76 | + // }, 0); | |
| 77 | + }, | |
| 78 | + beforeRename: function (treeId, treeNode, newName, isCancel) { | |
| 79 | + var _this = this; | |
| 80 | + // console.info('beforeRename'); | |
| 81 | + if (newName.length == 0) { | |
| 82 | + treeFoo.renameAlert("文件名名称不能为空.", treeNode); | |
| 83 | + return false; | |
| 84 | + }else if(newName != treeNode.name){ | |
| 85 | + for (var i = 0; i < treeLinkEditor.length; i++) { | |
| 86 | + // 判断是否重名 | |
| 87 | + if(treeLinkEditor[i].file === newName){ | |
| 88 | + treeFoo.renameAlert("文件名“" + newName + "”已被占用,请选取其他名称。", treeNode); | |
| 89 | + return false; | |
| 90 | + }else if(/.java$/.test(newName) && newName.split('.').length > 2){ | |
| 91 | + treeFoo.renameAlert("文件名“" + newName + "”有误,请选取其他名称。", treeNode); | |
| 92 | + return false; | |
| 93 | + }else if(!newName.split('.')[0]){ | |
| 94 | + treeFoo.renameAlert("文件名“" + newName + "”有误,请选取其他名称。", treeNode); | |
| 95 | + return false; | |
| 96 | + }else if(/[0-9]/.test(newName.substr(0,1))){ | |
| 97 | + treeFoo.renameAlert("文件“" + newName + "”有误,首字母不能是数字,请选取其他名称。", treeNode); | |
| 98 | + return false; | |
| 99 | + }else if(!/.java$/.test(newName)){ | |
| 100 | + treeFoo.renameAlert("文件后缀名“" + newName + "”有误,请选取其他名称。", treeNode); | |
| 101 | + return false; | |
| 102 | + }else{ | |
| 103 | + // 更新 treeLinkEditor 存值 | |
| 104 | + if(treeLinkEditor[i].file === treeNode.name){ | |
| 105 | + var _temName = treeLinkEditor[i].name; | |
| 106 | + var _name = Dir.manageName(newName); | |
| 40 | 107 | |
| 41 | - } | |
| 108 | + // 缓存值得更新 | |
| 109 | + treeLinkEditor[i].name = _name; | |
| 110 | + treeLinkEditor[i].file = newName; | |
| 111 | + treeLinkEditor[i].filePath = Dir.getTreePath(treeNode.name, newName); | |
| 112 | + treeLinkEditor[i].record = _name + 'Record'; | |
| 113 | + treeLinkEditor[i].replay = _name + 'Replay'; | |
| 114 | + treeLinkEditor[i].CodeMirrorRecordId = treeLinkEditor[i].record + 'CodeMirror'; | |
| 115 | + treeLinkEditor[i].CodeMirrorReplayId = treeLinkEditor[i].replay + 'CodeMirror'; | |
| 42 | 116 | |
| 43 | - function addHoverDom(treeId, treeNodes) { | |
| 44 | - // console.info('addHoverDom'); | |
| 45 | - // 修复第一个文件夹 | |
| 46 | - if(treeNode.isParent){ | |
| 47 | - $('a[title="'+ treeNode.name +'"]').find("#" + treeId + "_" + treeNode.id + "_edit").hide(); | |
| 48 | - return false; | |
| 49 | - } | |
| 117 | + mainPath = treeLinkEditor[i].filePath; | |
| 118 | + // 更新DOM相关 | |
| 119 | + $('#'+ _temName +'RecordWrap').attr({ | |
| 120 | + id: _name +'RecordWrap' | |
| 121 | + }); | |
| 122 | + $('#'+ _temName + 'Record').attr({ | |
| 123 | + id: _name + 'Record', | |
| 124 | + title: _name | |
| 125 | + }); | |
| 126 | + $('#'+ _temName + 'RecordCodeMirror').attr({ | |
| 127 | + id: _name + 'RecordCodeMirror' | |
| 128 | + }); | |
| 129 | + | |
| 130 | + $('#'+ _temName +'ReplayWrap').attr({ | |
| 131 | + id: _name +'ReplayWrap' | |
| 132 | + }); | |
| 133 | + $('#'+ _temName + 'Replay').attr({ | |
| 134 | + id: _name + 'Replay', | |
| 135 | + title: _name | |
| 136 | + }); | |
| 137 | + $('#'+ _temName + 'ReplayCodeMirror').attr({ | |
| 138 | + id: _name + 'ReplayCodeMirror' | |
| 139 | + }); | |
| 140 | + // treeLinkEditor[i].CodeMirrorRecord.setValue(treeLinkEditor[i].CodeMirrorRecord.getValue() + '\n\n'+ _name); | |
| 141 | + } | |
| 142 | + } | |
| 143 | + } | |
| 144 | + } | |
| 145 | + return true; | |
| 146 | + }, | |
| 147 | + onRename: function (e, treeId, treeNode, isCancel) { | |
| 148 | + console.info('onRename'); | |
| 149 | + }, | |
| 150 | + showRemoveBtn: function (treeId, treeNode) { | |
| 151 | + return !treeNode.isFirstNode; | |
| 152 | + }, | |
| 153 | + showRenameBtn: function (treeId, treeNode) { | |
| 154 | + return !treeNode.isLastNode; | |
| 155 | + }, | |
| 156 | + addHoverDom: function (treeId, treeNode) { | |
| 157 | + // console.info('addHoverDom'); | |
| 158 | + // 修复第一个文件夹 | |
| 159 | + if(treeNode.isParent){ | |
| 160 | + $('a[title="'+ treeNode.name +'"]').find("#" + treeId + "_" + treeNode.id + "_edit").hide(); | |
| 161 | + return false; | |
| 162 | + } | |
| 50 | 163 | |
| 51 | - // 不知道为什么 ztree 最后一项不显示编辑按钮 | |
| 52 | - // 只能通过改变参数的值来让它显示编辑按钮 | |
| 53 | - if(treeNode.isLastNode){ | |
| 54 | - treeNode.isLastNode = false; | |
| 164 | + // 不知道为什么 Dir 最后一项不显示编辑按钮 | |
| 165 | + // 只能通过改变参数的值来让它显示编辑按钮 | |
| 166 | + if(treeNode.isLastNode){ | |
| 167 | + treeNode.isLastNode = false; | |
| 168 | + } | |
| 169 | + }, | |
| 170 | + removeHoverDom: function (treeId, treeNode) { | |
| 171 | + // console.info('removeHoverDom'); | |
| 172 | + if(!treeNode.isParent){ | |
| 173 | + $("#folder_" + treeNode.tId + "_edit").unbind().remove(); | |
| 174 | + } | |
| 55 | 175 | } |
| 56 | 176 | } |
| 57 | 177 | |
| 58 | - function removeHoverDom(treeId, treeNodes){ | |
| 59 | - | |
| 60 | - } | |
| 178 | + var config = { | |
| 179 | + view: { | |
| 180 | + addHoverDom: treeFoo.addHoverDom, | |
| 181 | + removeHoverDom: treeFoo.removeHoverDom, | |
| 182 | + selectedMulti: false, | |
| 183 | + showLine: false | |
| 184 | + } | |
| 185 | + ,edit: { | |
| 186 | + enable: true, | |
| 187 | + editNameSelectAll: true, | |
| 188 | + showRemoveBtn: false, | |
| 189 | + showRenameBtn: treeFoo.showRenameBtn | |
| 190 | + } | |
| 191 | + ,data: { | |
| 192 | + simpleData: { enable: true } | |
| 193 | + } | |
| 194 | + ,callback: { | |
| 195 | + /** | |
| 196 | + * ztree 每一项点击事件 | |
| 197 | + * @Author syantao | |
| 198 | + * Created by Keystion on 2017-01-19 | |
| 199 | + */ | |
| 200 | + beforeClick: treeFoo.beforeClick, | |
| 201 | + beforeDrag: treeFoo.beforeDrag, | |
| 202 | + beforeEditName: treeFoo.beforeEditName, | |
| 203 | + beforeRename: treeFoo.beforeRename, | |
| 204 | + onRename: treeFoo.onRename | |
| 205 | + } | |
| 206 | + }; | |
| 207 | + | |
| 61 | 208 | |
| 62 | 209 | // 初始化目录:增、删、改文件,文件夹目录结构 |
| 63 | 210 | var Dir = { |
| 64 | 211 | treeData: {}, |
| 65 | 212 | init: function(){ |
| 66 | - console.log('Dir'); | |
| 213 | + }, | |
| 214 | + defaultTree: function(el, lang){ | |
| 215 | + var _this = this; | |
| 216 | + var _el = $(el); | |
| 217 | + var _lang = lang; | |
| 218 | + | |
| 219 | + $.ajax({ | |
| 220 | + type: "GET", | |
| 221 | + url: "js/lang.json", | |
| 222 | + dataType: "json", | |
| 223 | + contentType: "application/json", | |
| 224 | + success: function(res) { | |
| 225 | + console.log(res); | |
| 226 | + | |
| 227 | + treeData = res.langs[_lang]; | |
| 228 | + | |
| 229 | + console.log(treeData); | |
| 230 | + | |
| 231 | + _this.buildTree(_el, treeData); | |
| 232 | + initJavaPage(treeData) | |
| 233 | + // initJavaPage(treeData) | |
| 234 | + | |
| 235 | + | |
| 236 | + }, | |
| 237 | + error: function(XMLHttpRequest, textStatus, errorThrown) { | |
| 238 | + console.log('Ajax langs.json error'); | |
| 239 | + console.log(XMLHttpRequest); | |
| 240 | + } | |
| 241 | + }); | |
| 67 | 242 | }, |
| 68 | 243 | buildTree: function(select, treeData){ |
| 69 | - $.fn.zTree.init(select, config, treeData); | |
| 244 | + // var treeData = treeData | |
| 245 | + // $.fn.zTree.init(select, config, treeData); | |
| 246 | + treeObj = $.fn.zTree.init(select, config, treeData); | |
| 70 | 247 | }, |
| 71 | - getTreeData: function(){ | |
| 248 | + /** | |
| 249 | + * 通过目录树的点击来显示对应的编辑器 | |
| 250 | + * @Author syantao | |
| 251 | + * Created by Keystion on 2017-01-19 | |
| 252 | + * @param {[type]} treeNode 点击了哪一个目录 | |
| 253 | + * TODO treeNode放到一个变量或者隐藏域里面 | |
| 254 | + */ | |
| 255 | + showEdite: function (obj){ | |
| 256 | + // console.info('ZTREE.showEdite'); | |
| 257 | + // console.log(obj); | |
| 258 | + var _this = this, | |
| 259 | + _file, | |
| 260 | + _CodeMirrorRecordId, | |
| 261 | + _CodeMirrorReplayId, | |
| 262 | + _num = 0; | |
| 263 | + | |
| 264 | + console.log('---------------------------------------') | |
| 265 | + console.log(obj) | |
| 266 | + console.log('---------------------------------------') | |
| 267 | + // 判断是否是初始化选时候调用 showEdite | |
| 268 | + if(obj){ | |
| 269 | + for (var i = 0; i < treeLinkEditor.length; i++) { | |
| 270 | + if(treeLinkEditor[i].name == _this.manageName(obj.treeNode.name)){ | |
| 271 | + _num = i; | |
| 272 | + } | |
| 273 | + } | |
| 274 | + if(typeof obj.record != 'undefined' && obj.record){ | |
| 275 | + $('#recordertab a:eq(0)').tab('show'); | |
| 276 | + }else if(typeof obj.replay != 'undefined'&& obj.replay){ | |
| 277 | + $('#recordertab a:eq(1)').tab('show'); | |
| 278 | + } | |
| 279 | + } | |
| 280 | + | |
| 281 | + _file = treeLinkEditor[_num].file; | |
| 282 | + _CodeMirrorRecordId = treeLinkEditor[_num].CodeMirrorRecordId; | |
| 283 | + _CodeMirrorReplayId = treeLinkEditor[_num].CodeMirrorReplayId; | |
| 284 | + mainPath = treeLinkEditor[_num].filePath; // 更新mainPath值 | |
| 285 | + | |
| 286 | + // 显示代码编辑器 | |
| 287 | + $('#' + _CodeMirrorRecordId).show().parent().show().siblings().hide().find('.CodeMirror').hide(); | |
| 288 | + $('#' + _CodeMirrorReplayId).show().parent().show().siblings().hide().find('.CodeMirror').hide(); | |
| 72 | 289 | |
| 290 | + // console.log('当前选中文件(mainPath):'+ mainPath); | |
| 291 | + // console.log('当前显示代码编辑器:'+ '#' + _CodeMirrorReplayId); | |
| 292 | + | |
| 293 | + // 更新目录树选中状态 | |
| 294 | + _this.selectTreeItem(_file); | |
| 295 | + }, | |
| 296 | + /** | |
| 297 | + * 根据id获取当前编辑器对应的目录树文件 | |
| 298 | + * @Author syantao | |
| 299 | + * Created by Keystion on 2017-01-19 | |
| 300 | + * @param {[type]} id 代码编辑器的id | |
| 301 | + */ | |
| 302 | + getCurrentEditor: function (id){ | |
| 303 | + // console.info('ZTREE.getCurrentEditor'); | |
| 304 | + var _id = id || treeLinkEditor[0].CodeMirrorRecordId, | |
| 305 | + _name; | |
| 306 | + | |
| 307 | + for (var i = 0; i < treeLinkEditor.length; i++) { | |
| 308 | + if(treeLinkEditor[i].CodeMirrorRecordId == _id){ | |
| 309 | + // console.log(treeLinkEditor[i]); | |
| 310 | + _name = treeLinkEditor[i].name; | |
| 311 | + } | |
| 312 | + } | |
| 313 | + | |
| 314 | + return _name; | |
| 315 | + }, | |
| 316 | + /** | |
| 317 | + * 返回目录结构路径 | |
| 318 | + * @Author syantao | |
| 319 | + * Created by Keystion on 2017-01-19 | |
| 320 | + * @param {[type]} treeNode 点击了哪一个目录 | |
| 321 | + * TODO treeNode放到一个变量或者隐藏域里面 | |
| 322 | + */ | |
| 323 | + // 根据提供的 name 获取 pId , 再根据 pId 获取 夫级 name | |
| 324 | + // newName 替换 name 更名需求 | |
| 325 | + getTreePath: function (name, newName){ | |
| 326 | + | |
| 327 | + var _pid, _folder, _filename; | |
| 328 | + for (var i = 0; i < treeData.length; i++) { | |
| 329 | + if(treeData[i].name == name){ | |
| 330 | + _pid = treeData[i].pId; | |
| 331 | + if(newName){ | |
| 332 | + _filename = newName; | |
| 333 | + }else{ | |
| 334 | + _filename = treeData[i].name; | |
| 335 | + } | |
| 336 | + } | |
| 337 | + } | |
| 338 | + for (var i = 0; i < treeData.length; i++) { | |
| 339 | + if(treeData[i].id == _pid){ | |
| 340 | + _folder = treeData[i].name; | |
| 341 | + } | |
| 342 | + } | |
| 343 | + return _folder + '/' + _filename; | |
| 344 | + }, | |
| 345 | + /** | |
| 346 | + * 处理name | |
| 347 | + * @Author syantao | |
| 348 | + * Created by Keystion on 2017-01-23 | |
| 349 | + * @param {[type]} name Class1.java | |
| 350 | + * @return {[type]} Class1 | |
| 351 | + */ | |
| 352 | + manageName: function (name){ | |
| 353 | + // console.info('ZTREE.manageName'); | |
| 354 | + if(!name){ | |
| 355 | + return false; | |
| 356 | + } | |
| 357 | + return name.split('.')[0]; | |
| 358 | + }, | |
| 359 | + /** | |
| 360 | + * 通过文件名选中对应的目录 | |
| 361 | + * @Author syantao | |
| 362 | + * Created by Keystion on 2017-01-23 | |
| 363 | + * @param {[type]} name 例:Class1.java | |
| 364 | + */ | |
| 365 | + selectTreeItem: function (name){ | |
| 366 | + // console.info('ZTREE.selectTreeItem'); | |
| 367 | + var _thisName = name || treeData[1].name; | |
| 368 | + // 处理菜单选中状态 | |
| 369 | + var node = treeObj.getNodeByParam("name", _thisName, null); | |
| 370 | + | |
| 371 | + treeObj.selectNode(node, false, true); | |
| 73 | 372 | } |
| 74 | 373 | } |
| 75 | 374 | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 76 | 378 | // 记录编写代码过程:输入代码、记录存放代码 |
| 77 | - var Coding = { | |
| 379 | + var CodingEditer = { | |
| 380 | + recording_status: 1, //当前是否在录制 | |
| 78 | 381 | init: function(){ |
| 79 | - console.log('Coding'); | |
| 382 | + console.log('CodingEditer'); | |
| 383 | + }, | |
| 384 | + onChange: function(editor, changeobj){ | |
| 385 | + console.log(editor); | |
| 386 | + console.log(changeobj); | |
| 80 | 387 | } |
| 81 | 388 | } |
| 82 | 389 | |
| ... | ... | @@ -104,15 +411,115 @@ |
| 104 | 411 | |
| 105 | 412 | GxbIde.ide = GxbIde.prototype = { |
| 106 | 413 | constructor: GxbIde, |
| 107 | - init: function(){ | |
| 108 | - this.Coding.init() | |
| 414 | + options: { | |
| 415 | + el: "#dir", | |
| 416 | + languageid: null | |
| 417 | + }, | |
| 418 | + init: function(options){ | |
| 419 | + var _this = this; | |
| 420 | + _this.options = $.extend(_this.options, options); | |
| 421 | + _el = _this.options.el; | |
| 422 | + _lang = _this.options.lang; | |
| 423 | + | |
| 424 | + console.log(_el); | |
| 425 | + | |
| 426 | + Dir.defaultTree(_el, _lang); | |
| 109 | 427 | } |
| 110 | 428 | } |
| 111 | 429 | |
| 112 | - // 老师录制编辑 | |
| 113 | - GxbIde.ide.RecordIde = $.extend({ Coding, Dir, ToolBox, Theme, Record }) | |
| 114 | 430 | |
| 431 | + function initJavaPage(treeData){ | |
| 432 | + console.info('initJavaPage'); | |
| 433 | + | |
| 434 | + var _datalist = treeData || []; | |
| 435 | + var recordTemplate = ''; | |
| 436 | + var replayTemplate = ''; | |
| 437 | + var obj = [] | |
| 438 | + if(!_datalist.length){ | |
| 439 | + return false; | |
| 440 | + } | |
| 441 | + | |
| 442 | + // setHtmlButton(_languageid, 'JAVA'); | |
| 443 | + | |
| 444 | + // 生成 textarea | |
| 445 | + for (var i = 0; i < _datalist.length; i++) { | |
| 446 | + if(!_datalist[i].isParent){ | |
| 447 | + var _file = _datalist[i].name; | |
| 448 | + var _name = Dir.manageName(_file); | |
| 449 | + var defaultValue; | |
| 450 | + defaultValue = 'package '+ Dir.getTreePath(_file).split('/')[0] +';\n'; | |
| 451 | + treeLinkEditor.push({ | |
| 452 | + "name": _name, | |
| 453 | + "file": _file, | |
| 454 | + "filePath": Dir.getTreePath(_file), | |
| 455 | + "record": _name + 'Record', | |
| 456 | + "replay": _name + 'Replay' | |
| 457 | + }); | |
| 458 | + // 判断是否是播放页面,如果是则不显示录制区相关dom | |
| 459 | + if(!isReplayPage){ | |
| 460 | + recordTemplate += '<div id="'+ _name +'RecordWrap"><textarea id="'+ _name + 'Record" title="'+ _name +'" style="display: none;">'+defaultValue+'</textarea></div>' | |
| 461 | + } | |
| 462 | + | |
| 463 | + replayTemplate += '<div id="'+ _name +'ReplayWrap"><textarea id="'+ _name + 'Replay" title="'+ _name +'" style="display: none;"></textarea></div>' | |
| 464 | + } | |
| 465 | + } | |
| 466 | + // 判断是否是播放页面,如果是则不显示录制区相关dom | |
| 467 | + if(!isReplayPage){ | |
| 468 | + $('#recordzone').append(recordTemplate); | |
| 469 | + } | |
| 470 | + $('#replayzone').append(replayTemplate); | |
| 471 | + | |
| 472 | + // 生成 CodeMirror | |
| 473 | + for (var i = 0; i < treeLinkEditor.length; i++) { | |
| 474 | + // 判断是否是播放页面,如果是则不显示录制区相关dom | |
| 475 | + if(!isReplayPage){ | |
| 476 | + treeLinkEditor[i].CodeMirrorRecord = CodeMirror.fromTextArea($('#' + treeLinkEditor[i].record)[0], { | |
| 477 | + value: 'heoolo', | |
| 478 | + mode: "text/x-java", | |
| 479 | + lineNumbers: true, | |
| 480 | + smartIndent: false, | |
| 481 | + onChange: function(em, changeobj) { | |
| 482 | + if (CodingEditer.recording_status) { | |
| 483 | + CodingEditer.onChange(Dir.getCurrentEditor(em.getWrapperElement().getAttribute('id')), changeobj); | |
| 484 | + } | |
| 485 | + }, | |
| 486 | + onFocus: function(em) { | |
| 487 | + }, | |
| 488 | + onCursorActivity: function(em) { | |
| 489 | + } | |
| 490 | + }); | |
| 491 | + treeLinkEditor[i].CodeMirrorRecordId = treeLinkEditor[i].record + 'CodeMirror'; | |
| 492 | + $('#' + treeLinkEditor[i].record).next().attr('id', treeLinkEditor[i].CodeMirrorRecordId).hide(); | |
| 493 | + } | |
| 494 | + | |
| 495 | + treeLinkEditor[i].CodeMirrorReplay = CodeMirror.fromTextArea($('#' + treeLinkEditor[i].replay)[0], { | |
| 496 | + value: '', | |
| 497 | + mode: "text/x-java", | |
| 498 | + lineNumbers: true, | |
| 499 | + smartIndent: false, | |
| 500 | + onChange: function(em, changeobj) { | |
| 501 | + }, | |
| 502 | + onFocus: function(em) { | |
| 503 | + }, | |
| 504 | + onCursorActivity: function(em) { | |
| 505 | + } | |
| 506 | + }); | |
| 507 | + treeLinkEditor[i].CodeMirrorReplayId = treeLinkEditor[i].replay + 'CodeMirror'; | |
| 508 | + $('#' + treeLinkEditor[i].replay).next().attr('id', treeLinkEditor[i].CodeMirrorReplayId).hide(); | |
| 509 | + } | |
| 510 | + | |
| 511 | + // 默认显示第一个文件夹的第一个文件 | |
| 512 | + Dir.showEdite(); | |
| 513 | + } | |
| 514 | + | |
| 515 | + | |
| 516 | + // 老师录制编辑 | |
| 517 | + GxbIde.ide.RecordIde = $.extend({ Dir, CodingEditer, ToolBox, Theme, Record }) | |
| 115 | 518 | |
| 116 | 519 | window.GxbIde = GxbIde; |
| 117 | 520 | |
| 118 | -})(window) | |
| 119 | 521 | \ No newline at end of file |
| 522 | +})(window) | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | ... | ... |
src/js/lang.json
0 → 100644
| 1 | +{ | |
| 2 | + "langs": { | |
| 3 | + "java": [ | |
| 4 | + { "id": 1, "pId": 0, "name": "package1", "open": true, "isParent": true, "collapse": false }, | |
| 5 | + { "id": 11, "pId": 1, "name": "default1.java", "type": "java" }, | |
| 6 | + { "id": 12, "pId": 1, "name": "default2.java", "type": "java" }, | |
| 7 | + { "id": 13, "pId": 1, "name": "default3.java", "type": "java" }, | |
| 8 | + { "id": 14, "pId": 1, "name": "default4.java", "type": "java" }, | |
| 9 | + { "id": 15, "pId": 1, "name": "default5.java", "type": "java" }, | |
| 10 | + { "id": 2, "pId": 0, "name": "package2", "open": true, "isParent": true, "expand": true }, | |
| 11 | + { "id": 21, "pId": 2, "name": "defaultA.java", "type": "java" }, | |
| 12 | + { "id": 22, "pId": 2, "name": "defaultB.java", "type": "java" }, | |
| 13 | + { "id": 23, "pId": 2, "name": "defaultC.java", "type": "java" }, | |
| 14 | + { "id": 24, "pId": 2, "name": "defaultD.java", "type": "java" }, | |
| 15 | + { "id": 25, "pId": 2, "name": "defaultE.java", "type": "java" } | |
| 16 | + ], | |
| 17 | + "html": [ | |
| 18 | + { "id": 1, "pId": 0, "name": "folder1", "open": true, "isParent": true, "collapse": false }, | |
| 19 | + { "id": 11, "pId": 1, "name": "default1.html", "type": "html" }, | |
| 20 | + { "id": 12, "pId": 1, "name": "default2.html", "type": "html" }, | |
| 21 | + { "id": 13, "pId": 1, "name": "default3.html", "type": "html" }, | |
| 22 | + { "id": 14, "pId": 1, "name": "default4.html", "type": "html" }, | |
| 23 | + { "id": 15, "pId": 1, "name": "default5.html", "type": "html" }, | |
| 24 | + { "id": 2, "pId": 0, "name": "folder2", "open": true, "isParent": true, "expand": true }, | |
| 25 | + { "id": 21, "pId": 2, "name": "defaultA.html", "type": "html" }, | |
| 26 | + { "id": 22, "pId": 2, "name": "defaultB.html", "type": "html" }, | |
| 27 | + { "id": 23, "pId": 2, "name": "defaultC.html", "type": "html" }, | |
| 28 | + { "id": 24, "pId": 2, "name": "defaultD.html", "type": "html" }, | |
| 29 | + { "id": 25, "pId": 2, "name": "defaultE.html", "type": "html" } | |
| 30 | + ] | |
| 31 | + } | |
| 32 | +} | |
| 0 | 33 | \ No newline at end of file | ... | ... |