Files
atom/src/app/directory.coffee
Corey Johnson & Nathan Sobo 3ac49e1cd5 add $native.unwatch(path, id)
2012-04-25 18:03:51 -07:00

37 lines
899 B
CoffeeScript

_ = require 'underscore'
fs = require 'fs'
File = require 'file'
EventEmitter = require 'event-emitter'
module.exports =
class Directory
constructor: (@path) ->
getName: ->
fs.base(@path) + '/'
getEntries: ->
directories = []
files = []
for path in fs.list(@path)
if fs.isDirectory(path)
directories.push(new Directory(path))
else
files.push(new File(path))
directories.concat(files)
afterSubscribe: ->
@subscribeToNativeChangeEvents() if @subscriptionCount() == 1
afterUnsubscribe: ->
@unsubscribeFromNativeChangeEvents() if @subscriptionCount() == 0
subscribeToNativeChangeEvents: ->
@watchId = $native.watchPath @path, (eventTypes) =>
@trigger 'contents-change' if eventTypes.modified?
unsubscribeFromNativeChangeEvents: ->
$native.unwatchPath(@path, @watchId)
_.extend Directory.prototype, EventEmitter