ext-settings_menu.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. ace.define("ace/ext/menu_tools/element_generator",["require","exports","module"], function(require, exports, module) {
  2. 'use strict';
  3. module.exports.createOption = function createOption (obj) {
  4. var attribute;
  5. var el = document.createElement('option');
  6. for(attribute in obj) {
  7. if(obj.hasOwnProperty(attribute)) {
  8. if(attribute === 'selected') {
  9. el.setAttribute(attribute, obj[attribute]);
  10. } else {
  11. el[attribute] = obj[attribute];
  12. }
  13. }
  14. }
  15. return el;
  16. };
  17. module.exports.createCheckbox = function createCheckbox (id, checked, clss) {
  18. var el = document.createElement('input');
  19. el.setAttribute('type', 'checkbox');
  20. el.setAttribute('id', id);
  21. el.setAttribute('name', id);
  22. el.setAttribute('value', checked);
  23. el.setAttribute('class', clss);
  24. if(checked) {
  25. el.setAttribute('checked', 'checked');
  26. }
  27. return el;
  28. };
  29. module.exports.createInput = function createInput (id, value, clss) {
  30. var el = document.createElement('input');
  31. el.setAttribute('type', 'text');
  32. el.setAttribute('id', id);
  33. el.setAttribute('name', id);
  34. el.setAttribute('value', value);
  35. el.setAttribute('class', clss);
  36. return el;
  37. };
  38. module.exports.createLabel = function createLabel (text, labelFor) {
  39. var el = document.createElement('label');
  40. el.setAttribute('for', labelFor);
  41. el.textContent = text;
  42. return el;
  43. };
  44. module.exports.createSelection = function createSelection (id, values, clss) {
  45. var el = document.createElement('select');
  46. el.setAttribute('id', id);
  47. el.setAttribute('name', id);
  48. el.setAttribute('class', clss);
  49. values.forEach(function(item) {
  50. el.appendChild(module.exports.createOption(item));
  51. });
  52. return el;
  53. };
  54. });
  55. ace.define("ace/ext/modelist",["require","exports","module"], function(require, exports, module) {
  56. "use strict";
  57. var modes = [];
  58. function getModeForPath(path) {
  59. var mode = modesByName.text;
  60. var fileName = path.split(/[\/\\]/).pop();
  61. for (var i = 0; i < modes.length; i++) {
  62. if (modes[i].supportsFile(fileName)) {
  63. mode = modes[i];
  64. break;
  65. }
  66. }
  67. return mode;
  68. }
  69. var Mode = function(name, caption, extensions) {
  70. this.name = name;
  71. this.caption = caption;
  72. this.mode = "ace/mode/" + name;
  73. this.extensions = extensions;
  74. if (/\^/.test(extensions)) {
  75. var re = extensions.replace(/\|(\^)?/g, function(a, b){
  76. return "$|" + (b ? "^" : "^.*\\.");
  77. }) + "$";
  78. } else {
  79. var re = "^.*\\.(" + extensions + ")$";
  80. }
  81. this.extRe = new RegExp(re, "gi");
  82. };
  83. Mode.prototype.supportsFile = function(filename) {
  84. return filename.match(this.extRe);
  85. };
  86. var supportedModes = {
  87. ABAP: ["abap"],
  88. ActionScript:["as"],
  89. ADA: ["ada|adb"],
  90. Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],
  91. AsciiDoc: ["asciidoc"],
  92. Assembly_x86:["asm"],
  93. AutoHotKey: ["ahk"],
  94. BatchFile: ["bat|cmd"],
  95. C9Search: ["c9search_results"],
  96. C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp"],
  97. Cirru: ["cirru|cr"],
  98. Clojure: ["clj|cljs"],
  99. Cobol: ["CBL|COB"],
  100. coffee: ["coffee|cf|cson|^Cakefile"],
  101. ColdFusion: ["cfm"],
  102. CSharp: ["cs"],
  103. CSS: ["css"],
  104. Curly: ["curly"],
  105. D: ["d|di"],
  106. Dart: ["dart"],
  107. Diff: ["diff|patch"],
  108. Dockerfile: ["^Dockerfile"],
  109. Dot: ["dot"],
  110. Erlang: ["erl|hrl"],
  111. EJS: ["ejs"],
  112. Forth: ["frt|fs|ldr"],
  113. FTL: ["ftl"],
  114. Gherkin: ["feature"],
  115. Gitignore: ["^.gitignore"],
  116. Glsl: ["glsl|frag|vert"],
  117. golang: ["go"],
  118. Groovy: ["groovy"],
  119. HAML: ["haml"],
  120. Handlebars: ["hbs|handlebars|tpl|mustache"],
  121. Haskell: ["hs"],
  122. haXe: ["hx"],
  123. HTML: ["html|htm|xhtml"],
  124. HTML_Ruby: ["erb|rhtml|html.erb"],
  125. INI: ["ini|conf|cfg|prefs"],
  126. Jack: ["jack"],
  127. Jade: ["jade"],
  128. Java: ["java"],
  129. JavaScript: ["js|jsm"],
  130. JSON: ["json"],
  131. JSONiq: ["jq"],
  132. JSP: ["jsp"],
  133. JSX: ["jsx"],
  134. Julia: ["jl"],
  135. LaTeX: ["tex|latex|ltx|bib"],
  136. LESS: ["less"],
  137. Liquid: ["liquid"],
  138. Lisp: ["lisp"],
  139. LiveScript: ["ls"],
  140. LogiQL: ["logic|lql"],
  141. LSL: ["lsl"],
  142. Lua: ["lua"],
  143. LuaPage: ["lp"],
  144. Lucene: ["lucene"],
  145. Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"],
  146. MATLAB: ["matlab"],
  147. Markdown: ["md|markdown"],
  148. MEL: ["mel"],
  149. MySQL: ["mysql"],
  150. MUSHCode: ["mc|mush"],
  151. Nix: ["nix"],
  152. ObjectiveC: ["m|mm"],
  153. OCaml: ["ml|mli"],
  154. Pascal: ["pas|p"],
  155. Perl: ["pl|pm"],
  156. pgSQL: ["pgsql"],
  157. PHP: ["php|phtml"],
  158. Powershell: ["ps1"],
  159. Prolog: ["plg|prolog"],
  160. Properties: ["properties"],
  161. Protobuf: ["proto"],
  162. Python: ["py"],
  163. R: ["r"],
  164. RDoc: ["Rd"],
  165. RHTML: ["Rhtml"],
  166. Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],
  167. Rust: ["rs"],
  168. SASS: ["sass"],
  169. SCAD: ["scad"],
  170. Scala: ["scala"],
  171. Smarty: ["smarty|tpl"],
  172. Scheme: ["scm|rkt"],
  173. SCSS: ["scss"],
  174. SH: ["sh|bash|^.bashrc"],
  175. SJS: ["sjs"],
  176. Space: ["space"],
  177. snippets: ["snippets"],
  178. Soy_Template:["soy"],
  179. SQL: ["sql"],
  180. Stylus: ["styl|stylus"],
  181. SVG: ["svg"],
  182. Tcl: ["tcl"],
  183. Tex: ["tex"],
  184. Text: ["txt"],
  185. Textile: ["textile"],
  186. Toml: ["toml"],
  187. Twig: ["twig"],
  188. Typescript: ["ts|typescript|str"],
  189. Vala: ["vala"],
  190. VBScript: ["vbs"],
  191. Velocity: ["vm"],
  192. Verilog: ["v|vh|sv|svh"],
  193. XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl"],
  194. XQuery: ["xq"],
  195. YAML: ["yaml|yml"]
  196. };
  197. var nameOverrides = {
  198. ObjectiveC: "Objective-C",
  199. CSharp: "C#",
  200. golang: "Go",
  201. C_Cpp: "C/C++",
  202. coffee: "CoffeeScript",
  203. HTML_Ruby: "HTML (Ruby)",
  204. FTL: "FreeMarker"
  205. };
  206. var modesByName = {};
  207. for (var name in supportedModes) {
  208. var data = supportedModes[name];
  209. var displayName = (nameOverrides[name] || name).replace(/_/g, " ");
  210. var filename = name.toLowerCase();
  211. var mode = new Mode(filename, displayName, data[0]);
  212. modesByName[filename] = mode;
  213. modes.push(mode);
  214. }
  215. module.exports = {
  216. getModeForPath: getModeForPath,
  217. modes: modes,
  218. modesByName: modesByName
  219. };
  220. });
  221. ace.define("ace/ext/themelist",["require","exports","module","ace/lib/fixoldbrowsers"], function(require, exports, module) {
  222. "use strict";
  223. require("ace/lib/fixoldbrowsers");
  224. var themeData = [
  225. ["Chrome" ],
  226. ["Clouds" ],
  227. ["Crimson Editor" ],
  228. ["Dawn" ],
  229. ["Dreamweaver" ],
  230. ["Eclipse" ],
  231. ["GitHub" ],
  232. ["Solarized Light"],
  233. ["TextMate" ],
  234. ["Tomorrow" ],
  235. ["XCode" ],
  236. ["Kuroir"],
  237. ["KatzenMilch"],
  238. ["Ambiance" ,"ambiance" , "dark"],
  239. ["Chaos" ,"chaos" , "dark"],
  240. ["Clouds Midnight" ,"clouds_midnight" , "dark"],
  241. ["Cobalt" ,"cobalt" , "dark"],
  242. ["idle Fingers" ,"idle_fingers" , "dark"],
  243. ["krTheme" ,"kr_theme" , "dark"],
  244. ["Merbivore" ,"merbivore" , "dark"],
  245. ["Merbivore Soft" ,"merbivore_soft" , "dark"],
  246. ["Mono Industrial" ,"mono_industrial" , "dark"],
  247. ["Monokai" ,"monokai" , "dark"],
  248. ["Pastel on dark" ,"pastel_on_dark" , "dark"],
  249. ["Solarized Dark" ,"solarized_dark" , "dark"],
  250. ["Terminal" ,"terminal" , "dark"],
  251. ["Tomorrow Night" ,"tomorrow_night" , "dark"],
  252. ["Tomorrow Night Blue" ,"tomorrow_night_blue" , "dark"],
  253. ["Tomorrow Night Bright","tomorrow_night_bright" , "dark"],
  254. ["Tomorrow Night 80s" ,"tomorrow_night_eighties" , "dark"],
  255. ["Twilight" ,"twilight" , "dark"],
  256. ["Vibrant Ink" ,"vibrant_ink" , "dark"]
  257. ];
  258. exports.themesByName = {};
  259. exports.themes = themeData.map(function(data) {
  260. var name = data[1] || data[0].replace(/ /g, "_").toLowerCase();
  261. var theme = {
  262. caption: data[0],
  263. theme: "ace/theme/" + name,
  264. isDark: data[2] == "dark",
  265. name: name
  266. };
  267. exports.themesByName[name] = theme;
  268. return theme;
  269. });
  270. });
  271. ace.define("ace/ext/menu_tools/add_editor_menu_options",["require","exports","module","ace/ext/modelist","ace/ext/themelist"], function(require, exports, module) {
  272. 'use strict';
  273. module.exports.addEditorMenuOptions = function addEditorMenuOptions (editor) {
  274. var modelist = require('../modelist');
  275. var themelist = require('../themelist');
  276. editor.menuOptions = {
  277. setNewLineMode: [{
  278. textContent: "unix",
  279. value: "unix"
  280. }, {
  281. textContent: "windows",
  282. value: "windows"
  283. }, {
  284. textContent: "auto",
  285. value: "auto"
  286. }],
  287. setTheme: [],
  288. setMode: [],
  289. setKeyboardHandler: [{
  290. textContent: "ace",
  291. value: ""
  292. }, {
  293. textContent: "vim",
  294. value: "ace/keyboard/vim"
  295. }, {
  296. textContent: "emacs",
  297. value: "ace/keyboard/emacs"
  298. }, {
  299. textContent: "textarea",
  300. value: "ace/keyboard/textarea"
  301. }, {
  302. textContent: "sublime",
  303. value: "ace/keyboard/sublime"
  304. }]
  305. };
  306. editor.menuOptions.setTheme = themelist.themes.map(function(theme) {
  307. return {
  308. textContent: theme.caption,
  309. value: theme.theme
  310. };
  311. });
  312. editor.menuOptions.setMode = modelist.modes.map(function(mode) {
  313. return {
  314. textContent: mode.name,
  315. value: mode.mode
  316. };
  317. });
  318. };
  319. });
  320. ace.define("ace/ext/menu_tools/get_set_functions",["require","exports","module"], function(require, exports, module) {
  321. 'use strict';
  322. module.exports.getSetFunctions = function getSetFunctions (editor) {
  323. var out = [];
  324. var my = {
  325. 'editor' : editor,
  326. 'session' : editor.session,
  327. 'renderer' : editor.renderer
  328. };
  329. var opts = [];
  330. var skip = [
  331. 'setOption',
  332. 'setUndoManager',
  333. 'setDocument',
  334. 'setValue',
  335. 'setBreakpoints',
  336. 'setScrollTop',
  337. 'setScrollLeft',
  338. 'setSelectionStyle',
  339. 'setWrapLimitRange'
  340. ];
  341. ['renderer', 'session', 'editor'].forEach(function(esra) {
  342. var esr = my[esra];
  343. var clss = esra;
  344. for(var fn in esr) {
  345. if(skip.indexOf(fn) === -1) {
  346. if(/^set/.test(fn) && opts.indexOf(fn) === -1) {
  347. opts.push(fn);
  348. out.push({
  349. 'functionName' : fn,
  350. 'parentObj' : esr,
  351. 'parentName' : clss
  352. });
  353. }
  354. }
  355. }
  356. });
  357. return out;
  358. };
  359. });
  360. ace.define("ace/ext/menu_tools/generate_settings_menu",["require","exports","module","ace/ext/menu_tools/element_generator","ace/ext/menu_tools/add_editor_menu_options","ace/ext/menu_tools/get_set_functions"], function(require, exports, module) {
  361. 'use strict';
  362. var egen = require('./element_generator');
  363. var addEditorMenuOptions = require('./add_editor_menu_options').addEditorMenuOptions;
  364. var getSetFunctions = require('./get_set_functions').getSetFunctions;
  365. module.exports.generateSettingsMenu = function generateSettingsMenu (editor) {
  366. var elements = [];
  367. function cleanupElementsList() {
  368. elements.sort(function(a, b) {
  369. var x = a.getAttribute('contains');
  370. var y = b.getAttribute('contains');
  371. return x.localeCompare(y);
  372. });
  373. }
  374. function wrapElements() {
  375. var topmenu = document.createElement('div');
  376. topmenu.setAttribute('id', 'ace_settingsmenu');
  377. elements.forEach(function(element) {
  378. topmenu.appendChild(element);
  379. });
  380. return topmenu;
  381. }
  382. function createNewEntry(obj, clss, item, val) {
  383. var el;
  384. var div = document.createElement('div');
  385. div.setAttribute('contains', item);
  386. div.setAttribute('class', 'ace_optionsMenuEntry');
  387. div.setAttribute('style', 'clear: both;');
  388. div.appendChild(egen.createLabel(
  389. item.replace(/^set/, '').replace(/([A-Z])/g, ' $1').trim(),
  390. item
  391. ));
  392. if (Array.isArray(val)) {
  393. el = egen.createSelection(item, val, clss);
  394. el.addEventListener('change', function(e) {
  395. try{
  396. editor.menuOptions[e.target.id].forEach(function(x) {
  397. if(x.textContent !== e.target.textContent) {
  398. delete x.selected;
  399. }
  400. });
  401. obj[e.target.id](e.target.value);
  402. } catch (err) {
  403. throw new Error(err);
  404. }
  405. });
  406. } else if(typeof val === 'boolean') {
  407. el = egen.createCheckbox(item, val, clss);
  408. el.addEventListener('change', function(e) {
  409. try{
  410. obj[e.target.id](!!e.target.checked);
  411. } catch (err) {
  412. throw new Error(err);
  413. }
  414. });
  415. } else {
  416. el = egen.createInput(item, val, clss);
  417. el.addEventListener('change', function(e) {
  418. try{
  419. if(e.target.value === 'true') {
  420. obj[e.target.id](true);
  421. } else if(e.target.value === 'false') {
  422. obj[e.target.id](false);
  423. } else {
  424. obj[e.target.id](e.target.value);
  425. }
  426. } catch (err) {
  427. throw new Error(err);
  428. }
  429. });
  430. }
  431. el.style.cssText = 'float:right;';
  432. div.appendChild(el);
  433. return div;
  434. }
  435. function makeDropdown(item, esr, clss, fn) {
  436. var val = editor.menuOptions[item];
  437. var currentVal = esr[fn]();
  438. if (typeof currentVal == 'object')
  439. currentVal = currentVal.$id;
  440. val.forEach(function(valuex) {
  441. if (valuex.value === currentVal)
  442. valuex.selected = 'selected';
  443. });
  444. return createNewEntry(esr, clss, item, val);
  445. }
  446. function handleSet(setObj) {
  447. var item = setObj.functionName;
  448. var esr = setObj.parentObj;
  449. var clss = setObj.parentName;
  450. var val;
  451. var fn = item.replace(/^set/, 'get');
  452. if(editor.menuOptions[item] !== undefined) {
  453. elements.push(makeDropdown(item, esr, clss, fn));
  454. } else if(typeof esr[fn] === 'function') {
  455. try {
  456. val = esr[fn]();
  457. if(typeof val === 'object') {
  458. val = val.$id;
  459. }
  460. elements.push(
  461. createNewEntry(esr, clss, item, val)
  462. );
  463. } catch (e) {
  464. }
  465. }
  466. }
  467. addEditorMenuOptions(editor);
  468. getSetFunctions(editor).forEach(function(setObj) {
  469. handleSet(setObj);
  470. });
  471. cleanupElementsList();
  472. return wrapElements();
  473. };
  474. });
  475. ace.define("ace/ext/menu_tools/overlay_page",["require","exports","module","ace/lib/dom"], function(require, exports, module) {
  476. 'use strict';
  477. var dom = require("../../lib/dom");
  478. var cssText = "#ace_settingsmenu, #kbshortcutmenu {\
  479. background-color: #F7F7F7;\
  480. color: black;\
  481. box-shadow: -5px 4px 5px rgba(126, 126, 126, 0.55);\
  482. padding: 1em 0.5em 2em 1em;\
  483. overflow: auto;\
  484. position: absolute;\
  485. margin: 0;\
  486. bottom: 0;\
  487. right: 0;\
  488. top: 0;\
  489. z-index: 9991;\
  490. cursor: default;\
  491. }\
  492. .ace_dark #ace_settingsmenu, .ace_dark #kbshortcutmenu {\
  493. box-shadow: -20px 10px 25px rgba(126, 126, 126, 0.25);\
  494. background-color: rgba(255, 255, 255, 0.6);\
  495. color: black;\
  496. }\
  497. .ace_optionsMenuEntry:hover {\
  498. background-color: rgba(100, 100, 100, 0.1);\
  499. -webkit-transition: all 0.5s;\
  500. transition: all 0.3s\
  501. }\
  502. .ace_closeButton {\
  503. background: rgba(245, 146, 146, 0.5);\
  504. border: 1px solid #F48A8A;\
  505. border-radius: 50%;\
  506. padding: 7px;\
  507. position: absolute;\
  508. right: -8px;\
  509. top: -8px;\
  510. z-index: 1000;\
  511. }\
  512. .ace_closeButton{\
  513. background: rgba(245, 146, 146, 0.9);\
  514. }\
  515. .ace_optionsMenuKey {\
  516. color: darkslateblue;\
  517. font-weight: bold;\
  518. }\
  519. .ace_optionsMenuCommand {\
  520. color: darkcyan;\
  521. font-weight: normal;\
  522. }";
  523. dom.importCssString(cssText);
  524. module.exports.overlayPage = function overlayPage(editor, contentElement, top, right, bottom, left) {
  525. top = top ? 'top: ' + top + ';' : '';
  526. bottom = bottom ? 'bottom: ' + bottom + ';' : '';
  527. right = right ? 'right: ' + right + ';' : '';
  528. left = left ? 'left: ' + left + ';' : '';
  529. var closer = document.createElement('div');
  530. var contentContainer = document.createElement('div');
  531. function documentEscListener(e) {
  532. if (e.keyCode === 27) {
  533. closer.click();
  534. }
  535. }
  536. closer.style.cssText = 'margin: 0; padding: 0; ' +
  537. 'position: fixed; top:0; bottom:0; left:0; right:0;' +
  538. 'z-index: 9990; ' +
  539. 'background-color: rgba(0, 0, 0, 0.3);';
  540. closer.addEventListener('click', function() {
  541. document.removeEventListener('keydown', documentEscListener);
  542. closer.parentNode.removeChild(closer);
  543. editor.focus();
  544. closer = null;
  545. });
  546. document.addEventListener('keydown', documentEscListener);
  547. contentContainer.style.cssText = top + right + bottom + left;
  548. contentContainer.addEventListener('click', function(e) {
  549. e.stopPropagation();
  550. });
  551. var wrapper = dom.createElement("div");
  552. wrapper.style.position = "relative";
  553. var closeButton = dom.createElement("div");
  554. closeButton.className = "ace_closeButton";
  555. closeButton.addEventListener('click', function() {
  556. closer.click();
  557. });
  558. wrapper.appendChild(closeButton);
  559. contentContainer.appendChild(wrapper);
  560. contentContainer.appendChild(contentElement);
  561. closer.appendChild(contentContainer);
  562. document.body.appendChild(closer);
  563. editor.blur();
  564. };
  565. });
  566. ace.define("ace/ext/settings_menu",["require","exports","module","ace/ext/menu_tools/generate_settings_menu","ace/ext/menu_tools/overlay_page","ace/editor"], function(require, exports, module) {
  567. "use strict";
  568. var generateSettingsMenu = require('./menu_tools/generate_settings_menu').generateSettingsMenu;
  569. var overlayPage = require('./menu_tools/overlay_page').overlayPage;
  570. function showSettingsMenu(editor) {
  571. var sm = document.getElementById('ace_settingsmenu');
  572. if (!sm)
  573. overlayPage(editor, generateSettingsMenu(editor), '0', '0', '0');
  574. }
  575. module.exports.init = function(editor) {
  576. var Editor = require("ace/editor").Editor;
  577. Editor.prototype.showSettingsMenu = function() {
  578. showSettingsMenu(this);
  579. };
  580. };
  581. });
  582. ;
  583. (function() {
  584. ace.require(["ace/ext/settings_menu"], function() {});
  585. })();