Add application:open-file and application:open-folder command.

This commit is contained in:
Cheng Zhao
2014-04-10 16:43:58 +08:00
parent 8afd90b9f8
commit f37ca3e19c
2 changed files with 17 additions and 3 deletions

View File

@@ -135,7 +135,9 @@ class AtomApplication
@on 'application:quit', -> app.quit()
@on 'application:new-window', -> @openPath(windowDimensions: @focusedWindow()?.getDimensions())
@on 'application:new-file', -> (@focusedWindow() ? this).openPath()
@on 'application:open', -> @promptForPath()
@on 'application:open', -> @promptForPath(type: 'all')
@on 'application:open-file', -> @promptForPath(type: 'file')
@on 'application:open-folder', -> @promptForPath(type: 'folder')
@on 'application:open-dev', -> @promptForPath(devMode: true)
@on 'application:inspect', ({x,y}) -> @focusedWindow().browserWindow.inspectElement(x, y)
@on 'application:open-documentation', -> shell.openExternal('https://atom.io/docs/latest/?app')
@@ -407,9 +409,19 @@ class AtomApplication
# Once paths are selected, they're opened in a new or existing {AtomWindow}s.
#
# * options
# + type:
# A String which specifies the type of the dialog, could be 'file',
# 'folder' or 'all'. The 'all' is only available on OS X.
# + devMode:
# A Boolean which controls whether any newly opened windows should be in
# dev mode or not.
promptForPath: ({devMode}={}) ->
dialog.showOpenDialog title: 'Open', properties: ['openFile', 'openDirectory', 'multiSelections', 'createDirectory'], (pathsToOpen) =>
promptForPath: ({type, devMode}={}) ->
type ?= 'all'
properties =
switch type
when 'file' then ['openFile']
when 'folder' then ['openDirectory']
when 'all' then ['openFile', 'openDirectory']
else throw new Error("#{type} is an invalid type for promptForPath")
dialog.showOpenDialog title: 'Open', properties: properties.concat(['multiSelections', 'createDirectory']), (pathsToOpen) =>
@openPaths({pathsToOpen, devMode})

View File

@@ -116,6 +116,8 @@ class WorkspaceView extends View
@command 'application:new-window', -> ipc.sendChannel('command', 'application:new-window')
@command 'application:new-file', -> ipc.sendChannel('command', 'application:new-file')
@command 'application:open', -> ipc.sendChannel('command', 'application:open')
@command 'application:open-file', -> ipc.sendChannel('command', 'application:open-file')
@command 'application:open-folder', -> ipc.sendChannel('command', 'application:open-folder')
@command 'application:open-dev', -> ipc.sendChannel('command', 'application:open-dev')
@command 'application:minimize', -> ipc.sendChannel('command', 'application:minimize')
@command 'application:zoom', -> ipc.sendChannel('command', 'application:zoom')