diff --git a/qml/articles/4.Adding_entry_to_the_web_context_menu.md b/qml/articles/4.Adding_entry_to_the_web_context_menu.md index 38dc169..6736b2a 100644 --- a/qml/articles/4.Adding_entry_to_the_web_context_menu.md +++ b/qml/articles/4.Adding_entry_to_the_web_context_menu.md @@ -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 diff --git a/qml/extensions/qml_tutorial_4/main.qml b/qml/extensions/qml_tutorial_4/main.qml index ca76eef..f65385a 100644 --- a/qml/extensions/qml_tutorial_4/main.qml +++ b/qml/extensions/qml_tutorial_4/main.qml @@ -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)) + }) + } + } }