Skip to content
This repository was archived by the owner on Oct 5, 2022. It is now read-only.

Commit 9cf614c

Browse files
committed
Status bar tile
1 parent b9cfddb commit 9cf614c

File tree

11 files changed

+281
-3
lines changed

11 files changed

+281
-3
lines changed

lib/ide-haskell.js

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/output-panel/index.js

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/plugin-manager.js

+29-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/status-bar/index.js

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
"versions": {
3232
"1.0.0": "consumeLinter"
3333
}
34+
},
35+
"status-bar": {
36+
"versions": {
37+
"^1.0.0": "consumeStatusBar"
38+
}
39+
},
40+
"ide-haskell-upi-plugin": {
41+
"versions": {
42+
"^0.3.0": "consumeUpi3"
43+
}
3444
}
3545
},
3646
"dependencies": {

resources/haskell.svg

+63
Loading

src/ide-haskell.ts

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {PluginManager, IState} from './plugin-manager'
33
import {prettifyFile} from './prettify'
44
import {MAIN_MENU_LABEL} from './utils'
55
import {ILinterRegistry} from './linter-support'
6+
import {IStatusBar} from './status-bar'
67
import * as UPI from './upi-2'
78
import * as UPI3 from './upi-3'
89

@@ -149,3 +150,13 @@ export function consumeLinter (indieRegistry: ILinterRegistry): Disposable | und
149150
pluginManager.setLinter(linter)
150151
return linter
151152
}
153+
154+
export function consumeStatusBar (statusBar: IStatusBar): Disposable | undefined {
155+
if (!(disposables && pluginManager)) { return }
156+
pluginManager.setStatusBar(statusBar)
157+
return new Disposable(() => {
158+
if (pluginManager) {
159+
pluginManager.removeStatusBar()
160+
}
161+
})
162+
}

src/output-panel/index.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ export class OutputPanel {
178178
return this.emitter.on('did-change-icon', callback)
179179
}
180180

181+
public getStatus (): IStatus {
182+
return this.currentStatus
183+
}
184+
181185
public addPanelControl<T> ({element, opts}: TControlDefinition<T>) {
182186
if (typeof element === 'string') {
183187
const {events, classes, style, attrs} = (opts as IControlOpts)

src/plugin-manager.ts

+33
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {EditorControl, TTextBufferCallback} from './editor-control'
66
import {LinterSupport, ILinter} from './linter-support'
77
import {TooltipRegistry} from './tooltip-registry'
88
import {CheckResultsProvider} from './check-results-provider'
9+
import {IStatusBar, ITile, StatusBarView} from './status-bar'
910

1011
export {IParamState, IOutputViewState}
1112

@@ -37,6 +38,9 @@ export class PluginManager {
3738
private controllers: ECMap<EditorControl>
3839
private controllerClasses: Set<{map?: ECMap<IEditorController>, factory: IEditorControllerFactory}>
3940
private editorDispMap: WeakMap<TextEditor, CompositeDisposable>
41+
private statusBarTile?: ITile
42+
private statusBarView?: StatusBarView
43+
private statusBarDisp?: Disposable
4044
constructor (state: IState) {
4145
this.disposables = new CompositeDisposable()
4246
this.emitter = new Emitter()
@@ -67,6 +71,7 @@ export class PluginManager {
6771
this.deleteEditorControllers()
6872
this.outputPanel.reallyDestroy()
6973
this.configParamManager.destroy()
74+
this.removeStatusBar()
7075
if (this.linterSupport) {
7176
this.linterSupport.destroy()
7277
this.linterSupport = undefined
@@ -140,6 +145,34 @@ export class PluginManager {
140145
this.controllerClasses.add({map, factory})
141146
}
142147

148+
public setStatusBar (sb: IStatusBar) {
149+
this.statusBarView = new StatusBarView(this.outputPanel)
150+
this.statusBarTile = sb.addRightTile({
151+
item: this.statusBarView.element,
152+
priority: 100
153+
})
154+
this.statusBarDisp = this.outputPanel.onDidChangeIcon(() => {
155+
if (this.statusBarView) {
156+
this.statusBarView.setStatus(this.outputPanel.getStatus())
157+
}
158+
})
159+
}
160+
161+
public removeStatusBar () {
162+
if (this.statusBarTile) {
163+
this.statusBarTile.destroy()
164+
this.statusBarTile = undefined
165+
}
166+
if (this.statusBarView) {
167+
this.statusBarView.destroy()
168+
this.statusBarView = undefined
169+
}
170+
if (this.statusBarDisp) {
171+
this.statusBarDisp.dispose()
172+
this.statusBarDisp = undefined
173+
}
174+
}
175+
143176
private controllerOnGrammar (editor: TextEditor, grammar: Grammar) {
144177
if (grammar.scopeName.match(/haskell$/)) {
145178
this.addController(editor)

src/status-bar/index.tsx

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as etch from 'etch'
2+
import {IStatus, OutputPanel} from '../output-panel'
3+
4+
export interface ITile {
5+
getPriority (): number
6+
getItem (): Object
7+
destroy (): void
8+
}
9+
10+
export interface IStatusBar {
11+
addLeftTile (params: {item: Object, priority: number}): ITile
12+
addRightTile (params: {item: Object, priority: number}): ITile
13+
}
14+
15+
export class StatusBarView {
16+
// tslint:disable-next-line:no-uninitialized-class-properties
17+
public element: HTMLElement
18+
private currentStatus: IStatus
19+
constructor (private panel: OutputPanel) {
20+
this.currentStatus = { status: 'ready', detail: '' }
21+
etch.initialize(this)
22+
}
23+
24+
public render () {
25+
return (
26+
<div class="ide-haskell inline-block" on={{click: this.didClick.bind(this)}}>
27+
<span>
28+
<ide-haskell-lambda/>
29+
<ide-haskell-status-icon ref="status" id="status" dataset={{status: this.currentStatus.status}}/>
30+
</span>
31+
</div>
32+
)
33+
}
34+
35+
public update () {
36+
return etch.update(this)
37+
}
38+
39+
public setStatus (status: IStatus) {
40+
this.currentStatus = status
41+
this.update()
42+
}
43+
44+
public async destroy () {
45+
await etch.destroy(this)
46+
}
47+
48+
private didClick () {
49+
atom.workspace.toggle(this.panel)
50+
}
51+
}

styles/ide-haskell.less

+22
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,25 @@ ide-haskell-tooltip {
406406
atom-overlay.ide-haskell {
407407
pointer-events: none;
408408
}
409+
410+
.status-bar-right .ide-haskell {
411+
padding-bottom: -0.3em;
412+
&:hover span {
413+
border-bottom: solid 1px;
414+
}
415+
ide-haskell-lambda {
416+
-webkit-mask: url('atom://ide-haskell/resources/haskell.svg') no-repeat 50% 50%;
417+
mask: url('atom://ide-haskell/resources/haskell.svg') no-repeat 50% 50%;
418+
-webkit-mask-size: contain;
419+
mask-size: contain;
420+
background-color: @text-color;
421+
width: 2em;
422+
height: 1em;
423+
display: inline-block;
424+
margin-bottom: -0.1em;
425+
}
426+
ide-haskell-status-icon {
427+
.status-icon();
428+
margin-right: 0;
429+
}
430+
}

0 commit comments

Comments
 (0)