1

Add submenu example for QML Menu

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2022-03-29 09:12:20 +02:00
parent b153fae27a
commit 5f2a9cbd8b
Signed by: SGOrava
GPG Key ID: 13660A3F1D9F093B
2 changed files with 59 additions and 0 deletions

View File

@ -9,6 +9,8 @@ increment the badge counter when menu entry is selected.
## Create entry in context menu
### Directly add actions to the menu
```qml
populateWebViewMenu: function(menu, webHitTestResult) {
// Create a menu entry
@ -24,6 +26,28 @@ populateWebViewMenu: function(menu, webHitTestResult) {
}
```
### Create a submenu
```qml
populateWebViewMenu: function(menu, webHitTestResult) {
var subMenu = menu.addMenu({
title: 'Example submenu',
ivon: 'falkon'
})
// Create a menu entry
var action = subMenu.addAction({
text: 'Action',
icon: 'falkon'
})
// Bind some function to it
action.triggered.connect(function() {
// Do something
})
}
```
### Argument: menu
Menu to which the action will be added.
The submenu can also be created, might be added later. For now just go

View File

@ -41,6 +41,7 @@ Falkon.PluginInterface {
}
populateWebViewMenu: function(menu, webHitTestResult) {
/* Directly add actions to the menu */
var action_always = menu.addAction({
text: 'Increment counter by one',
icon: 'falkon'
@ -63,6 +64,40 @@ Falkon.PluginInterface {
console.log(i18n('"Tutorial4" clickCount increased to ' + tutorial3Object.clickCount))
})
}
/* Add a separator between these 2 examples */
menu.addSeparator()
/* Create a submenu */
var subMenu = menu.addMenu({
title: 'Example submenu',
icon: 'falkon'
})
/* Copy the actions from before */
var sm_action_always = subMenu.addAction({
text: 'Increment counter by one',
icon: 'falkon'
})
sm_action_always.triggered.connect(function() {
tutorial3Object.clickCount++;
console.log(i18n('"Tutorial4" clickCount increased to ' + tutorial3Object.clickCount))
})
if (webHitTestResult.isImage()) {
var sm_action_image = subMenu.addAction({
text: 'Image, increment by two',
icon: 'falkon'
})
sm_action_image.triggered.connect(function() {
tutorial3Object.clickCount += 2;
console.log(i18n('"Tutorial4" Surprise, this is an image with url: ' + webHitTestResult.imageUrl))
console.log(i18n('"Tutorial4" clickCount increased to ' + tutorial3Object.clickCount))
})
}
}
}