|
3 | 3 | // See detailed docs in https://github.com/phcode-dev/phoenix/wiki/How-To-Write-Extensions-And-Themes |
4 | 4 | // A good place to look for code examples for extensions: https://github.com/phcode-dev/phoenix/tree/main/src/extensions/default |
5 | 5 |
|
| 6 | +// A simple extension that adds an entry in "file menu> hello world" |
6 | 7 | define(function (require, exports, module) { |
7 | 8 | "use strict"; |
8 | 9 |
|
9 | 10 | // Brackets modules |
10 | | - var AppInit = brackets.getModule("utils/AppInit"), |
11 | | - DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"), |
12 | | - Dialogs = brackets.getModule("widgets/Dialogs"); |
| 11 | + const AppInit = brackets.getModule("utils/AppInit"), |
| 12 | + DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"), |
| 13 | + Dialogs = brackets.getModule("widgets/Dialogs"), |
| 14 | + CommandManager = brackets.getModule("command/CommandManager"), |
| 15 | + Menus = brackets.getModule("command/Menus"); |
13 | 16 |
|
14 | | - // Initialize extension once shell is finished initializing. |
15 | | - AppInit.appReady(function () { |
16 | | - console.log("hello world"); |
| 17 | + // Function to run when the menu item is clicked |
| 18 | + function handleHelloWorld() { |
17 | 19 | Dialogs.showModalDialog( |
18 | 20 | DefaultDialogs.DIALOG_ID_INFO, |
19 | | - "hello", "world" |
| 21 | + "hello", |
| 22 | + "world" |
20 | 23 | ); |
21 | | - }); |
| 24 | + } |
22 | 25 |
|
23 | | -}); |
| 26 | + // First, register a command - a UI-less object associating an id to a handler |
| 27 | + var MY_COMMAND_ID = "helloworld.sayhello"; // package-style naming to avoid collisions |
| 28 | + CommandManager.register("Hello World", MY_COMMAND_ID, handleHelloWorld); |
24 | 29 |
|
| 30 | + // Then create a menu item bound to the command |
| 31 | + // The label of the menu item is the name we gave the command (see above) |
| 32 | + var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU); |
| 33 | + menu.addMenuItem(MY_COMMAND_ID); |
| 34 | + |
| 35 | + // We could also add a key binding at the same time: |
| 36 | + //menu.addMenuItem(MY_COMMAND_ID, "Ctrl-Alt-W"); |
| 37 | + // (Note: "Ctrl" is automatically mapped to "Cmd" on Mac) |
| 38 | + |
| 39 | + // Initialize extension once shell is finished initializing. |
| 40 | + AppInit.appReady(function () { |
| 41 | + console.log("hello world"); |
| 42 | + }); |
| 43 | +}); |
0 commit comments