eureka, less code, props rtomayko

This commit is contained in:
Corey Johnson
2011-11-11 15:49:39 -08:00
parent 691f4c02d0
commit 004ac4faf2
5 changed files with 28 additions and 18 deletions

View File

@@ -1,7 +1,9 @@
Todo
- Make handlers not suck
Intent
- open a folder
- child urls of folder open in same window
- open/save/close on project
Want
- cmd-shift-t: reopen last closed tab

View File

@@ -4,7 +4,7 @@ Document = require 'document'
module.exports =
class Browser extends Document
window.resourceTypes.push [this, (url) -> /^https?:/.test url]
window.resourceTypes.push this
path: null
html: $ "<div id='browser'></div>"
@@ -12,6 +12,8 @@ class Browser extends Document
$ "<iframe src='#{@path}' style='width:100%;height:100%'></iframe>"
open: (path) ->
return false if not /^https?:/.test path
@path = path
@html.html @iframe().bind 'load', (e) =>
window.setTitle e.target.contentWindow.document.title

View File

@@ -9,7 +9,7 @@ ace = require 'ace/ace'
module.exports =
class Editor extends Document
window.resourceTypes.push [this, (url) -> not url or fs.isFile url]
window.resourceTypes.push this
dirty: false
path: null
@@ -73,7 +73,9 @@ class Editor extends Document
if @path then _.last @path.split '/' else 'untitled'
open: (path) ->
return false if @path
if path
return false if not fs.isFile path
return false if @path
@path = path
@dirty = false

View File

@@ -5,11 +5,21 @@ Document = require 'document'
module.exports =
class Project extends Document
window.resourceTypes.push [this, (url) -> fs.isDirectory url]
window.resourceTypes.push this
html:
$ '<img src="http://fc01.deviantart.net/fs70/f/2010/184/4/9/Neru_Troll_Face_by_nerutrollfaceplz.jpg">'
open: (path) ->
return false if not fs.isDirectory url
#if not @path
#parent = @path.replace(/([^\/])$/, "$1/")
#child = path.replace(/([^\/])$/, "$1/")
# If the child is contained by the parent, it can be opened by this window
#child.match "^" + parent
@path = path
@show()

View File

@@ -9,15 +9,12 @@ windowAdditions =
url: $atomController.url?.toString()
startup: ->
resourceType = @resourceTypeForURL(@url)
@resource = new resourceType
@resource.open @url
success = false
for resourceType in @resourceTypes
@resource = new resourceType
break if success = @resource.open @url
resourceTypeForURL: (url) ->
window.x = this
resourceType = type for [type, test] in @resourceTypes when test url
throw "I DON'T KNOW ABOUT #{@url}" if not resourceType
resourceType
throw "I DON'T KNOW ABOUT #{@url}" if not success
shutdown: ->
@@ -33,10 +30,7 @@ windowAdditions =
open: (url) ->
url = atom.native.openPanel() unless url
if (@resourceTypeForURL url) == @resource.constructor and @resource.open url
# Cool (ICK)
else
atom.app.open url
(@resource.open url) or atom.app.open url
close: (path) ->
@shutdown()