ext-settings_menu.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. ace.define("ace/ext/menu_tools/overlay_page",[], function(require, exports, module) {
  2. 'use strict';
  3. var dom = require("../../lib/dom");
  4. var cssText = "#ace_settingsmenu, #kbshortcutmenu {\
  5. background-color: #F7F7F7;\
  6. color: black;\
  7. box-shadow: -5px 4px 5px rgba(126, 126, 126, 0.55);\
  8. padding: 1em 0.5em 2em 1em;\
  9. overflow: auto;\
  10. position: absolute;\
  11. margin: 0;\
  12. bottom: 0;\
  13. right: 0;\
  14. top: 0;\
  15. z-index: 9991;\
  16. cursor: default;\
  17. }\
  18. .ace_dark #ace_settingsmenu, .ace_dark #kbshortcutmenu {\
  19. box-shadow: -20px 10px 25px rgba(126, 126, 126, 0.25);\
  20. background-color: rgba(255, 255, 255, 0.6);\
  21. color: black;\
  22. }\
  23. .ace_optionsMenuEntry:hover {\
  24. background-color: rgba(100, 100, 100, 0.1);\
  25. transition: all 0.3s\
  26. }\
  27. .ace_closeButton {\
  28. background: rgba(245, 146, 146, 0.5);\
  29. border: 1px solid #F48A8A;\
  30. border-radius: 50%;\
  31. padding: 7px;\
  32. position: absolute;\
  33. right: -8px;\
  34. top: -8px;\
  35. z-index: 100000;\
  36. }\
  37. .ace_closeButton{\
  38. background: rgba(245, 146, 146, 0.9);\
  39. }\
  40. .ace_optionsMenuKey {\
  41. color: darkslateblue;\
  42. font-weight: bold;\
  43. }\
  44. .ace_optionsMenuCommand {\
  45. color: darkcyan;\
  46. font-weight: normal;\
  47. }\
  48. .ace_optionsMenuEntry input, .ace_optionsMenuEntry button {\
  49. vertical-align: middle;\
  50. }\
  51. .ace_optionsMenuEntry button[ace_selected_button=true] {\
  52. background: #e7e7e7;\
  53. box-shadow: 1px 0px 2px 0px #adadad inset;\
  54. border-color: #adadad;\
  55. }\
  56. .ace_optionsMenuEntry button {\
  57. background: white;\
  58. border: 1px solid lightgray;\
  59. margin: 0px;\
  60. }\
  61. .ace_optionsMenuEntry button:hover{\
  62. background: #f0f0f0;\
  63. }";
  64. dom.importCssString(cssText);
  65. module.exports.overlayPage = function overlayPage(editor, contentElement, top, right, bottom, left) {
  66. top = top ? 'top: ' + top + ';' : '';
  67. bottom = bottom ? 'bottom: ' + bottom + ';' : '';
  68. right = right ? 'right: ' + right + ';' : '';
  69. left = left ? 'left: ' + left + ';' : '';
  70. var closer = document.createElement('div');
  71. var contentContainer = document.createElement('div');
  72. function documentEscListener(e) {
  73. if (e.keyCode === 27) {
  74. closer.click();
  75. }
  76. }
  77. closer.style.cssText = 'margin: 0; padding: 0; ' +
  78. 'position: fixed; top:0; bottom:0; left:0; right:0;' +
  79. 'z-index: 9990; ' +
  80. 'background-color: rgba(0, 0, 0, 0.3);';
  81. closer.addEventListener('click', function() {
  82. document.removeEventListener('keydown', documentEscListener);
  83. closer.parentNode.removeChild(closer);
  84. editor.focus();
  85. closer = null;
  86. });
  87. document.addEventListener('keydown', documentEscListener);
  88. contentContainer.style.cssText = top + right + bottom + left;
  89. contentContainer.addEventListener('click', function(e) {
  90. e.stopPropagation();
  91. });
  92. var wrapper = dom.createElement("div");
  93. wrapper.style.position = "relative";
  94. var closeButton = dom.createElement("div");
  95. closeButton.className = "ace_closeButton";
  96. closeButton.addEventListener('click', function() {
  97. closer.click();
  98. });
  99. wrapper.appendChild(closeButton);
  100. contentContainer.appendChild(wrapper);
  101. contentContainer.appendChild(contentElement);
  102. closer.appendChild(contentContainer);
  103. document.body.appendChild(closer);
  104. editor.blur();
  105. };
  106. });
  107. ace.define("ace/ext/modelist",[], function(require, exports, module) {
  108. "use strict";
  109. var modes = [];
  110. function getModeForPath(path) {
  111. var mode = modesByName.text;
  112. var fileName = path.split(/[\/\\]/).pop();
  113. for (var i = 0; i < modes.length; i++) {
  114. if (modes[i].supportsFile(fileName)) {
  115. mode = modes[i];
  116. break;
  117. }
  118. }
  119. return mode;
  120. }
  121. var Mode = function(name, caption, extensions) {
  122. this.name = name;
  123. this.caption = caption;
  124. this.mode = "ace/mode/" + name;
  125. this.extensions = extensions;
  126. var re;
  127. if (/\^/.test(extensions)) {
  128. re = extensions.replace(/\|(\^)?/g, function(a, b){
  129. return "$|" + (b ? "^" : "^.*\\.");
  130. }) + "$";
  131. } else {
  132. re = "^.*\\.(" + extensions + ")$";
  133. }
  134. this.extRe = new RegExp(re, "gi");
  135. };
  136. Mode.prototype.supportsFile = function(filename) {
  137. return filename.match(this.extRe);
  138. };
  139. var supportedModes = {
  140. ABAP: ["abap"],
  141. ABC: ["abc"],
  142. ActionScript:["as"],
  143. ADA: ["ada|adb"],
  144. Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],
  145. AsciiDoc: ["asciidoc|adoc"],
  146. ASL: ["dsl|asl"],
  147. Assembly_x86:["asm|a"],
  148. AutoHotKey: ["ahk"],
  149. Apex: ["apex|cls|trigger|tgr"],
  150. BatchFile: ["bat|cmd"],
  151. Bro: ["bro"],
  152. C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp|ino"],
  153. C9Search: ["c9search_results"],
  154. Cirru: ["cirru|cr"],
  155. Clojure: ["clj|cljs"],
  156. Cobol: ["CBL|COB"],
  157. coffee: ["coffee|cf|cson|^Cakefile"],
  158. ColdFusion: ["cfm"],
  159. CSharp: ["cs"],
  160. Csound_Document: ["csd"],
  161. Csound_Orchestra: ["orc"],
  162. Csound_Score: ["sco"],
  163. CSS: ["css"],
  164. Curly: ["curly"],
  165. D: ["d|di"],
  166. Dart: ["dart"],
  167. Diff: ["diff|patch"],
  168. Dockerfile: ["^Dockerfile"],
  169. Dot: ["dot"],
  170. Drools: ["drl"],
  171. Edifact: ["edi"],
  172. Eiffel: ["e|ge"],
  173. EJS: ["ejs"],
  174. Elixir: ["ex|exs"],
  175. Elm: ["elm"],
  176. Erlang: ["erl|hrl"],
  177. Forth: ["frt|fs|ldr|fth|4th"],
  178. Fortran: ["f|f90"],
  179. FSharp: ["fsi|fs|ml|mli|fsx|fsscript"],
  180. FSL: ["fsl"],
  181. FTL: ["ftl"],
  182. Gcode: ["gcode"],
  183. Gherkin: ["feature"],
  184. Gitignore: ["^.gitignore"],
  185. Glsl: ["glsl|frag|vert"],
  186. Gobstones: ["gbs"],
  187. golang: ["go"],
  188. GraphQLSchema: ["gql"],
  189. Groovy: ["groovy"],
  190. HAML: ["haml"],
  191. Handlebars: ["hbs|handlebars|tpl|mustache"],
  192. Haskell: ["hs"],
  193. Haskell_Cabal: ["cabal"],
  194. haXe: ["hx"],
  195. Hjson: ["hjson"],
  196. HTML: ["html|htm|xhtml|vue|we|wpy"],
  197. HTML_Elixir: ["eex|html.eex"],
  198. HTML_Ruby: ["erb|rhtml|html.erb"],
  199. INI: ["ini|conf|cfg|prefs"],
  200. Io: ["io"],
  201. Jack: ["jack"],
  202. Jade: ["jade|pug"],
  203. Java: ["java"],
  204. JavaScript: ["js|jsm|jsx"],
  205. JSON: ["json"],
  206. JSONiq: ["jq"],
  207. JSP: ["jsp"],
  208. JSSM: ["jssm|jssm_state"],
  209. JSX: ["jsx"],
  210. Julia: ["jl"],
  211. Kotlin: ["kt|kts"],
  212. LaTeX: ["tex|latex|ltx|bib"],
  213. LESS: ["less"],
  214. Liquid: ["liquid"],
  215. Lisp: ["lisp"],
  216. LiveScript: ["ls"],
  217. LogiQL: ["logic|lql"],
  218. LSL: ["lsl"],
  219. Lua: ["lua"],
  220. LuaPage: ["lp"],
  221. Lucene: ["lucene"],
  222. Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"],
  223. Markdown: ["md|markdown"],
  224. Mask: ["mask"],
  225. MATLAB: ["matlab"],
  226. Maze: ["mz"],
  227. MEL: ["mel"],
  228. MIXAL: ["mixal"],
  229. MUSHCode: ["mc|mush"],
  230. MySQL: ["mysql"],
  231. Nix: ["nix"],
  232. NSIS: ["nsi|nsh"],
  233. ObjectiveC: ["m|mm"],
  234. OCaml: ["ml|mli"],
  235. Pascal: ["pas|p"],
  236. Perl: ["pl|pm"],
  237. Perl6: ["p6|pl6|pm6"],
  238. pgSQL: ["pgsql"],
  239. PHP_Laravel_blade: ["blade.php"],
  240. PHP: ["php|inc|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp|module"],
  241. Puppet: ["epp|pp"],
  242. Pig: ["pig"],
  243. Powershell: ["ps1"],
  244. Praat: ["praat|praatscript|psc|proc"],
  245. Prolog: ["plg|prolog"],
  246. Properties: ["properties"],
  247. Protobuf: ["proto"],
  248. Python: ["py"],
  249. R: ["r"],
  250. Razor: ["cshtml|asp"],
  251. RDoc: ["Rd"],
  252. Red: ["red|reds"],
  253. RHTML: ["Rhtml"],
  254. RST: ["rst"],
  255. Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],
  256. Rust: ["rs"],
  257. SASS: ["sass"],
  258. SCAD: ["scad"],
  259. Scala: ["scala"],
  260. Scheme: ["scm|sm|rkt|oak|scheme"],
  261. SCSS: ["scss"],
  262. SH: ["sh|bash|^.bashrc"],
  263. SJS: ["sjs"],
  264. Slim: ["slim|skim"],
  265. Smarty: ["smarty|tpl"],
  266. snippets: ["snippets"],
  267. Soy_Template:["soy"],
  268. Space: ["space"],
  269. SQL: ["sql"],
  270. SQLServer: ["sqlserver"],
  271. Stylus: ["styl|stylus"],
  272. SVG: ["svg"],
  273. Swift: ["swift"],
  274. Tcl: ["tcl"],
  275. Terraform: ["tf", "tfvars", "terragrunt"],
  276. Tex: ["tex"],
  277. Text: ["txt"],
  278. Textile: ["textile"],
  279. Toml: ["toml"],
  280. TSX: ["tsx"],
  281. Twig: ["latte|twig|swig"],
  282. Typescript: ["ts|typescript|str"],
  283. Vala: ["vala"],
  284. VBScript: ["vbs|vb"],
  285. Velocity: ["vm"],
  286. Verilog: ["v|vh|sv|svh"],
  287. VHDL: ["vhd|vhdl"],
  288. Visualforce: ["vfp|component|page"],
  289. Wollok: ["wlk|wpgm|wtest"],
  290. XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"],
  291. XQuery: ["xq"],
  292. YAML: ["yaml|yml"],
  293. Django: ["html"]
  294. };
  295. var nameOverrides = {
  296. ObjectiveC: "Objective-C",
  297. CSharp: "C#",
  298. golang: "Go",
  299. C_Cpp: "C and C++",
  300. Csound_Document: "Csound Document",
  301. Csound_Orchestra: "Csound",
  302. Csound_Score: "Csound Score",
  303. coffee: "CoffeeScript",
  304. HTML_Ruby: "HTML (Ruby)",
  305. HTML_Elixir: "HTML (Elixir)",
  306. FTL: "FreeMarker",
  307. PHP_Laravel_blade: "PHP (Blade Template)",
  308. Perl6: "Perl 6",
  309. AutoHotKey: "AutoHotkey / AutoIt"
  310. };
  311. var modesByName = {};
  312. for (var name in supportedModes) {
  313. var data = supportedModes[name];
  314. var displayName = (nameOverrides[name] || name).replace(/_/g, " ");
  315. var filename = name.toLowerCase();
  316. var mode = new Mode(filename, displayName, data[0]);
  317. modesByName[filename] = mode;
  318. modes.push(mode);
  319. }
  320. module.exports = {
  321. getModeForPath: getModeForPath,
  322. modes: modes,
  323. modesByName: modesByName
  324. };
  325. });
  326. ace.define("ace/ext/themelist",[], function(require, exports, module) {
  327. "use strict";
  328. var themeData = [
  329. ["Chrome" ],
  330. ["Clouds" ],
  331. ["Crimson Editor" ],
  332. ["Dawn" ],
  333. ["Dreamweaver" ],
  334. ["Eclipse" ],
  335. ["GitHub" ],
  336. ["IPlastic" ],
  337. ["Solarized Light"],
  338. ["TextMate" ],
  339. ["Tomorrow" ],
  340. ["XCode" ],
  341. ["Kuroir"],
  342. ["KatzenMilch"],
  343. ["SQL Server" ,"sqlserver" , "light"],
  344. ["Ambiance" ,"ambiance" , "dark"],
  345. ["Chaos" ,"chaos" , "dark"],
  346. ["Clouds Midnight" ,"clouds_midnight" , "dark"],
  347. ["Dracula" ,"" , "dark"],
  348. ["Cobalt" ,"cobalt" , "dark"],
  349. ["Gruvbox" ,"gruvbox" , "dark"],
  350. ["Green on Black" ,"gob" , "dark"],
  351. ["idle Fingers" ,"idle_fingers" , "dark"],
  352. ["krTheme" ,"kr_theme" , "dark"],
  353. ["Merbivore" ,"merbivore" , "dark"],
  354. ["Merbivore Soft" ,"merbivore_soft" , "dark"],
  355. ["Mono Industrial" ,"mono_industrial" , "dark"],
  356. ["Monokai" ,"monokai" , "dark"],
  357. ["Pastel on dark" ,"pastel_on_dark" , "dark"],
  358. ["Solarized Dark" ,"solarized_dark" , "dark"],
  359. ["Terminal" ,"terminal" , "dark"],
  360. ["Tomorrow Night" ,"tomorrow_night" , "dark"],
  361. ["Tomorrow Night Blue" ,"tomorrow_night_blue" , "dark"],
  362. ["Tomorrow Night Bright","tomorrow_night_bright" , "dark"],
  363. ["Tomorrow Night 80s" ,"tomorrow_night_eighties" , "dark"],
  364. ["Twilight" ,"twilight" , "dark"],
  365. ["Vibrant Ink" ,"vibrant_ink" , "dark"]
  366. ];
  367. exports.themesByName = {};
  368. exports.themes = themeData.map(function(data) {
  369. var name = data[1] || data[0].replace(/ /g, "_").toLowerCase();
  370. var theme = {
  371. caption: data[0],
  372. theme: "ace/theme/" + name,
  373. isDark: data[2] == "dark",
  374. name: name
  375. };
  376. exports.themesByName[name] = theme;
  377. return theme;
  378. });
  379. });
  380. ace.define("ace/ext/options",[], function(require, exports, module) {
  381. "use strict";
  382. var overlayPage = require('./menu_tools/overlay_page').overlayPage;
  383. var dom = require("../lib/dom");
  384. var oop = require("../lib/oop");
  385. var EventEmitter = require("../lib/event_emitter").EventEmitter;
  386. var buildDom = dom.buildDom;
  387. var modelist = require("./modelist");
  388. var themelist = require("./themelist");
  389. var themes = { Bright: [], Dark: [] };
  390. themelist.themes.forEach(function(x) {
  391. themes[x.isDark ? "Dark" : "Bright"].push({ caption: x.caption, value: x.theme });
  392. });
  393. var modes = modelist.modes.map(function(x){
  394. return { caption: x.caption, value: x.mode };
  395. });
  396. var optionGroups = {
  397. Main: {
  398. Mode: {
  399. path: "mode",
  400. type: "select",
  401. items: modes
  402. },
  403. Theme: {
  404. path: "theme",
  405. type: "select",
  406. items: themes
  407. },
  408. "Keybinding": {
  409. type: "buttonBar",
  410. path: "keyboardHandler",
  411. items: [
  412. { caption : "Ace", value : null },
  413. { caption : "Vim", value : "ace/keyboard/vim" },
  414. { caption : "Emacs", value : "ace/keyboard/emacs" },
  415. { caption : "Sublime", value : "ace/keyboard/sublime" }
  416. ]
  417. },
  418. "Font Size": {
  419. path: "fontSize",
  420. type: "number",
  421. defaultValue: 12,
  422. defaults: [
  423. {caption: "12px", value: 12},
  424. {caption: "24px", value: 24}
  425. ]
  426. },
  427. "Soft Wrap": {
  428. type: "buttonBar",
  429. path: "wrap",
  430. items: [
  431. { caption : "Off", value : "off" },
  432. { caption : "View", value : "free" },
  433. { caption : "margin", value : "printMargin" },
  434. { caption : "40", value : "40" }
  435. ]
  436. },
  437. "Cursor Style": {
  438. path: "cursorStyle",
  439. items: [
  440. { caption : "Ace", value : "ace" },
  441. { caption : "Slim", value : "slim" },
  442. { caption : "Smooth", value : "smooth" },
  443. { caption : "Smooth And Slim", value : "smooth slim" },
  444. { caption : "Wide", value : "wide" }
  445. ]
  446. },
  447. "Folding": {
  448. path: "foldStyle",
  449. items: [
  450. { caption : "Manual", value : "manual" },
  451. { caption : "Mark begin", value : "markbegin" },
  452. { caption : "Mark begin and end", value : "markbeginend" }
  453. ]
  454. },
  455. "Soft Tabs": [{
  456. path: "useSoftTabs"
  457. }, {
  458. path: "tabSize",
  459. type: "number",
  460. values: [2, 3, 4, 8, 16]
  461. }],
  462. "Overscroll": {
  463. type: "buttonBar",
  464. path: "scrollPastEnd",
  465. items: [
  466. { caption : "None", value : 0 },
  467. { caption : "Half", value : 0.5 },
  468. { caption : "Full", value : 1 }
  469. ]
  470. }
  471. },
  472. More: {
  473. "Atomic soft tabs": {
  474. path: "navigateWithinSoftTabs"
  475. },
  476. "Enable Behaviours": {
  477. path: "behavioursEnabled"
  478. },
  479. "Full Line Selection": {
  480. type: "checkbox",
  481. values: "text|line",
  482. path: "selectionStyle"
  483. },
  484. "Highlight Active Line": {
  485. path: "highlightActiveLine"
  486. },
  487. "Show Invisibles": {
  488. path: "showInvisibles"
  489. },
  490. "Show Indent Guides": {
  491. path: "displayIndentGuides"
  492. },
  493. "Persistent Scrollbar": [{
  494. path: "hScrollBarAlwaysVisible"
  495. }, {
  496. path: "vScrollBarAlwaysVisible"
  497. }],
  498. "Animate scrolling": {
  499. path: "animatedScroll"
  500. },
  501. "Show Gutter": {
  502. path: "showGutter"
  503. },
  504. "Show Line Numbers": {
  505. path: "showLineNumbers"
  506. },
  507. "Relative Line Numbers": {
  508. path: "relativeLineNumbers"
  509. },
  510. "Fixed Gutter Width": {
  511. path: "fixedWidthGutter"
  512. },
  513. "Show Print Margin": [{
  514. path: "showPrintMargin"
  515. }, {
  516. type: "number",
  517. path: "printMarginColumn"
  518. }],
  519. "Indented Soft Wrap": {
  520. path: "indentedSoftWrap"
  521. },
  522. "Highlight selected word": {
  523. path: "highlightSelectedWord"
  524. },
  525. "Fade Fold Widgets": {
  526. path: "fadeFoldWidgets"
  527. },
  528. "Use textarea for IME": {
  529. path: "useTextareaForIME"
  530. },
  531. "Merge Undo Deltas": {
  532. path: "mergeUndoDeltas",
  533. items: [
  534. { caption : "Always", value : "always" },
  535. { caption : "Never", value : "false" },
  536. { caption : "Timed", value : "true" }
  537. ]
  538. },
  539. "Elastic Tabstops": {
  540. path: "useElasticTabstops"
  541. },
  542. "Incremental Search": {
  543. path: "useIncrementalSearch"
  544. },
  545. "Read-only": {
  546. path: "readOnly"
  547. },
  548. "Copy without selection": {
  549. path: "copyWithEmptySelection"
  550. },
  551. "Live Autocompletion": {
  552. path: "enableLiveAutocompletion"
  553. }
  554. }
  555. };
  556. var OptionPanel = function(editor, element) {
  557. this.editor = editor;
  558. this.container = element || document.createElement("div");
  559. this.groups = [];
  560. this.options = {};
  561. };
  562. (function() {
  563. oop.implement(this, EventEmitter);
  564. this.add = function(config) {
  565. if (config.Main)
  566. oop.mixin(optionGroups.Main, config.Main);
  567. if (config.More)
  568. oop.mixin(optionGroups.More, config.More);
  569. };
  570. this.render = function() {
  571. this.container.innerHTML = "";
  572. buildDom(["table", {id: "controls"},
  573. this.renderOptionGroup(optionGroups.Main),
  574. ["tr", null, ["td", {colspan: 2},
  575. ["table", {id: "more-controls"},
  576. this.renderOptionGroup(optionGroups.More)
  577. ]
  578. ]]
  579. ], this.container);
  580. };
  581. this.renderOptionGroup = function(group) {
  582. return Object.keys(group).map(function(key, i) {
  583. var item = group[key];
  584. if (!item.position)
  585. item.position = i / 10000;
  586. if (!item.label)
  587. item.label = key;
  588. return item;
  589. }).sort(function(a, b) {
  590. return a.position - b.position;
  591. }).map(function(item) {
  592. return this.renderOption(item.label, item);
  593. }, this);
  594. };
  595. this.renderOptionControl = function(key, option) {
  596. var self = this;
  597. if (Array.isArray(option)) {
  598. return option.map(function(x) {
  599. return self.renderOptionControl(key, x);
  600. });
  601. }
  602. var control;
  603. var value = self.getOption(option);
  604. if (option.values && option.type != "checkbox") {
  605. if (typeof option.values == "string")
  606. option.values = option.values.split("|");
  607. option.items = option.values.map(function(v) {
  608. return { value: v, name: v };
  609. });
  610. }
  611. if (option.type == "buttonBar") {
  612. control = ["div", option.items.map(function(item) {
  613. return ["button", {
  614. value: item.value,
  615. ace_selected_button: value == item.value,
  616. onclick: function() {
  617. self.setOption(option, item.value);
  618. var nodes = this.parentNode.querySelectorAll("[ace_selected_button]");
  619. for (var i = 0; i < nodes.length; i++) {
  620. nodes[i].removeAttribute("ace_selected_button");
  621. }
  622. this.setAttribute("ace_selected_button", true);
  623. }
  624. }, item.desc || item.caption || item.name];
  625. })];
  626. } else if (option.type == "number") {
  627. control = ["input", {type: "number", value: value || option.defaultValue, style:"width:3em", oninput: function() {
  628. self.setOption(option, parseInt(this.value));
  629. }}];
  630. if (option.defaults) {
  631. control = [control, option.defaults.map(function(item) {
  632. return ["button", {onclick: function() {
  633. var input = this.parentNode.firstChild;
  634. input.value = item.value;
  635. input.oninput();
  636. }}, item.caption];
  637. })];
  638. }
  639. } else if (option.items) {
  640. var buildItems = function(items) {
  641. return items.map(function(item) {
  642. return ["option", { value: item.value || item.name }, item.desc || item.caption || item.name];
  643. });
  644. };
  645. var items = Array.isArray(option.items)
  646. ? buildItems(option.items)
  647. : Object.keys(option.items).map(function(key) {
  648. return ["optgroup", {"label": key}, buildItems(option.items[key])];
  649. });
  650. control = ["select", { id: key, value: value, onchange: function() {
  651. self.setOption(option, this.value);
  652. } }, items];
  653. } else {
  654. if (typeof option.values == "string")
  655. option.values = option.values.split("|");
  656. if (option.values) value = value == option.values[1];
  657. control = ["input", { type: "checkbox", id: key, checked: value || null, onchange: function() {
  658. var value = this.checked;
  659. if (option.values) value = option.values[value ? 1 : 0];
  660. self.setOption(option, value);
  661. }}];
  662. if (option.type == "checkedNumber") {
  663. control = [control, []];
  664. }
  665. }
  666. return control;
  667. };
  668. this.renderOption = function(key, option) {
  669. if (option.path && !option.onchange && !this.editor.$options[option.path])
  670. return;
  671. this.options[option.path] = option;
  672. var safeKey = "-" + option.path;
  673. var control = this.renderOptionControl(safeKey, option);
  674. return ["tr", {class: "ace_optionsMenuEntry"}, ["td",
  675. ["label", {for: safeKey}, key]
  676. ], ["td", control]];
  677. };
  678. this.setOption = function(option, value) {
  679. if (typeof option == "string")
  680. option = this.options[option];
  681. if (value == "false") value = false;
  682. if (value == "true") value = true;
  683. if (value == "null") value = null;
  684. if (value == "undefined") value = undefined;
  685. if (typeof value == "string" && parseFloat(value).toString() == value)
  686. value = parseFloat(value);
  687. if (option.onchange)
  688. option.onchange(value);
  689. else if (option.path)
  690. this.editor.setOption(option.path, value);
  691. this._signal("setOption", {name: option.path, value: value});
  692. };
  693. this.getOption = function(option) {
  694. if (option.getValue)
  695. return option.getValue();
  696. return this.editor.getOption(option.path);
  697. };
  698. }).call(OptionPanel.prototype);
  699. exports.OptionPanel = OptionPanel;
  700. });
  701. ace.define("ace/ext/settings_menu",[], function(require, exports, module) {
  702. "use strict";
  703. var OptionPanel = require("ace/ext/options").OptionPanel;
  704. var overlayPage = require('./menu_tools/overlay_page').overlayPage;
  705. function showSettingsMenu(editor) {
  706. if (!document.getElementById('ace_settingsmenu')) {
  707. var options = new OptionPanel(editor);
  708. options.render();
  709. options.container.id = "ace_settingsmenu";
  710. overlayPage(editor, options.container, '0', '0', '0');
  711. options.container.querySelector("select,input,button,checkbox").focus();
  712. }
  713. }
  714. module.exports.init = function(editor) {
  715. var Editor = require("ace/editor").Editor;
  716. Editor.prototype.showSettingsMenu = function() {
  717. showSettingsMenu(this);
  718. };
  719. };
  720. });
  721. (function() {
  722. ace.require(["ace/ext/settings_menu"], function(m) {
  723. if (typeof module == "object" && typeof exports == "object" && module) {
  724. module.exports = m;
  725. }
  726. });
  727. })();