From 655a7bc4cafe9b4406cea45c3a704ed527d24d7f Mon Sep 17 00:00:00 2001 From: Arun Bose Date: Mon, 13 Mar 2023 22:41:42 +0530 Subject: [PATCH] hello world menu --- main.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index 9501680..01565be 100644 --- a/main.js +++ b/main.js @@ -3,22 +3,41 @@ // See detailed docs in https://github.com/phcode-dev/phoenix/wiki/How-To-Write-Extensions-And-Themes // A good place to look for code examples for extensions: https://github.com/phcode-dev/phoenix/tree/main/src/extensions/default +// A simple extension that adds an entry in "file menu> hello world" define(function (require, exports, module) { "use strict"; // Brackets modules - var AppInit = brackets.getModule("utils/AppInit"), - DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"), - Dialogs = brackets.getModule("widgets/Dialogs"); + const AppInit = brackets.getModule("utils/AppInit"), + DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"), + Dialogs = brackets.getModule("widgets/Dialogs"), + CommandManager = brackets.getModule("command/CommandManager"), + Menus = brackets.getModule("command/Menus"); - // Initialize extension once shell is finished initializing. - AppInit.appReady(function () { - console.log("hello world"); + // Function to run when the menu item is clicked + function handleHelloWorld() { Dialogs.showModalDialog( DefaultDialogs.DIALOG_ID_INFO, - "hello", "world" + "hello", + "world" ); - }); + } -}); + // First, register a command - a UI-less object associating an id to a handler + var MY_COMMAND_ID = "helloworld.sayhello"; // package-style naming to avoid collisions + CommandManager.register("Hello World", MY_COMMAND_ID, handleHelloWorld); + // Then create a menu item bound to the command + // The label of the menu item is the name we gave the command (see above) + var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU); + menu.addMenuItem(MY_COMMAND_ID); + + // We could also add a key binding at the same time: + //menu.addMenuItem(MY_COMMAND_ID, "Ctrl-Alt-W"); + // (Note: "Ctrl" is automatically mapped to "Cmd" on Mac) + + // Initialize extension once shell is finished initializing. + AppInit.appReady(function () { + console.log("hello world"); + }); +});