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

Commit 44de402

Browse files
authored
Merge pull request #19 from Gijom/master
Status bar added
2 parents cfc30bc + c4ec811 commit 44de402

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

lib/init.coffee

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
VirtualenvView = require './virtualenv-view'
22
VirtualenvListView = require './virtualenv-list-view'
33
VirtualenvManger = require './virtualenv-manager'
4+
VirtualenvStatusView = require './virtualenv-status-view'
45
MakeDialog = require './virtualenv-dialog'
56

67
module.exports =
@@ -81,3 +82,19 @@ module.exports =
8182
@manager.on 'selector:show', =>
8283
view = new VirtualenvListView(@manager)
8384
view.attach()
85+
86+
# Create the view for the status bar and change the status string according
87+
# to the changed environement
88+
@virtualenvStatusView = new VirtualenvStatusView()
89+
@manager.on 'virtualenv:changed', =>
90+
if @manager.env?
91+
@virtualenvStatusView.setStatus(@manager.env.name)
92+
else
93+
@virtualenvStatusView.clearStatus()
94+
95+
consumeStatusBar: (statusBar) ->
96+
@statusBarTile = statusBar.addLeftTile(item: @virtualenvStatusView.getStatus(), priority: 100);
97+
98+
deactivate: ->
99+
@statusBarTile?.destroy()
100+
@statusBarTile = null

lib/virtualenv-manager.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ module.exports =
105105
deactivate: () ->
106106
if @env?
107107
process.env.PATH = process.env.PATH.replace(@getPathForEnv(@env), '')
108+
@env = null
108109
@emit('virtualenv:changed')
109110
atom.notifications.addSuccess('Virtualenv deactivated with success!')
110-
@env = null
111111

112112
make: (name) ->
113113
cmd = 'virtualenv ' + name

lib/virtualenv-status-view.coffee

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{Disposable} = require 'atom'
2+
3+
module.exports =
4+
class VirtualenvStatusView
5+
6+
# constant string when there is no venv selected
7+
@NO_ENV_STR: 'no virtualenv'
8+
9+
# Initialize the status element to show in the status bar
10+
constructor: ->#(serializedState)->
11+
12+
# Construct status element and content
13+
@status = document.createElement('div')
14+
@status.classList.add('inline-block')
15+
link = document.createElement('a')
16+
link.textContent = VirtualenvStatusView.NO_ENV_STR
17+
@status.appendChild(link)
18+
19+
# Add a tooltip to the status
20+
@tooltip = atom.tooltips.add(@status, title: => "Current virtualenv: #{@status.childNodes[0].textContent} (left click to change)") # 0 index cause only one child: the link
21+
22+
# Set click handler
23+
@status.addEventListener('click', @clickHandler)
24+
@clickSubscription = new Disposable => @status.removeEventListener('click', @clickHandler)
25+
26+
# In the case on a virtualenv status click -> select venv
27+
clickHandler: (event) ->
28+
atom.commands.dispatch(atom.views.getView(atom.workspace), 'virtualenv:select')
29+
30+
# Set the status element string to the no env constant
31+
clearStatus: ->
32+
@status.childNodes[0].textContent = VirtualenvStatusView.NO_ENV_STR # 0 index cause only one child: the link
33+
34+
# Set the status element string as strStatus
35+
setStatus: (strStatus) ->
36+
@status.childNodes[0].textContent = strStatus # 0 index cause only one child: the link
37+
38+
# Get the full status element
39+
getStatus: ->
40+
@status
41+
42+
destroy: ->
43+
@status.remove()
44+
@tooltip.dispose()
45+
@clickSubscription.dispose()

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@
1818
"dependencies": {
1919
"atom-space-pen-views": "latest",
2020
"status-bar": ">=0.41.0"
21+
},
22+
"consumedServices": {
23+
"status-bar": {
24+
"versions": {
25+
"^1.0.0": "consumeStatusBar"
26+
}
27+
}
2128
}
2229
}

0 commit comments

Comments
 (0)