Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1672 from bsclifton/context-menu-upgrade
Browse files Browse the repository at this point in the history
See #1253
  • Loading branch information
bbondy committed May 12, 2016
2 parents 2d79090 + 1a274fb commit ce36253
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/extensions/brave/locales/en-US/menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bookmarkPage=Bookmark Page
bookmarkLink=Bookmark This Link
openFile=Open File...
openLocation=Open Location...
openSearch=Open Search...
openSearch=Search for "{{selectedVariable}}"
importFrom=Import from...
closeWindow=Close Window
savePageAs=Save Page as...
Expand Down
50 changes: 22 additions & 28 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,18 @@ const copyEmailAddressMenuItem = (location) => {
}
}

const searchSelectionMenuItem = (location) => {
return {
label: locale.translation('openSearch').replace(/{{\s*selectedVariable\s*}}/, location),
click: (item, focusedWindow) => {
if (focusedWindow && location) {
let searchUrl = windowStore.getState().getIn(['searchDetail', 'searchURL']).replace('{searchTerms}', encodeURIComponent(location))
windowActions.newFrame({ location: searchUrl }, true)
}
}
}
}

function mainTemplateInit (nodeProps, frame) {
const template = []
const nodeName = nodeProps.name
Expand Down Expand Up @@ -660,25 +672,22 @@ function mainTemplateInit (nodeProps, frame) {
focusedWindow.webContents.downloadURL(nodeProps.src)
}
}
})
template.push({
}, {
label: locale.translation('openImageInNewTab'),
click: (item, focusedWindow) => {
if (focusedWindow && nodeProps.src) {
// TODO: open this in the next tab instead of last tab
focusedWindow.webContents.send(messages.SHORTCUT_NEW_FRAME, nodeProps.src)
}
}
})
template.push({
}, {
label: locale.translation('copyImageAddress'),
click: (item, focusedWindow) => {
if (focusedWindow && nodeProps.src) {
clipboard.writeText(nodeProps.src)
}
}
})
template.push(CommonMenu.separatorMenuItem)
}, CommonMenu.separatorMenuItem)
}

if (nodeName === 'TEXTAREA' || nodeName === 'INPUT' || nodeProps.isContentEditable) {
Expand All @@ -694,33 +703,18 @@ function mainTemplateInit (nodeProps, frame) {
role: 'redo'
}, CommonMenu.separatorMenuItem, ...editableItems, CommonMenu.separatorMenuItem)
} else if (nodeProps.hasSelection) {
template.push(
// {
// label: locale.translation('openSearch'),
// enabled: false,
// click: (item, focusedWindow) => {
// // TODO: ..
// }
// },
{
label: locale.translation('copy'),
accelerator: 'CmdOrCtrl+C',
role: 'copy'
}, CommonMenu.separatorMenuItem)
template.push(searchSelectionMenuItem(nodeProps.selection), {
label: locale.translation('copy'),
accelerator: 'CmdOrCtrl+C',
role: 'copy'
}, CommonMenu.separatorMenuItem)
} else {
if (nodeProps.href) {
template.push(addBookmarkMenuItem('bookmarkLink', {
location: nodeProps.href,
tags: [siteTags.BOOKMARK]
}, false)
// ,{
// label: locale.translation('openSearch'),
// enabled: false,
// click: (item, focusedWindow) => {
// // TODO: ..
// }
// }
)
}, false),
searchSelectionMenuItem(nodeProps.href))
} else {
template.push(
{
Expand Down

0 comments on commit ce36253

Please sign in to comment.