Skip to content

Commit

Permalink
Added close tab page
Browse files Browse the repository at this point in the history
Resolves brave#5489

Auditors: @bbondy @bsclifton

Test Plan:
- open two tab pages
- right click on one and click close tab page
- all tabs in tab pages should be closed
  • Loading branch information
NejcZdovc committed Jan 7, 2017
1 parent 361e09b commit 292c3de
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ openLocation=Open Location…
openSearch=Search for "{{selectedVariable}}"
importFrom=Import from…
closeWindow=Close Window
closeTabPage=Close tab page
savePageAs=Save Page as…
spreadTheWord=Spread the Word About Brave…
share=Share…
Expand Down
1 change: 1 addition & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var rendererIdentifiers = function () {
'closeOtherTabs',
'closeTabsToRight',
'closeTabsToLeft',
'closeTabPage',
'bookmarkPage',
'bookmarkLink',
'openFile',
Expand Down
13 changes: 13 additions & 0 deletions docs/windowActions.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,19 @@ Dispatches a mute/unmute call to all frames in a provided list (used by TabList)



### closeTabPage(framesList, framePropsList)

Dispatches a close call to all frames in tab page
The provided frame will be closed.

**Parameters**

**framesList**: `Object`, List of frames

**framePropsList**: `Object`, List of frame properties to consider



### muteAllAudioExcept(frameToSkip)

Dispatches a mute call to all frames except the one provided.
Expand Down
13 changes: 13 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,19 @@ const windowActions = {
})
},

/**
* Dispatches a close call to all frames in tab page
* The provided frame will be closed.
*
* @param {Object} framesList - List of frames
* @param {Object} framePropsList - List of frame properties to consider
*/
closeTabPage: function (framesList, framePropsList) {
framePropsList.forEach((frameProps) => {
this.closeFrame(framesList, frameProps)
})
},

/**
* Dispatches a mute call to all frames except the one provided.
* The provided frame will have its audio unmuted.
Expand Down
11 changes: 6 additions & 5 deletions js/components/tabPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class TabPage extends ImmutableComponent {
}

onDrop (e) {
if (this.props.frames.size === 0) {
if (this.props.tabPageFrames.size === 0) {
return
}
const moveToFrame = this.props.frames.get(0)
const moveToFrame = this.props.tabPageFrames.get(0)
const sourceDragData = dndData.getDragData(e.dataTransfer, dragTypes.TAB)
const sourceDragFromPageIndex = this.props.sourceDragFromPageIndex
// This must be executed async because the state change that this causes
Expand All @@ -63,7 +63,7 @@ class TabPage extends ImmutableComponent {
}

render () {
const audioPlaybackActive = this.props.frames.find((frame) =>
const audioPlaybackActive = this.props.tabPageFrames.find((frame) =>
frame.get('audioPlaybackActive') && !frame.get('audioMuted'))
return <span data-tab-page={this.props.index}
onDragOver={this.onDragOver.bind(this)}
Expand All @@ -74,7 +74,7 @@ class TabPage extends ImmutableComponent {
tabPage: true,
audioPlaybackActive,
active: this.props.active})}
onContextMenu={onTabPageContextMenu.bind(this, this.props.frames)}
onContextMenu={onTabPageContextMenu.bind(this, this.props.tabPageFrames, this.props.frames)}
onClick={windowActions.setTabPageIndex.bind(this, this.props.index)
} />
}
Expand All @@ -97,7 +97,8 @@ class TabPages extends ImmutableComponent {
Array.from(new Array(tabPageCount)).map((x, i) =>
<TabPage
key={`tabPage-${i}`}
frames={this.props.frames.slice(i * this.props.tabsPerTabPage, i * this.props.tabsPerTabPage + this.props.tabsPerTabPage)}
tabPageFrames={this.props.frames.slice(i * this.props.tabsPerTabPage, i * this.props.tabsPerTabPage + this.props.tabsPerTabPage)}
frames={this.props.frames}
previewTabPage={this.props.previewTabPage}
index={i}
sourceDragFromPageIndex={sourceDragFromPageIndex}
Expand Down
11 changes: 8 additions & 3 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const getDownloadsBarHeight = () => {
return Number.parseInt(root.getPropertyValue('--downloads-bar-height'), 10)
}

function tabPageTemplateInit (framePropsList) {
function tabPageTemplateInit (framePropsList, framesList) {
return [{
label: locale.translation('unmuteTabs'),
click: (item, focusedWindow) => {
Expand All @@ -87,6 +87,11 @@ function tabPageTemplateInit (framePropsList) {
click: (item, focusedWindow) => {
windowActions.muteAllAudio(framePropsList, true)
}
}, {
label: locale.translation('closeTabPage'),
click: () => {
windowActions.closeTabPage(framesList, framePropsList)
}
}]
}

Expand Down Expand Up @@ -1288,9 +1293,9 @@ function onDownloadsToolbarContextMenu (downloadId, downloadItem, e) {
downloadsToolbarMenu.destroy()
}

function onTabPageContextMenu (framePropsList, e) {
function onTabPageContextMenu (framePropsList, framesList, e) {
e.stopPropagation()
const tabPageMenu = Menu.buildFromTemplate(tabPageTemplateInit(framePropsList))
const tabPageMenu = Menu.buildFromTemplate(tabPageTemplateInit(framePropsList, framesList))
tabPageMenu.popup(currentWindow)
tabPageMenu.destroy()
}
Expand Down

0 comments on commit 292c3de

Please sign in to comment.