keybinding_menu.js 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2013 Matthew Christopher Kastor-Inare III, Atropa Inc. Intl
  5. * All rights reserved.
  6. *
  7. * Contributed to Ajax.org under the BSD license.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * * Neither the name of Ajax.org B.V. nor the
  17. * names of its contributors may be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  27. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * ***** END LICENSE BLOCK ***** */
  32. /*jslint indent: 4, maxerr: 50, white: true, browser: true, vars: true*/
  33. /*global define, require */
  34. /**
  35. * Show Keyboard Shortcuts
  36. * @fileOverview Show Keyboard Shortcuts <br />
  37. * Generates a menu which displays the keyboard shortcuts.
  38. * @author <a href="mailto:matthewkastor@gmail.com">
  39. * Matthew Christopher Kastor-Inare III </a><br />
  40. * ☭ Hial Atropa!! ☭
  41. */
  42. define(function(require, exports, module) {
  43. "use strict";
  44. var Editor = require("ace/editor").Editor;
  45. /**
  46. * Generates a menu which displays the keyboard shortcuts.
  47. * @author <a href="mailto:matthewkastor@gmail.com">
  48. * Matthew Christopher Kastor-Inare III </a><br />
  49. * ☭ Hial Atropa!! ☭
  50. * @param {ace.Editor} editor An instance of the ace editor.
  51. */
  52. function showKeyboardShortcuts (editor) {
  53. // make sure the menu isn't open already.
  54. if(!document.getElementById('kbshortcutmenu')) {
  55. var overlayPage = require('./menu_tools/overlay_page').overlayPage;
  56. var getEditorKeybordShortcuts = require('./menu_tools/get_editor_keyboard_shortcuts').getEditorKeybordShortcuts;
  57. var kb = getEditorKeybordShortcuts(editor);
  58. var el = document.createElement('div');
  59. var commands = kb.reduce(function(previous, current) {
  60. return previous + '<div class="ace_optionsMenuEntry"><span class="ace_optionsMenuCommand">'
  61. + current.command + '</span> : '
  62. + '<span class="ace_optionsMenuKey">' + current.key + '</span></div>';
  63. }, '');
  64. el.id = 'kbshortcutmenu';
  65. el.innerHTML = '<h1>Keyboard Shortcuts</h1>' + commands + '</div>';
  66. overlayPage(editor, el, '0', '0', '0', null);
  67. }
  68. };
  69. module.exports.init = function(editor) {
  70. Editor.prototype.showKeyboardShortcuts = function() {
  71. showKeyboardShortcuts(this);
  72. };
  73. editor.commands.addCommands([{
  74. name: "showKeyboardShortcuts",
  75. bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"},
  76. exec: function(editor, line) {
  77. editor.showKeyboardShortcuts();
  78. }
  79. }]);
  80. };
  81. });