mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-08 15:55:15 +01:00
activityService.showViewActivity
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
|
||||
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { MarkersModel, compareMarkersByUri } from './markersModel';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { Disposable, MutableDisposable, IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IMarkerService, MarkerSeverity, IMarker } from 'vs/platform/markers/common/markers';
|
||||
import { NumberBadge, ViewContaierActivityByView } from 'vs/workbench/services/activity/common/activity';
|
||||
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
|
||||
import { localize } from 'vs/nls';
|
||||
import Constants from './constants';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
@@ -55,22 +55,21 @@ export class MarkersWorkbenchService extends Disposable implements IMarkersWorkb
|
||||
|
||||
export class ActivityUpdater extends Disposable implements IWorkbenchContribution {
|
||||
|
||||
private readonly activity: ViewContaierActivityByView;
|
||||
private readonly activity = this._register(new MutableDisposable<IDisposable>());
|
||||
|
||||
constructor(
|
||||
@IInstantiationService instantiationService: IInstantiationService,
|
||||
@IActivityService private readonly activityService: IActivityService,
|
||||
@IMarkerService private readonly markerService: IMarkerService
|
||||
) {
|
||||
super();
|
||||
this.activity = this._register(instantiationService.createInstance(ViewContaierActivityByView, Constants.MARKERS_VIEW_ID));
|
||||
this._register(this.markerService.onMarkerChanged(() => this.updateActivity()));
|
||||
this.updateActivity();
|
||||
this._register(this.markerService.onMarkerChanged(() => this.updateBadge()));
|
||||
this.updateBadge();
|
||||
}
|
||||
|
||||
private updateActivity(): void {
|
||||
private updateBadge(): void {
|
||||
const { errors, warnings, infos } = this.markerService.getStatistics();
|
||||
const total = errors + warnings + infos;
|
||||
const message = localize('totalProblems', 'Total {0} Problems', total);
|
||||
this.activity.setActivity({ badge: new NumberBadge(total, () => message) });
|
||||
this.activity.value = this.activityService.showViewActivity(Constants.MARKERS_VIEW_ID, { badge: new NumberBadge(total, () => message) });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,20 +5,68 @@
|
||||
|
||||
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
|
||||
import { IActivityService, IActivity } from 'vs/workbench/services/activity/common/activity';
|
||||
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, Disposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IActivityBarService } from 'vs/workbench/services/activityBar/browser/activityBarService';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/common/views';
|
||||
import { GLOBAL_ACTIVITY_ID, ACCOUNTS_ACTIIVTY_ID } from 'vs/workbench/common/activity';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
class ViewContainerActivityByView extends Disposable {
|
||||
|
||||
private activity: IActivity | undefined = undefined;
|
||||
private activityDisposable: IDisposable = Disposable.None;
|
||||
|
||||
constructor(
|
||||
private readonly viewId: string,
|
||||
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService,
|
||||
@IActivityService private readonly activityService: IActivityService,
|
||||
) {
|
||||
super();
|
||||
this._register(Event.filter(this.viewDescriptorService.onDidChangeContainer, e => e.views.some(view => view.id === viewId))(() => this.update()));
|
||||
this._register(Event.filter(this.viewDescriptorService.onDidChangeLocation, e => e.views.some(view => view.id === viewId))(() => this.update()));
|
||||
}
|
||||
|
||||
setActivity(activity: IActivity): void {
|
||||
this.activity = activity;
|
||||
this.update();
|
||||
}
|
||||
|
||||
clearActivity(): void {
|
||||
this.activity = undefined;
|
||||
this.update();
|
||||
}
|
||||
|
||||
private update(): void {
|
||||
this.activityDisposable.dispose();
|
||||
const container = this.viewDescriptorService.getViewContainerByViewId(this.viewId);
|
||||
if (container && this.activity) {
|
||||
this.activityDisposable = this.activityService.showViewContainerActivity(container.id, this.activity);
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.activityDisposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
interface IViewActivity {
|
||||
id: number;
|
||||
readonly activity: ViewContainerActivityByView;
|
||||
}
|
||||
|
||||
export class ActivityService implements IActivityService {
|
||||
|
||||
public _serviceBrand: undefined;
|
||||
|
||||
private viewActivities = new Map<string, IViewActivity>();
|
||||
|
||||
constructor(
|
||||
@IPanelService private readonly panelService: IPanelService,
|
||||
@IActivityBarService private readonly activityBarService: IActivityBarService,
|
||||
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService,
|
||||
@IInstantiationService private readonly instantiationService: IInstantiationService
|
||||
) { }
|
||||
|
||||
showViewContainerActivity(viewContainerId: string, { badge, clazz, priority }: IActivity): IDisposable {
|
||||
@@ -35,6 +83,30 @@ export class ActivityService implements IActivityService {
|
||||
return Disposable.None;
|
||||
}
|
||||
|
||||
showViewActivity(viewId: string, activity: IActivity): IDisposable {
|
||||
let maybeItem = this.viewActivities.get(viewId);
|
||||
|
||||
if (maybeItem) {
|
||||
maybeItem.id++;
|
||||
} else {
|
||||
maybeItem = {
|
||||
id: 1,
|
||||
activity: this.instantiationService.createInstance(ViewContainerActivityByView, viewId)
|
||||
};
|
||||
}
|
||||
|
||||
const id = maybeItem.id;
|
||||
maybeItem.activity.setActivity(activity);
|
||||
|
||||
const item = maybeItem;
|
||||
return toDisposable(() => {
|
||||
if (item.id === id) {
|
||||
item.activity.dispose();
|
||||
this.viewActivities.delete(viewId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
showAccountsActivity({ badge, clazz, priority }: IActivity): IDisposable {
|
||||
return this.activityBarService.showActivity(ACCOUNTS_ACTIIVTY_ID, badge, clazz, priority);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IViewDescriptorService } from 'vs/workbench/common/views';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
|
||||
export interface IActivity {
|
||||
readonly badge: IBadge;
|
||||
@@ -25,6 +23,11 @@ export interface IActivityService {
|
||||
*/
|
||||
showViewContainerActivity(viewContainerId: string, badge: IActivity): IDisposable;
|
||||
|
||||
/**
|
||||
* Show activity for the given view
|
||||
*/
|
||||
showViewActivity(viewId: string, badge: IActivity): IDisposable;
|
||||
|
||||
/**
|
||||
* Show accounts activity
|
||||
*/
|
||||
@@ -36,39 +39,6 @@ export interface IActivityService {
|
||||
showGlobalActivity(activity: IActivity): IDisposable;
|
||||
}
|
||||
|
||||
export class ViewContaierActivityByView extends Disposable {
|
||||
|
||||
private activity: IActivity | undefined = undefined;
|
||||
private activityDisposable: IDisposable = Disposable.None;
|
||||
|
||||
constructor(
|
||||
private readonly viewId: string,
|
||||
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService,
|
||||
@IActivityService private readonly activityService: IActivityService,
|
||||
) {
|
||||
super();
|
||||
this._register(Event.filter(this.viewDescriptorService.onDidChangeContainer, e => e.views.some(view => view.id === viewId))(() => this.update()));
|
||||
this._register(Event.filter(this.viewDescriptorService.onDidChangeLocation, e => e.views.some(view => view.id === viewId))(() => this.update()));
|
||||
}
|
||||
|
||||
setActivity(activity: IActivity): void {
|
||||
this.activity = activity;
|
||||
this.update();
|
||||
}
|
||||
|
||||
private update(): void {
|
||||
this.activityDisposable.dispose();
|
||||
const container = this.viewDescriptorService.getViewContainerByViewId(this.viewId);
|
||||
if (container && this.activity) {
|
||||
this.activityDisposable = this.activityService.showViewContainerActivity(container.id, this.activity);
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.activityDisposable.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
export interface IBadge {
|
||||
getDescription(): string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user