By configuring the context menu, an application can register custom menu items in the context menus of the desktop and File Manager. When a user clicks a custom menu item, the application is started to perform the corresponding operation. In this way, application capabilities can be conveniently integrated into the system file operation process. Typical scenarios are as follows:
The following is a complete menu.json configuration file example, including the More menu and New menu.
{
"fileContextMenu": [
{
"abilityName": "EntryAbility",
"menuItem": "$string:compress_menu",
"menuIcon": "$media:compress_icon",
"menuHandler": "compress",
"menuContext": [
{
"menuKind": 0
},
{
"menuKind": 1,
"menuRule": "both",
"fileSupportType": [
".rar",
".zip"
]
}
]
}
],
"newFile": [
{
"menuName": "$string:menu1",
"menuIcon": "icon/menuIcon1.png",
"fileType": ".docx",
"fileContent": "template/demo.docx"
},
{
"menuName": "$string:menu2",
"menuIcon": "icon/menuIcon2.png",
"fileType": ".txt",
"fileContent": "template/demo.txt"
},
{
"menuName": "$string:menu3",
"menuIcon": "icon/menuIcon3.png",
"fileType": ".xlsx",
"fileContent": "template/demo.xlsx"
}
]
} The following figure shows the effect.
