| 1 |
function ed_ct_resize(t, is_sel) { |
| 2 |
var cbox = t.get('panelNode'); |
| 3 |
|
| 4 |
var ed_tv = document['ed_tv']; |
| 5 |
var w = ed_tv.get('width'); |
| 6 |
w = Math.floor(w * 0.25); |
| 7 |
var lh = cbox.ancestor().ancestor().one('.yui3-tabview-list').get('clientHeight'); |
| 8 |
var h = ed_tv.get('height') - lh; |
| 9 |
|
| 10 |
if (is_sel) { |
| 11 |
if (cbox['g_table_h'] == h && cbox['g_table_w'] == w) { |
| 12 |
return; |
| 13 |
} |
| 14 |
} |
| 15 |
cbox['g_table_h'] = h |
| 16 |
cbox['g_table_w'] = w |
| 17 |
|
| 18 |
var table = cbox['g_table']; |
| 19 |
var dv = cbox['g_dv']; |
| 20 |
table.draw(dv, { |
| 21 |
width: w, |
| 22 |
height: h, |
| 23 |
page : 'enable', |
| 24 |
pageSize : 200, |
| 25 |
}); |
| 26 |
} |
| 27 |
|
| 28 |
function ed_ace_resize(t, is_sel) { |
| 29 |
var cbox = t.get('panelNode'); |
| 30 |
var ed_tv = document['ed_tv']; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
var editor = cbox['a_ed']; |
| 37 |
editor.resize(); |
| 38 |
} |
| 39 |
|
| 40 |
function ed_tv_resize(e) { |
| 41 |
var ed_tv = document['ed_tv']; |
| 42 |
if (!ed_tv.size()) { |
| 43 |
return; |
| 44 |
} |
| 45 |
var t = ed_tv.get('selection'); |
| 46 |
if (!t) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
ed_ct_resize(t); |
| 51 |
ed_ace_resize(t); |
| 52 |
} |
| 53 |
|
| 54 |
function ed_tv_resize_sel(e) { |
| 55 |
var ed_tv = document['ed_tv']; |
| 56 |
if (!ed_tv.size()) { |
| 57 |
return; |
| 58 |
} |
| 59 |
var t = ed_tv.get('selection'); |
| 60 |
if (!t) { |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
ed_ct_resize(t, true); |
| 65 |
ed_ace_resize(t, true); |
| 66 |
} |
| 67 |
|
| 68 |
function ed_get_cur_word() { |
| 69 |
var ed_tv = document['ed_tv']; |
| 70 |
if (!ed_tv.size()) { |
| 71 |
return ''; |
| 72 |
} |
| 73 |
|
| 74 |
var t = ed_tv.get('selection'); |
| 75 |
var cbox = t.get('panelNode'); |
| 76 |
var editor = cbox['a_ed']; |
| 77 |
var word = editor.getCopyText(); |
| 78 |
|
| 79 |
if (!word) { |
| 80 |
var pos = editor.getCursorPosition(); |
| 81 |
word = editor.getSession().getLine(pos.row); |
| 82 |
function is_word_char(c) { |
| 83 |
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || |
| 84 |
(c >= '0' && c <= '9') || (c == '_')) { |
| 85 |
return true; |
| 86 |
} |
| 87 |
return false; |
| 88 |
} |
| 89 |
var linx = pos.column; |
| 90 |
while(linx > 0 && is_word_char(word.charAt(linx - 1))) { |
| 91 |
linx--; |
| 92 |
} |
| 93 |
var rinx = pos.column; |
| 94 |
while(rinx < word.length && is_word_char(word.charAt(rinx))) { |
| 95 |
rinx++; |
| 96 |
} |
| 97 |
word = word.slice(linx, rinx); |
| 98 |
} |
| 99 |
return (word); |
| 100 |
} |
| 101 |
|
| 102 |
function ed_get_cur_file() { |
| 103 |
var ed_tv = document['ed_tv']; |
| 104 |
if (!ed_tv.size()) { |
| 105 |
return ''; |
| 106 |
} |
| 107 |
|
| 108 |
var t = ed_tv.get('selection'); |
| 109 |
if (!t) { |
| 110 |
return null; |
| 111 |
} |
| 112 |
return t['ed_file']; |
| 113 |
} |
| 114 |
|
| 115 |
function createCtTable(t) { |
| 116 |
var cbox = t.get('panelNode'); |
| 117 |
var ctNode = cbox.one('#ctTbl'); |
| 118 |
|
| 119 |
if (ctNode) { |
| 120 |
ctNode = ctNode.getDOMNode(); |
| 121 |
} |
| 122 |
if (!ctNode) { |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
var dt = new google.visualization.DataTable(); |
| 127 |
dt.addColumn('string', 'name'); |
| 128 |
dt.addColumn('number', 'line'); |
| 129 |
dt.addColumn('string', 'type'); |
| 130 |
|
| 131 |
dt.addRows(1); |
| 132 |
dt.setCell(0, 0, 'fetching ctags...'); |
| 133 |
|
| 134 |
var dv = new google.visualization.DataView(dt); |
| 135 |
var table = new google.visualization.Table(ctNode); |
| 136 |
|
| 137 |
cbox['g_dt'] = dt; |
| 138 |
cbox['g_dv'] = dv; |
| 139 |
cbox['g_table'] = table; |
| 140 |
|
| 141 |
var ed_tv = document['ed_tv']; |
| 142 |
ed_ct_resize(t); |
| 143 |
|
| 144 |
google.visualization.events.addListener(table, 'select', function() { |
| 145 |
var sel = table.getSelection() |
| 146 |
if (sel.length == 0) { |
| 147 |
return |
| 148 |
} |
| 149 |
var row = sel[0].row; |
| 150 |
var line = cbox['g_dv'].getValue(row, 1); |
| 151 |
|
| 152 |
var editor = cbox['a_ed']; |
| 153 |
editor.gotoLine(line); |
| 154 |
editor.focus(); |
| 155 |
}); |
| 156 |
} |
| 157 |
|
| 158 |
function populateCtTable(t, res) { |
| 159 |
var cbox = t.get('panelNode'); |
| 160 |
var table = cbox['g_table']; |
| 161 |
var dt = cbox['g_dt']; |
| 162 |
|
| 163 |
dt.removeRow(0); |
| 164 |
for (var i = 0; i < res.length; i++) { |
| 165 |
var r = res[i]; |
| 166 |
dt.addRow([r[0], parseInt(r[1]), r[2]]); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
ed_ct_resize(t); |
| 171 |
} |
| 172 |
|
| 173 |
function ed_ct_line_change(t, line) { |
| 174 |
var cbox = t.get('panelNode'); |
| 175 |
var table = cbox['g_table']; |
| 176 |
var dv = cbox['g_dv']; |
| 177 |
|
| 178 |
function line_val(dv, inx) { |
| 179 |
return dv.getValue(inx, 1); |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
var num_rows = dv.getNumberOfRows(); |
| 184 |
if (num_rows == 0) { |
| 185 |
return; |
| 186 |
} |
| 187 |
|
| 188 |
var inx; |
| 189 |
|
| 190 |
var sel = table.getSelection(); |
| 191 |
if (sel.length) { |
| 192 |
inx = sel[0].row; |
| 193 |
} else { |
| 194 |
inx = 0; |
| 195 |
} |
| 196 |
|
| 197 |
if (line_val(dv, inx) == line) { |
| 198 |
return; |
| 199 |
} |
| 200 |
if (line_val(dv, inx) < line) { |
| 201 |
while (inx + 1 < num_rows) { |
| 202 |
if (line_val(dv, inx + 1) > line) { |
| 203 |
break; |
| 204 |
} |
| 205 |
inx++; |
| 206 |
} |
| 207 |
} else { |
| 208 |
while (inx - 1 >= 0) { |
| 209 |
inx--; |
| 210 |
if (line_val(dv, inx) <= line) { |
| 211 |
break; |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
table.setSelection([{row:inx, col:null}]); |
| 216 |
|
| 217 |
} |
| 218 |
|
| 219 |
function focusAceEditor(cbox, res, line) { |
| 220 |
var editor = cbox['a_ed']; |
| 221 |
if (editor) { |
| 222 |
editor.focus(); |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
function setAceEditorText(t, res, line) { |
| 227 |
var cbox = t.get('panelNode'); |
| 228 |
var editor = cbox['a_ed']; |
| 229 |
|
| 230 |
var file = t['ed_file']; |
| 231 |
var fp = file.split('.') |
| 232 |
if (fp.length > 1) { |
| 233 |
var sfx = fp[fp.length - 1]; |
| 234 |
if (['c', 'cpp', 'c++', 'h'].indexOf(sfx) >= 0) { |
| 235 |
editor.getSession().setMode("ace/mode/c_cpp"); |
| 236 |
} else if (['java'].indexOf(sfx) >= 0) { |
| 237 |
editor.getSession().setMode("ace/mode/java"); |
| 238 |
} else if (['py'].indexOf(sfx) >= 0) { |
| 239 |
editor.getSession().setMode("ace/mode/python"); |
| 240 |
} else if (['tin', 'tac', 'itin'].indexOf(sfx) >= 0) { |
| 241 |
editor.getSession().setMode("ace/mode/c_cpp"); |
| 242 |
} |
| 243 |
} else { |
| 244 |
editor.getSession().setMode("ace/mode/c_cpp"); |
| 245 |
} |
| 246 |
editor.getSession().setTabSize(8); |
| 247 |
|
| 248 |
editor.setValue(res); |
| 249 |
editor.getSession().selection.on('changeCursor', function(e, e2, e3) { |
| 250 |
var old_line = cbox['a_ed_last_line']; |
| 251 |
var new_line = editor.getCursorPosition().row + 1; |
| 252 |
if (new_line != old_line) { |
| 253 |
cbox['a_ed_last_line'] = new_line; |
| 254 |
ed_ct_line_change(t, new_line); |
| 255 |
|
| 256 |
} |
| 257 |
}); |
| 258 |
editor.gotoLine(line); |
| 259 |
editor.scrollToLine(line, true); |
| 260 |
|
| 261 |
editor.focus(); |
| 262 |
ed_ace_resize(t); |
| 263 |
} |
| 264 |
|
| 265 |
function createAceEditor(t) { |
| 266 |
var cbox = t.get('panelNode'); |
| 267 |
var edNode = cbox.one('#aceEditor'); |
| 268 |
|
| 269 |
if (edNode) { |
| 270 |
edNode = edNode.getDOMNode(); |
| 271 |
} |
| 272 |
if (!edNode) { |
| 273 |
return; |
| 274 |
} |
| 275 |
var editor = ace.edit(edNode); |
| 276 |
|
| 277 |
editor.getSession().setUseWorker(false); |
| 278 |
editor.setTheme("ace/theme/eclipse"); |
| 279 |
|
| 280 |
editor.setReadOnly(true); |
| 281 |
|
| 282 |
|
| 283 |
editor.gotoLine("1"); |
| 284 |
editor.focus(); |
| 285 |
cbox['a_ed'] = editor; |
| 286 |
cbox['a_ed_last_line'] = 0; |
| 287 |
} |
| 288 |
|
| 289 |
function show_ctags_new(t, file) { |
| 290 |
if (!t) { |
| 291 |
return; |
| 292 |
} |
| 293 |
|
| 294 |
var Y = document['edy']; |
| 295 |
var src; |
| 296 |
src = new Y.DataSource.Get({ |
| 297 |
source : document['server_info'].url, |
| 298 |
}); |
| 299 |
src.plug(Y.Plugin.DataSourceJSONSchema, { |
| 300 |
schema : { |
| 301 |
resultListLocator : 'res', |
| 302 |
} |
| 303 |
}); |
| 304 |
var request = '?' + to_query_string({ |
| 305 |
project : document['project'], |
| 306 |
cmd_type : 'query', |
| 307 |
cmd_str : 'FCTAGS', |
| 308 |
req : file, |
| 309 |
}); |
| 310 |
src.sendRequest({ |
| 311 |
request : request, |
| 312 |
callback : { |
| 313 |
success: function (e) { |
| 314 |
var res = e.response.results; |
| 315 |
populateCtTable(t, res[0]); |
| 316 |
}, |
| 317 |
failure: function (e) { |
| 318 |
var cbox = t.get('panelNode'); |
| 319 |
cbox['g_dt'].setCell(0, 0, e.error.message); |
| 320 |
cbox['g_table'].draw(cbox['g_dv']); |
| 321 |
alert(e.error.message); |
| 322 |
}, |
| 323 |
}, |
| 324 |
}); |
| 325 |
} |
| 326 |
|
| 327 |
function show_ace_editor_new(t, file, line) { |
| 328 |
var Y = document['edy']; |
| 329 |
var src; |
| 330 |
src = new Y.DataSource.Get({ |
| 331 |
source : document['server_info'].url, |
| 332 |
}); |
| 333 |
src.plug(Y.Plugin.DataSourceJSONSchema, { |
| 334 |
schema : { |
| 335 |
resultListLocator : 'res', |
| 336 |
} |
| 337 |
}); |
| 338 |
var request = '?' + to_query_string({ |
| 339 |
project : document['project'], |
| 340 |
cmd_type : 'query', |
| 341 |
cmd_str : 'FDATA', |
| 342 |
req : file, |
| 343 |
}); |
| 344 |
src.sendRequest({ |
| 345 |
request : request, |
| 346 |
callback : { |
| 347 |
success: function (e) { |
| 348 |
var res = e.response.results; |
| 349 |
setAceEditorText(t, res[0], line); |
| 350 |
}, |
| 351 |
failure: function (e) { |
| 352 |
setAceEditorText(t, e.error.message, 1); |
| 353 |
alert(e.error.message); |
| 354 |
}, |
| 355 |
}, |
| 356 |
}); |
| 357 |
} |
| 358 |
|
| 359 |
function ed_show_file_line_new(file, line) { |
| 360 |
var ed_tv = document['ed_tv']; |
| 361 |
var fp = file.split('/'); |
| 362 |
var fname = fp[fp.length - 1]; |
| 363 |
var content2 = |
| 364 |
'<table style="position:relative; width: 100%; height: 85%;">' + |
| 365 |
'<tr style="vertical-align: top;">' + |
| 366 |
'<td style="position:relative; width: 10%;">' + |
| 367 |
' <div id="ctTbl" style="position:relative; width: 100%; "> </div>' + |
| 368 |
'</td>' + |
| 369 |
'<td style="position:relative; width: 80%; height: 100%;">' + |
| 370 |
' <div id="aceEditor" style="background-color: white; position:relative; width: 100%; height: 100%;"> </div>' + |
| 371 |
'</td>' + |
| 372 |
'</tr>' + |
| 373 |
'</table>'; |
| 374 |
var content = |
| 375 |
'<table style="position:relative; width: 100%; height: 85%;">' + |
| 376 |
'<tr style="vertical-align: top;">' + |
| 377 |
'<td style="position:relative; width: 25%;">' + |
| 378 |
' <div id="ctTbl"> </div>' + |
| 379 |
'</td>' + |
| 380 |
'<td style="position:relative; width: 75%; height: 100%;">' + |
| 381 |
' <div id="aceEditor" style="background-color: white; position:relative; width: 100%; height: 100%;"> </div>' + |
| 382 |
'</td>' + |
| 383 |
'</tr>' + |
| 384 |
'</table>'; |
| 385 |
var input = { |
| 386 |
label: fname, |
| 387 |
content : content, |
| 388 |
} |
| 389 |
ed_tv.add(input); |
| 390 |
found = ed_tv.size() - 1; |
| 391 |
t = ed_tv.item(found); |
| 392 |
t['ed_file'] = file; |
| 393 |
t['ed_line'] = line; |
| 394 |
ed_tv.selectChild(found); |
| 395 |
|
| 396 |
show_ace_editor_new(t, file, line) |
| 397 |
show_ctags_new(t, file); |
| 398 |
} |
| 399 |
|
| 400 |
function ed_show_file_line(file, line) { |
| 401 |
|
| 402 |
var edf = document['edf']; |
| 403 |
|
| 404 |
var ed_tv = document['ed_tv']; |
| 405 |
|
| 406 |
var found = -1; |
| 407 |
for (i = 0; i < ed_tv.size(); i++) { |
| 408 |
t = ed_tv.item(i); |
| 409 |
if (t['ed_file'] == file) { |
| 410 |
found = i; |
| 411 |
break; |
| 412 |
} |
| 413 |
} |
| 414 |
if (found == -1) { |
| 415 |
ed_show_file_line_new(file, line); |
| 416 |
} else { |
| 417 |
ed_tv.selectChild(found); |
| 418 |
var cbox = t.get('panelNode'); |
| 419 |
var editor = cbox['a_ed']; |
| 420 |
editor.gotoLine(line); |
| 421 |
editor.focus(); |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
YUI().use('datasource-get', 'datasource-jsonschema', |
| 426 |
'node-event-delegate', 'event-key', |
| 427 |
'tabview', 'escape', 'plugin', 'node', function(Y) { |
| 428 |
|
| 429 |
document['edy'] = Y; |
| 430 |
|
| 431 |
var EdAddable = function(config) { |
| 432 |
EdAddable.superclass.constructor.apply(this, arguments); |
| 433 |
}; |
| 434 |
|
| 435 |
EdAddable.NAME = 'addableTabs'; |
| 436 |
EdAddable.NS = 'addable'; |
| 437 |
|
| 438 |
Y.extend(EdAddable, Y.Plugin.Base, { |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
initializer: function(config) { |
| 443 |
var tabview = this.get('host'); |
| 444 |
tabview.after('render', this.afterRender, this); |
| 445 |
tabview.get('contentBox').delegate('click', this.onAddClick, '.yui3-tab-add', this); |
| 446 |
|
| 447 |
tabview.after('tab:render', this.afterTabRender, this); |
| 448 |
|
| 449 |
tabview.after('selectionChange', function() { |
| 450 |
var t = tabview.get('activeDescendant'); |
| 451 |
if (t) { |
| 452 |
focusAceEditor(t.get('panelNode')); |
| 453 |
} |
| 454 |
}); |
| 455 |
|
| 456 |
tabview.get('listNode').setStyle('border-width', '0 0 0px'); |
| 457 |
tabview.get('panelNode').setStyle('padding', '0em'); |
| 458 |
}, |
| 459 |
|
| 460 |
afterRender: function(e) { |
| 461 |
var tabview = this.get('host'); |
| 462 |
|
| 463 |
}, |
| 464 |
|
| 465 |
onAddClick: function(e) { |
| 466 |
}, |
| 467 |
|
| 468 |
afterTabRender: function(e) { |
| 469 |
|
| 470 |
var t = e.target; |
| 471 |
tv = this.get('host'); |
| 472 |
|
| 473 |
createAceEditor(t); |
| 474 |
createCtTable(t); |
| 475 |
} |
| 476 |
}); |
| 477 |
|
| 478 |
var EdRemoveable = function(config) { |
| 479 |
EdRemoveable.superclass.constructor.apply(this, arguments); |
| 480 |
}; |
| 481 |
|
| 482 |
EdRemoveable.NAME = 'removeableTabs'; |
| 483 |
EdRemoveable.NS = 'removeable'; |
| 484 |
|
| 485 |
Y.extend(EdRemoveable, Y.Plugin.Base, { |
| 486 |
REMOVE_TEMPLATE: '<a class="yui3-tab-remove" title="remove tab">x</a>', |
| 487 |
|
| 488 |
initializer: function(config) { |
| 489 |
var tabview = this.get('host'), |
| 490 |
cb = tabview.get('contentBox'); |
| 491 |
|
| 492 |
cb.addClass('yui3-tabview-removeable'); |
| 493 |
cb.delegate('click', this.onRemoveClick, '.yui3-tab-remove', this); |
| 494 |
|
| 495 |
|
| 496 |
tabview.after('tab:render', this.afterTabRender, this); |
| 497 |
}, |
| 498 |
|
| 499 |
afterTabRender: function(e) { |
| 500 |
|
| 501 |
e.target.get('boundingBox').append(this.REMOVE_TEMPLATE); |
| 502 |
}, |
| 503 |
|
| 504 |
onRemoveClick: function(e) { |
| 505 |
e.stopPropagation(); |
| 506 |
var tab = Y.Widget.getByNode(e.target); |
| 507 |
tab.remove(); |
| 508 |
} |
| 509 |
}); |
| 510 |
|
| 511 |
var ed_tv= new Y.TabView({ |
| 512 |
children: [], |
| 513 |
plugins: [EdAddable, EdRemoveable] |
| 514 |
}); |
| 515 |
|
| 516 |
ed_tab_list_pop_dlg_setup(function(cargs) { |
| 517 |
if (cargs.choice == 'close_all') { |
| 518 |
ed_tv.removeAll(); |
| 519 |
} |
| 520 |
}); |
| 521 |
ed_pop_dlg_setup(function(cargs) { |
| 522 |
qry_dlg_show(start_query, cargs.choice); |
| 523 |
}); |
| 524 |
|
| 525 |
ed_tv.after('heightChange', ed_tv_resize); |
| 526 |
ed_tv.after('widthChange', ed_tv_resize); |
| 527 |
ed_tv.after("selectionChange", function(e) { |
| 528 |
Y.later(0, null, ed_tv_resize_sel, e); |
| 529 |
}); |
| 530 |
|
| 531 |
document['ed_tv'] = ed_tv; |
| 532 |
|
| 533 |
|
| 534 |
ed_tv.render('#edTabs'); |
| 535 |
|
| 536 |
function queryAction(e) { |
| 537 |
e.stopPropagation(); |
| 538 |
confirm('queryAction'); |
| 539 |
qry_dlg_show(); |
| 540 |
} |
| 541 |
var key1 = 'm+ctrl'; |
| 542 |
|
| 543 |
Y.one('#edTabs').on('key', queryAction, key1); |
| 544 |
|
| 545 |
var key2 = ']+ctrl'; |
| 546 |
function qdefAction(e) { |
| 547 |
confirm('qdefAction'); |
| 548 |
var word = ed_get_cur_word(); |
| 549 |
if (word) { |
| 550 |
if (word.length < 3) { |
| 551 |
qry_dlg_show(); |
| 552 |
} else { |
| 553 |
start_query(word, 'DEF'); |
| 554 |
} |
| 555 |
} |
| 556 |
} |
| 557 |
Y.one('#edTabs').on('key', qdefAction, key2); |
| 558 |
}); |