feat: add BrowserWindow.showAllTabs() for macOS (#38965)

This commit is contained in:
Mikhail Leliakin 2023-07-10 18:43:37 +10:00 committed by GitHub
parent 040e9a027a
commit 56b5c00312
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 31 additions and 2 deletions

View file

@ -1531,6 +1531,10 @@ tabs in the window.
Selects the next tab when native tabs are enabled and there are other Selects the next tab when native tabs are enabled and there are other
tabs in the window. tabs in the window.
#### `win.showAllTabs()` _macOS_
Shows or hides the tab overview when native tabs are enabled.
#### `win.mergeAllWindows()` _macOS_ #### `win.mergeAllWindows()` _macOS_
Merges all windows into one window with multiple tabs when native tabs Merges all windows into one window with multiple tabs when native tabs

View file

@ -14,7 +14,7 @@ See [`Menu`](menu.md) for examples.
* `menuItem` MenuItem * `menuItem` MenuItem
* `browserWindow` [BrowserWindow](browser-window.md) | undefined - This will not be defined if no window is open. * `browserWindow` [BrowserWindow](browser-window.md) | undefined - This will not be defined if no window is open.
* `event` [KeyboardEvent](structures/keyboard-event.md) * `event` [KeyboardEvent](structures/keyboard-event.md)
* `role` string (optional) - Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `toggleSpellChecker`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `showSubstitutions`, `toggleSmartQuotes`, `toggleSmartDashes`, `toggleTextReplacement`, `startSpeaking`, `stopSpeaking`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `shareMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow` or `windowMenu` - Define the action of the menu item, when specified the * `role` string (optional) - Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `toggleSpellChecker`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `showSubstitutions`, `toggleSmartQuotes`, `toggleSmartDashes`, `toggleTextReplacement`, `startSpeaking`, `stopSpeaking`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `shareMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `showAllTabs`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow` or `windowMenu` - Define the action of the menu item, when specified the
`click` property will be ignored. See [roles](#roles). `click` property will be ignored. See [roles](#roles).
* `type` string (optional) - Can be `normal`, `separator`, `submenu`, `checkbox` or * `type` string (optional) - Can be `normal`, `separator`, `submenu`, `checkbox` or
`radio`. `radio`.
@ -111,6 +111,7 @@ The following additional roles are available on _macOS_:
* `toggleTabBar` - Map to the `toggleTabBar` action. * `toggleTabBar` - Map to the `toggleTabBar` action.
* `selectNextTab` - Map to the `selectNextTab` action. * `selectNextTab` - Map to the `selectNextTab` action.
* `selectPreviousTab` - Map to the `selectPreviousTab` action. * `selectPreviousTab` - Map to the `selectPreviousTab` action.
* `showAllTabs` - Map to the `showAllTabs` action.
* `mergeAllWindows` - Map to the `mergeAllWindows` action. * `mergeAllWindows` - Map to the `mergeAllWindows` action.
* `moveTabToNewWindow` - Map to the `moveTabToNewWindow` action. * `moveTabToNewWindow` - Map to the `moveTabToNewWindow` action.
* `window` - The submenu is a "Window" menu. * `window` - The submenu is a "Window" menu.
@ -159,7 +160,7 @@ A `string` indicating the type of the item. Can be `normal`, `separator`, `subme
#### `menuItem.role` #### `menuItem.role`
A `string` (optional) indicating the item's role, if set. Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `toggleSpellChecker`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `startSpeaking`, `stopSpeaking`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `shareMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow` or `windowMenu` A `string` (optional) indicating the item's role, if set. Can be `undo`, `redo`, `cut`, `copy`, `paste`, `pasteAndMatchStyle`, `delete`, `selectAll`, `reload`, `forceReload`, `toggleDevTools`, `resetZoom`, `zoomIn`, `zoomOut`, `toggleSpellChecker`, `togglefullscreen`, `window`, `minimize`, `close`, `help`, `about`, `services`, `hide`, `hideOthers`, `unhide`, `quit`, `startSpeaking`, `stopSpeaking`, `zoom`, `front`, `appMenu`, `fileMenu`, `editMenu`, `viewMenu`, `shareMenu`, `recentDocuments`, `toggleTabBar`, `selectNextTab`, `selectPreviousTab`, `showAllTabs`, `mergeAllWindows`, `clearRecentDocuments`, `moveTabToNewWindow` or `windowMenu`
#### `menuItem.accelerator` #### `menuItem.accelerator`

View file

@ -915,6 +915,10 @@ void BaseWindow::SelectNextTab() {
window_->SelectNextTab(); window_->SelectNextTab();
} }
void BaseWindow::ShowAllTabs() {
window_->ShowAllTabs();
}
void BaseWindow::MergeAllWindows() { void BaseWindow::MergeAllWindows() {
window_->MergeAllWindows(); window_->MergeAllWindows();
} }
@ -1280,6 +1284,7 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
.SetMethod("selectPreviousTab", &BaseWindow::SelectPreviousTab) .SetMethod("selectPreviousTab", &BaseWindow::SelectPreviousTab)
.SetMethod("selectNextTab", &BaseWindow::SelectNextTab) .SetMethod("selectNextTab", &BaseWindow::SelectNextTab)
.SetMethod("showAllTabs", &BaseWindow::ShowAllTabs)
.SetMethod("mergeAllWindows", &BaseWindow::MergeAllWindows) .SetMethod("mergeAllWindows", &BaseWindow::MergeAllWindows)
.SetMethod("moveTabToNewWindow", &BaseWindow::MoveTabToNewWindow) .SetMethod("moveTabToNewWindow", &BaseWindow::MoveTabToNewWindow)
.SetMethod("toggleTabBar", &BaseWindow::ToggleTabBar) .SetMethod("toggleTabBar", &BaseWindow::ToggleTabBar)

View file

@ -210,6 +210,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item); void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item);
void SelectPreviousTab(); void SelectPreviousTab();
void SelectNextTab(); void SelectNextTab();
void ShowAllTabs();
void MergeAllWindows(); void MergeAllWindows();
void MoveTabToNewWindow(); void MoveTabToNewWindow();
void ToggleTabBar(); void ToggleTabBar();

View file

@ -457,6 +457,8 @@ void NativeWindow::SelectPreviousTab() {}
void NativeWindow::SelectNextTab() {} void NativeWindow::SelectNextTab() {}
void NativeWindow::ShowAllTabs() {}
void NativeWindow::MergeAllWindows() {} void NativeWindow::MergeAllWindows() {}
void NativeWindow::MoveTabToNewWindow() {} void NativeWindow::MoveTabToNewWindow() {}

View file

@ -245,6 +245,7 @@ class NativeWindow : public base::SupportsUserData,
// Native Tab API // Native Tab API
virtual void SelectPreviousTab(); virtual void SelectPreviousTab();
virtual void SelectNextTab(); virtual void SelectNextTab();
virtual void ShowAllTabs();
virtual void MergeAllWindows(); virtual void MergeAllWindows();
virtual void MoveTabToNewWindow(); virtual void MoveTabToNewWindow();
virtual void ToggleTabBar(); virtual void ToggleTabBar();

View file

@ -139,6 +139,7 @@ class NativeWindowMac : public NativeWindow,
void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item) override; void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item) override;
void SelectPreviousTab() override; void SelectPreviousTab() override;
void SelectNextTab() override; void SelectNextTab() override;
void ShowAllTabs() override;
void MergeAllWindows() override; void MergeAllWindows() override;
void MoveTabToNewWindow() override; void MoveTabToNewWindow() override;
void ToggleTabBar() override; void ToggleTabBar() override;

View file

@ -1535,6 +1535,10 @@ void NativeWindowMac::SelectNextTab() {
[window_ selectNextTab:nil]; [window_ selectNextTab:nil];
} }
void NativeWindowMac::ShowAllTabs() {
[window_ toggleTabOverview:nil];
}
void NativeWindowMac::MergeAllWindows() { void NativeWindowMac::MergeAllWindows() {
[window_ mergeAllWindows:nil]; [window_ mergeAllWindows:nil];
} }

View file

@ -65,6 +65,7 @@ Role kRolesMap[] = {
{@selector(toggleFullScreenMode:), "togglefullscreen"}, {@selector(toggleFullScreenMode:), "togglefullscreen"},
{@selector(toggleTabBar:), "toggletabbar"}, {@selector(toggleTabBar:), "toggletabbar"},
{@selector(selectNextTab:), "selectnexttab"}, {@selector(selectNextTab:), "selectnexttab"},
{@selector(toggleTabOverview:), "showalltabs"},
{@selector(selectPreviousTab:), "selectprevioustab"}, {@selector(selectPreviousTab:), "selectprevioustab"},
{@selector(mergeAllWindows:), "mergeallwindows"}, {@selector(mergeAllWindows:), "mergeallwindows"},
{@selector(moveTabToNewWindow:), "movetabtonewwindow"}, {@selector(moveTabToNewWindow:), "movetabtonewwindow"},

View file

@ -2072,6 +2072,14 @@ describe('BrowserWindow module', () => {
}); });
}); });
describe('BrowserWindow.showAllTabs()', () => {
it('does not throw', () => {
expect(() => {
w.showAllTabs();
}).to.not.throw();
});
});
describe('BrowserWindow.mergeAllWindows()', () => { describe('BrowserWindow.mergeAllWindows()', () => {
it('does not throw', () => { it('does not throw', () => {
expect(() => { expect(() => {

View file

@ -824,6 +824,7 @@ Menu.buildFromTemplate([
{ role: 'toggleTabBar' }, { role: 'toggleTabBar' },
{ role: 'selectNextTab' }, { role: 'selectNextTab' },
{ role: 'selectPreviousTab' }, { role: 'selectPreviousTab' },
{ role: 'showAllTabs' },
{ role: 'mergeAllWindows' }, { role: 'mergeAllWindows' },
{ role: 'clearRecentDocuments' }, { role: 'clearRecentDocuments' },
{ role: 'moveTabToNewWindow' } { role: 'moveTabToNewWindow' }