ext-settings_menu.js 23 KB

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