From 1ca7fcdf11a003f5bb3cd9b32b1c5cf700d784df Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sat, 12 Nov 2011 01:58:59 -0800 Subject: [PATCH] project can open files --- src/atom/project.coffee | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/atom/project.coffee b/src/atom/project.coffee index 403a58c4b..400aa10a3 100644 --- a/src/atom/project.coffee +++ b/src/atom/project.coffee @@ -16,11 +16,40 @@ class Project extends Resource ''' + resources: [] + open: (url) -> - return false if not fs.isDirectory url + if not @url + # Can only open directories. + return false if not fs.isDirectory url - @url = url - @show() - atom.trigger 'project:load', this + @url = url + @show() + atom.trigger 'project:load', this - true + true + else if @url + # Can't open directories once we have a URL. + if fs.isDirectory url + return false + + # Ignore non-children files + if fs.isFile and not @childURL url + return false + + # Try to open all others + for resourceType in window.resourceTypes + resource = new resourceType + break if success = resource.open url + + if success + @resources.push resource + true + + # Determines if a passed URL is a child of @url. + # Returns a Boolean. + childURL: (url) -> + return false if not @url + parent = @url.replace /([^\/])$/, "$1/" + child = url.replace /([^\/])$/, "$1/" + child.match "^" + parent