Skip to content

Commit a74e176

Browse files
authored
Merge pull request #741 from JunoLab/avi/project
project monitor tile
2 parents 3b173c2 + a218317 commit a74e176

File tree

10 files changed

+162
-50
lines changed

10 files changed

+162
-50
lines changed

lib/connection/client.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ module.exports =
155155
@ipc.reset()
156156

157157
clargs: ->
158-
{precompiled, optimisationLevel, deprecationWarnings} =
158+
{optimisationLevel, deprecationWarnings} =
159159
atom.config.get 'julia-client.juliaOptions'
160160
as = []
161161
as.push "--depwarn=#{if deprecationWarnings then 'yes' else 'no'}"

lib/package/commands.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ module.exports =
194194
'julia-client:activate-default-environment': (ev) ->
195195
requireClient 'activate an environment', ->
196196
juno.runtime.evaluation.activateDefaultProject()
197+
'julia-client:set-working-environment': (ev) ->
198+
juno.runtime.environments.chooseEnvironment()
197199

198200
deactivate: ->
199201
@subs.dispose()

lib/package/menu.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module.exports =
4747
{label: 'Environment in Current File\'s Folder', command: 'julia-client:activate-environment-in-current-folder'}
4848
{label: 'Environment in Parent Folder', command: 'julia-client:activate-environment-in-parent-folder'}
4949
{label: 'Default Environment', command: 'julia-client:activate-default-environment'}
50+
{label: 'Set Working Environment', command: 'julia-client:set-working-environment'}
5051
]
5152
}
5253
{label: 'Set Working Module', command: 'julia-client:set-working-module'}

lib/runtime.coffee

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
{ CompositeDisposable, Disposable } = require 'atom'
22

33
module.exports =
4-
modules: require './runtime/modules'
5-
evaluation: require './runtime/evaluation'
6-
console: require './runtime/console'
7-
completions: require './runtime/completions'
8-
workspace: require './runtime/workspace'
9-
plots: require './runtime/plots'
10-
frontend: require './runtime/frontend'
11-
debugger: require './runtime/debugger'
12-
profiler: require './runtime/profiler'
13-
outline: require './runtime/outline'
14-
linter: require './runtime/linter'
15-
packages: require './runtime/packages'
16-
debuginfo: require './runtime/debuginfo'
17-
formatter: require './runtime/formatter'
18-
goto: require './runtime/goto'
4+
modules: require './runtime/modules'
5+
environments: require './runtime/environments'
6+
evaluation: require './runtime/evaluation'
7+
console: require './runtime/console'
8+
completions: require './runtime/completions'
9+
workspace: require './runtime/workspace'
10+
plots: require './runtime/plots'
11+
frontend: require './runtime/frontend'
12+
debugger: require './runtime/debugger'
13+
profiler: require './runtime/profiler'
14+
outline: require './runtime/outline'
15+
linter: require './runtime/linter'
16+
packages: require './runtime/packages'
17+
debuginfo: require './runtime/debuginfo'
18+
formatter: require './runtime/formatter'
19+
goto: require './runtime/goto'
1920

2021
activate: ->
2122
@subs = new CompositeDisposable()
@@ -41,15 +42,22 @@ module.exports =
4142
for mod in [@workspace, @plots]
4243
mod.ink = ink
4344
mod.activate()
44-
@subs.add new Disposable(=>
45-
mod.deactivate() for mod in [@console, @debugger, @profiler, @linter, @goto, @outline])
45+
@subs.add new Disposable =>
46+
mod.deactivate() for mod in [@console, @debugger, @profiler, @linter, @goto, @outline]
47+
@environments.consumeInk(ink)
4648

4749
provideAutoComplete: -> @completions
4850

4951
provideHyperclick: -> @goto.provideHyperclick()
5052

