mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Reuse existing windows when opening paths from command line
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user