Merge pull request #17529 from karevn/issue-17528

File -> Open works without open windows
This commit is contained in:
David Wilson
2019-02-07 15:34:31 -08:00
committed by GitHub
2 changed files with 39 additions and 0 deletions

View File

@@ -638,6 +638,31 @@ describe('AtomApplication', function () {
assert(atomApplication.getAllWindows().length === 0)
})
if (process.platform === 'darwin') {
it('allows opening a new folder after all windows are closed', async () => {
const atomApplication = buildAtomApplication()
sinon.stub(atomApplication, 'promptForPathToOpen')
// Open a window and then close it, leaving the app running
const [window] = await atomApplication.launch(parseCommandLine([]))
await focusWindow(window)
window.close()
await window.closedPromise
atomApplication.emit('application:open')
await conditionPromise(() => atomApplication.promptForPathToOpen.calledWith('all'))
atomApplication.promptForPathToOpen.reset()
atomApplication.emit('application:open-file')
await conditionPromise(() => atomApplication.promptForPathToOpen.calledWith('file'))
atomApplication.promptForPathToOpen.reset()
atomApplication.emit('application:open-folder')
await conditionPromise(() => atomApplication.promptForPathToOpen.calledWith('file'))
atomApplication.promptForPathToOpen.reset()
})
}
function buildAtomApplication (params = {}) {
const atomApplication = new AtomApplication(Object.assign({
resourcePath: ATOM_RESOURCE_PATH,

View File

@@ -23,6 +23,17 @@ const ConfigSchema = require('../config-schema')
const LocationSuffixRegExp = /(:\d+)(:\d+)?$/
const getDefaultPath = () => {
const editor = atom.workspace.getActiveTextEditor()
if (!editor || !editor.getPath()) {
return
}
const paths = atom.project.getPaths()
if (paths) {
return paths[0]
}
}
// The application's singleton class.
//
// It's the entry point into the Atom application and maintains the global state
@@ -371,6 +382,9 @@ class AtomApplication extends EventEmitter {
this.on('application:new-file', () => (this.focusedWindow() || this).openPath())
this.on('application:open-dev', () => this.promptForPathToOpen('all', {devMode: true}))
this.on('application:open-safe', () => this.promptForPathToOpen('all', {safeMode: true}))
this.on('application:open', () => this.promptForPathToOpen('all', getLoadSettings(), getDefaultPath()))
this.on('application:open-file', () => this.promptForPathToOpen('file', getLoadSettings(), getDefaultPath()))
this.on('application:open-folder', () => this.promptForPathToOpen('file', getLoadSettings(), getDefaultPath()))
this.on('application:inspect', ({x, y, atomWindow}) => {
if (!atomWindow) atomWindow = this.focusedWindow()
if (atomWindow) atomWindow.browserWindow.inspectElement(x, y)