show badge for markers

This commit is contained in:
isidor
2016-09-23 17:55:39 +02:00
parent 09601caa09
commit 93e53de0f9
2 changed files with 71 additions and 7 deletions

View File

@@ -38,7 +38,7 @@ export class ActivitybarPart extends Part implements IActivityService {
private activityActionItems: { [actionId: string]: IActionItem; };
private compositeIdToActions: { [compositeId: string]: ActivityAction; };
private panelActions: ActivityAction[];
private showPanelAction: TogglePanelAction;
private togglePanelAction: TogglePanelAction;
constructor(
id: string,
@@ -95,6 +95,12 @@ export class ActivitybarPart extends Part implements IActivityService {
public showActivity(compositeId: string, badge: IBadge, clazz?: string): void {
const action = this.compositeIdToActions[compositeId];
if (action) {
if (action instanceof PanelActivityAction && this.partService.isPanelHidden()) {
// while the panel badges are hidden we show the badge on the parent action which is visible
this.togglePanelAction.setBadge(badge);
return;
}
action.setBadge(badge);
if (clazz) {
action.class = clazz;
@@ -148,8 +154,8 @@ export class ActivitybarPart extends Part implements IActivityService {
const allPanels = (<PanelRegistry>Registry.as(PanelExtensions.Panels)).getPanels();
this.showPanelAction = this.instantiationService.createInstance(TogglePanelAction, TogglePanelAction.ID, TogglePanelAction.LABEL);
this.activityActionItems[this.showPanelAction.id] = new ActivityActionItem(this.showPanelAction, TogglePanelAction.LABEL, this.getKeybindingLabel(TogglePanelAction.ID));
this.togglePanelAction = this.instantiationService.createInstance(TogglePanelAction, TogglePanelAction.ID, TogglePanelAction.LABEL);
this.activityActionItems[this.togglePanelAction.id] = new ActivityActionItem(this.togglePanelAction, TogglePanelAction.LABEL, this.getKeybindingLabel(TogglePanelAction.ID));
this.panelActions = allPanels.sort((p1, p2) => p1.order - p2.order).map(panel => this.toAction(panel));
// Add both viewlet and panel actions to the switcher
@@ -158,12 +164,25 @@ export class ActivitybarPart extends Part implements IActivityService {
private updatePanelSwitcher(): void {
this.panelSwitcherBar.clear();
const actions:ActivityAction[] = [this.showPanelAction];
const actions: ActivityAction[] = [this.togglePanelAction];
if (!this.partService.isPanelHidden()) {
actions.push(...this.panelActions);
}
this.panelSwitcherBar.push(actions, { label: true, icon: true });
// TODO@Isidor fix this aweful badge(r) hacks
if (!this.partService.isPanelHidden()) {
if (!this.panelActions[0].getBadge()) {
this.panelActions[0].setBadge(this.togglePanelAction.getBadge());
} else {
this.panelActions[0].setBadge(this.panelActions[0].getBadge());
}
this.togglePanelAction.setBadge(null);
} else {
this.togglePanelAction.setBadge(this.panelActions[0].getBadge());
this.panelActions[0].setBadge(null);
}
}
private toAction(composite: CompositeDescriptor<Viewlet | Panel>): ActivityAction {
@@ -203,8 +222,8 @@ export class ActivitybarPart extends Part implements IActivityService {
this.panelSwitcherBar = null;
}
if (this.showPanelAction) {
this.showPanelAction.dispose();
if (this.togglePanelAction) {
this.togglePanelAction.dispose();
}
super.dispose();

View File

@@ -3,16 +3,56 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import {localize} from 'vs/nls';
import lifecycle = require('vs/base/common/lifecycle');
import Messages from 'vs/workbench/parts/markers/common/messages';
import Constants from 'vs/workbench/parts/markers/common/constants';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import * as platform from 'vs/platform/platform';
import { IMarkerService } from 'vs/platform/markers/common/markers';
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activityService';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
import * as panel from 'vs/workbench/browser/panel';
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
import * as markersPanelActions from 'vs/workbench/parts/markers/browser/markersPanelActions';
class StatusUpdater implements IWorkbenchContribution
{
static ID = 'vs.markers.statusUpdater';
private toDispose: lifecycle.IDisposable[];
constructor(
@IMarkerService private markerService: IMarkerService,
@IActivityService private activityService: IActivityService
) {
this.toDispose = [];
this.toDispose.push(markerService.onMarkerChanged(() => this.updateActivityBadge());
}
private updateActivityBadge(): void {
const stats = this.markerService.getStatistics();
const problemCount = stats.errors + stats.warnings + stats.infos + stats.unknowns;
if (problemCount > 0) {
const badge = new NumberBadge(problemCount, n => localize('errorsAndWarnings', '{0} Errors and Warnings', n));
this.activityService.showActivity(Constants.MARKERS_PANEL_ID, badge);
} else {
this.activityService.showActivity(Constants.MARKERS_PANEL_ID, null);
}
}
public getId(): string {
return StatusUpdater.ID;
}
public dispose(): void {
this.toDispose = lifecycle.dispose(this.toDispose);
}
}
export function registerContributions(): void {
(<IConfigurationRegistry>platform.Registry.as(Extensions.Configuration)).registerConfiguration({
@@ -46,4 +86,9 @@ export function registerContributions(): void {
// Retaining old action to show errors and warnings, so that custom bindings to this action for existing users works.
registry.registerWorkbenchAction(new SyncActionDescriptor(markersPanelActions.ToggleErrorsAndWarningsAction, markersPanelActions.ToggleErrorsAndWarningsAction.ID, ''), Messages.SHOW_ERRORS_WARNINGS_ACTION_LABEL);
}
// Register StatusUpdater
(<IWorkbenchContributionsRegistry>platform.Registry.as(WorkbenchExtensions.Workbench)).registerWorkbenchContribution(
StatusUpdater
);
}