提交 4e3fc0f7 编写于 作者: S Sandeep Somavarapu

implementation

上级 e6e6658e
......@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/markers';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import dom = require('vs/base/browser/dom');
import lifecycle = require('vs/base/common/lifecycle');
......@@ -24,6 +25,7 @@ import Messages from 'vs/workbench/parts/markers/common/Messages';
export class MarkersPanel extends Panel {
private markersModel: MarkersModel;
private tree: Tree.ITree;
private _toDispose: lifecycle.IDisposable[];
......@@ -34,6 +36,7 @@ export class MarkersPanel extends Panel {
@ITelemetryService telemetryService: ITelemetryService
) {
super(Constants.MARKERS_PANEL_ID, telemetryService);
this.markersModel= new MarkersModel();
this._toDispose = [];
}
......@@ -43,7 +46,7 @@ export class MarkersPanel extends Panel {
var actionProvider = this.instantiationService.createInstance(ActionProvider);
var renderer = this.instantiationService.createInstance(Viewer.Renderer, this.getActionRunner(), actionProvider);
var controller = this.instantiationService.createInstance(Controller, actionProvider);
var controller = this.instantiationService.createInstance(Controller);
this.tree = new TreeImpl.Tree(parent.getHTMLElement(), {
dataSource: new Viewer.DataSource(),
renderer: renderer,
......@@ -54,7 +57,9 @@ export class MarkersPanel extends Panel {
});
this._toDispose.push(this.markerService.onMarkerChanged((changedResources) => {
this.render();
this.updateTitleArea();
this.updateResources(changedResources);
this.tree.refresh();
}));
this.render();
return TPromise.as(null);
......@@ -89,11 +94,17 @@ export class MarkersPanel extends Panel {
this.tree.layout(dimension.height);
}
private updateResources(resources: URI[]) {
resources.forEach((resource) => {
let markers= this.markerService.read({resource: resource}).slice(0)
this.markersModel.updateResource(resource, markers);
})
}
private render(): void {
this.updateTitleArea();
let allMarkers = this.markerService.read().slice(0);
let model= new MarkersModel(allMarkers);
this.tree.setInput(model);
this.markersModel.updateMarkers(allMarkers);
this.tree.setInput(this.markersModel);
}
public dispose(): void {
......
......@@ -21,14 +21,8 @@ export class Controller extends treedefaults.DefaultController {
private contextMenuService:IContextMenuService;
private actionProvider:actionsrenderer.IActionProvider;
constructor(actionProvider:actionsrenderer.IActionProvider,
@IContextMenuService contextMenuService: IContextMenuService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService) {
constructor(@IWorkbenchEditorService private editorService: IWorkbenchEditorService) {
super({ clickBehavior: treedefaults.ClickBehavior.ON_MOUSE_UP });
this.actionProvider = actionProvider;
this.contextMenuService = contextMenuService;
this.downKeyBindingDispatcher.set(CommonKeybindings.SHIFT_UP_ARROW, this.onUp.bind(this));
this.downKeyBindingDispatcher.set(CommonKeybindings.SHIFT_DOWN_ARROW, this.onDown.bind(this));
this.downKeyBindingDispatcher.set(CommonKeybindings.SHIFT_PAGE_UP, this.onPageUp.bind(this));
......
......@@ -5,11 +5,12 @@
'use strict';
import * as Map from 'vs/base/common/map';
import Severity from 'vs/base/common/severity';
import URI from 'vs/base/common/uri';
import { IMarker } from 'vs/platform/markers/common/markers';
import { IMarker, MarkerStatistics } from 'vs/platform/markers/common/markers';
export class Resource {
constructor(public uri: URI, public markers: Marker[]){};
constructor(public uri: URI, public markers: Marker[], public statistics: MarkerStatistics){};
}
export class Marker {
......@@ -20,18 +21,33 @@ export class MarkersModel {
private markersByResource: Map.SimpleMap<URI, IMarker[]>;
constructor(private markers: IMarker[]= []) {
constructor(markers: IMarker[]= []) {
this.markersByResource= new Map.SimpleMap<URI, IMarker[]>();
this.process(markers);
this.updateMarkers(markers);
}
public getResources():Resource[] {
return this.markersByResource.entries().map((entry) => {
return new Resource(entry.key, entry.value.map(this.toMarker));
var resources= <Resource[]>this.markersByResource.entries().map(this.toResource.bind(this));
resources.sort((a: Resource, b: Resource) => {
let compare= this.compare(a.statistics, b.statistics);
if (compare !== 0) {
return compare;
}
return a.uri.toString().localeCompare(b.uri.toString());
});
return resources;
}
public updateResource(resourceUri: URI, markers: IMarker[]) {
if (this.markersByResource.has(resourceUri)) {
this.markersByResource.delete(resourceUri);
}
if (markers.length > 0) {
this.markersByResource.set(resourceUri, markers);
}
}
private process(markers: IMarker[]) {
public updateMarkers(markers: IMarker[]) {
markers.forEach((marker:IMarker) => {
let uri:URI= marker.resource;
let markers:IMarker[]= this.markersByResource.get(uri);
......@@ -43,7 +59,62 @@ export class MarkersModel {
});
}
private toResource(entry: Map.Entry<URI, IMarker[]>) {
let markers= entry.value.map(this.toMarker);
let resource= new Resource(entry.key, markers, this.getStatistics(entry.value));
return resource;
}
private toMarker(marker: IMarker, index: number):Marker {
return new Marker(marker.resource.toString() + index, marker);
}
private compare(stat1: MarkerStatistics, stat2: MarkerStatistics): number {
if (stat1.errors > stat2.errors) {
return -1;
}
if (stat2.errors > stat1.errors) {
return 1;
}
if (stat1.warnings > stat2.warnings) {
return -1;
}
if (stat2.warnings > stat1.warnings) {
return 1;
}
if (stat1.infos > stat2.infos) {
return -1;
}
if (stat2.infos > stat1.infos) {
return 1;
}
if (stat1.unknwons > stat2.unknwons) {
return -1;
}
if (stat2.unknwons > stat1.unknwons) {
return 1;
}
return 0;
}
private getStatistics(markers: IMarker[]): MarkerStatistics {
let errors= 0, warnings= 0, infos= 0, unknowns = 0;
markers.forEach((marker) => {
switch (marker.severity) {
case Severity.Error:
errors++;
return;
case Severity.Warning:
warnings++;
return;
case Severity.Info:
infos++;
return;
default:
unknowns++;
return;
}
});
return {errors: errors, warnings: warnings, infos: infos, unknwons: unknowns};
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册