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

Context menu upgrades #1504

Merged
merged 1 commit into from
Apr 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions app/extensions/brave/locales/en-US/menu.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
newTab=New Tab
closeTab=Close Tab
bookmarkPage=Bookmark this Page
closeTab=Close
closeOtherTabs=Close other Tabs
bookmarkPage=Bookmark Page
bookmarkLink=Bookmark This Link
openFile=Open File...
openLocation=Open Location...
openSearch=Open Search...
Expand Down Expand Up @@ -49,7 +51,7 @@ minimize=Minimize
zoom=Zoom
selectNextTab=Select Next Tab
selectPreviousTab=Select Previous Tab
moveTabToNewWindow=Move Tab to New Window
moveTabToNewWindow=Move to New Window
mergeAllWindows=Merge All Windows
downloads=Downloads
history=History
Expand All @@ -65,6 +67,7 @@ newWindow=New Window
reopenLastClosedTab=Reopen Last Closed Tab
print=Print...
findOnPage=Find on Page...
find=Find...
checkForUpdates=Check for Updates...
preferences=Preferences...
bookmarksManager=Bookmarks Manager...
Expand All @@ -87,22 +90,25 @@ editFolder=Edit Folder...
editBookmark=Edit Bookmark...
deleteFolder=Delete Folder
deleteBookmark=Delete Bookmark
reloadTab=Reload Tab
unpinTab=Unpin Tab
pinTab=Pin Tab
reloadTab=Reload
unpinTab=Unpin
pinTab=Pin
unmuteTab=Unmute Tab
muteTab=Mute Tab
disableTrackingProtection=Disable tracking protection
disableAdBlock=Disable ad block
openInNewTab=Open in new tab
openInNewTab=Open Link in New Tab
openAllInTabs=Open all in tabs
openInNewPrivateTab=Open in new private tab
openInNewSessionTab=Open in new session tab
copyLinkAddress=Copy link address
openInNewPrivateTab=Open Link in New Private Tab
openInNewWindow=Open Link in New Window
openInNewSessionTab=Open Link in New Session Tab
copyLinkAddress=Copy Link Address
copyEmailAddress=Copy Email Address
saveLinkAs=Save Link As...
saveImage=Save Image...
openImageInNewTab=Open image in new tab
copyImageAddress=Copy image address
viewPageSource=View page source
viewPageSource=View Page Source
addToReadingList=Add to reading list
quit=Quit
about=About
Expand Down
6 changes: 6 additions & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var rendererIdentifiers = function () {
'openImageInNewTab',
'saveImage',
'copyLinkAddress',
'copyEmailAddress',
'saveLinkAs',
'openInNewWindow',
'openInNewSessionTab',
'openInNewPrivateTab',
'openInNewTab',
Expand All @@ -43,7 +46,9 @@ var rendererIdentifiers = function () {
'addFolder',
'newTab',
'closeTab',
'closeOtherTabs',
'bookmarkPage',
'bookmarkLink',
'openFile',
'openLocation',
'openSearch',
Expand Down Expand Up @@ -110,6 +115,7 @@ var rendererIdentifiers = function () {
'reopenLastClosedTab',
'print',
'findOnPage',
'find',
'checkForUpdates',
'preferences',
'bookmarksManager',
Expand Down
202 changes: 122 additions & 80 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const settings = require('./constants/settings')
* Obtains an add bookmark menu item
* @param {object} Detail of the bookmark to initialize with
*/
const addBookmarkMenuItem = (siteDetail, closestDestinationDetail, isParent) => {
const addBookmarkMenuItem = (label, siteDetail, closestDestinationDetail, isParent) => {
return {
label: locale.translation('addBookmark'),
label: locale.translation(label),
click: () => {
if (isParent) {
siteDetail = siteDetail.set('parentFolderId', closestDestinationDetail && (closestDestinationDetail.get('folderId') || closestDestinationDetail.get('parentFolderId')))
Expand Down Expand Up @@ -90,7 +90,7 @@ function tabsToolbarTemplateInit (activeFrame, closestDestinationDetail, isParen
CommonMenu.bookmarksMenuItem(),
CommonMenu.bookmarksToolbarMenuItem(),
CommonMenu.separatorMenuItem,
addBookmarkMenuItem(siteUtil.getDetailFromFrame(activeFrame, siteTags.BOOKMARK), closestDestinationDetail, isParent),
addBookmarkMenuItem('addBookmark', siteUtil.getDetailFromFrame(activeFrame, siteTags.BOOKMARK), closestDestinationDetail, isParent),
addFolderMenuItem(closestDestinationDetail, isParent)
]
}
Expand Down Expand Up @@ -212,7 +212,7 @@ function bookmarkTemplateInit (siteDetail, activeFrame) {
}, CommonMenu.separatorMenuItem)
}

template.push(addBookmarkMenuItem(siteUtil.getDetailFromFrame(activeFrame, siteTags.BOOKMARK), siteDetail, true),
template.push(addBookmarkMenuItem('addBookmark', siteUtil.getDetailFromFrame(activeFrame, siteTags.BOOKMARK), siteDetail, true),
addFolderMenuItem(siteDetail, true))
return template
}
Expand Down Expand Up @@ -315,14 +315,17 @@ function usernameTemplateInit (usernames, origin, action) {
function tabTemplateInit (frameProps) {
const tabKey = frameProps.get('key')
const items = []
items.push({
label: locale.translation('reloadTab'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_FRAME_RELOAD, tabKey)
items.push(
CommonMenu.newTabMenuItem(),
CommonMenu.separatorMenuItem,
{
label: locale.translation('reloadTab'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_FRAME_RELOAD, tabKey)
}
}
}
})
})

if (!frameProps.get('isPrivate')) {
if (frameProps.get('pinnedLocation')) {
Expand All @@ -344,7 +347,17 @@ function tabTemplateInit (frameProps) {
}
}

items.push({
label: locale.translation('moveTabToNewWindow'),
enabled: false,
click: (item, focusedWindow) => {
//TODO: actually move tab to new window
}
})

if (frameProps.get('audioPlaybackActive')) {
items.push(CommonMenu.separatorMenuItem)

if (frameProps.get('audioMuted')) {
items.push({
label: locale.translation('unmuteTab'),
Expand All @@ -354,21 +367,15 @@ function tabTemplateInit (frameProps) {
})
} else {
items.push({
label: locale.translation('Mute Tab'),
label: locale.translation('muteTab'),
click: (item) => {
windowActions.setAudioMuted(frameProps, true)
}
})
}
}

Array.prototype.push.apply(items, [{
label: locale.translation('disableTrackingProtection'),
enabled: false
}, {
label: locale.translation('disableAdBlock'),
enabled: false
}])
items.push(CommonMenu.separatorMenuItem)

if (!frameProps.get('pinnedLocation')) {
items.push({
Expand All @@ -382,29 +389,13 @@ function tabTemplateInit (frameProps) {
})
}

items.push(CommonMenu.separatorMenuItem)

items.push({
label: 'Close other tabs',
label: locale.translation('closeOtherTabs'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_CLOSE_OTHER_FRAMES, tabKey, true, true)
}
}
}, {
label: 'Close tabs to the right',
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_CLOSE_OTHER_FRAMES, tabKey, true, false)
}
}
}, {
label: 'Close tabs to the left',
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_CLOSE_OTHER_FRAMES, tabKey, false, true)
}
}
},
CommonMenu.separatorMenuItem)

