opening paths and multiple windows is working!

This commit is contained in:
Corey Johnson
2011-10-31 16:14:43 -07:00
parent cebd600e62
commit 912654cddf
7 changed files with 87 additions and 36 deletions

View File

@@ -1,4 +1,5 @@
KeyBinder = require 'key-binder'
fs = require 'fs'
require 'window'
module.exports =
@@ -7,5 +8,8 @@ class App
KeyBinder.register "app", @
window.startup()
@open: (path) ->
OSX.NSApp.open path
@quit: ->
OSX.NSApp.terminate null

View File

@@ -12,7 +12,11 @@ class Event
@off: (name, callback) ->
window.document.removeEventListener name, callback
@trigger: (name, data) ->
@trigger: (name, data, bubbleToApp=true) ->
if bubbleToApp and name.match /^app:/
OSX.NSApp.triggerGlobalEvent_data name, data
return
event = @events[name]
if not event
event = window.document.createEvent "CustomEvent"

View File

@@ -5,7 +5,7 @@ Native = require 'native'
fs = require 'fs'
# This file is a weirdo. We don't create a Window class, we just add stuff to
# This a weirdo file. We don't create a Window class, we just add stuff to
# the DOM window.
windowAdditions =
editor: null
@@ -14,14 +14,18 @@ windowAdditions =
appRoot: OSX.NSBundle.mainBundle.resourcePath
path: null
startup: () ->
@path = atomController.path ? @recentPath()
if atomController.path
@setRecentPath atomController.path
else
atomController.path = @recentPath()
KeyBinder.register "window", window
@editor = new Editor @path
@editor = if fs.isFile atomController.path
new Editor atomController.path
else
new Editor @tmpFile()
@loadExtensions()
@@ -50,31 +54,49 @@ windowAdditions =
console.warn error
recentPath: ->
localStorage.lastOpenedPath ? "/tmp/atom"
localStorage.lastOpenedPath ? @tmpFile()
setRecentPath: (path) ->
localStorage.lastOpenedPath = path
handleKeyEvent: ->
KeyBinder.handleEvent.apply KeyBinder, arguments
tmpFile: ->
"/tmp/atom"
showConsole: ->
atomController.webView.inspector.showConsole true
reload: ->
@close()
Native.newWindow @path
Native.newWindow atomController.path
open: (path) ->
path = Native.openPanel() if not path
if path
@path = path
@setRecentPath path
atomController.window.makeKeyAndOrderFront atomController
if fs.isFile path
Event.trigger 'window:open', path
close: ->
atomController.close
# Global methods that are used by the cocoa side of things
handleKeyEvent: ->
KeyBinder.handleEvent.apply KeyBinder, arguments
triggerEvent: ->
Event.trigger.apply Event, arguments
canOpen: (path) ->
parent = atomController.path.replace(/([^\/])$/, "$1/")
child = path.replace(/([^\/])$/, "$1/")
console.log parent
console.log child
window.x = parent
window.y = child
# If the child is contained by the parent, it can be opened by this window
return child.match "^" + parent
for key, value of windowAdditions
console.warn "DOMWindow already has a key named `#{key}`" if window[key]
window[key] = value