ext-settings_menu.js 24 KB

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