Open .atom files from browser process

This allows a new window to be created if there is no currently
focused window.
This commit is contained in:
Kevin Sawicki
2014-01-20 09:46:49 -08:00
parent 4ac3be7ab5
commit 71c48ec07f
4 changed files with 31 additions and 20 deletions

View File

@@ -134,9 +134,9 @@
]
}
{ type: 'separator' }
{ label: 'Open Your Config', command: 'window:open-your-config' }
{ label: 'Open Your Keymap', command: 'window:open-your-keymap' }
{ label: 'Open Your Stylesheet', command: 'window:open-your-stylesheet' }
{ label: 'Open Your Config', command: 'application:open-your-config' }
{ label: 'Open Your Keymap', command: 'application:open-your-keymap' }
{ label: 'Open Your Stylesheet', command: 'application:open-your-stylesheet' }
{ type: 'separator' }
{ label: 'Toggle Soft Wrap', command: 'editor:toggle-soft-wrap' }
]

View File

@@ -146,11 +146,11 @@ class AtomApplication
@on 'application:inspect', ({x,y}) -> @focusedWindow().browserWindow.inspectElement(x, y)
@on 'application:open-documentation', -> shell.openExternal('https://www.atom.io/docs/latest/?app')
@on 'application:report-issue', -> shell.openExternal('https://github.com/atom/atom/issues/new')
@on 'application:show-settings', ->
if @focusedWindow()
@focusedWindow().openPath("atom://config")
else
@openPath(pathToOpen: "atom://config")
@openPathOnEvent('application:show-settings', 'atom://config')
@openPathOnEvent('application:open-your-stylesheet', 'atom://.atom/stylesheet')
@openPathOnEvent('application:open-your-keymap', 'atom://.atom/keymap')
@openPathOnEvent('application:open-your-config', 'atom://.atom/config')
app.on 'window-all-closed', ->
app.quit() if process.platform is 'win32'
@@ -203,6 +203,20 @@ class AtomApplication
unless @emit(command, args...)
@focusedWindow()?.sendCommand(command, args...)
# Public: Open the given path in the focused window when the event is
# triggered.
#
# A new window will be created if there is no currently focused window.
#
# * eventName: The event to listen for.
# * pathToOpen: The path to open when the event is triggered.
openPathOnEvent: (eventName, pathToOpen) ->
@on eventName, ->
if window = @focusedWindow()
window.openPath(pathToOpen)
else
@openPath({pathToOpen})
# Private: Returns the {AtomWindow} for the given path.
windowForPath: (pathToOpen) ->
for atomWindow in @windows

View File

@@ -99,6 +99,7 @@ class WorkspaceView extends View
@command 'application:minimize', -> ipc.sendChannel('command', 'application:minimize')
@command 'application:zoom', -> ipc.sendChannel('command', 'application:zoom')
@command 'application:bring-all-windows-to-front', -> ipc.sendChannel('command', 'application:bring-all-windows-to-front')
@command 'application:open-your-stylesheet', -> ipc.sendChannel('command', 'application:open-your-stylesheet')
@command 'window:run-package-specs', => ipc.sendChannel('run-package-specs', path.join(atom.project.getPath(), 'spec'))
@command 'window:increase-font-size', =>

View File

@@ -27,6 +27,14 @@ class Workspace extends Model
constructor: ->
super
@subscribe @paneContainer, 'item-destroyed', @onPaneItemDestroyed
atom.project.registerOpener (filePath) =>
switch filePath
when 'atom://.atom/stylesheet'
@open(atom.themes.getUserStylesheetPath())
when 'atom://.atom/keymap'
@open(atom.keymap.getUserKeymapPath())
when 'atom://.atom/config'
@open(atom.config.getUserConfigPath())
# Private: Called by the Serializable mixin during deserialization
deserializeParams: (params) ->
@@ -38,18 +46,6 @@ class Workspace extends Model
paneContainer: @paneContainer.serialize()
fullScreen: atom.isFullScreen()
# Private: Open ~/.atom/user.less or ~/.atom/user.css
openUserStylesheet: ->
@open(atom.themes.getUserStylesheetPath())
# Private: Open ~/.atom/keymap.cson or ~/.atom/keymap.json
openUserKeymap: ->
@open(atom.keymap.getUserKeymapPath())
# Private: Open ~/.atom/config.cson or ~/.atom/config.json
openUserConfig: ->
@open(atom.config.getUserConfigPath())
# Public: Asynchronously opens a given a filepath in Atom.
#
# * filePath: A file path