mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-11-04 22:13:13 +00:00
Add tabs in window submenu.
This commit is contained in:
@@ -153,7 +153,9 @@ app.on('activate', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
appMenu.setMenu();
|
appMenu.setMenu({
|
||||||
|
tabs: []
|
||||||
|
});
|
||||||
mainWindow = createMainWindow();
|
mainWindow = createMainWindow();
|
||||||
|
|
||||||
const page = mainWindow.webContents;
|
const page = mainWindow.webContents;
|
||||||
@@ -224,6 +226,10 @@ app.on('ready', () => {
|
|||||||
page.send(listener, ...params);
|
page.send(listener, ...params);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipc.on('update-menu', (event, props) => {
|
||||||
|
appMenu.setMenu(props);
|
||||||
|
});
|
||||||
|
|
||||||
ipc.on('register-server-tab-shortcut', (event, index) => {
|
ipc.on('register-server-tab-shortcut', (event, index) => {
|
||||||
electronLocalshortcut.register(mainWindow, `CommandOrControl+${index}`, () => {
|
electronLocalshortcut.register(mainWindow, `CommandOrControl+${index}`, () => {
|
||||||
// Array index == Shown index - 1
|
// Array index == Shown index - 1
|
||||||
|
|||||||
@@ -133,13 +133,43 @@ class AppMenu {
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
getDarwinTpl() {
|
getWindowSubmenu(tabs, activeTabIndex) {
|
||||||
|
const initialSubmenu = [{
|
||||||
|
role: 'minimize'
|
||||||
|
}, {
|
||||||
|
role: 'close'
|
||||||
|
}];
|
||||||
|
|
||||||
|
if (tabs.length > 0) {
|
||||||
|
initialSubmenu.push({
|
||||||
|
type: 'separator'
|
||||||
|
});
|
||||||
|
for (let i = 0; i < tabs.length; i++) {
|
||||||
|
initialSubmenu.push({
|
||||||
|
label: tabs[i].webview.props.name,
|
||||||
|
accelerator: tabs[i].props.role === 'function' ? '' : `Cmd+${tabs[i].props.index + 1}`,
|
||||||
|
checked: tabs[i].props.index === activeTabIndex,
|
||||||
|
click(item, focusedWindow) {
|
||||||
|
if (focusedWindow) {
|
||||||
|
AppMenu.sendAction('switch-server-tab', tabs[i].props.index);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
type: 'radio'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return initialSubmenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDarwinTpl(props) {
|
||||||
|
const {tabs, activeTabIndex} = props;
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
label: `${app.getName()}`,
|
label: `${app.getName()}`,
|
||||||
submenu: [{
|
submenu: [{
|
||||||
label: 'Zulip Desktop',
|
label: 'Zulip Desktop',
|
||||||
click(item, focusedWindow) {
|
click(item, focusedWindow) {
|
||||||
console.log(this);
|
|
||||||
if (focusedWindow) {
|
if (focusedWindow) {
|
||||||
AppMenu.sendAction('open-about');
|
AppMenu.sendAction('open-about');
|
||||||
}
|
}
|
||||||
@@ -223,16 +253,8 @@ class AppMenu {
|
|||||||
label: 'History',
|
label: 'History',
|
||||||
submenu: this.getHistorySubmenu()
|
submenu: this.getHistorySubmenu()
|
||||||
}, {
|
}, {
|
||||||
role: 'window',
|
label: 'Window',
|
||||||
submenu: [{
|
submenu: this.getWindowSubmenu(tabs, activeTabIndex)
|
||||||
role: 'minimize'
|
|
||||||
}, {
|
|
||||||
role: 'close'
|
|
||||||
}, {
|
|
||||||
type: 'separator'
|
|
||||||
}, {
|
|
||||||
role: 'front'
|
|
||||||
}]
|
|
||||||
}, {
|
}, {
|
||||||
role: 'help',
|
role: 'help',
|
||||||
submenu: this.getHelpSubmenu()
|
submenu: this.getHelpSubmenu()
|
||||||
@@ -343,8 +365,8 @@ class AppMenu {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setMenu() {
|
setMenu(props) {
|
||||||
const tpl = process.platform === 'darwin' ? this.getDarwinTpl() : this.getOtherTpl();
|
const tpl = process.platform === 'darwin' ? this.getDarwinTpl(props) : this.getOtherTpl();
|
||||||
const menu = Menu.buildFromTemplate(tpl);
|
const menu = Menu.buildFromTemplate(tpl);
|
||||||
Menu.setApplicationMenu(menu);
|
Menu.setApplicationMenu(menu);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class ServerManagerView {
|
|||||||
|
|
||||||
initServer(server, index) {
|
initServer(server, index) {
|
||||||
this.tabs.push(new ServerTab({
|
this.tabs.push(new ServerTab({
|
||||||
|
role: 'server',
|
||||||
icon: server.icon,
|
icon: server.icon,
|
||||||
$root: this.$tabsContainer,
|
$root: this.$tabsContainer,
|
||||||
onClick: this.activateTab.bind(this, index),
|
onClick: this.activateTab.bind(this, index),
|
||||||
@@ -113,8 +114,10 @@ class ServerManagerView {
|
|||||||
this.functionalTabs[tabProps.name] = this.tabs.length;
|
this.functionalTabs[tabProps.name] = this.tabs.length;
|
||||||
|
|
||||||
this.tabs.push(new FunctionalTab({
|
this.tabs.push(new FunctionalTab({
|
||||||
|
role: 'function',
|
||||||
materialIcon: tabProps.materialIcon,
|
materialIcon: tabProps.materialIcon,
|
||||||
$root: this.$tabsContainer,
|
$root: this.$tabsContainer,
|
||||||
|
index: this.functionalTabs[tabProps.name],
|
||||||
onClick: this.activateTab.bind(this, this.functionalTabs[tabProps.name]),
|
onClick: this.activateTab.bind(this, this.functionalTabs[tabProps.name]),
|
||||||
onDestroy: this.destroyTab.bind(this, tabProps.name, this.functionalTabs[tabProps.name]),
|
onDestroy: this.destroyTab.bind(this, tabProps.name, this.functionalTabs[tabProps.name]),
|
||||||
webview: new WebView({
|
webview: new WebView({
|
||||||
@@ -175,6 +178,11 @@ class ServerManagerView {
|
|||||||
|
|
||||||
this.activeTabIndex = index;
|
this.activeTabIndex = index;
|
||||||
this.tabs[index].activate();
|
this.tabs[index].activate();
|
||||||
|
|
||||||
|
ipcRenderer.send('update-menu', {
|
||||||
|
tabs: this.tabs,
|
||||||
|
activeTabIndex: this.activeTabIndex
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
destroyTab(name, index) {
|
destroyTab(name, index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user