提交 abac09b4 编写于 作者: B Benjamin Pasero

debt - remove statusbar registry

上级 997ee7cf
......@@ -108,6 +108,10 @@ export class BaseDropdown extends ActionRunner {
this.visible = false;
}
isVisible(): boolean {
return this.visible;
}
protected onEvent(e: Event, activeElement: HTMLElement): void {
this.hide();
}
......
......@@ -75,26 +75,23 @@
padding-right: 10px;
}
.monaco-workbench .part.statusbar > .items-container > .statusbar-item a {
.monaco-workbench .part.statusbar > .items-container > .statusbar-item > a {
cursor: pointer;
display: inline-block;
height: 100%;
}
.monaco-workbench .part.statusbar > .items-container > .statusbar-entry > a {
padding: 0 5px 0 5px;
white-space: pre; /* gives some degree of styling */
}
.monaco-workbench .part.statusbar > .items-container > .statusbar-entry > a.disabled {
.monaco-workbench .part.statusbar > .items-container > .statusbar-item > a:hover {
text-decoration: none;
}
.monaco-workbench .part.statusbar > .items-container > .statusbar-item > a.disabled {
pointer-events: none;
}
.monaco-workbench .part.statusbar > .items-container > .statusbar-entry span.octicon {
.monaco-workbench .part.statusbar > .items-container > .statusbar-item span.octicon {
text-align: center;
font-size: 14px;
}
.monaco-workbench .part.statusbar > .items-container > .statusbar-item a:hover {
text-decoration: none;
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* 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/registry/common/platform';
import { IDisposable } from 'vs/base/common/lifecycle';
import { StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar';
import { SyncDescriptor0, createSyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation';
export interface IStatusbarItem {
render(element: HTMLElement): IDisposable;
}
export class StatusbarItemDescriptor {
readonly syncDescriptor: SyncDescriptor0<IStatusbarItem>;
readonly id: string;
readonly name: string;
readonly alignment: StatusbarAlignment;
readonly priority: number;
constructor(
ctor: IConstructorSignature0<IStatusbarItem>,
id: string,
name: string,
alignment?: StatusbarAlignment,
priority?: number
) {
this.id = id;
this.name = name;
this.syncDescriptor = createSyncDescriptor(ctor);
this.alignment = alignment || StatusbarAlignment.LEFT;
this.priority = priority || 0;
}
}
export interface IStatusbarRegistry {
readonly items: StatusbarItemDescriptor[];
registerStatusbarItem(descriptor: StatusbarItemDescriptor): void;
}
class StatusbarRegistry implements IStatusbarRegistry {
private readonly _items: StatusbarItemDescriptor[] = [];
get items(): StatusbarItemDescriptor[] { return this._items; }
registerStatusbarItem(descriptor: StatusbarItemDescriptor): void {
this._items.push(descriptor);
}
}
export const Extensions = {
Statusbar: 'workbench.contributions.statusbar'
};
Registry.add(Extensions.Statusbar, new StatusbarRegistry());
......@@ -8,11 +8,9 @@ import * as nls from 'vs/nls';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { dispose, IDisposable, Disposable, toDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { OcticonLabel } from 'vs/base/browser/ui/octiconLabel/octiconLabel';
import { Registry } from 'vs/platform/registry/common/platform';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { Part } from 'vs/workbench/browser/part';
import { IStatusbarRegistry, Extensions } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { IInstantiationService, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { StatusbarAlignment, IStatusbarService, IStatusbarEntry, IStatusbarEntryAccessor } from 'vs/platform/statusbar/common/statusbar';
......@@ -397,7 +395,7 @@ export class StatusbarPart extends Part implements IStatusbarService {
private doAddEntry(entry: IStatusbarEntry, id: string, name: string, alignment: StatusbarAlignment, priority: number): IStatusbarEntryAccessor {
// Create item
const itemContainer = this.doCreateStatusItem(id, name, alignment, priority, ...coalesce(['statusbar-entry', entry.showBeak ? 'has-beak' : undefined]));
const itemContainer = this.doCreateStatusItem(id, name, alignment, priority, ...coalesce([entry.showBeak ? 'has-beak' : undefined]));
const item = this.instantiationService.createInstance(StatusbarEntryItem, itemContainer, entry);
// Append to parent
......@@ -450,20 +448,6 @@ export class StatusbarPart extends Part implements IStatusbarService {
}
private createInitialStatusbarEntries(): void {
const registry = Registry.as<IStatusbarRegistry>(Extensions.Statusbar);
// Create initial items that were contributed from the registry
for (const { id, name, alignment, priority, syncDescriptor } of registry.items) {
// Create item
const item = this.instantiationService.createInstance(syncDescriptor);
const itemContainer = this.doCreateStatusItem(id, name, alignment, priority);
this._register(item.render(itemContainer));
// Add to view model
const viewModelEntry: IStatusbarViewModelEntry = { id, name, alignment, priority, container: itemContainer };
this.viewModel.add(viewModelEntry);
}
// Add items in order according to alignment
this.appendAllStatusbarEntries();
......
......@@ -4,16 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import { Registry } from 'vs/platform/registry/common/platform';
import { IStatusbarRegistry, Extensions, StatusbarItemDescriptor } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar';
import { FeedbackStatusbarItem } from 'vs/workbench/contrib/feedback/browser/feedbackStatusbarItem';
import { localize } from 'vs/nls';
import { FeedbackStatusbarConribution } from 'vs/workbench/contrib/feedback/browser/feedbackStatusbarItem';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
// Register Statusbar item
Registry.as<IStatusbarRegistry>(Extensions.Statusbar).registerStatusbarItem(new StatusbarItemDescriptor(
FeedbackStatusbarItem,
'status.feedback',
localize('status.feedback', "Tweet Feedback"),
StatusbarAlignment.RIGHT,
-100 /* towards the end of the right hand side */
));
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(FeedbackStatusbarConribution, LifecyclePhase.Starting);
\ No newline at end of file
......@@ -5,7 +5,7 @@
import 'vs/css!./media/feedback';
import * as nls from 'vs/nls';
import { IDisposable, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Dropdown } from 'vs/base/browser/ui/dropdown/dropdown';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import * as dom from 'vs/base/browser/dom';
......@@ -17,7 +17,6 @@ import { editorWidgetBackground, widgetShadow, inputBorder, inputForeground, inp
import { IAnchor } from 'vs/base/browser/ui/contextview/contextview';
import { Button } from 'vs/base/browser/ui/button/button';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { OcticonLabel } from 'vs/base/browser/ui/octiconLabel/octiconLabel';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { IProductService } from 'vs/platform/product/common/product';
......@@ -68,15 +67,7 @@ export class FeedbackDropdown extends Dropdown {
@IStatusbarService private readonly statusbarService: IStatusbarService,
@IProductService productService: IProductService
) {
super(container, {
contextViewProvider: options.contextViewProvider,
labelRenderer: (container: HTMLElement): IDisposable => {
const label = new OcticonLabel(container);
label.text = '$(smiley)';
return Disposable.None;
}
});
super(container, options);
this.feedbackDelegate = options.feedbackService;
this.maxFeedbackCharacters = this.feedbackDelegate.getCharacterLimit(this.sentiment);
......
......@@ -3,16 +3,15 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
import { Disposable } from 'vs/base/common/lifecycle';
import { FeedbackDropdown, IFeedback, IFeedbackDelegate } from 'vs/workbench/contrib/feedback/browser/feedback';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Themable, STATUS_BAR_ITEM_HOVER_BACKGROUND } from 'vs/workbench/common/theme';
import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { clearNode, EventHelper, addClass, removeClass, addDisposableListener } from 'vs/base/browser/dom';
import { IProductService } from 'vs/platform/product/common/product';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IStatusbarService, StatusbarAlignment, IStatusbarEntry, IStatusbarEntryAccessor } from 'vs/platform/statusbar/common/statusbar';
import { localize } from 'vs/nls';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
class TwitterFeedbackService implements IFeedbackDelegate {
......@@ -47,76 +46,50 @@ class TwitterFeedbackService implements IFeedbackDelegate {
}
}
export class FeedbackStatusbarItem extends Themable implements IStatusbarItem {
private dropdown: FeedbackDropdown | undefined;
private container: HTMLElement;
export class FeedbackStatusbarConribution extends Disposable implements IWorkbenchContribution {
private dropdown: FeedbackDropdown;
private entry: IStatusbarEntryAccessor;
constructor(
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IContextViewService private readonly contextViewService: IContextViewService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@IThemeService themeService: IThemeService,
@IProductService private productService: IProductService
@IStatusbarService statusbarService: IStatusbarService,
@IProductService productService: IProductService,
@IInstantiationService private instantiationService: IInstantiationService,
@IContextViewService private contextViewService: IContextViewService
) {
super(themeService);
super();
this.registerListeners();
}
private registerListeners(): void {
this._register(this.contextService.onDidChangeWorkbenchState(() => this.updateStyles()));
}
render(element: HTMLElement): IDisposable {
this.container = element;
if (productService.sendASmile) {
this.entry = this._register(statusbarService.addEntry(this.getStatusEntry(), 'status.feedback', localize('status.feedback', "Tweet Feedback"), StatusbarAlignment.RIGHT, -100 /* towards the end of the right hand side */));
// Prevent showing dropdown on anything but left click
this._register(addDisposableListener(this.container, 'mousedown', (e: MouseEvent) => {
if (e.button !== 0) {
EventHelper.stop(e, true);
}
}, true));
return this.update();
CommandsRegistry.registerCommand('_feedback.open', () => this.toggleFeedback());
}
}
private update(): IDisposable {
// Create
if (this.productService.sendASmile) {
if (!this.dropdown) {
this.dropdown = this._register(this.instantiationService.createInstance(FeedbackDropdown, this.container, {
private toggleFeedback(): void {
if (!this.dropdown) {
const statusContainr = document.getElementById('status.feedback');
if (statusContainr) {
this.dropdown = this._register(this.instantiationService.createInstance(FeedbackDropdown, statusContainr.getElementsByClassName('octicon').item(0), {
contextViewProvider: this.contextViewService,
feedbackService: this.instantiationService.createInstance(TwitterFeedbackService),
onFeedbackVisibilityChange: (visible: boolean) => {
if (visible) {
addClass(this.container, 'has-beak');
} else {
removeClass(this.container, 'has-beak');
}
}
onFeedbackVisibilityChange: visible => this.entry.update(this.getStatusEntry(visible))
}));
this.updateStyles();
return this.dropdown;
}
}
// Dispose
else {
dispose(this.dropdown);
this.dropdown = undefined;
clearNode(this.container);
if (!this.dropdown.isVisible()) {
this.dropdown.show();
} else {
this.dropdown.hide();
}
return Disposable.None;
}
}
registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
const statusBarItemHoverBackground = theme.getColor(STATUS_BAR_ITEM_HOVER_BACKGROUND);
if (statusBarItemHoverBackground) {
collector.addRule(`.monaco-workbench .part.statusbar > .items-container > .statusbar-item .monaco-dropdown.send-feedback:hover { background-color: ${statusBarItemHoverBackground}; }`);
private getStatusEntry(showBeak?: boolean): IStatusbarEntry {
return {
text: '$(smiley)',
command: '_feedback.open',
showBeak
};
}
});
}
\ No newline at end of file
......@@ -113,17 +113,6 @@
background-color: #eaeaea;
}
/* Statusbar */
.monaco-workbench .statusbar > .items-container > .statusbar-item > .monaco-dropdown.send-feedback {
display: inline-block;
padding: 0 5px 0 5px;
}
.monaco-workbench .statusbar > .items-container > .statusbar-item > .monaco-dropdown.send-feedback span.octicon {
text-align: center;
font-size: 14px;
}
/* Theming */
.vs .monaco-workbench .feedback-form .feedback-alias, .vs .monaco-workbench .feedback-form .feedback-description {
font-family: inherit;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册