Merge pull request #19058 from rafeca/fix-reopen-project

Fix reopen project when there are no open windows
This commit is contained in:
Rafael Oleza
2019-03-27 16:21:45 +01:00
committed by GitHub
4 changed files with 51 additions and 7 deletions

View File

@@ -900,6 +900,43 @@ describe('AtomApplication', function () {
)
atomApplication.promptForPathToOpen.reset()
})
it('allows reopening an existing project after all windows are closed', async () => {
const tempDirPath = makeTempDir('reopen')
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
// Reopen one of the recent projects
atomApplication.emit('application:reopen-project', { paths: [tempDirPath] })
const windows = atomApplication.getAllWindows()
assert(windows.length === 1)
await focusWindow(windows[0])
await conditionPromise(
async () => (await getTreeViewRootDirectories(windows[0])).length === 1
)
// Check that the project was opened correctly.
assert.deepEqual(
await evalInWebContents(
windows[0].browserWindow.webContents,
send => {
send(atom.project.getPaths())
}
),
[tempDirPath]
)
})
}
function buildAtomApplication (params = {}) {

View File

@@ -137,12 +137,12 @@ describe('ReopenProjectMenuManager', () => {
const first = projectsMenu.submenu[0]
expect(first.label).toBe('/a')
expect(first.command).toBe('application:reopen-project')
expect(first.commandDetail).toEqual({ index: 0 })
expect(first.commandDetail).toEqual({ index: 0, paths: ['/a'] })
const second = projectsMenu.submenu[1]
expect(second.label).toBe('b, c:\\')
expect(second.command).toBe('application:reopen-project')
expect(second.commandDetail).toEqual({ index: 1 })
expect(second.commandDetail).toEqual({ index: 1, paths: ['/b', 'c:\\'] })
})
it("adds only the number of menu items specified in the 'core.reopenProjectMenuCount' config", () => {
@@ -199,12 +199,12 @@ describe('ReopenProjectMenuManager', () => {
const first = projectsMenu.submenu[0]
expect(first.label).toBe('/a')
expect(first.command).toBe('application:reopen-project')
expect(first.commandDetail).toEqual({ index: 0 })
expect(first.commandDetail).toEqual({ index: 0, paths: ['/a'] })
const second = projectsMenu.submenu[1]
expect(second.label).toBe('b, c:\\')
expect(second.command).toBe('application:reopen-project')
expect(second.commandDetail).toEqual({ index: 1 })
expect(second.commandDetail).toEqual({ index: 1, paths: ['/b', 'c:\\'] })
})
})
@@ -226,12 +226,15 @@ describe('ReopenProjectMenuManager', () => {
const first = recentMenu.submenu[0]
expect(first.label).toBe('/users/neila')
expect(first.command).toBe('application:reopen-project')
expect(first.commandDetail).toEqual({ index: 0 })
expect(first.commandDetail).toEqual({ index: 0, paths: ['/users/neila'] })
const second = recentMenu.submenu[1]
expect(second.label).toBe('buzza, michaelc')
expect(second.command).toBe('application:reopen-project')
expect(second.commandDetail).toEqual({ index: 1 })
expect(second.commandDetail).toEqual({
index: 1,
paths: ['/users/buzza', 'users/michaelc']
})
})
})

View File

@@ -406,6 +406,10 @@ class AtomApplication extends EventEmitter {
this.on('application:check-for-update', () => this.autoUpdateManager.check())
if (process.platform === 'darwin') {
this.on('application:reopen-project', ({ paths }) => {
this.openPaths({ pathsToOpen: paths })
})
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('folder', getLoadSettings(), getDefaultPath()))

View File

@@ -125,7 +125,7 @@ class ReopenProjectMenuManager {
submenu: projects.map((project, index) => ({
label: this.createLabel(project),
command: 'application:reopen-project',
commandDetail: {index: index}
commandDetail: { index: index, paths: project.paths }
}))
}
]