Skip to content

Commit e2c7a8c

Browse files
committed
updated the zoom logic for the zoom in/out menu items so that if you zoom it reflects in the status bar and the config. Also added an actual size / zoom reset menu item for convenience.
1 parent fdb1ef5 commit e2c7a8c

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

browser/main/StatusBar/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import styles from './StatusBar.styl'
55
import ZoomManager from 'browser/main/lib/ZoomManager'
66
import i18n from 'browser/lib/i18n'
77
import context from 'browser/lib/context'
8+
import EventEmitter from 'browser/main/lib/eventEmitter'
89

910
const electron = require('electron')
1011
const { remote, ipcRenderer } = electron
@@ -13,6 +14,26 @@ const { dialog } = remote
1314
const zoomOptions = [0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]
1415

1516
class StatusBar extends React.Component {
17+
18+
constructor (props) {
19+
super(props)
20+
this.handleZoomInMenuItem = this.handleZoomInMenuItem.bind(this)
21+
this.handleZoomOutMenuItem = this.handleZoomOutMenuItem.bind(this)
22+
this.handleZoomResetMenuItem = this.handleZoomResetMenuItem.bind(this)
23+
}
24+
25+
componentDidMount () {
26+
EventEmitter.on('status:zoomin', this.handleZoomInMenuItem)
27+
EventEmitter.on('status:zoomout', this.handleZoomOutMenuItem)
28+
EventEmitter.on('status:zoomreset', this.handleZoomResetMenuItem)
29+
}
30+
31+
componentWillUnmount () {
32+
EventEmitter.off('status:zoomin', this.handleZoomInMenuItem)
33+
EventEmitter.off('status:zoomout', this.handleZoomOutMenuItem)
34+
EventEmitter.off('status:zoomreset', this.handleZoomResetMenuItem)
35+
}
36+
1637
updateApp () {
1738
const index = dialog.showMessageBox(remote.getCurrentWindow(), {
1839
type: 'warning',
@@ -48,6 +69,20 @@ class StatusBar extends React.Component {
4869
})
4970
}
5071

72+
handleZoomInMenuItem () {
73+
const zoomFactor = ZoomManager.getZoom() + 0.1
74+
this.handleZoomMenuItemClick(zoomFactor)
75+
}
76+
77+
handleZoomOutMenuItem () {
78+
const zoomFactor = ZoomManager.getZoom() - 0.1
79+
this.handleZoomMenuItemClick(zoomFactor)
80+
}
81+
82+
handleZoomResetMenuItem () {
83+
this.handleZoomMenuItemClick(1.0)
84+
}
85+
5186
render () {
5287
const { config, status } = this.context
5388

lib/main-menu.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,25 @@ const view = {
310310
type: 'separator'
311311
},
312312
{
313-
role: 'zoomin',
314-
accelerator: macOS ? 'CommandOrControl+Plus' : 'Control+='
313+
label: 'Actual Size',
314+
accelerator: macOS ? 'CommandOrControl+0' : 'Control+0',
315+
click () {
316+
mainWindow.webContents.send('status:zoomreset')
317+
}
318+
},
319+
{
320+
label: 'Zoom In',
321+
accelerator: macOS ? 'CommandOrControl+=' : 'Control+=',
322+
click () {
323+
mainWindow.webContents.send('status:zoomin')
324+
}
315325
},
316326
{
317-
role: 'zoomout'
327+
label: 'Zoom Out',
328+
accelerator: macOS ? 'CmdOrCtrl+-' : 'Control+-',
329+
click () {
330+
mainWindow.webContents.send('status:zoomout')
331+
}
318332
}
319333
]
320334
}

0 commit comments

Comments
 (0)