Expand Down Expand Up @@ -538,6 +529,15 @@ const openInNewPrivateTabMenuItem = (location) => {
}
}

const openInNewWindowMenuItem = (location, isPrivate, partitionNumber) => {
return {
label: locale.translation('openInNewWindow'),
click: () => {
appActions.newWindow({ location, isPrivate, partitionNumber })
}
}
}

const openInNewSessionTabMenuItem = (location) => {
return {
label: locale.translation('openInNewSessionTab'),
Expand All @@ -561,7 +561,7 @@ const copyLinkLocationMenuItem = (location) => {

const copyEmailAddressMenuItem = (location) => {
return {
label: 'Copy Email Address',
label: locale.translation('copyEmailAddress'),
click: () => {
clipboard.writeText(location.substring('mailto:'.length, location.length))
}
Expand All @@ -575,14 +575,24 @@ function mainTemplateInit (nodeProps, frame) {
if (nodeProps.href) {
template.push(openInNewTabMenuItem(nodeProps.href, frame.get('isPrivate'), frame.get('partitionNumber')),
openInNewPrivateTabMenuItem(nodeProps.href),
openInNewSessionTabMenuItem(nodeProps.href))
openInNewWindowMenuItem(nodeProps.href, frame.get('isPrivate'), frame.get('partitionNumber')),
CommonMenu.separatorMenuItem,
openInNewSessionTabMenuItem(nodeProps.href),
CommonMenu.separatorMenuItem)

if (nodeProps.href.toLowerCase().startsWith('mailto:')) {
template.push(copyEmailAddressMenuItem(nodeProps.href))
} else {
template.push(copyLinkLocationMenuItem(nodeProps.href))
template.push(copyLinkLocationMenuItem(nodeProps.href), {
label: locale.translation('saveLinkAs'),
click: (item, focusedWindow) => {
if (focusedWindow && nodeProps.href) {
focusedWindow.webContents.downloadURL(nodeProps.href)
}
}
},
CommonMenu.separatorMenuItem)
}
template.push(CommonMenu.separatorMenuItem)
}

if (nodeName === 'IMG') {
Expand Down Expand Up @@ -627,55 +637,87 @@ function mainTemplateInit (nodeProps, frame) {
}, 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)
} 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: ..
}
})
} else {
template.push(
{
label: locale.translation('back'),
enabled: frame.get('canGoBack'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_BACK)
}
}
}, {
label: locale.translation('forward'),
enabled: frame.get('canGoForward'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_FORWARD)
}
}
},
CommonMenu.separatorMenuItem, {
label: locale.translation('reloadPage'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_RELOAD)
}
}
},
addBookmarkMenuItem('bookmarkPage', siteUtil.getDetailFromFrame(frame, siteTags.BOOKMARK), false), {
label: locale.translation('find'),
accelerator: 'CmdOrCtrl+F',
click: function (item, focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_SHOW_FINDBAR)
}
}
//CommonMenu.separatorMenuItem
//TODO: bravery menu goes here
)
}

