forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace-element.coffee
145 lines (111 loc) · 5.56 KB
/
workspace-element.coffee
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
{ipcRenderer} = require 'electron'
path = require 'path'
fs = require 'fs-plus'
{CompositeDisposable} = require 'event-kit'
scrollbarStyle = require 'scrollbar-style'
module.exports =
class WorkspaceElement extends HTMLElement
globalTextEditorStyleSheet: null
attachedCallback: ->
@focus()
detachedCallback: ->
@subscriptions.dispose()
initializeContent: ->
@classList.add 'workspace'
@setAttribute 'tabindex', -1
@verticalAxis = document.createElement('atom-workspace-axis')
@verticalAxis.classList.add('vertical')
@horizontalAxis = document.createElement('atom-workspace-axis')
@horizontalAxis.classList.add('horizontal')
@horizontalAxis.appendChild(@verticalAxis)
@appendChild(@horizontalAxis)
observeScrollbarStyle: ->
@subscriptions.add scrollbarStyle.observePreferredScrollbarStyle (style) =>
switch style
when 'legacy'
@classList.remove('scrollbars-visible-when-scrolling')
@classList.add("scrollbars-visible-always")
when 'overlay'
@classList.remove('scrollbars-visible-always')
@classList.add("scrollbars-visible-when-scrolling")
observeTextEditorFontConfig: ->
@updateGlobalTextEditorStyleSheet()
@subscriptions.add @config.onDidChange 'editor.fontSize', @updateGlobalTextEditorStyleSheet.bind(this)
@subscriptions.add @config.onDidChange 'editor.fontFamily', @updateGlobalTextEditorStyleSheet.bind(this)
@subscriptions.add @config.onDidChange 'editor.lineHeight', @updateGlobalTextEditorStyleSheet.bind(this)
updateGlobalTextEditorStyleSheet: ->
fontFamily = @config.get('editor.fontFamily')
# TODO: There is a bug in how some emojis (e.g. ❤️) are rendered on macOS.
# This workaround should be removed once we update to Chromium 51, where the
# problem was fixed.
fontFamily += ', "Apple Color Emoji"' if process.platform is 'darwin'
styleSheetSource = """
atom-text-editor {
font-size: #{@config.get('editor.fontSize')}px;
font-family: #{fontFamily};
line-height: #{@config.get('editor.lineHeight')};
}
"""
@styles.addStyleSheet(styleSheetSource, sourcePath: 'global-text-editor-styles')
@views.performDocumentPoll()
initialize: (@model, {@views, @workspace, @project, @config, @styles}) ->
throw new Error("Must pass a views parameter when initializing WorskpaceElements") unless @views?
throw new Error("Must pass a workspace parameter when initializing WorskpaceElements") unless @workspace?
throw new Error("Must pass a project parameter when initializing WorskpaceElements") unless @project?
throw new Error("Must pass a config parameter when initializing WorskpaceElements") unless @config?
throw new Error("Must pass a styles parameter when initializing WorskpaceElements") unless @styles?
@subscriptions = new CompositeDisposable
@initializeContent()
@observeScrollbarStyle()
@observeTextEditorFontConfig()
@paneContainer = @views.getView(@model.paneContainer)
@verticalAxis.appendChild(@paneContainer)
@addEventListener 'focus', @handleFocus.bind(this)
@addEventListener 'mousewheel', @handleMousewheel.bind(this), true
@panelContainers =
top: @views.getView(@model.panelContainers.top)
left: @views.getView(@model.panelContainers.left)
right: @views.getView(@model.panelContainers.right)
bottom: @views.getView(@model.panelContainers.bottom)
header: @views.getView(@model.panelContainers.header)
footer: @views.getView(@model.panelContainers.footer)
modal: @views.getView(@model.panelContainers.modal)
@horizontalAxis.insertBefore(@panelContainers.left, @verticalAxis)
@horizontalAxis.appendChild(@panelContainers.right)
@verticalAxis.insertBefore(@panelContainers.top, @paneContainer)
@verticalAxis.appendChild(@panelContainers.bottom)
@insertBefore(@panelContainers.header, @horizontalAxis)
@appendChild(@panelContainers.footer)
@appendChild(@panelContainers.modal)
this
getModel: -> @model
handleMousewheel: (event) ->
if event.ctrlKey and @config.get('editor.zoomFontWhenCtrlScrolling') and event.target.matches('atom-text-editor')
if event.wheelDeltaY > 0
@model.increaseFontSize()
else if event.wheelDeltaY < 0
@model.decreaseFontSize()
event.preventDefault()
event.stopPropagation()
handleFocus: (event) ->
@model.getActivePane().activate()
focusPaneViewAbove: -> @paneContainer.focusPaneViewAbove()
focusPaneViewBelow: -> @paneContainer.focusPaneViewBelow()
focusPaneViewOnLeft: -> @paneContainer.focusPaneViewOnLeft()
focusPaneViewOnRight: -> @paneContainer.focusPaneViewOnRight()
moveActiveItemToPaneAbove: (params) -> @paneContainer.moveActiveItemToPaneAbove(params)
moveActiveItemToPaneBelow: (params) -> @paneContainer.moveActiveItemToPaneBelow(params)
moveActiveItemToPaneOnLeft: (params) -> @paneContainer.moveActiveItemToPaneOnLeft(params)
moveActiveItemToPaneOnRight: (params) -> @paneContainer.moveActiveItemToPaneOnRight(params)
runPackageSpecs: ->
if activePath = @workspace.getActivePaneItem()?.getPath?()
[projectPath] = @project.relativizePath(activePath)
else
[projectPath] = @project.getPaths()
if projectPath
specPath = path.join(projectPath, 'spec')
testPath = path.join(projectPath, 'test')
if not fs.existsSync(specPath) and fs.existsSync(testPath)
specPath = testPath
ipcRenderer.send('run-package-specs', specPath)
module.exports = WorkspaceElement = document.registerElement 'atom-workspace', prototype: WorkspaceElement.prototype