mirror of
https://github.com/atom/atom.git
synced 2026-01-25 06:48:28 -05:00
64 lines
1.6 KiB
CoffeeScript
64 lines
1.6 KiB
CoffeeScript
$ = require 'jquery'
|
|
_ = require 'underscore'
|
|
|
|
{activeWindow} = require 'app'
|
|
File = require 'fs'
|
|
Pane = require 'pane'
|
|
|
|
module.exports =
|
|
class Project extends Pane
|
|
showing: false
|
|
|
|
position: 'left'
|
|
html: require "project/project.html"
|
|
|
|
keymap:
|
|
'Command-Ctrl-N': 'toggle'
|
|
|
|
initialize: ->
|
|
activeWindow.document.ace.on 'open', =>
|
|
@reload() if @dir? and File.workingDirectory() isnt @dir
|
|
|
|
$('#project li').live 'click', (event) =>
|
|
$('#project .active').removeClass 'active'
|
|
el = $(event.currentTarget)
|
|
path = decodeURIComponent el.attr 'path'
|
|
if File.isDirectory(path)
|
|
if el.hasClass 'open'
|
|
el.removeClass 'open'
|
|
el.children("ul").remove()
|
|
else
|
|
el.addClass 'open'
|
|
list = @createList(path)
|
|
el.append("<ul>#{list}</ul>")
|
|
else
|
|
el.addClass 'active'
|
|
activeWindow.open path
|
|
|
|
false # Don't bubble!
|
|
|
|
toggle: ->
|
|
if @showing
|
|
$('#project').parent().remove()
|
|
else
|
|
activeWindow.addPane this
|
|
@reload()
|
|
|
|
@showing = not @showing
|
|
|
|
reload: ->
|
|
@dir = dir = File.workingDirectory()
|
|
$('#project .cwd').text _.last dir.split '/'
|
|
$('#project li').remove()
|
|
$('#project .files').append (@createList dir)
|
|
|
|
createList: (dir) ->
|
|
files = File.list dir
|
|
listItems = _.map files, (path) ->
|
|
filename = path.replace(dir, "").substring 1
|
|
type = if File.isDirectory(path) then 'dir' else 'file'
|
|
path = encodeURIComponent path
|
|
"<li class='#{type}' path='#{path}'>#{filename}</li>"
|
|
|
|
listItems.join '\n'
|