🐛 Ctrl-O opens file dialog in directory of currently active editor

This commit is contained in:
David Elliott
2016-04-27 10:52:57 -07:00
parent e0688bef1a
commit 6ec5cf497b
2 changed files with 25 additions and 19 deletions

View File

@@ -58,7 +58,6 @@ class AtomApplication
resourcePath: null
version: null
quitting: false
lastFilePathOpened: null
exit: (status) -> app.exit(status)
@@ -171,11 +170,6 @@ class AtomApplication
@on 'application:quit', -> app.quit()
@on 'application:new-window', -> @openPath(getLoadSettings())
@on 'application:new-file', -> (@focusedWindow() ? this).openPath()
@on 'application:open', -> @promptForPathToOpen('all', getLoadSettings())
@on 'application:open-file', -> @promptForPathToOpen('file', getLoadSettings())
@on 'application:open-folder', -> @promptForPathToOpen('folder', getLoadSettings())
@on 'application:open-dev', -> @promptForPathToOpen('all', devMode: true)
@on 'application:open-safe', -> @promptForPathToOpen('all', safeMode: true)
@on 'application:inspect', ({x, y, atomWindow}) ->
atomWindow ?= @focusedWindow()
atomWindow?.browserWindow.inspectElement(x, y)
@@ -256,6 +250,15 @@ class AtomApplication
ipcMain.on 'command', (event, command) =>
@emit(command)
ipcMain.on 'open-command', (event, command, args...) =>
switch command
when 'application:open' then @promptForPathToOpen('all', getLoadSettings())
when 'application:open-file' then @promptForPathToOpen('file', getLoadSettings(), args[0])
when 'application:open-folder' then @promptForPathToOpen('folder', getLoadSettings())
when 'application:open-dev' then @promptForPathToOpen('all', devMode: true)
when 'application:open-safe' then @promptForPathToOpen('all', safeMode: true)
else console.log "Invalid open-command received: " + command
ipcMain.on 'window-command', (event, command, args...) ->
win = BrowserWindow.fromWebContents(event.sender)
win.emit(command, args...)
@@ -654,12 +657,13 @@ class AtomApplication
# :safeMode - A Boolean which controls whether any newly opened windows
# should be in safe mode or not.
# :window - An {AtomWindow} to use for opening a selected file path.
promptForPathToOpen: (type, {devMode, safeMode, window}) ->
@promptForPath type, (pathsToOpen) =>
@lastFilePathOpened = pathsToOpen[0] if pathsToOpen.length > 0
@openPaths({pathsToOpen, devMode, safeMode, window})
# :path - An optional String which controls the default path to which the
# file dialog opens.
promptForPathToOpen: (type, {devMode, safeMode, window}, path=null) ->
@promptForPath type, ((pathsToOpen) =>
@openPaths({pathsToOpen, devMode, safeMode, window})), path
promptForPath: (type, callback) ->
promptForPath: (type, callback, path) ->
properties =
switch type
when 'file' then ['openFile']
@@ -682,8 +686,8 @@ class AtomApplication
when 'folder' then 'Open Folder'
else 'Open'
# If a file was previously opened, set default path to open there again.
if @lastFilePathOpened? and type is 'file'
openOptions.defaultPath = @lastFilePathOpened
# File dialog defaults to project directory of currently active editor
if path? and type is 'file'
openOptions.defaultPath = path
dialog.showOpenDialog(parentWindow, openOptions, callback)

View File

@@ -31,11 +31,13 @@ module.exports = ({commandRegistry, commandInstaller, config, notificationManage
'application:unhide-all-applications': -> ipcRenderer.send('command', 'application:unhide-all-applications')
'application:new-window': -> ipcRenderer.send('command', 'application:new-window')
'application:new-file': -> ipcRenderer.send('command', 'application:new-file')
'application:open': -> ipcRenderer.send('command', 'application:open')
'application:open-file': -> ipcRenderer.send('command', 'application:open-file')
'application:open-folder': -> ipcRenderer.send('command', 'application:open-folder')
'application:open-dev': -> ipcRenderer.send('command', 'application:open-dev')
'application:open-safe': -> ipcRenderer.send('command', 'application:open-safe')
'application:open': -> ipcRenderer.send('open-command', 'application:open')
'application:open-file': ->
defaultPath = atom.workspace.getActiveTextEditor()?.getPath() ? atom.project.getPaths()?[0]
ipcRenderer.send('open-command', 'application:open-file', defaultPath)
'application:open-folder': -> ipcRenderer.send('open-command', 'application:open-folder')
'application:open-dev': -> ipcRenderer.send('open-command', 'application:open-dev')
'application:open-safe': -> ipcRenderer.send('open-command', 'application:open-safe')
'application:add-project-folder': -> atom.addProjectFolder()
'application:minimize': -> ipcRenderer.send('command', 'application:minimize')
'application:zoom': -> ipcRenderer.send('command', 'application:zoom')