Skip to content

Commit 655a7bc

Browse files
authored
hello world menu
1 parent 1167934 commit 655a7bc

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

main.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,41 @@
33
// See detailed docs in https://github.com/phcode-dev/phoenix/wiki/How-To-Write-Extensions-And-Themes
44
// A good place to look for code examples for extensions: https://github.com/phcode-dev/phoenix/tree/main/src/extensions/default
55

6+
// A simple extension that adds an entry in "file menu> hello world"
67
define(function (require, exports, module) {
78
"use strict";
89

910
// 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");
1316

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() {
1719
Dialogs.showModalDialog(
1820
DefaultDialogs.DIALOG_ID_INFO,
19-
"hello", "world"
21+
"hello",
22+
"world"
2023
);
21-
});
24+
}
2225

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);
2429

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

Comments
 (0)