Files
atom/plugins/project/project.coffee
Chris Wanstrath 804b67f8df osx.coffee is dead.
Split Chrome into App and Window, in app.coffee and window.coffee
2011-09-04 14:17:46 -07:00

51 lines
1.3 KiB
CoffeeScript

$ = require 'jquery'
_ = require 'underscore'
{activeWindow} = require 'app'
File = require 'fs'
Editor = require 'editor'
bindKey = Editor.bindKey
exports.init = ->
@html = require "project/project.html"
bindKey 'toggleProjectDrawer', 'Command-Ctrl-N', (env) =>
@toggle()
Editor.ace.on 'open', =>
@reload() if @dir? and File.workingDirectory() isnt @dir
$('#project .cwd').live 'click', (event) =>
Editor.open @dir.replace _.last(@dir.split '/'), ''
$('#project li').live 'click', (event) =>
$('#project .active').removeClass 'active'
el = $(event.currentTarget)
el.addClass 'active'
path = decodeURIComponent el.attr 'path'
Editor.open path
exports.toggle = ->
if @showing
$('#project').parent().remove()
else
activeWindow.addPane 'left', @html
@reload()
@showing = not @showing
exports.reload = ->
@dir = dir = File.workingDirectory()
$('#project .cwd').text _.last dir.split '/'
$('#project li').remove()
files = File.list dir
listItems = _.map files, (path) ->
filename = path.replace(dir, "").substring 1
type = if File.isDirectory(path) then 'dir' else 'file'
"<li class='#{type}' path='#{encodeURIComponent path}'>#{filename}</li>"
$('#project .files').append listItems.join '\n'