提交 040f338d 编写于 作者: J Johannes Rieken

refine service, allow to set only one decoration per type and resource

上级 b5b32087
......@@ -44,12 +44,14 @@ class MarkersFileDecorations implements IWorkbenchContribution {
private _onDidChangeMarker(resources: URI[]): void {
for (const resource of resources) {
const markers = this._markerService.read({ resource });
const markers = this._markerService.read({ resource })
.sort((a, b) => Severity.compare(a.severity, b.severity));
if (!isFalsyOrEmpty(markers)) {
const data = markers.map(this._toFileDecorationData, this);
this._decorationsService.setFileDecorations(this._type, resource, data);
const data = this._toFileDecorationData(markers[0]);
this._decorationsService.setFileDecoration(this._type, resource, data);
} else {
this._decorationsService.unsetFileDecorations(this._type, resource);
this._decorationsService.unsetFileDecoration(this._type, resource);
}
}
}
......
......@@ -49,11 +49,11 @@ export class FileDecorations implements IWorkbenchContribution {
for (const resource of group.resourceCollection.resources) {
// TODO@Joh have a better color and icon which is based
// on the resource decoration
this._decorationsService.setFileDecorations(type, resource.sourceUri, [{
this._decorationsService.setFileDecoration(type, resource.sourceUri, {
severity: Severity.Info,
message: resource.decorations.tooltip,
color
}]);
});
newDecorations.set(resource.sourceUri.toString(), resource.sourceUri);
}
......@@ -61,7 +61,7 @@ export class FileDecorations implements IWorkbenchContribution {
oldDecorations.forEach((value, key) => {
if (!newDecorations.has(key)) {
this._decorationsService.unsetFileDecorations(type, value);
this._decorationsService.unsetFileDecoration(type, value);
}
});
......
......@@ -43,9 +43,9 @@ export interface IFileDecorationsService {
registerDecorationType(label: string): DecorationType;
setFileDecorations(type: DecorationType, target: URI, data: IFileDecorationData[]): void;
setFileDecoration(type: DecorationType, target: URI, data: IFileDecorationData): void;
unsetFileDecorations(type: DecorationType, target: URI): void;
unsetFileDecoration(type: DecorationType, target: URI): void;
getDecorations(uri: URI, includeChildren: boolean): IFileDecoration[];
......
......@@ -9,15 +9,13 @@ import Severity from 'vs/base/common/severity';
import Event, { Emitter, debounceEvent } from 'vs/base/common/event';
import { IFileDecorationsService, IFileDecoration, DecorationType, IFileDecorationData } from 'vs/workbench/services/fileDecorations/browser/fileDecorations';
import { TernarySearchTree } from 'vs/base/common/map';
import { mergeSort, isFalsyOrEmpty } from 'vs/base/common/arrays';
export class FileDecorationsService implements IFileDecorationsService {
readonly _serviceBrand;
private readonly _onDidChangeFileDecoration = new Emitter<URI>();
private readonly _types = new Map<DecorationType, TernarySearchTree<IFileDecoration[]>>();
private readonly _types = new Map<DecorationType, TernarySearchTree<IFileDecoration>>();
readonly onDidChangeFileDecoration: Event<URI[]> = debounceEvent<URI, URI[]>(
this._onDidChangeFileDecoration.event,
......@@ -44,17 +42,16 @@ export class FileDecorationsService implements IFileDecorationsService {
}
}
};
this._types.set(type, TernarySearchTree.forPaths<IFileDecoration[]>());
this._types.set(type, TernarySearchTree.forPaths<IFileDecoration>());
return type;
}
setFileDecorations(type: DecorationType, target: URI, data: IFileDecorationData[]): void {
let decorations = mergeSort(data.map(data => ({ type, ...data })), FileDecorationsService._compareFileDecorationsBySeverity);
this._types.get(type).set(target.toString(), decorations);
setFileDecoration(type: DecorationType, target: URI, data: IFileDecorationData): void {
this._types.get(type).set(target.toString(), { type, ...data });
this._onDidChangeFileDecoration.fire(target);
}
unsetFileDecorations(type: DecorationType, target: URI): void {
unsetFileDecoration(type: DecorationType, target: URI): void {
this._types.get(type).delete(target.toString());
this._onDidChangeFileDecoration.fire(target);
}
......@@ -76,7 +73,7 @@ export class FileDecorationsService implements IFileDecorationsService {
if (!top || FileDecorationsService._compareFileDecorationsBySeverity(top, decoration) > 0) {
top = decoration;
}
return top.severity === Severity.Error;
return top !== undefined && top.severity === Severity.Error;
});
return top;
}
......@@ -91,13 +88,11 @@ export class FileDecorationsService implements IFileDecorationsService {
if (includeChildren) {
let newTree = tree.findSuperstr(key);
if (newTree) {
newTree.forEach(([, data]) => done = done || data.some(callback));
newTree.forEach(([, deco]) => done = done || callback(deco));
}
} else {
let list = tree.get(key);
if (!isFalsyOrEmpty(list)) {
done = list.some(callback);
}
let deco = tree.get(key);
done = done || deco && callback(deco);
}
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册