From e0688bef1ab96e75baa417c52dcaee01590c49c0 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Tue, 26 Apr 2016 16:15:41 -0700 Subject: [PATCH 1/5] Ctrl-o opens last directory where you opened a file --- src/browser/atom-application.coffee | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 69eff1845..38c2a354a 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -58,6 +58,7 @@ class AtomApplication resourcePath: null version: null quitting: false + lastFilePathOpened: null exit: (status) -> app.exit(status) @@ -655,6 +656,7 @@ class AtomApplication # :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}) promptForPath: (type, callback) -> @@ -680,8 +682,8 @@ class AtomApplication when 'folder' then 'Open Folder' else 'Open' - if process.platform is 'linux' - if projectPath = @lastFocusedWindow?.projectPath - openOptions.defaultPath = projectPath + # If a file was previously opened, set default path to open there again. + if @lastFilePathOpened? and type is 'file' + openOptions.defaultPath = @lastFilePathOpened dialog.showOpenDialog(parentWindow, openOptions, callback) From 6ec5cf497b0357657cffd30b5ad89bc6b909c7a2 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Wed, 27 Apr 2016 10:52:57 -0700 Subject: [PATCH 2/5] :bug: Ctrl-O opens file dialog in directory of currently active editor --- src/browser/atom-application.coffee | 32 ++++++++++++++++------------ src/register-default-commands.coffee | 12 ++++++----- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 38c2a354a..b40dbfaad 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -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) diff --git a/src/register-default-commands.coffee b/src/register-default-commands.coffee index 035750363..e0b08abdc 100644 --- a/src/register-default-commands.coffee +++ b/src/register-default-commands.coffee @@ -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') From 398ae4491ec8b4a03f3d47343c410c46788975ef Mon Sep 17 00:00:00 2001 From: David Elliott Date: Thu, 28 Apr 2016 11:13:07 -0700 Subject: [PATCH 3/5] :art: Removed application:open-dev and application:open-safe from new method. --- src/browser/atom-application.coffee | 7 ++++--- src/register-default-commands.coffee | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index b40dbfaad..f39c50ce4 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -170,6 +170,8 @@ class AtomApplication @on 'application:quit', -> app.quit() @on 'application:new-window', -> @openPath(getLoadSettings()) @on 'application:new-file', -> (@focusedWindow() ? this).openPath() + @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) @@ -251,12 +253,11 @@ class AtomApplication @emit(command) ipcMain.on 'open-command', (event, command, args...) => + defaultPath = args[0] if args.length > 0 switch command when 'application:open' then @promptForPathToOpen('all', getLoadSettings()) - when 'application:open-file' then @promptForPathToOpen('file', getLoadSettings(), args[0]) + when 'application:open-file' then @promptForPathToOpen('file', getLoadSettings(), defaultPath) 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...) -> diff --git a/src/register-default-commands.coffee b/src/register-default-commands.coffee index e0b08abdc..b2dc1fd68 100644 --- a/src/register-default-commands.coffee +++ b/src/register-default-commands.coffee @@ -36,8 +36,8 @@ module.exports = ({commandRegistry, commandInstaller, config, notificationManage 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:open-dev': -> ipcRenderer.send('command', 'application:open-dev') + 'application:open-safe': -> ipcRenderer.send('command', 'application:open-safe') 'application:add-project-folder': -> atom.addProjectFolder() 'application:minimize': -> ipcRenderer.send('command', 'application:minimize') 'application:zoom': -> ipcRenderer.send('command', 'application:zoom') From e2fa948ac8e541ecefe7fcdfac4f87535486a004 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 29 Apr 2016 08:20:52 -0700 Subject: [PATCH 4/5] :bug: Add support for Mac and Open Folder dialog. --- src/browser/atom-application.coffee | 6 +++--- src/register-default-commands.coffee | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index f39c50ce4..f90afad83 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -255,9 +255,9 @@ class AtomApplication ipcMain.on 'open-command', (event, command, args...) => defaultPath = args[0] if args.length > 0 switch command - when 'application:open' then @promptForPathToOpen('all', getLoadSettings()) + when 'application:open' then @promptForPathToOpen('all', getLoadSettings(), defaultPath) when 'application:open-file' then @promptForPathToOpen('file', getLoadSettings(), defaultPath) - when 'application:open-folder' then @promptForPathToOpen('folder', getLoadSettings()) + when 'application:open-folder' then @promptForPathToOpen('folder', getLoadSettings(), defaultPath) else console.log "Invalid open-command received: " + command ipcMain.on 'window-command', (event, command, args...) -> @@ -688,7 +688,7 @@ class AtomApplication else 'Open' # File dialog defaults to project directory of currently active editor - if path? and type is 'file' + if path? openOptions.defaultPath = path dialog.showOpenDialog(parentWindow, openOptions, callback) diff --git a/src/register-default-commands.coffee b/src/register-default-commands.coffee index b2dc1fd68..74da2786e 100644 --- a/src/register-default-commands.coffee +++ b/src/register-default-commands.coffee @@ -1,6 +1,7 @@ {ipcRenderer} = require 'electron' module.exports = ({commandRegistry, commandInstaller, config, notificationManager}) -> + commandRegistry.add 'atom-workspace', 'pane:show-next-recently-used-item': -> @getModel().getActivePane().activateNextRecentlyUsedItem() 'pane:show-previous-recently-used-item': -> @getModel().getActivePane().activatePreviousRecentlyUsedItem() @@ -31,11 +32,15 @@ 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('open-command', 'application:open') - 'application:open-file': -> + 'application:open': -> + defaultPath = atom.workspace.getActiveTextEditor()?.getPath() ? atom.project.getPaths()?[0] + ipcRenderer.send('open-command', 'application:open', defaultPath) + '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-folder': -> + defaultPath = atom.workspace.getActiveTextEditor()?.getPath() ? atom.project.getPaths()?[0] + ipcRenderer.send('open-command', 'application:open-folder', defaultPath) 'application:open-dev': -> ipcRenderer.send('command', 'application:open-dev') 'application:open-safe': -> ipcRenderer.send('command', 'application:open-safe') 'application:add-project-folder': -> atom.addProjectFolder() From 6c9d7ecc2884075655e1583129afc99aa75dea47 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Fri, 29 Apr 2016 08:39:14 -0700 Subject: [PATCH 5/5] Remove random space --- src/register-default-commands.coffee | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/register-default-commands.coffee b/src/register-default-commands.coffee index 74da2786e..086a55497 100644 --- a/src/register-default-commands.coffee +++ b/src/register-default-commands.coffee @@ -1,7 +1,6 @@ {ipcRenderer} = require 'electron' module.exports = ({commandRegistry, commandInstaller, config, notificationManager}) -> - commandRegistry.add 'atom-workspace', 'pane:show-next-recently-used-item': -> @getModel().getActivePane().activateNextRecentlyUsedItem() 'pane:show-previous-recently-used-item': -> @getModel().getActivePane().activatePreviousRecentlyUsedItem() @@ -32,13 +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': -> + 'application:open': -> defaultPath = atom.workspace.getActiveTextEditor()?.getPath() ? atom.project.getPaths()?[0] ipcRenderer.send('open-command', 'application:open', defaultPath) - 'application:open-file': -> + 'application:open-file': -> defaultPath = atom.workspace.getActiveTextEditor()?.getPath() ? atom.project.getPaths()?[0] ipcRenderer.send('open-command', 'application:open-file', defaultPath) - 'application:open-folder': -> + 'application:open-folder': -> defaultPath = atom.workspace.getActiveTextEditor()?.getPath() ? atom.project.getPaths()?[0] ipcRenderer.send('open-command', 'application:open-folder', defaultPath) 'application:open-dev': -> ipcRenderer.send('command', 'application:open-dev')