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

Commit

Permalink
Moved store into context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Jun 26, 2017
1 parent d776d63 commit 7178a74
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
13 changes: 5 additions & 8 deletions app/renderer/components/bookmarks/bookmarkToolbarButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ class BookmarkToolbarButton extends React.Component {
this.bookmarkNode.addEventListener('auxclick', this.onAuxClick)
}

get activeFrame () {
return windowStore.getFrame(this.props.activeFrameKey)
}

onAuxClick (e) {
if (e.button === 1) {
this.onClick(e)
Expand Down Expand Up @@ -143,16 +139,16 @@ class BookmarkToolbarButton extends React.Component {
}

openContextMenu (e) {
contextMenus.onSiteDetailContextMenu(this.props.bookmark, this.activeFrame, e)
contextMenus.onSiteDetailContextMenu(this.props.bookmarkKey, this.props.activeFrameKey, e)
}

clickBookmarkItem (e) {
return bookmarkActions.clickBookmarkItem(this.props.bookmarks, this.props.bookmark, this.activeFrame, e)
return bookmarkActions.clickBookmarkItem(this.props.bookmarkKey, this.props.tabId, e)
}

showBookmarkFolderMenu (e) {
windowActions.setBookmarksToolbarSelectedFolderId(this.props.folderId)
contextMenus.onShowBookmarkFolderMenu(this.props.bookmarks, this.props.bookmark, this.activeFrame, e)
contextMenus.onShowBookmarkFolderMenu(this.props.bookmarkKey, e)
}

mergeProps (state, ownProps) {
Expand All @@ -176,8 +172,9 @@ class BookmarkToolbarButton extends React.Component {

// used in other function
props.bookmarkKey = ownProps.bookmarkKey
props.bookmarks = siteUtil.getBookmarks(state.get('sites')) // TODO (nejc) only primitives
props.tabId = activeFrame.get('tabId')
props.contextMenuDetail = !!currentWindow.get('contextMenuDetail')
props.bookmark = bookmark // TODO (nejc) only primitives
props.draggingOverData = draggingOverData // TODO (nejc) only primitives
props.activeFrameKey = activeFrame.get('key')
props.selectedFolderId = currentWindow.getIn(['ui', 'bookmarksToolbar', 'selectedFolderId'])
Expand Down
7 changes: 1 addition & 6 deletions app/renderer/components/bookmarks/bookmarksToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ class BookmarksToolbar extends React.Component {
this.onMoreBookmarksMenu = this.onMoreBookmarksMenu.bind(this)
}

get activeFrame () {
return windowStore.getFrame(this.props.activeFrameKey)
}

onDrop (e) {
e.preventDefault()
const bookmark = dnd.prepareBookmarkDataFromCompatible(e.dataTransfer)
Expand Down Expand Up @@ -127,7 +123,7 @@ class BookmarksToolbar extends React.Component {
}

onMoreBookmarksMenu (e) {
contextMenus.onMoreBookmarksMenu(this.activeFrame, this.props.bookmarks, this.props.hiddenBookmarks, e)
contextMenus.onMoreBookmarksMenu(this.props.activeFrameKey, this.props.hiddenBookmarks, e)
}

onContextMenu (e) {
Expand Down Expand Up @@ -159,7 +155,6 @@ class BookmarksToolbar extends React.Component {
props.activeFrameKey = activeFrame.get('key')
props.title = activeFrame.get('title')
props.location = activeFrame.get('location')
props.bookmarks = siteUtil.getBookmarks(state.get('sites', Immutable.List())) // TODO (nejc) only primitives

return props
}
Expand Down
10 changes: 6 additions & 4 deletions js/actions/bookmarkActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const {SWITCH_TO_NEW_TABS} = require('../constants/settings')
const getSetting = require('../settings').getSetting

const bookmarkActions = {
openBookmarksInFolder: function (allBookmarkItems, folderDetail) {
openBookmarksInFolder: function (folderDetail) {
const allBookmarkItems = siteUtil.getBookmarks(state.get('sites'))
// We have a middle clicked folder
const bookmarks = allBookmarkItems
.filter((bookmark) => (bookmark.get('parentFolderId') || 0) === (folderDetail.get('folderId') || 0) && siteUtil.isBookmark(bookmark))
Expand All @@ -39,7 +40,8 @@ const bookmarkActions = {
* Performs an action based on the passed in event to the bookmark item
* @return true if an action was performed
*/
clickBookmarkItem: function (allBookmarkItems, bookmarkItem, activeFrame, e) {
clickBookmarkItem: function (bookmarkKey, tabId, e) {
const bookmarkItem = appStoreRenderer.state.getIn(['sites', bookmarkKey], Immutable.Map())
const isFolder = siteUtil.isFolder(bookmarkItem)
if (!isFolder) {
if (eventUtil.isForSecondaryAction(e)) {
Expand All @@ -49,12 +51,12 @@ const bookmarkActions = {
active: !!e.shiftKey || getSetting(SWITCH_TO_NEW_TABS)
})
} else {
appActions.loadURLRequested(activeFrame.get('tabId'), bookmarkItem.get('location'))
appActions.loadURLRequested(tabId, bookmarkItem.get('location'))
}
windowActions.setContextMenuDetail()
return true
} else if (eventUtil.isForSecondaryAction(e)) {
this.openBookmarksInFolder(allBookmarkItems, bookmarkItem)
this.openBookmarksInFolder(bookmarkItem)
windowActions.setContextMenuDetail()
return true
}
Expand Down
52 changes: 31 additions & 21 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const urlParse = require('../app/common/urlParse')
const {getCurrentWindow} = require('../app/renderer/currentWindow')
const extensionState = require('../app/common/state/extensionState')
const extensionActions = require('../app/common/actions/extensionActions')
const appStore = require('./stores/appStoreRenderer')
const bookmarkUtil = require('../app/common/lib/bookmarkUtil')
const {makeImmutable} = require('../app/common/state/immutableUtil')

Expand Down Expand Up @@ -245,14 +244,18 @@ function downloadsToolbarTemplateInit (downloadId, downloadItem) {
return menuUtil.sanitizeTemplateItems(template)
}

function siteDetailTemplateInit (siteDetail, activeFrame) {
function siteDetailTemplateInit (site, activeFrame) {
let isHistoryEntry = false
let multipleHistoryEntries = false
let multipleBookmarks = false
let isFolder = false
let isSystemFolder = false
let deleteLabel
let deleteTag
let siteDetail = site
if (typeof site === 'string') {
siteDetail = appStoreRenderer.state.getIn(['sites', site], Immutable.Map())
}

// TODO(bsclifton): pull this out to a method
if (siteUtil.isBookmark(siteDetail) && activeFrame) {
Expand Down Expand Up @@ -311,8 +314,7 @@ function siteDetailTemplateInit (siteDetail, activeFrame) {
CommonMenu.separatorMenuItem)
}
} else {
template.push(openAllInNewTabsMenuItem(appStoreRenderer.state.get('sites'), siteDetail),
CommonMenu.separatorMenuItem)
template.push(openAllInNewTabsMenuItem(siteDetail), CommonMenu.separatorMenuItem)
}

if (!isSystemFolder) {
Expand Down Expand Up @@ -354,7 +356,9 @@ function siteDetailTemplateInit (siteDetail, activeFrame) {
return menuUtil.sanitizeTemplateItems(template)
}

function showBookmarkFolderInit (allBookmarkItems, parentBookmarkFolder, activeFrame) {
function showBookmarkFolderInit (parentBookmarkFolderKey) {
const allBookmarkItems = siteUtil.getBookmarks(appStoreRenderer.state.get('sites', Immutable.List()))
const parentBookmarkFolder = appStoreRenderer.state.getIn(['sites', parentBookmarkFolderKey])
const items = siteUtil.filterSitesRelativeTo(allBookmarkItems, parentBookmarkFolder)
if (items.size === 0) {
return [{
Expand All @@ -369,19 +373,18 @@ function showBookmarkFolderInit (allBookmarkItems, parentBookmarkFolder, activeF
const bookmark = dnd.prepareBookmarkDataFromCompatible(e.dataTransfer)
if (bookmark) {
const bookmarkSiteKey = siteUtil.getSiteKey(bookmark)
const parentBookmarkFolderKey = siteUtil.getSiteKey(parentBookmarkFolder)
appActions.moveSite(bookmarkSiteKey, parentBookmarkFolderKey, false, true)
}
}
}]
}
return bookmarkItemsInit(allBookmarkItems, items, activeFrame)
return bookmarkItemsInit(items, activeFrame)
}

function bookmarkItemsInit (allBookmarkItems, items, activeFrame) {
function bookmarkItemsInit (items, activeFrame) {
const showFavicon = bookmarkUtil.showFavicon()
const itemsList = items.toList()
const template = itemsList.map((site) => {
const template = items.map((siteKey) => {
const site = appStoreRenderer.state.getIn(['sites', siteKey], Immutable.Map())
const isFolder = siteUtil.isFolder(site)
let faIcon
if (showFavicon && !site.get('favicon')) {
Expand All @@ -394,7 +397,7 @@ function bookmarkItemsInit (allBookmarkItems, items, activeFrame) {
icon: showFavicon ? site.get('favicon') : undefined,
faIcon,
contextMenu: function (e) {
onSiteDetailContextMenu(site, activeFrame, e)
onSiteDetailContextMenu(siteKey, activeFrame.get('key'), e)
},
dragEnd: function (e) {
dnd.onDragEnd(dragTypes.BOOKMARK, site, e)
Expand All @@ -417,11 +420,11 @@ function bookmarkItemsInit (allBookmarkItems, items, activeFrame) {
}
},
click: function (e) {
bookmarkActions.clickBookmarkItem(allBookmarkItems, site, activeFrame, e)
bookmarkActions.clickBookmarkItem(siteKey, activeFrame.get('tabId'), e)
}
}
if (isFolder) {
templateItem.submenu = showBookmarkFolderInit(allBookmarkItems, site, activeFrame)
templateItem.submenu = showBookmarkFolderInit(siteKey)
}
return templateItem
}).toJS()
Expand Down Expand Up @@ -831,11 +834,11 @@ const openInNewTabMenuItem = (url, isPrivate, partitionNumber, openerTabId) => {
}
}

const openAllInNewTabsMenuItem = (allSites, folderDetail) => {
const openAllInNewTabsMenuItem = (folderDetail) => {
return {
label: locale.translation('openAllInTabs'),
click: () => {
bookmarkActions.openBookmarksInFolder(allSites, folderDetail)
bookmarkActions.openBookmarksInFolder(folderDetail)
}
}
}
Expand Down Expand Up @@ -1216,7 +1219,7 @@ function mainTemplateInit (nodeProps, frame, tab) {

const extensionContextMenus = isPrivate
? undefined
: extensionState.getContextMenusProperties(appStore.state)
: extensionState.getContextMenusProperties(appStoreRenderer.state)
if (extensionContextMenus !== undefined &&
extensionContextMenus.length) {
template.push(CommonMenu.separatorMenuItem)
Expand Down Expand Up @@ -1398,11 +1401,16 @@ function onFindBarContextMenu (e) {
findBarMenu.popup(getCurrentWindow())
}

function onSiteDetailContextMenu (siteDetail, activeFrame, e) {
function onSiteDetailContextMenu (site, frame, e) {
if (e) {
e.stopPropagation()
}
const menu = Menu.buildFromTemplate(siteDetailTemplateInit(siteDetail, activeFrame))
let activeFrame = frame
if (typeof frame === 'string') {
activeFrame = windowStore.getFrame(frame)
}

const menu = Menu.buildFromTemplate(siteDetailTemplateInit(site, activeFrame))
menu.popup(getCurrentWindow())
}

Expand All @@ -1421,11 +1429,11 @@ function onLedgerContextMenu (location, hostPattern) {
menu.popup(getCurrentWindow())
}

function onShowBookmarkFolderMenu (bookmarks, bookmark, activeFrame, e) {
function onShowBookmarkFolderMenu (bookmarkKey, e) {
if (e && e.stopPropagation) {
e.stopPropagation()
}
const menuTemplate = showBookmarkFolderInit(bookmarks, bookmark, activeFrame)
const menuTemplate = showBookmarkFolderInit(bookmarkKey)
const rectLeft = e.target.getBoundingClientRect()
const rectBottom = e.target.parentNode.getBoundingClientRect()
windowActions.setContextMenuDetail(Immutable.fromJS({
Expand All @@ -1450,7 +1458,9 @@ function onShowAutofillMenu (suggestions, targetRect, frame, boundingClientRect)
}))
}

function onMoreBookmarksMenu (activeFrame, allBookmarkItems, overflowItems, e) {
function onMoreBookmarksMenu (activeFrameKey, overflowItems, e) {
const activeFrame = windowStore.getFrame(activeFrameKey)
const allBookmarkItems = siteUtil.getBookmarks(appStoreRenderer.state.get('sites', Immutable.List()))
const menuTemplate = moreBookmarksTemplateInit(allBookmarkItems, overflowItems, activeFrame)
const rect = e.target.getBoundingClientRect()
windowActions.setContextMenuDetail(Immutable.fromJS({
Expand Down

0 comments on commit 7178a74

Please sign in to comment.