|
|
@ -18,22 +18,20 @@ export class FileDecorator extends Plugin { |
|
|
|
constructor() { |
|
|
|
constructor() { |
|
|
|
super(profile) |
|
|
|
super(profile) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onActivation(): void { |
|
|
|
|
|
|
|
this.on('filePanel', 'setWorkspace', async () => { |
|
|
|
|
|
|
|
await this.clearAllFileDecorators() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param fileStates Array of file states |
|
|
|
* @param fileStates Array of file states |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async setFileDecorators(fileStates: fileDecoration[] | fileDecoration) { |
|
|
|
async setFileDecorators(fileStates: fileDecoration[] | fileDecoration) { |
|
|
|
|
|
|
|
const { from } = this.currentRequest |
|
|
|
const workspace = await this.call('filePanel', 'getCurrentWorkspace') |
|
|
|
const workspace = await this.call('filePanel', 'getCurrentWorkspace') |
|
|
|
function sortByPath( a: fileDecoration, b: fileDecoration ) { |
|
|
|
|
|
|
|
if ( a.path < b.path ){ |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ( a.path > b.path ){ |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fileStatesPayload = Array.isArray(fileStates) ? fileStates : [fileStates] |
|
|
|
const fileStatesPayload = Array.isArray(fileStates) ? fileStates : [fileStates] |
|
|
|
// clear all file states in the previous state of this owner on the files called
|
|
|
|
// clear all file states in the previous state of this owner on the files called
|
|
|
|
fileStatesPayload.forEach((state) => { |
|
|
|
fileStatesPayload.forEach((state) => { |
|
|
@ -48,6 +46,22 @@ export class FileDecorator extends Plugin { |
|
|
|
}) |
|
|
|
}) |
|
|
|
const newState = [...filteredState, ...fileStatesPayload].sort(sortByPath) |
|
|
|
const newState = [...filteredState, ...fileStatesPayload].sort(sortByPath) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!deepequal(newState, this._fileStates)) { |
|
|
|
|
|
|
|
this._fileStates = newState |
|
|
|
|
|
|
|
this.emit('fileDecoratorsChanged', this._fileStates) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clearFileDecorators(path?: string) { |
|
|
|
|
|
|
|
const { from } = this.currentRequest |
|
|
|
|
|
|
|
if (!from) return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filteredState = this._fileStates.filter((state) => { |
|
|
|
|
|
|
|
if(state.owner != from) return true |
|
|
|
|
|
|
|
if(path && state.path != path) return true |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
const newState = [...filteredState].sort(sortByPath) |
|
|
|
|
|
|
|
|
|
|
|
if (!deepequal(newState, this._fileStates)) { |
|
|
|
if (!deepequal(newState, this._fileStates)) { |
|
|
|
this._fileStates = newState |
|
|
|
this._fileStates = newState |
|
|
|
this.emit('fileDecoratorsChanged', this._fileStates) |
|
|
|
this.emit('fileDecoratorsChanged', this._fileStates) |
|
|
@ -55,8 +69,18 @@ export class FileDecorator extends Plugin { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async clearFileDecorators() { |
|
|
|
async clearAllFileDecorators() { |
|
|
|
this._fileStates = [] |
|
|
|
this._fileStates = [] |
|
|
|
this.emit('fileDecoratorsChanged', []) |
|
|
|
this.emit('fileDecoratorsChanged', []) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sortByPath = (a: fileDecoration, b: fileDecoration) => { |
|
|
|
|
|
|
|
if (a.path < b.path) { |
|
|
|
|
|
|
|
return -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (a.path > b.path) { |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |