Customising Context Menus
The following context menus can be customised:
file_optionscontrollers:- Map view:
ditamap_viewer_controller - Repository Panel:
repository_panel_controller - Favorites Panel:
collection_tree_controller - File Properties Reference Links:
file_references_links_controller - Repository Search Panel:
repository_search_controller - Subject Scheme Panel:
subject_scheme_tree_controller
- Map view:
folder_optionscontrollers:- Repository Panel:
repository_panel_controller - Favorites Panel:
collection_tree_controller
- Repository Panel:
collection_optionscontrollers:- Favorites Panel:
collection_tree_controller
- Favorites Panel:
map_view_optionscontrollers:- Map view:
ditamap_viewer_controller
- Map view:
baseline_panel_menucontrollers:- Baseline Panel:
baseline_panel
- Baseline Panel:
preset_item_menucontrollers:- Preset Panel:
preset_panel
- Preset Panel:
You can also create your own context menu by defining a new unique id.
Now each context menu has a controller id associated with it. This controller handles the on-event functionality for the various context menu options
Let us take an example to understand
customise_context_menu.js"
const fileOptions = {
id: "file_options",
contextMenuWidget: "repository_panel",
view: {
items: [
{
component: "div",
target: {
key:"displayName",value: "Delete",
viewState: VIEW_STATE.REPLACE
}
},
{
component: "div",
target: {
key:"displayName",value: "Edit",
viewState: VIEW_STATE.REPLACE
}
},
{
"displayName": "Download",
"data": {
"eventid": "downloadFile"
},
"icon": "downloadFromCloud",
"class": "menu-separator",
target: {
key:"displayName",value: "Duplicate",
viewState: VIEW_STATE.REPLACE
}
},
]
},
controller: {
downloadFile(){
const path = this.model.selectedItem.path
this.loader.loadDitaFile(path).then((file) => {
function download_file(name, contents) {
const mime_type = "text/plain";
const blob = new Blob([contents], {type: mime_type});
const dlink = document.createElement('a');
dlink.download = name;
dlink.href = window.URL.createObjectURL(blob);
dlink.onclick = function() {
// revokeObjectURL needs a delay to work properly
const that = this;
setTimeout(function() {
window.URL.revokeObjectURL(that.href);
}, 1500);
};
dlink.click();
dlink.remove();
}
download_file(path,file.xml)
});
}
}
}
Now let us understand what this code is doing.
idis used to identify the context menu we want to customise.contextMenuWidgetis used to define thewidget idor thecomponentwhich calls the context menu and handles theevents.
The rest of it remains the same, whereby view is used to define the items, target identifies where to replace, append or prepend the option and the contextMenuWidget controller handles the on-click events.