From b4277d16ade70763e907f7279e6d779b69cc6b82 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Sat, 7 Jan 2017 10:48:17 +0100 Subject: [PATCH] Added close tab page Resolves #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 --- app/extensions/brave/locales/en-US/menu.properties | 1 + app/locale.js | 1 + docs/windowActions.md | 13 +++++++++++++ js/actions/windowActions.js | 13 +++++++++++++ js/components/tabPages.js | 11 ++++++----- js/contextMenus.js | 11 ++++++++--- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/app/extensions/brave/locales/en-US/menu.properties b/app/extensions/brave/locales/en-US/menu.properties index 1a333825a81..d21f83ec99d 100644 --- a/app/extensions/brave/locales/en-US/menu.properties +++ b/app/extensions/brave/locales/en-US/menu.properties @@ -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… diff --git a/app/locale.js b/app/locale.js index eca05ddeff9..2c0d8c60e63 100644 --- a/app/locale.js +++ b/app/locale.js @@ -75,6 +75,7 @@ var rendererIdentifiers = function () { 'closeOtherTabs', 'closeTabsToRight', 'closeTabsToLeft', + 'closeTabPage', 'bookmarkPage', 'bookmarkLink', 'openFile', diff --git a/docs/windowActions.md b/docs/windowActions.md index 2bf162d9a31..39d148c8308 100644 --- a/docs/windowActions.md +++ b/docs/windowActions.md @@ -512,6 +512,19 @@ Dispatches a mute/unmute call to all frames in a provided list (used by TabList) +### tabPageClosed(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. diff --git a/js/actions/windowActions.js b/js/actions/windowActions.js index a0cf5a7c84c..14fb3b3e3ab 100644 --- a/js/actions/windowActions.js +++ b/js/actions/windowActions.js @@ -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 + */ + tabPageClosed: 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. diff --git a/js/components/tabPages.js b/js/components/tabPages.js index ebb85c844aa..865d06852cc 100644 --- a/js/components/tabPages.js +++ b/js/components/tabPages.js @@ -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 @@ -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 } @@ -97,7 +97,8 @@ class TabPages extends ImmutableComponent { Array.from(new Array(tabPageCount)).map((x, i) => { return Number.parseInt(root.getPropertyValue('--downloads-bar-height'), 10) } -function tabPageTemplateInit (framePropsList) { +function tabPageTemplateInit (framePropsList, framesList) { return [{ label: locale.translation('unmuteTabs'), click: (item, focusedWindow) => { @@ -87,6 +87,11 @@ function tabPageTemplateInit (framePropsList) { click: (item, focusedWindow) => { windowActions.muteAllAudio(framePropsList, true) } + }, { + label: locale.translation('closeTabPage'), + click: () => { + windowActions.tabPageClosed(framesList, framePropsList) + } }] } @@ -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() }