This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 978
/
windowCaptionButtons.js
113 lines (100 loc) · 3.38 KB
/
windowCaptionButtons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
const React = require('react')
// Components
const ImmutableComponent = require('../immutableComponent')
// Actions
const appActions = require('../../../../js/actions/appActions')
const windowActions = require('../../../../js/actions/windowActions')
// Utils
const locale = require('../../../../js/l10n')
const {getCurrentWindowId, isMaximized, isFullScreen} = require('../../currentWindow')
const cx = require('../../../../js/lib/classSet')
class WindowCaptionButtons extends ImmutableComponent {
constructor () {
super()
this.onDoubleClick = this.onDoubleClick.bind(this)
this.onMinimizeClick = this.onMinimizeClick.bind(this)
this.onMaximizeClick = this.onMaximizeClick.bind(this)
this.onCloseClick = this.onCloseClick.bind(this)
}
get maximizeTitle () {
return this.props.windowMaximized
? 'windowCaptionButtonRestore'
: 'windowCaptionButtonMaximize'
}
onMinimizeClick (e) {
windowActions.shouldMinimize(getCurrentWindowId())
}
onMaximizeClick (e) {
if (isFullScreen()) {
// If full screen, toggle full screen status and restore window (make smaller)
windowActions.shouldExitFullScreen(getCurrentWindowId())
if (isMaximized()) windowActions.shouldUnmaximize(getCurrentWindowId())
return false
}
return (!isMaximized()) ? windowActions.shouldMaximize(getCurrentWindowId()) : windowActions.shouldUnmaximize(getCurrentWindowId())
}
onCloseClick (e) {
appActions.closeWindow(getCurrentWindowId())
}
onDoubleClick (e) {
if (!e.target.className.includes('navigatorWrapper')) {
return
}
this.onMaximizeClick(e)
}
render () {
const props = { tabIndex: -1 }
return <div className={cx({
fullscreen: this.props.windowMaximized,
windowCaptionButtons: true,
verticallyCenter: this.props.verticallyCenter
})}>
<div className='container'>
<button
{...props}
className={cx({
normalizeButton: true,
fullscreen: this.props.windowMaximized,
captionButton: true,
minimize: true
})}
onClick={this.onMinimizeClick}
title={locale.translation('windowCaptionButtonMinimize')}>
<div className='widget' />
</button>
<button
{...props}
className={cx({
normalizeButton: true,
fullscreen: this.props.windowMaximized,
captionButton: true,
maximize: true
})}
onClick={this.onMaximizeClick}
title={locale.translation(this.maximizeTitle)}>
<div className='widget'>
<div className='widget1' />
<div className='widget2' />
<div className='widget3' />
</div>
</button>
<button
{...props}
className={cx({
normalizeButton: true,
fullscreen: this.props.windowMaximized,
captionButton: true,
close: true
})}
onClick={this.onCloseClick}
title={locale.translation('windowCaptionButtonClose')}>
<div className='widget' />
</button>
</div>
</div>
}
}
module.exports = WindowCaptionButtons