5153
consumeStatusBar: (bar) ->
52-
@modules.consumeStatusBar bar
54+
m = @modules.consumeStatusBar bar
55+
e = @environments.consumeStatusBar bar
56+
d = new Disposable =>
57+
m.dispose()
58+
e.dispose()
59+
@subs.add d
60+
return d
5361

5462
consumeDatatip: (datatipService) ->
5563
datatipProvider = require './runtime/datatip'

lib/runtime/console.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export function activate (_ink) {
6767
modules.onDidChange(debounce(() => changemodule({mod: modules.current()}), 200))
6868

6969
client.handle({
70-
updateWorkspace: () => require('./workspace').update(),
7170
clearconsole: () => terminal.clear(),
7271
cursorpos: () => terminal.cursorPosition(),
7372
writeToTerminal: (str) => {

lib/runtime/environments.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/** @babel */
2+
3+
import fs from 'fs'
4+
import path from 'path'
5+
import { CompositeDisposable, Disposable } from 'atom'
6+
import { client } from '../connection'
7+
import { show } from '../ui/selector'
8+
9+
const { allProjects, activateProject } = client.import({ rpc: ['allProjects'], msg: ['activateProject'] })
10+
11+
let ink
12+
export function consumeInk (_ink) {
13+
ink = _ink
14+
}
15+
16+
export function consumeStatusBar (statusBar) {
17+
const subs = new CompositeDisposable()
18+
19+
const dom = document.createElement('a')
20+
const tileDom = document.createElement('span') // only `span` element can be hide completely
21+
tileDom.classList.add('julia', 'inline-block')
22+
tileDom.appendChild(dom)
23+
const tile = statusBar.addRightTile({
24+
item: tileDom,
25+
priority: 10
26+
})
27+
28+
let projectName = ''
29+
let projectPath = ''
30+
31+
const showTile = () => tileDom.style.display = ''
32+
const hideTile = () => tileDom.style.display = 'none'
33+
const updateTile = (proj) => {
34+
if (!proj) return hideTile()
35+
projectName = proj.name
36+
dom.innerText = 'Env: ' + projectName
37+
projectPath = proj.path
38+
showTile()
39+
}
40+
client.handle({ updateProject: updateTile })
41+
42+
const onClick = (event) => {
43+
if (process.platform === 'darwin' ? event.metaKey : event.ctrlKey) {
44+
if (!fs.existsSync(projectPath)) return
45+
const pending = atom.config.get('core.allowPendingPaneItems')
46+
if (ink) {
47+
ink.Opener.open(projectPath, {
48+
pending,
49+
})
50+
} else {
51+
atom.workspace.open(projectPath, {
52+
pending,
53+
searchAllPanes: true
54+
})
55+
}
56+
} else {
57+
chooseEnvironment()
58+
}
59+
}
60+
61+
const modifiler = process.platform == 'darwin' ? 'Cmd' : 'Ctrl'
62+
const title = () => {
63+
return `Currently working in environment ${projectName} at ${projectPath}<br >` +
64+
`Click to choose an environment<br >` +
65+
`${modifiler}-Click to open project file`
66+
}
67+
68+
dom.addEventListener('click', onClick)
69+
subs.add(
70+
client.onDetached(hideTile),
71+
atom.tooltips.add(dom, { title }),
72+
new Disposable(() => {
73+
dom.removeEventListener('click', onClick)
74+
tile.destroy()
75+
})
76+
)
77+
78+
hideTile()
79+
return subs
80+
}
81+
82+
export function chooseEnvironment () {
83+
client.require('choose environment', () => {
84+
allProjects()
85+
.then(({ projects, active }) => {
86+
if (!projects) throw '`allProject` handler unsupported'
87+
if (projects.length === 0) throw 'no environment found'
88+
projects = projects.map(proj => {
89+
proj.primary = proj.name
90+
proj.secondary = proj.path
91+
return proj
92+
})
93+
return { projects, active }
94+
})
95+
.then(({ projects, active }) => {
96+
show(projects, { active }).then(proj => {
97+
if (!proj) return
98+
const dir = path.dirname(proj.path)
99+
activateProject(dir)
100+
})
101+
})
102+
.catch(err => console.log(err))
103+
})
104+
}

lib/runtime/modules.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ module.exports =
153153
@subs.add(disposable)
154154
disposable
155155

156-
updateView: (m) ->
156+
updateView: (m = @_current) ->
157157
return unless @tile?
158158
if not m?
159159
@dom.style.display = 'none'
@@ -162,7 +162,7 @@ module.exports =
162162
if main is @follow
163163
return @updateView @lastEditorModule
164164
@dom.style.display = ''
165-
@mainView.innerText = main or 'Main'
165+
@mainView.innerText = 'Module: ' + (main or 'Main')
166166
if sub
167167
@subView.innerText = sub
168168
@dividerView.innerText = '/'

lib/runtime/workspace.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports =
1111
activate: ->
1212
@create()
1313

14+
client.handle { updateWorkspace: => @update() }
1415
client.onDetached =>
1516
@ws.setItems []
1617
@lazyTrees = []

lib/ui/selector.js

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,41 +75,37 @@ export function show (items, { active, emptyMessage, errorMessage, infoMessage,
7575
}
7676
}
7777
}
78-
selector.props.filterKeyForItem = (items.length > 0 && items[0] instanceof Object) ?
79-
item => item.primary : item => item
80-
if (items.constructor == Promise) {
81-
items.then(items => {
82-
selector.update({
83-
items,
84-
emptyMessage,
85-
errorMessage,
86-
infoMessage,
87-
loadingMessage: ''
88-
})
89-
if (active) {
90-
const index = (active instanceof Number) ? active :
91-
(active instanceof Function) ? items.findIndex(active) :
92-
items.findIndex(item => item == active)
93-
selector.selectIndex(index)
94-
}
95-
}).catch(err => {
96-
reject(err)
97-
selector.cancelSelection()
98-
})
99-
} else {
78+
// for handling `Promise`
79+
function updateSelector (items) {
80+
selector.props.filterKeyForItem = (items.length > 0 && items[0] instanceof Object) ?
81+
item => item.primary : item => item
10082
selector.update({
10183
items,
10284
emptyMessage,
10385
errorMessage,
10486
infoMessage,
10587
loadingMessage: ''
10688
})
107-
if (active) {
108-
const index = (active instanceof Number) ? active :
109-
(active instanceof Function) ? items.findIndex(active) :
110-
items.findIndex(item => item == active)
111-
selector.selectIndex(index)
112-
}
89+
if (active) selectActiveItem(selector, items, active)
90+
}
91+
if (items.constructor == Promise) {
92+
items.then(items => {
93+
updateSelector(items)
94+
}).catch(err => {
95+
reject(err)
96+
selector.cancelSelection()
97+
})
98+
} else {
99+
updateSelector(items)
113100
}
114101
})
115102
}
103+
104+
function selectActiveItem (selector, items, active) {
105+
const index = (active instanceof Number) ? active :
106+
(active instanceof Function) ? items.findIndex(active) :
107+
(items.length > 0 && items[0].primary) ? items.findIndex(item => item.primary === active) :
108+
items.indexOf(active)
109+
if (index === -1) return // do nothing
110+
selector.selectIndex(index)
111+
}

menus/julia-client.cson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
{label: 'Work in Current Folder', command: 'julia-client:work-in-current-folder'}
2020
{label: 'Activate Environment in Current Folder', command: 'julia-client:activate-environment-in-current-folder'}
2121
{label: 'Activate Environment in Parent Folder', command: 'julia-client:activate-environment-in-parent-folder'}
22+
{label: 'Set Working Environment', command: 'julia-client:set-working-environment'}
2223
{label: 'Set Working Module', command: 'julia-client:set-working-module'}
2324
]
2425
}

0 commit comments

Comments
 (0)