Notify about missing project folders

This commit is contained in:
Ash Wilson 2019-01-24 10:39:50 -05:00
parent f6837d1f97
commit 02e1ae4b0f
No known key found for this signature in database
GPG Key ID: 81B1DDB704F69D2A
2 changed files with 46 additions and 4 deletions

View File

@ -671,6 +671,8 @@ describe('AtomEnvironment', () => {
})
it('may be required to be an existing directory', async () => {
spyOn(atom.notifications, 'addWarning')
const nonExistent = path.join(__dirname, 'no')
const existingFile = __filename
const existingDir = path.join(__dirname, 'fixtures')
@ -683,6 +685,11 @@ describe('AtomEnvironment', () => {
expect(atom.workspace.getTextEditors()).toEqual([])
expect(atom.project.getPaths()).toEqual([existingDir])
expect(atom.notifications.addWarning).toHaveBeenCalledWith(
'Unable to open project folders',
{description: `The directories \`${nonExistent}\` and \`${existingFile}\` do not exist.`}
)
})
})

View File

@ -1364,6 +1364,7 @@ or use Pane::saveItemAs for programmatic saving.`)
const needsProjectPaths = this.project && this.project.getPaths().length === 0
const foldersToAddToProject = new Set()
const fileLocationsToOpen = []
const missingFolders = []
// Asynchronously fetch stat information about each requested path to open.
const locationStats = await Promise.all(
@ -1386,9 +1387,13 @@ or use Pane::saveItemAs for programmatic saving.`)
if (stats.isDirectory()) {
// Directory: add as a project folder
foldersToAddToProject.add(this.project.getDirectoryForProjectPath(pathToOpen).getPath())
} else if (stats.isFile() && !location.mustBeDirectory) {
// File: add as a file location
fileLocationsToOpen.push(location)
} else if (stats.isFile()) {
if (!location.mustBeDirectory) {
// File: add as a file location
fileLocationsToOpen.push(location)
} else {
missingFolders.push(location)
}
}
} else {
// Path does not exist
@ -1397,7 +1402,10 @@ or use Pane::saveItemAs for programmatic saving.`)
if (directory) {
// Found: add as a project folder
foldersToAddToProject.add(directory.getPath())
} else if (!location.mustBeDirectory) {
} else if (location.mustBeDirectory) {
// Not found and must be a directory: add to missing list
missingFolders.push(location)
} else {
// Not found: open as a new file
fileLocationsToOpen.push(location)
}
@ -1430,6 +1438,33 @@ or use Pane::saveItemAs for programmatic saving.`)
await Promise.all(fileOpenPromises)
}
if (missingFolders.length > 0) {
let message = 'Unable to open project folder'
if (missingFolders.length > 1) {
message += 's'
}
let description = 'The '
if (missingFolders.length === 1) {
description += 'directory `'
description += missingFolders[0].pathToOpen
description += '` does not exist.'
} else if (missingFolders.length === 2) {
description += `directories \`${missingFolders[0].pathToOpen}\` `
description += `and \`${missingFolders[1].pathToOpen}\` do not exist.`
} else {
description += 'directories '
description += (missingFolders
.slice(0, -1)
.map(location => location.pathToOpen)
.map(pathToOpen => '`' + pathToOpen + '`, ')
.join(''))
description += 'and `' + missingFolders[missingFolders.length - 1].pathToOpen + '` do not exist.'
}
this.notifications.addWarning(message, {description})
}
ipcRenderer.send('window-command', 'window:locations-opened')
}