Reuse existing windows when opening paths from command line

This commit is contained in:
Corey Johnson & Kevin Sawicki
2013-05-28 14:45:54 -07:00
parent ba60324426
commit 7bc905d352
3 changed files with 40 additions and 17 deletions

View File

@@ -2,14 +2,19 @@ $ = require 'jquery'
_ = require 'underscore'
ipc = require 'ipc'
Subscriber = require 'subscriber'
fsUtils = require 'fs-utils'
module.exports =
class WindowEventHandler
constructor: ->
@subscribe ipc, 'command', (command) -> $(window).trigger command
@subscribe ipc, 'command', (command, args...) ->
$(window).trigger(command, args...)
@subscribe $(window), 'focus', -> $("body").removeClass('is-blurred')
@subscribe $(window), 'blur', -> $("body").addClass('is-blurred')
@subscribe $(window), 'window:open-path', (event, pathToOpen) ->
rootView.open(pathToOpen) unless fsUtils.isDirectory(pathToOpen)
@subscribeToCommand $(window), 'window:toggle-full-screen', => atom.toggleFullScreen()
@subscribeToCommand $(window), 'window:close', =>
if rootView?
@@ -30,6 +35,7 @@ class WindowEventHandler
@subscribe $(document), 'click', 'a', @openLink
openLink: (event) =>
location = $(event.target).attr('href')
return unless location

View File

@@ -171,27 +171,38 @@ class AtomApplication
ipc.on 'get-version', (event) =>
event.result = @version
sendCommand: (command) ->
atomWindow.sendCommand command for atomWindow in @windows when atomWindow.browserWindow.isFocused()
sendCommand: (command, args...) ->
for atomWindow in @windows when atomWindow.isFocused()
atomWindow.sendCommand(command, args...)
windowForPath: (pathToOpen) ->
return null unless pathToOpen
for atomWindow in @windows
if pathToOpen is atomWindow.pathToOpen
return atomWindow
if pathToOpen.indexOf(path.join(atomWindow.pathToOpen, path.sep)) is 0
return atomWindow
null
open: (pathsToOpen) ->
pathsToOpen ?= [null]
for pathToOpen in pathsToOpen
pathToOpen = path.resolve(@executedFrom, pathToOpen) if @executedFrom and pathToOpen
if pathToOpen
for atomWindow in @windows
if pathToOpen is atomWindow.pathToOpen
atomWindow.browserWindow.focus()
return
atomWindow = new AtomWindow
pathToOpen: pathToOpen
bootstrapScript: 'window-bootstrap'
resourcePath: @resourcePath
if existingWindow = @windowForPath(pathToOpen)
existingWindow.focus()
existingWindow.sendCommand('window:open-path', pathToOpen)
else
atomWindow = new AtomWindow
pathToOpen: pathToOpen
bootstrapScript: 'window-bootstrap'
resourcePath: @resourcePath
openConfig: ->
if @configWindow
@configWindow.browserWindow.focus()
@configWindow.focus()
return
@configWindow = new AtomWindow
@@ -207,4 +218,4 @@ class AtomApplication
exitWhenDone: exitWhenDone
isSpec: true
specWindow.browserWindow.show()
specWindow.show()

View File

@@ -30,5 +30,11 @@ class AtomWindow
event.preventDefault()
@sendCommand 'window:close'
sendCommand: (command) ->
ipc.sendChannel @browserWindow.getProcessId(), @browserWindow.getRoutingId(), 'command', command
sendCommand: (command, args...) ->
ipc.sendChannel @browserWindow.getProcessId(), @browserWindow.getRoutingId(), 'command', command, args...
focus: -> @browserWindow.focus()
isFocused: -> @browserWindow.isFocused()
show: -> @browserWindow.show()