Improve activity title behaviour

fixes #33540
fixes #27779
This commit is contained in:
Benjamin Pasero
2017-09-04 11:16:17 +02:00
parent cb5d03296f
commit 7712905526
3 changed files with 59 additions and 40 deletions
@@ -83,11 +83,15 @@ export class ViewletActivityAction extends ActivityAction {
private lastRun: number = 0;
constructor(
private viewlet: ViewletDescriptor,
private _viewlet: ViewletDescriptor,
@IViewletService private viewletService: IViewletService,
@IPartService private partService: IPartService
) {
super(viewlet);
super(_viewlet);
}
public get descriptor(): ViewletDescriptor {
return this._viewlet;
}
public run(event): TPromise<any> {
@@ -106,11 +110,11 @@ export class ViewletActivityAction extends ActivityAction {
const activeViewlet = this.viewletService.getActiveViewlet();
// Hide sidebar if selected viewlet already visible
if (sideBarVisible && activeViewlet && activeViewlet.getId() === this.viewlet.id) {
if (sideBarVisible && activeViewlet && activeViewlet.getId() === this._viewlet.id) {
return this.partService.setSideBarHidden(true);
}
return this.viewletService.openViewlet(this.viewlet.id, true)
return this.viewletService.openViewlet(this._viewlet.id, true)
.then(() => this.activate());
}
}
@@ -240,11 +244,22 @@ export class ActivityActionItem extends BaseActionItem {
else if (badge instanceof ProgressBadge) {
this.$badge.show();
}
const description = badge.getDescription();
this.$label.attr('aria-label', `${this.activity.name} - ${description}`);
this.$label.title(description);
}
// Title
let title: string;
if (badge && badge.getDescription()) {
title = `${this.activity.name} - ${badge.getDescription()}`;
} else {
title = this.activity.name;
}
[this.$label, this.$badge, this.$container].forEach(b => {
if (b) {
b.attr('aria-label', title);
b.title(title);
}
});
}
private handleBadgeChangeEvenet(): void {
@@ -271,7 +286,7 @@ export class ViewletActionItem extends ActivityActionItem {
private static toggleViewletPinnedAction: ToggleViewletPinnedAction;
private static draggedViewlet: ViewletDescriptor;
private _keybinding: string;
private viewletActivity: IActivity;
private cssClass: string;
constructor(
@@ -285,7 +300,6 @@ export class ViewletActionItem extends ActivityActionItem {
super(action, { draggable: true }, themeService);
this.cssClass = action.class;
this._keybinding = this.getKeybindingLabel(this.viewlet.id);
if (!ViewletActionItem.manageExtensionAction) {
ViewletActionItem.manageExtensionAction = instantiationService.createInstance(ManageExtensionAction);
@@ -296,8 +310,29 @@ export class ViewletActionItem extends ActivityActionItem {
}
}
protected get activity(): IActivity {
if (!this.viewletActivity) {
let activityName: string;
const keybinding = this.getKeybindingLabel(this.viewlet.id);
if (keybinding) {
activityName = nls.localize('titleKeybinding', "{0} ({1})", this.viewlet.name, keybinding);
} else {
activityName = this.viewlet.name;
}
this.viewletActivity = {
id: this.viewlet.id,
cssClass: this.cssClass,
name: activityName
};
}
return this.viewletActivity;
}
private get viewlet(): ViewletDescriptor {
return this.action.activity as ViewletDescriptor;
return this.action.descriptor;
}
private getKeybindingLabel(id: string): string {
@@ -374,9 +409,6 @@ export class ViewletActionItem extends ActivityActionItem {
}
});
// Keybinding
this.keybinding = this._keybinding; // force update
// Activate on drag over to reveal targets
[this.$badge, this.$label].forEach(b => new DelayedDragHandler(b.getHTMLElement(), () => {
if (!ViewletActionItem.getDraggedViewlet() && !this.getAction().checked) {
@@ -431,25 +463,6 @@ export class ViewletActionItem extends ActivityActionItem {
this.$container.domFocus();
}
public set keybinding(keybinding: string) {
this._keybinding = keybinding;
if (!this.$label) {
return;
}
let title: string;
if (keybinding) {
title = nls.localize('titleKeybinding', "{0} ({1})", this.activity.name, keybinding);
} else {
title = this.activity.name;
}
this.$label.title(title);
this.$badge.title(title);
this.$container.title(title);
}
protected _updateClass(): void {
if (this.cssClass) {
this.$badge.removeClass(this.cssClass);
@@ -156,14 +156,17 @@ export class ActivitybarPart extends Part implements IActivityBarService {
if (!stack) {
return;
}
const idx = stack.indexOf(activity);
if (idx < 0) {
return;
}
stack.splice(idx, 1);
if (stack.length === 0) {
delete this.viewletIdToActivityStack[viewletId];
}
this.updateActivity(viewletId);
}
};
@@ -174,13 +177,16 @@ export class ActivitybarPart extends Part implements IActivityBarService {
if (!action) {
return;
}
const stack = this.viewletIdToActivityStack[viewletId];
if (!stack || !stack.length) {
// reset
action.setBadge(undefined);
} else {
// update
const stack = this.viewletIdToActivityStack[viewletId];
// reset
if (!stack || !stack.length) {
action.setBadge(undefined);
}
// update
else {
const [{ badge, clazz }] = stack;
action.setBadge(badge);
if (clazz) {
@@ -141,7 +141,7 @@ export class DirtyFilesTracker implements IWorkbenchContribution {
this.lastDirtyCount = dirtyCount;
dispose(this.badgeHandle);
if (dirtyCount > 0) {
this.badgeHandle = this.activityBarService.showActivity(VIEWLET_ID, new NumberBadge(dirtyCount, num => nls.localize('dirtyFiles', "{0} unsaved files", dirtyCount)), 'explorer-viewlet-label');
this.badgeHandle = this.activityBarService.showActivity(VIEWLET_ID, new NumberBadge(dirtyCount, num => num === 1 ? nls.localize('dirtyFile', "1 unsaved file") : nls.localize('dirtyFiles', "{0} unsaved files", dirtyCount)), 'explorer-viewlet-label');
}
}