template.push(CommonMenu.separatorMenuItem);

if (!nodeProps.href) {
template.push({
label: locale.translation('viewPageSource'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_VIEW_SOURCE)
}
}
})
}
}

template.push({
label: locale.translation('back'),
enabled: frame.get('canGoBack'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_BACK)
}
}
}, {
label: locale.translation('forward'),
enabled: frame.get('canGoForward'),
label: locale.translation('inspectElement'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_FORWARD)
}
windowActions.inspectElement(nodeProps.offsetX, nodeProps.offsetY)
}
}, {
label: locale.translation('reload'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_RELOAD)
}
}
}, CommonMenu.separatorMenuItem)

template.push(addBookmarkMenuItem(siteUtil.getDetailFromFrame(frame, siteTags.BOOKMARK), false),
{
label: locale.translation('addToReadingList'),
enabled: false
}, CommonMenu.separatorMenuItem,
{
label: locale.translation('viewPageSource'),
click: (item, focusedWindow) => {
if (focusedWindow) {
focusedWindow.webContents.send(messages.SHORTCUT_ACTIVE_FRAME_VIEW_SOURCE)
}
}
}, {
label: locale.translation('inspectElement'),
click: (item, focusedWindow) => {
windowActions.inspectElement(nodeProps.offsetX, nodeProps.offsetY)
}
})
})

if (getSetting(settings.ONE_PASSWORD_ENABLED)) {
template.push(
Expand Down