3131 * PreferencesManager.on("change", AllPreferences.EMMET, preferenceChanged);
3232 preferenceChanged();
3333 * ```
34+ * NB: JSDOC/Comments marked with * are required for adding the option to Menu
3435 */
3536
36- define ( function ( require , exports , module ) {
37+ define ( function ( require , exports , module ) {
3738 const PreferencesManager = require ( "preferences/PreferencesManager" ) ;
3839 const Strings = require ( "strings" ) ;
40+ const Menus = require ( "command/Menus" ) ;
41+ const AppInit = require ( "utils/AppInit" ) ;
42+ const CommandManager = require ( "command/CommandManager" ) ;
43+ const Commands = require ( "command/Commands" ) ;
44+
45+ // * list of all the commands
46+ const EMMET_COMMAND_ID = "edit.emmet" ;
47+ const EMMET_COMMAND_REGISTER = CommandManager . register ( Strings . CMD_TOGGLE_EMMET , EMMET_COMMAND_ID , toggleEmmet ) ;
48+
49+
3950
4051 // list of all the preferences
4152 const PREFERENCES_LIST = {
4253 EMMET : "emmet"
4354 } ;
4455
56+
57+ // define Emmet in preferences file
4558 PreferencesManager . definePreference ( PREFERENCES_LIST . EMMET , "boolean" , true , {
4659 description : Strings . DESCRIPTION_EMMET
4760 } ) ;
4861
62+
63+ // * emmet helper function to toggle emmet preferences
64+ function toggleEmmet ( ) {
65+ PreferencesManager . set ( PREFERENCES_LIST . EMMET , ! PreferencesManager . get ( PREFERENCES_LIST . EMMET ) ) ;
66+ EMMET_COMMAND_REGISTER . setChecked ( PreferencesManager . get ( PREFERENCES_LIST . EMMET ) ) ;
67+ }
68+
69+
70+ AppInit . appReady ( function ( ) {
71+ // * Register the command and add it to Menu bar
72+ EMMET_COMMAND_REGISTER . setChecked ( PreferencesManager . get ( PREFERENCES_LIST . EMMET ) ) ;
73+ var menu = Menus . getMenu ( Menus . AppMenuBar . EDIT_MENU ) ;
74+
75+ // * a slight 10ms delay is added because the beautify command is not registered until then
76+ setTimeout ( function ( ) {
77+ menu . addMenuItem ( EMMET_COMMAND_ID , "" , Menus . AFTER , Commands . EDIT_BEAUTIFY_CODE_ON_SAVE ) ;
78+ } , 10 ) ;
79+
80+ } ) ;
81+
4982 module . exports = PREFERENCES_LIST ;
50- } ) ;
83+ } ) ;
0 commit comments