Honor removing projects from the Windows jump list

This commit is contained in:
Damien Guard
2017-01-23 20:54:25 -08:00
parent 88a190532c
commit 50f49cf794
2 changed files with 38 additions and 2 deletions

View File

@@ -61,6 +61,19 @@ export class HistoryManager {
this.didChangeProjects()
}
removeProject (paths) {
if (paths.length === 0) return
let project = this.getProject(paths)
if (!project) return
let index = this.projects.indexOf(project)
this.projects.splice(index, 1)
this.saveState()
this.didChangeProjects()
}
getProject (paths) {
for (var i = 0; i < this.projects.length; i++) {
if (arrayEquivalent(paths, this.projects[i].paths)) {

View File

@@ -19,6 +19,8 @@ export default class ReopenProjectMenuManager {
}),
commands.add('atom-workspace', { 'application:reopen-project': this.reopenProjectCommand.bind(this) })
)
this.applyWindowsJumpListRemovals()
}
reopenProjectCommand (e) {
@@ -49,9 +51,30 @@ export default class ReopenProjectMenuManager {
this.updateWindowsJumpList()
}
static taskDescription (paths) {
return paths.map(path => `${ReopenProjectMenuManager.betterBaseName(path)} (${path})`).join(' ')
}
// Windows users can right-click Atom taskbar and remove project from the jump list.
// We have to honor that or the group stops working. As we only get a partial list
// each time we remove them from history entirely.
applyWindowsJumpListRemovals () {
if (process.platform !== 'win32') return
if (this.app === undefined) {
this.app = require('remote').app
}
const removed = this.app.getJumpListSettings().removedItems.map(i => i.description)
if (removed.length === 0) return
for (let project of this.historyManager.getProjects()) {
if (removed.includes(ReopenProjectMenuManager.taskDescription(project.paths))) {
this.historyManager.removeProject(project.paths)
}
}
}
updateWindowsJumpList () {
if (process.platform !== 'win32') return
if (this.app === undefined) {
this.app = require('remote').app
}
@@ -64,7 +87,7 @@ export default class ReopenProjectMenuManager {
({
type: 'task',
title: project.paths.map(ReopenProjectMenuManager.betterBaseName).join(', '),
description: project.paths.map(path => `${ReopenProjectMenuManager.betterBaseName(path)} (${path})`).join(' '),
description: ReopenProjectMenuManager.taskDescription(project.paths),
program: process.execPath,
args: project.paths.map(path => `"${path}"`).join(' '),
iconPath: path.join(path.dirname(process.execPath), 'resources', 'cli', 'folder.ico'),