Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/init.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
VirtualenvView = require './virtualenv-view'
VirtualenvListView = require './virtualenv-list-view'
VirtualenvManger = require './virtualenv-manager'
VirtualenvStatusView = require './virtualenv-status-view'
MakeDialog = require './virtualenv-dialog'

module.exports =
Expand Down Expand Up @@ -81,3 +82,19 @@ module.exports =
@manager.on 'selector:show', =>
view = new VirtualenvListView(@manager)
view.attach()

# Create the view for the status bar and change the status string according
# to the changed environement
@virtualenvStatusView = new VirtualenvStatusView()
@manager.on 'virtualenv:changed', =>
if @manager.env?
@virtualenvStatusView.setStatus(@manager.env.name)
else
@virtualenvStatusView.clearStatus()

consumeStatusBar: (statusBar) ->
@statusBarTile = statusBar.addLeftTile(item: @virtualenvStatusView.getStatus(), priority: 100);

deactivate: ->
@statusBarTile?.destroy()
@statusBarTile = null
2 changes: 1 addition & 1 deletion lib/virtualenv-manager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ module.exports =
deactivate: () ->
if @env?
process.env.PATH = process.env.PATH.replace(@getPathForEnv(@env), '')
@env = null
@emit('virtualenv:changed')
atom.notifications.addSuccess('Virtualenv deactivated with success!')
@env = null

make: (name) ->
cmd = 'virtualenv ' + name
Expand Down
45 changes: 45 additions & 0 deletions lib/virtualenv-status-view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{Disposable} = require 'atom'

module.exports =
class VirtualenvStatusView

# constant string when there is no venv selected
@NO_ENV_STR: 'no virtualenv'

# Initialize the status element to show in the status bar
constructor: ->#(serializedState)->

# Construct status element and content
@status = document.createElement('div')
@status.classList.add('inline-block')
link = document.createElement('a')
link.textContent = VirtualenvStatusView.NO_ENV_STR
@status.appendChild(link)

# Add a tooltip to the status
@tooltip = atom.tooltips.add(@status, title: => "Current virtualenv: #{@status.childNodes[0].textContent} (left click to change)") # 0 index cause only one child: the link

# Set click handler
@status.addEventListener('click', @clickHandler)
@clickSubscription = new Disposable => @status.removeEventListener('click', @clickHandler)

# In the case on a virtualenv status click -> select venv
clickHandler: (event) ->
atom.commands.dispatch(atom.views.getView(atom.workspace), 'virtualenv:select')

# Set the status element string to the no env constant
clearStatus: ->
@status.childNodes[0].textContent = VirtualenvStatusView.NO_ENV_STR # 0 index cause only one child: the link

# Set the status element string as strStatus
setStatus: (strStatus) ->
@status.childNodes[0].textContent = strStatus # 0 index cause only one child: the link

# Get the full status element
getStatus: ->
@status

destroy: ->
@status.remove()
@tooltip.dispose()
@clickSubscription.dispose()
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,12 @@
"dependencies": {
"atom-space-pen-views": "latest",
"status-bar": ">=0.41.0"
},
"consumedServices": {
"status-bar": {
"versions": {
"^1.0.0": "consumeStatusBar"
}
}
}
}