Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Add new window option (#1111)
Browse files Browse the repository at this point in the history
* add new window menu option [WIP]

* Add dock menu building function

add option to create new window to top menu bar
  • Loading branch information
akinsho authored and bryphe committed Dec 13, 2017
1 parent e0c84b9 commit 40e54a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path"
import { app, BrowserWindow, ipcMain, Menu, webContents } from "electron"

import * as Log from "./Log"
import { buildMenu } from "./menu"
import { buildDockMenu, buildMenu } from "./menu"
import { makeSingleInstance } from "./ProcessLifecycle"

global["getLogs"] = Log.getAllLogs // tslint:disable-line no-string-literal
Expand Down Expand Up @@ -57,7 +57,7 @@ if (!isDevelopment && !isDebug) {
})
}

function createWindow(commandLineArguments, workingDirectory) {
export function createWindow(commandLineArguments, workingDirectory) {
Log.info(`Creating window with arguments: ${commandLineArguments} and working directory: ${workingDirectory}`)

const webPreferences = {
Expand Down Expand Up @@ -130,6 +130,8 @@ function updateMenu(mainWindow, loadInit) {
if (process.platform === "darwin") {
// all osx windows share the same menu
Menu.setApplicationMenu(menu)
const dockMenu = buildDockMenu(mainWindow, loadInit)
app.dock.setMenu(dockMenu)
} else {
// on windows and linux, set menu per window
mainWindow.setMenu(menu)
Expand Down
22 changes: 22 additions & 0 deletions main/src/menu.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import * as os from "os"

import { app, dialog, Menu, shell } from "electron"
import { createWindow } from "./main"

export const buildDockMenu = (mainWindow, loadInit) => {
const menu = []
menu.push({
label: "New Window",
click() {
createWindow([], process.cwd())
},
})

return Menu.buildFromTemplate(menu)
}

export const buildMenu = (mainWindow, loadInit) => {
const menu = []
Expand Down Expand Up @@ -98,6 +111,15 @@ export const buildMenu = (mainWindow, loadInit) => {
{
type: "separator",
},
{
label: "New Window",
click() {
createWindow([], process.cwd())
},
},
{
type: "separator",
},
{
label: "Save",
click(item, focusedWindow) {
Expand Down

0 comments on commit 40e54a6

Please sign in to comment.