提交 4cb9ee7f 编写于 作者: J Joao Moreno

Revert "LightUpdateContribution"

This reverts commit d310662a.

Revert "wip: update contribution 2"

This reverts commit 0722ad47.

Revert "wip: global update activity"

This reverts commit 3b769612.

Revert "wip: ViewletActivityAction in activity bar"

This reverts commit 95c23d21.
上级 eaa90930
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Registry } from 'vs/platform/platform';
import { IAction } from 'vs/base/common/actions';
import { IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation';
export interface IActivity {
id: string;
name: string;
cssClass: string;
}
export interface IGlobalActivity extends IActivity {
getActions(): IAction[];
}
export const GlobalActivityExtensions = 'workbench.contributions.globalActivities';
export interface IGlobalActivityRegistry {
registerActivity(descriptor: IConstructorSignature0<IGlobalActivity>): void;
getActivities(): IConstructorSignature0<IGlobalActivity>[];
}
export class GlobalActivityRegistry implements IGlobalActivityRegistry {
private activityDescriptors = new Set<IConstructorSignature0<IGlobalActivity>>();
registerActivity(descriptor: IConstructorSignature0<IGlobalActivity>): void {
this.activityDescriptors.add(descriptor);
}
getActivities(): IConstructorSignature0<IGlobalActivity>[] {
const result: IConstructorSignature0<IGlobalActivity>[] = [];
this.activityDescriptors.forEach(d => result.push(d));
return result;
}
}
Registry.add(GlobalActivityExtensions, new GlobalActivityRegistry());
\ No newline at end of file
......@@ -13,14 +13,13 @@ import { Builder, $ } from 'vs/base/browser/builder';
import { DelayedDragHandler } from 'vs/base/browser/dnd';
import { Action } from 'vs/base/common/actions';
import { BaseActionItem, Separator, IBaseActionItemOptions } from 'vs/base/browser/ui/actionbar/actionbar';
import { IActivityBarService, DotBadge, ProgressBadge, TextBadge, NumberBadge, IconBadge, IBadge } from 'vs/workbench/services/activity/common/activityBarService';
import { IActivityBarService, ProgressBadge, TextBadge, NumberBadge, IconBadge, IBadge } from 'vs/workbench/services/activity/common/activityBarService';
import Event, { Emitter } from 'vs/base/common/event';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { IActivity } from 'vs/workbench/browser/activity';
import { dispose } from 'vs/base/common/lifecycle';
import { IViewletService, } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IPartService, Parts } from 'vs/workbench/services/part/common/partService';
......@@ -32,12 +31,8 @@ export class ActivityAction extends Action {
private badge: IBadge;
private _onDidChangeBadge = new Emitter<this>();
get activity(): IActivity {
return this._activity;
}
constructor(private _activity: IActivity) {
super(_activity.id, _activity.name, _activity.cssClass);
constructor(id: string, name: string, clazz: string) {
super(id, name, clazz);
this.badge = null;
}
......@@ -79,7 +74,7 @@ export class ViewletActivityAction extends ActivityAction {
@IViewletService private viewletService: IViewletService,
@IPartService private partService: IPartService
) {
super(viewlet);
super(viewlet.id, viewlet.name, viewlet.cssClass);
}
public run(event): TPromise<any> {
......@@ -107,15 +102,7 @@ export class ViewletActivityAction extends ActivityAction {
}
}
export class ActivityActionItem extends BaseActionItem {
protected $label: Builder;
protected $badge: Builder;
private $badgeContent: Builder;
protected get activity(): IActivity {
return (this._action as ActivityAction).activity;
}
export abstract class ThemableActivityActionItem extends BaseActionItem {
constructor(
action: ActivityAction,
......@@ -125,133 +112,33 @@ export class ActivityActionItem extends BaseActionItem {
super(null, action, options);
this.themeService.onThemeChange(this.onThemeChange, this, this._callOnDispose);
action.onDidChangeBadge(this.handleBadgeChangeEvenet, this, this._callOnDispose);
}
protected updateStyles(): void {
const theme = this.themeService.getTheme();
// Label
if (this.$label) {
const background = theme.getColor(ACTIVITY_BAR_FOREGROUND);
this.$label.style('background-color', background ? background.toString() : null);
}
// Badge
if (this.$badgeContent) {
const badgeForeground = theme.getColor(ACTIVITY_BAR_BADGE_FOREGROUND);
const badgeBackground = theme.getColor(ACTIVITY_BAR_BADGE_BACKGROUND);
const contrastBorderColor = theme.getColor(contrastBorder);
this.$badgeContent.style('color', badgeForeground ? badgeForeground.toString() : null);
this.$badgeContent.style('background-color', badgeBackground ? badgeBackground.toString() : null);
this.$badgeContent.style('border-style', contrastBorderColor ? 'solid' : null);
this.$badgeContent.style('border-width', contrastBorderColor ? '1px' : null);
this.$badgeContent.style('border-color', contrastBorderColor ? contrastBorderColor.toString() : null);
}
}
public render(container: HTMLElement): void {
super.render(container);
container.title = this.activity.name;
// Label
this.$label = $('a.action-label').appendTo(this.builder);
if (this.activity.cssClass) {
this.$label.addClass(this.activity.cssClass);
}
this.$badge = this.builder.clone().div({ 'class': 'badge' }, (badge: Builder) => {
this.$badgeContent = badge.div({ 'class': 'badge-content' });
});
this.$badge.hide();
this.updateStyles();
}
private onThemeChange(theme: ITheme): void {
this.updateStyles();
}
public setBadge(badge: IBadge): void {
this.updateBadge(badge);
}
protected updateBadge(badge: IBadge): void {
this.$badgeContent.empty();
this.$badge.hide();
if (badge) {
// Number
if (badge instanceof NumberBadge) {
if (badge.number) {
this.$badgeContent.text(badge.number > 99 ? '99+' : badge.number.toString());
this.$badge.show();
}
}
// Text
else if (badge instanceof TextBadge) {
this.$badgeContent.text(badge.text);
this.$badge.show();
}
// Text
else if (badge instanceof IconBadge) {
this.$badge.show();
}
// Dot
else if (badge instanceof DotBadge) {
this.$badge.addClass('dot-badge');
this.$badge.title(badge.getDescription());
this.$badge.show();
}
// Progress
else if (badge instanceof ProgressBadge) {
this.$badge.show();
}
this.$label.attr('aria-label', `${this.activity.name} - ${badge.getDescription()}`);
}
}
private handleBadgeChangeEvenet(): void {
const action = this.getAction();
if (action instanceof ActivityAction) {
this.updateBadge(action.getBadge());
}
}
public dispose(): void {
super.dispose();
this.$badge.destroy();
}
protected abstract updateStyles(): void;
}
export class ViewletActionItem extends ActivityActionItem {
export class ActivityActionItem extends ThemableActivityActionItem {
private static manageExtensionAction: ManageExtensionAction;
private static toggleViewletPinnedAction: ToggleViewletPinnedAction;
private static draggedViewlet: ViewletDescriptor;
private $container: Builder;
private $label: Builder;
private name: string;
private _keybinding: string;
private cssClass: string;
private $badge: Builder;
private $badgeContent: Builder;
private mouseUpTimeout: number;
private get viewlet(): ViewletDescriptor {
return this.action.activity as ViewletDescriptor;
}
constructor(
private action: ViewletActivityAction,
action: ActivityAction,
private viewlet: ViewletDescriptor,
@IContextMenuService private contextMenuService: IContextMenuService,
@IActivityBarService private activityBarService: IActivityBarService,
@IKeybindingService private keybindingService: IKeybindingService,
......@@ -261,14 +148,42 @@ export class ViewletActionItem extends ActivityActionItem {
super(action, { draggable: true }, themeService);
this.cssClass = action.class;
this._keybinding = this.getKeybindingLabel(this.viewlet.id);
this.name = viewlet.name;
this._keybinding = this.getKeybindingLabel(viewlet.id);
if (!ViewletActionItem.manageExtensionAction) {
ViewletActionItem.manageExtensionAction = instantiationService.createInstance(ManageExtensionAction);
if (!ActivityActionItem.manageExtensionAction) {
ActivityActionItem.manageExtensionAction = instantiationService.createInstance(ManageExtensionAction);
}
if (!ViewletActionItem.toggleViewletPinnedAction) {
ViewletActionItem.toggleViewletPinnedAction = instantiationService.createInstance(ToggleViewletPinnedAction, void 0);
if (!ActivityActionItem.toggleViewletPinnedAction) {
ActivityActionItem.toggleViewletPinnedAction = instantiationService.createInstance(ToggleViewletPinnedAction, void 0);
}
action.onDidChangeBadge(this.handleBadgeChangeEvenet, this, this._callOnDispose);
}
protected updateStyles(): void {
const theme = this.themeService.getTheme();
// Label
if (this.$label) {
const background = theme.getColor(ACTIVITY_BAR_FOREGROUND);
this.$label.style('background-color', background ? background.toString() : null);
}
// Badge
if (this.$badgeContent) {
const badgeForeground = theme.getColor(ACTIVITY_BAR_BADGE_FOREGROUND);
const badgeBackground = theme.getColor(ACTIVITY_BAR_BADGE_BACKGROUND);
const contrastBorderColor = theme.getColor(contrastBorder);
this.$badgeContent.style('color', badgeForeground ? badgeForeground.toString() : null);
this.$badgeContent.style('background-color', badgeBackground ? badgeBackground.toString() : null);
this.$badgeContent.style('border-style', contrastBorderColor ? 'solid' : null);
this.$badgeContent.style('border-width', contrastBorderColor ? '1px' : null);
this.$badgeContent.style('border-color', contrastBorderColor ? contrastBorderColor.toString() : null);
}
}
......@@ -325,7 +240,7 @@ export class ViewletActionItem extends ActivityActionItem {
// Drag enter
let counter = 0; // see https://github.com/Microsoft/vscode/issues/14470
this.$container.on(DOM.EventType.DRAG_ENTER, (e: DragEvent) => {
const draggedViewlet = ViewletActionItem.getDraggedViewlet();
const draggedViewlet = ActivityActionItem.getDraggedViewlet();
if (draggedViewlet && draggedViewlet.id !== this.viewlet.id) {
counter++;
this.updateFromDragging(container, true);
......@@ -334,7 +249,7 @@ export class ViewletActionItem extends ActivityActionItem {
// Drag leave
this.$container.on(DOM.EventType.DRAG_LEAVE, (e: DragEvent) => {
const draggedViewlet = ViewletActionItem.getDraggedViewlet();
const draggedViewlet = ActivityActionItem.getDraggedViewlet();
if (draggedViewlet) {
counter--;
if (counter === 0) {
......@@ -345,12 +260,12 @@ export class ViewletActionItem extends ActivityActionItem {
// Drag end
this.$container.on(DOM.EventType.DRAG_END, (e: DragEvent) => {
const draggedViewlet = ViewletActionItem.getDraggedViewlet();
const draggedViewlet = ActivityActionItem.getDraggedViewlet();
if (draggedViewlet) {
counter = 0;
this.updateFromDragging(container, false);
ViewletActionItem.clearDraggedViewlet();
ActivityActionItem.clearDraggedViewlet();
}
});
......@@ -358,21 +273,34 @@ export class ViewletActionItem extends ActivityActionItem {
this.$container.on(DOM.EventType.DROP, (e: DragEvent) => {
DOM.EventHelper.stop(e, true);
const draggedViewlet = ViewletActionItem.getDraggedViewlet();
const draggedViewlet = ActivityActionItem.getDraggedViewlet();
if (draggedViewlet && draggedViewlet.id !== this.viewlet.id) {
this.updateFromDragging(container, false);
ViewletActionItem.clearDraggedViewlet();
ActivityActionItem.clearDraggedViewlet();
this.activityBarService.move(draggedViewlet.id, this.viewlet.id);
}
});
// Label
this.$label = $('a.action-label').appendTo(this.builder);
if (this.cssClass) {
this.$label.addClass(this.cssClass);
}
// Badge
this.$badge = this.builder.div({ 'class': 'badge' }, (badge: Builder) => {
this.$badgeContent = badge.div({ 'class': 'badge-content' });
});
this.$badge.hide();
// 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) {
if (!ActivityActionItem.getDraggedViewlet() && !this.getAction().checked) {
this.getAction().run();
}
}));
......@@ -388,29 +316,29 @@ export class ViewletActionItem extends ActivityActionItem {
}
public static getDraggedViewlet(): ViewletDescriptor {
return ViewletActionItem.draggedViewlet;
return ActivityActionItem.draggedViewlet;
}
private setDraggedViewlet(viewlet: ViewletDescriptor): void {
ViewletActionItem.draggedViewlet = viewlet;
ActivityActionItem.draggedViewlet = viewlet;
}
public static clearDraggedViewlet(): void {
ViewletActionItem.draggedViewlet = void 0;
ActivityActionItem.draggedViewlet = void 0;
}
private showContextMenu(container: HTMLElement): void {
const actions: Action[] = [ViewletActionItem.toggleViewletPinnedAction];
const actions: Action[] = [ActivityActionItem.toggleViewletPinnedAction];
if (this.viewlet.extensionId) {
actions.push(new Separator());
actions.push(ViewletActionItem.manageExtensionAction);
actions.push(ActivityActionItem.manageExtensionAction);
}
const isPinned = this.activityBarService.isPinned(this.viewlet.id);
if (isPinned) {
ViewletActionItem.toggleViewletPinnedAction.label = nls.localize('removeFromActivityBar', "Remove from Activity Bar");
ActivityActionItem.toggleViewletPinnedAction.label = nls.localize('removeFromActivityBar', "Remove from Activity Bar");
} else {
ViewletActionItem.toggleViewletPinnedAction.label = nls.localize('keepInActivityBar', "Keep in Activity Bar");
ActivityActionItem.toggleViewletPinnedAction.label = nls.localize('keepInActivityBar', "Keep in Activity Bar");
}
this.contextMenuService.showContextMenu({
......@@ -424,6 +352,10 @@ export class ViewletActionItem extends ActivityActionItem {
this.$container.domFocus();
}
public setBadge(badge: IBadge): void {
this.updateBadge(badge);
}
public set keybinding(keybinding: string) {
this._keybinding = keybinding;
......@@ -433,15 +365,49 @@ export class ViewletActionItem extends ActivityActionItem {
let title: string;
if (keybinding) {
title = nls.localize('titleKeybinding', "{0} ({1})", this.activity.name, keybinding);
title = nls.localize('titleKeybinding', "{0} ({1})", this.name, keybinding);
} else {
title = this.activity.name;
title = this.name;
}
this.$label.title(title);
this.$badge.title(title);
}
private updateBadge(badge: IBadge): void {
this.$badgeContent.empty();
this.$badge.hide();
if (badge) {
// Number
if (badge instanceof NumberBadge) {
if (badge.number) {
this.$badgeContent.text(badge.number > 99 ? '99+' : badge.number.toString());
this.$badge.show();
}
}
// Text
else if (badge instanceof TextBadge) {
this.$badgeContent.text(badge.text);
this.$badge.show();
}
// Text
else if (badge instanceof IconBadge) {
this.$badge.show();
}
// Progress
else if (badge instanceof ProgressBadge) {
this.$badge.show();
}
this.$label.attr('aria-label', `${this.name} - ${badge.getDescription()}`);
}
}
protected _updateClass(): void {
if (this.cssClass) {
this.$badge.removeClass(this.cssClass);
......@@ -459,6 +425,13 @@ export class ViewletActionItem extends ActivityActionItem {
}
}
private handleBadgeChangeEvenet(): void {
const action = this.getAction();
if (action instanceof ActivityAction) {
this.updateBadge(action.getBadge());
}
}
protected _updateEnabled(): void {
if (this.getAction().enabled) {
this.builder.removeClass('disabled');
......@@ -470,12 +443,13 @@ export class ViewletActionItem extends ActivityActionItem {
public dispose(): void {
super.dispose();
ViewletActionItem.clearDraggedViewlet();
ActivityActionItem.clearDraggedViewlet();
if (this.mouseUpTimeout) {
clearTimeout(this.mouseUpTimeout);
}
this.$badge.destroy();
this.$label.destroy();
}
}
......@@ -485,11 +459,7 @@ export class ViewletOverflowActivityAction extends ActivityAction {
constructor(
private showMenu: () => void
) {
super({
id: 'activitybar.additionalViewlets.action',
name: nls.localize('additionalViews', "Additional Views"),
cssClass: 'toggle-more'
});
super('activitybar.additionalViewlets.action', nls.localize('additionalViews', "Additional Views"), 'toggle-more');
}
public run(event): TPromise<any> {
......@@ -499,8 +469,8 @@ export class ViewletOverflowActivityAction extends ActivityAction {
}
}
export class ViewletOverflowActivityActionItem extends ActivityActionItem {
export class ViewletOverflowActivityActionItem extends ThemableActivityActionItem {
private $label: Builder;
private name: string;
private cssClass: string;
private actions: OpenViewletAction[];
......
......@@ -13,13 +13,11 @@ import * as arrays from 'vs/base/common/arrays';
import { illegalArgument } from 'vs/base/common/errors';
import { Builder, $, Dimension } from 'vs/base/browser/builder';
import { Action } from 'vs/base/common/actions';
import { ActionsOrientation, ActionBar, IActionItem, Separator, IBaseActionItemOptions } from 'vs/base/browser/ui/actionbar/actionbar';
import { ActionsOrientation, ActionBar, IActionItem, Separator } from 'vs/base/browser/ui/actionbar/actionbar';
import { ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { IGlobalActivity, GlobalActivityExtensions, IGlobalActivityRegistry } from 'vs/workbench/browser/activity';
import { Registry } from 'vs/platform/platform';
import { Part } from 'vs/workbench/browser/part';
import { IViewlet } from 'vs/workbench/common/viewlet';
import { ToggleViewletPinnedAction, ViewletActivityAction, ActivityAction, ActivityActionItem, ViewletActionItem, ViewletOverflowActivityAction, ViewletOverflowActivityActionItem } from 'vs/workbench/browser/parts/activitybar/activitybarActions';
import { ToggleViewletPinnedAction, ViewletActivityAction, ActivityAction, ActivityActionItem, ViewletOverflowActivityAction, ViewletOverflowActivityActionItem } from 'vs/workbench/browser/parts/activitybar/activitybarActions';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IActivityBarService, IBadge } from 'vs/workbench/services/activity/common/activityBarService';
import { IPartService, Position as SideBarPosition } from 'vs/workbench/services/part/common/partService';
......@@ -29,7 +27,7 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
import { Scope as MementoScope } from 'vs/workbench/common/memento';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { StandardMouseEvent } from 'vs/base/browser/mouseEvent';
import { dispose, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { ToggleActivityBarVisibilityAction } from 'vs/workbench/browser/actions/toggleActivityBarVisibility';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ACTIVITY_BAR_BACKGROUND, ACTIVITY_BAR_BORDER } from 'vs/workbench/common/theme';
......@@ -40,41 +38,6 @@ interface IViewletActivity {
clazz: string;
}
class GlobalActivityAction extends ActivityAction {
constructor(activity: IGlobalActivity) {
super(activity);
}
}
class GlobalActivityActionItem extends ActivityActionItem {
constructor(
action: GlobalActivityAction,
options: IBaseActionItemOptions,
@IThemeService themeService: IThemeService,
@IContextMenuService protected contextMenuService: IContextMenuService
) {
super(action, options, themeService);
}
onClick(e: MouseEvent): void {
const globalAction = this._action as GlobalActivityAction;
const activity = globalAction.activity as IGlobalActivity;
const actions = activity.getActions();
const event = new StandardMouseEvent(e);
event.stopPropagation();
event.preventDefault();
this.contextMenuService.showContextMenu({
getAnchor: () => ({ x: event.posx, y: event.posy }),
getActions: () => TPromise.as(actions),
onHide: () => dispose(actions)
});
}
}
export class ActivitybarPart extends Part implements IActivityBarService {
private static readonly ACTIVITY_ACTION_HEIGHT = 50;
......@@ -85,11 +48,9 @@ export class ActivitybarPart extends Part implements IActivityBarService {
private dimension: Dimension;
private viewletSwitcherBar: ActionBar;
private activityActionBar: ActionBar;
private viewletOverflowAction: ViewletOverflowActivityAction;
private viewletOverflowActionItem: ViewletOverflowActivityActionItem;
private globalActivityIdToActions: { [globalActivityId: string]: GlobalActivityAction; };
private viewletIdToActions: { [viewletId: string]: ActivityAction; };
private viewletIdToActionItems: { [viewletId: string]: IActionItem; };
private viewletIdToActivityStack: { [viewletId: string]: IViewletActivity[]; };
......@@ -110,7 +71,6 @@ export class ActivitybarPart extends Part implements IActivityBarService {
) {
super(id, { hasTitle: false }, themeService);
this.globalActivityIdToActions = Object.create(null);
this.viewletIdToActionItems = Object.create(null);
this.viewletIdToActions = Object.create(null);
this.viewletIdToActivityStack = Object.create(null);
......@@ -163,21 +123,6 @@ export class ActivitybarPart extends Part implements IActivityBarService {
}
}
public showGlobalActivity(globalActivityId: string, badge: IBadge): IDisposable {
if (!badge) {
throw illegalArgument('badge');
}
const action = this.globalActivityIdToActions[globalActivityId];
if (!action) {
throw illegalArgument('globalActivityId');
}
action.setBadge(badge);
return toDisposable(() => action.setBadge(undefined));
}
public showActivity(viewletId: string, badge: IBadge, clazz?: string): IDisposable {
if (!badge) {
throw illegalArgument('badge');
......@@ -235,9 +180,6 @@ export class ActivitybarPart extends Part implements IActivityBarService {
// Top Actionbar with action items for each viewlet action
this.createViewletSwitcher($result.clone());
// Top Actionbar with action items for each viewlet action
this.createGlobalActivityActionBar($result.getHTMLElement());
// Contextmenu for viewlets
$(parent).on('contextmenu', (e: MouseEvent) => {
DOM.EventHelper.stop(e, true);
......@@ -247,11 +189,11 @@ export class ActivitybarPart extends Part implements IActivityBarService {
// Allow to drop at the end to move viewlet to the end
$(parent).on(DOM.EventType.DROP, (e: DragEvent) => {
const draggedViewlet = ViewletActionItem.getDraggedViewlet();
const draggedViewlet = ActivityActionItem.getDraggedViewlet();
if (draggedViewlet) {
DOM.EventHelper.stop(e, true);
ViewletActionItem.clearDraggedViewlet();
ActivityActionItem.clearDraggedViewlet();
const targetId = this.pinnedViewlets[this.pinnedViewlets.length - 1];
if (targetId !== draggedViewlet.id) {
......@@ -310,26 +252,6 @@ export class ActivitybarPart extends Part implements IActivityBarService {
this.extensionService.onReady().then(() => this.updateViewletSwitcher());
}
private createGlobalActivityActionBar(container: HTMLElement): void {
const activityRegistry = Registry.as<IGlobalActivityRegistry>(GlobalActivityExtensions);
const descriptors = activityRegistry.getActivities();
const actions = descriptors
.map(d => this.instantiationService.createInstance(d))
.map(a => new GlobalActivityAction(a));
this.activityActionBar = new ActionBar(container, {
actionItemProvider: a => this.instantiationService.createInstance(GlobalActivityActionItem, a),
orientation: ActionsOrientation.VERTICAL,
ariaLabel: nls.localize('globalActions', "Global Actions"),
animated: false
});
actions.forEach(a => {
this.globalActivityIdToActions[a.id] = a;
this.activityActionBar.push(a);
});
}
private updateViewletSwitcher() {
let viewletsToShow = this.getPinnedViewlets();
......@@ -449,7 +371,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
private toAction(viewlet: ViewletDescriptor): ActivityAction {
const action = this.instantiationService.createInstance(ViewletActivityAction, viewlet);
this.viewletIdToActionItems[action.id] = this.instantiationService.createInstance(ViewletActionItem, action);
this.viewletIdToActionItems[action.id] = this.instantiationService.createInstance(ActivityActionItem, action, viewlet);
this.viewletIdToActions[viewlet.id] = action;
return action;
......
......@@ -67,16 +67,6 @@
text-align: center;
}
.monaco-workbench > .activitybar > .content .monaco-action-bar .badge.dot-badge .badge-content {
box-sizing: border-box;
content: '';
top: 9px;
width: 11px;
height: 11px;
min-width: inherit;
padding: 0;
}
/* Right aligned */
.monaco-workbench > .activitybar.right > .content .monaco-action-bar .action-label {
......
......@@ -9,9 +9,6 @@
.monaco-workbench > .activitybar > .content {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.monaco-workbench > .activitybar > .content .monaco-action-bar {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.update-activity {
-webkit-mask: url('update.svg') no-repeat 50% 50%;
-webkit-mask-size: 22px;
}
\ No newline at end of file
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 260 260">
<path fill="#fff" d="M194 2L92.4 103.6 27.6 53.2 2 66v128l25.6 12.8 64.8-50.4L194 258l64-25.6V27.6L194 2zM27 169V91l39 39-39 39zm99.4-39L194 77v106l-67.6-53z" class="st0"/>
</svg>
......@@ -6,31 +6,20 @@
'use strict';
import * as nls from 'vs/nls';
import 'vs/css!./media/update.contribution';
import { Registry } from 'vs/platform/platform';
import { isMacintosh } from 'vs/base/common/platform';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { ShowCurrentReleaseNotesAction, UpdateContribution } from 'vs/workbench/parts/update/electron-browser/update';
import { ReleaseNotesEditor } from 'vs/workbench/parts/update/electron-browser/releaseNotesEditor';
import { ReleaseNotesInput } from 'vs/workbench/parts/update/electron-browser/releaseNotesInput';
import { EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { IGlobalActivityRegistry, GlobalActivityExtensions } from 'vs/workbench/browser/activity';
import { IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/common/editor';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import { ShowCurrentReleaseNotesAction, ProductContribution, UpdateContribution, LightUpdateContribution } from './update';
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(ProductContribution);
if (isMacintosh) {
Registry.as<IGlobalActivityRegistry>(GlobalActivityExtensions)
.registerActivity(LightUpdateContribution);
} else {
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(UpdateContribution);
}
.registerWorkbenchContribution(UpdateContribution);
// Editor
const editorDescriptor = new EditorDescriptor(
......@@ -46,6 +35,7 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors)
Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions)
.registerWorkbenchAction(new SyncActionDescriptor(ShowCurrentReleaseNotesAction, ShowCurrentReleaseNotesAction.ID, ShowCurrentReleaseNotesAction.LABEL), 'Open Release Notes');
// Configuration: Update
const configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigurationExtensions.Configuration);
configurationRegistry.registerConfiguration({
......
......@@ -8,25 +8,22 @@
import nls = require('vs/nls');
import severity from 'vs/base/common/severity';
import { TPromise } from 'vs/base/common/winjs.base';
import { IAction, Action } from 'vs/base/common/actions';
import { Action } from 'vs/base/common/actions';
import { IMessageService, CloseAction, Severity } from 'vs/platform/message/common/message';
import pkg from 'vs/platform/node/package';
import product from 'vs/platform/node/product';
import URI from 'vs/base/common/uri';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IActivityBarService, DotBadge } from 'vs/workbench/services/activity/common/activityBarService';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ReleaseNotesInput } from 'vs/workbench/parts/update/electron-browser/releaseNotesInput';
import { IGlobalActivity } from 'vs/workbench/browser/activity';
import { IRequestService } from 'vs/platform/request/node/request';
import { asText } from 'vs/base/node/request';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { KeybindingIO } from 'vs/workbench/services/keybinding/common/keybindingIO';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IUpdateService, State as UpdateState } from 'vs/platform/update/common/update';
import { IUpdateService } from 'vs/platform/update/common/update';
import * as semver from 'semver';
import { OS } from 'vs/base/common/platform';
......@@ -192,22 +189,24 @@ const LinkAction = (id: string, message: string, licenseUrl: string) => new Acti
() => { window.open(licenseUrl); return TPromise.as(null); }
);
export class ProductContribution implements IWorkbenchContribution {
export class UpdateContribution implements IWorkbenchContribution {
private static KEY = 'releaseNotes/lastVersion';
getId() { return 'vs.product'; }
getId() { return 'vs.update'; }
constructor(
@IStorageService storageService: IStorageService,
@IInstantiationService instantiationService: IInstantiationService,
@IMessageService messageService: IMessageService,
@IUpdateService updateService: IUpdateService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService
) {
const lastVersion = storageService.get(ProductContribution.KEY, StorageScope.GLOBAL, '');
const lastVersion = storageService.get(UpdateContribution.KEY, StorageScope.GLOBAL, '');
// was there an update? if so, open release notes
// was there an update?
if (product.releaseNotesUrl && lastVersion && pkg.version !== lastVersion) {
instantiationService.invokeFunction(loadReleaseNotes, pkg.version).then(
instantiationService.invokeFunction(loadReleaseNotes, pkg.version)
.then(
text => editorService.openEditor(instantiationService.createInstance(ReleaseNotesInput, pkg.version, text), { pinned: true }),
() => {
messageService.show(Severity.Info, {
......@@ -231,19 +230,8 @@ export class ProductContribution implements IWorkbenchContribution {
});
}
storageService.store(ProductContribution.KEY, pkg.version, StorageScope.GLOBAL);
}
}
export class UpdateContribution implements IWorkbenchContribution {
getId() { return 'vs.update'; }
storageService.store(UpdateContribution.KEY, pkg.version, StorageScope.GLOBAL);
constructor(
@IInstantiationService instantiationService: IInstantiationService,
@IMessageService messageService: IMessageService,
@IUpdateService updateService: IUpdateService
) {
updateService.onUpdateReady(update => {
const applyUpdateAction = instantiationService.createInstance(ApplyUpdateAction);
const releaseNotesAction = instantiationService.createInstance(ShowReleaseNotesAction, false, update.version);
......@@ -274,51 +262,4 @@ export class UpdateContribution implements IWorkbenchContribution {
updateService.onError(err => messageService.show(severity.Error, err));
}
}
export class LightUpdateContribution implements IGlobalActivity {
get id() { return 'vs.update'; }
get name() { return 'VS Code'; }
get cssClass() { return 'update-activity'; }
constructor(
@IStorageService storageService: IStorageService,
@ICommandService private commandService: ICommandService,
@IInstantiationService instantiationService: IInstantiationService,
@IMessageService messageService: IMessageService,
@IUpdateService private updateService: IUpdateService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IActivityBarService activityBarService: IActivityBarService
) {
this.updateService.onUpdateReady(() => {
const badge = new DotBadge(() => nls.localize('updateIsReady', "New update available."));
activityBarService.showGlobalActivity(this.id, badge);
});
this.updateService.onError(err => messageService.show(severity.Error, err));
}
getActions(): IAction[] {
switch (this.updateService.state) {
case UpdateState.Uninitialized:
return [new Action('update.notavailable', nls.localize('not available', "Updates Not Available"), undefined, false)];
case UpdateState.CheckingForUpdate:
return [new Action('update.checking', nls.localize('checkingForUpdates', "Checking For Updates..."), undefined, false)];
case UpdateState.UpdateAvailable:
return [new Action('update.installing', nls.localize('installingUpdate', "Installing Update..."), undefined, false)];
case UpdateState.UpdateDownloaded:
return [new Action('update.restart', nls.localize('restartToUpdate', "Restart To Update..."), undefined, true, () =>
this.updateService.quitAndInstall()
)];
default:
return [new Action('update.check', nls.localize('checkForUpdates', "Check For Updates..."), undefined, this.updateService.state === UpdateState.Idle, () =>
this.updateService.checkForUpdates(true)
)];
}
}
}
\ No newline at end of file
......@@ -24,8 +24,6 @@ export class BaseBadge implements IBadge {
}
}
export class DotBadge extends BaseBadge { }
export class NumberBadge extends BaseBadge {
public number: number;
......@@ -65,11 +63,6 @@ export const IActivityBarService = createDecorator<IActivityBarService>('activit
export interface IActivityBarService {
_serviceBrand: any;
/**
* Show activity in the activitybar for the given global activity.
*/
showGlobalActivity(globalActivityId: string, badge: IBadge): IDisposable;
/**
* Show activity in the activitybar for the given viewlet.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册