Skip to content

Commit abac09b

Browse files
author
Benjamin Pasero
committed
debt - remove statusbar registry
1 parent 997ee7c commit abac09b

8 files changed

Lines changed: 53 additions & 182 deletions

File tree

src/vs/base/browser/ui/dropdown/dropdown.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export class BaseDropdown extends ActionRunner {
108108
this.visible = false;
109109
}
110110

111+
isVisible(): boolean {
112+
return this.visible;
113+
}
114+
111115
protected onEvent(e: Event, activeElement: HTMLElement): void {
112116
this.hide();
113117
}

src/vs/workbench/browser/parts/statusbar/media/statusbarpart.css

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,23 @@
7575
padding-right: 10px;
7676
}
7777

78-
.monaco-workbench .part.statusbar > .items-container > .statusbar-item a {
78+
.monaco-workbench .part.statusbar > .items-container > .statusbar-item > a {
7979
cursor: pointer;
8080
display: inline-block;
8181
height: 100%;
82-
}
83-
84-
.monaco-workbench .part.statusbar > .items-container > .statusbar-entry > a {
8582
padding: 0 5px 0 5px;
8683
white-space: pre; /* gives some degree of styling */
8784
}
8885

89-
.monaco-workbench .part.statusbar > .items-container > .statusbar-entry > a.disabled {
86+
.monaco-workbench .part.statusbar > .items-container > .statusbar-item > a:hover {
87+
text-decoration: none;
88+
}
89+
90+
.monaco-workbench .part.statusbar > .items-container > .statusbar-item > a.disabled {
9091
pointer-events: none;
9192
}
9293

93-
.monaco-workbench .part.statusbar > .items-container > .statusbar-entry span.octicon {
94+
.monaco-workbench .part.statusbar > .items-container > .statusbar-item span.octicon {
9495
text-align: center;
9596
font-size: 14px;
9697
}
97-
98-
.monaco-workbench .part.statusbar > .items-container > .statusbar-item a:hover {
99-
text-decoration: none;
100-
}

src/vs/workbench/browser/parts/statusbar/statusbar.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/vs/workbench/browser/parts/statusbar/statusbarPart.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import * as nls from 'vs/nls';
88
import { toErrorMessage } from 'vs/base/common/errorMessage';
99
import { dispose, IDisposable, Disposable, toDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
1010
import { OcticonLabel } from 'vs/base/browser/ui/octiconLabel/octiconLabel';
11-
import { Registry } from 'vs/platform/registry/common/platform';
1211
import { ICommandService } from 'vs/platform/commands/common/commands';
1312
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1413
import { Part } from 'vs/workbench/browser/part';
15-
import { IStatusbarRegistry, Extensions } from 'vs/workbench/browser/parts/statusbar/statusbar';
1614
import { IInstantiationService, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
1715
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1816
import { StatusbarAlignment, IStatusbarService, IStatusbarEntry, IStatusbarEntryAccessor } from 'vs/platform/statusbar/common/statusbar';
@@ -397,7 +395,7 @@ export class StatusbarPart extends Part implements IStatusbarService {
397395
private doAddEntry(entry: IStatusbarEntry, id: string, name: string, alignment: StatusbarAlignment, priority: number): IStatusbarEntryAccessor {
398396

399397
// Create item
400-
const itemContainer = this.doCreateStatusItem(id, name, alignment, priority, ...coalesce(['statusbar-entry', entry.showBeak ? 'has-beak' : undefined]));
398+
const itemContainer = this.doCreateStatusItem(id, name, alignment, priority, ...coalesce([entry.showBeak ? 'has-beak' : undefined]));
401399
const item = this.instantiationService.createInstance(StatusbarEntryItem, itemContainer, entry);
402400

403401
// Append to parent
@@ -450,20 +448,6 @@ export class StatusbarPart extends Part implements IStatusbarService {
450448
}
451449

452450
private createInitialStatusbarEntries(): void {
453-
const registry = Registry.as<IStatusbarRegistry>(Extensions.Statusbar);
454-
455-
// Create initial items that were contributed from the registry
456-
for (const { id, name, alignment, priority, syncDescriptor } of registry.items) {
457-
458-
// Create item
459-
const item = this.instantiationService.createInstance(syncDescriptor);
460-
const itemContainer = this.doCreateStatusItem(id, name, alignment, priority);
461-
this._register(item.render(itemContainer));
462-
463-
// Add to view model
464-
const viewModelEntry: IStatusbarViewModelEntry = { id, name, alignment, priority, container: itemContainer };
465-
this.viewModel.add(viewModelEntry);
466-
}
467451

468452
// Add items in order according to alignment
469453
this.appendAllStatusbarEntries();

src/vs/workbench/contrib/feedback/browser/feedback.contribution.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Registry } from 'vs/platform/registry/common/platform';
7-
import { IStatusbarRegistry, Extensions, StatusbarItemDescriptor } from 'vs/workbench/browser/parts/statusbar/statusbar';
8-
import { StatusbarAlignment } from 'vs/platform/statusbar/common/statusbar';
9-
import { FeedbackStatusbarItem } from 'vs/workbench/contrib/feedback/browser/feedbackStatusbarItem';
10-
import { localize } from 'vs/nls';
7+
import { FeedbackStatusbarConribution } from 'vs/workbench/contrib/feedback/browser/feedbackStatusbarItem';
8+
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
9+
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
1110

12-
// Register Statusbar item
13-
Registry.as<IStatusbarRegistry>(Extensions.Statusbar).registerStatusbarItem(new StatusbarItemDescriptor(
14-
FeedbackStatusbarItem,
15-
'status.feedback',
16-
localize('status.feedback', "Tweet Feedback"),
17-
StatusbarAlignment.RIGHT,
18-
-100 /* towards the end of the right hand side */
19-
));
11+
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(FeedbackStatusbarConribution, LifecyclePhase.Starting);

src/vs/workbench/contrib/feedback/browser/feedback.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import 'vs/css!./media/feedback';
77
import * as nls from 'vs/nls';
8-
import { IDisposable, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
8+
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
99
import { Dropdown } from 'vs/base/browser/ui/dropdown/dropdown';
1010
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
1111
import * as dom from 'vs/base/browser/dom';
@@ -17,7 +17,6 @@ import { editorWidgetBackground, widgetShadow, inputBorder, inputForeground, inp
1717
import { IAnchor } from 'vs/base/browser/ui/contextview/contextview';
1818
import { Button } from 'vs/base/browser/ui/button/button';
1919
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
20-
import { OcticonLabel } from 'vs/base/browser/ui/octiconLabel/octiconLabel';
2120
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
2221
import { IProductService } from 'vs/platform/product/common/product';
2322

@@ -68,15 +67,7 @@ export class FeedbackDropdown extends Dropdown {
6867
@IStatusbarService private readonly statusbarService: IStatusbarService,
6968
@IProductService productService: IProductService
7069
) {
71-
super(container, {
72-
contextViewProvider: options.contextViewProvider,
73-
labelRenderer: (container: HTMLElement): IDisposable => {
74-
const label = new OcticonLabel(container);
75-
label.text = '$(smiley)';
76-
77-
return Disposable.None;
78-
}
79-
});
70+
super(container, options);
8071

8172
this.feedbackDelegate = options.feedbackService;
8273
this.maxFeedbackCharacters = this.feedbackDelegate.getCharacterLimit(this.sentiment);

src/vs/workbench/contrib/feedback/browser/feedbackStatusbarItem.ts

Lines changed: 35 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
7-
import { IStatusbarItem } from 'vs/workbench/browser/parts/statusbar/statusbar';
6+
import { Disposable } from 'vs/base/common/lifecycle';
87
import { FeedbackDropdown, IFeedback, IFeedbackDelegate } from 'vs/workbench/contrib/feedback/browser/feedback';
98
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
109
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
11-
import { Themable, STATUS_BAR_ITEM_HOVER_BACKGROUND } from 'vs/workbench/common/theme';
12-
import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
13-
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
14-
import { clearNode, EventHelper, addClass, removeClass, addDisposableListener } from 'vs/base/browser/dom';
1510
import { IProductService } from 'vs/platform/product/common/product';
11+
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
12+
import { IStatusbarService, StatusbarAlignment, IStatusbarEntry, IStatusbarEntryAccessor } from 'vs/platform/statusbar/common/statusbar';
13+
import { localize } from 'vs/nls';
14+
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
1615

1716
class TwitterFeedbackService implements IFeedbackDelegate {
1817

@@ -47,76 +46,50 @@ class TwitterFeedbackService implements IFeedbackDelegate {
4746
}
4847
}
4948

50-
export class FeedbackStatusbarItem extends Themable implements IStatusbarItem {
51-
private dropdown: FeedbackDropdown | undefined;
52-
private container: HTMLElement;
49+
export class FeedbackStatusbarConribution extends Disposable implements IWorkbenchContribution {
50+
private dropdown: FeedbackDropdown;
51+
private entry: IStatusbarEntryAccessor;
5352

5453
constructor(
55-
@IInstantiationService private readonly instantiationService: IInstantiationService,
56-
@IContextViewService private readonly contextViewService: IContextViewService,
57-
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
58-
@IThemeService themeService: IThemeService,
59-
@IProductService private productService: IProductService
54+
@IStatusbarService statusbarService: IStatusbarService,
55+
@IProductService productService: IProductService,
56+
@IInstantiationService private instantiationService: IInstantiationService,
57+
@IContextViewService private contextViewService: IContextViewService
6058
) {
61-
super(themeService);
59+
super();
6260

63-
this.registerListeners();
64-
}
65-
66-
private registerListeners(): void {
67-
this._register(this.contextService.onDidChangeWorkbenchState(() => this.updateStyles()));
68-
}
69-
70-
render(element: HTMLElement): IDisposable {
71-
this.container = element;
61+
if (productService.sendASmile) {
62+
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 */));
7263

73-
// Prevent showing dropdown on anything but left click
74-
this._register(addDisposableListener(this.container, 'mousedown', (e: MouseEvent) => {
75-
if (e.button !== 0) {
76-
EventHelper.stop(e, true);
77-
}
78-
}, true));
79-
80-
return this.update();
64+
CommandsRegistry.registerCommand('_feedback.open', () => this.toggleFeedback());
65+
}
8166
}
8267

83-
private update(): IDisposable {
84-
85-
// Create
86-
if (this.productService.sendASmile) {
87-
if (!this.dropdown) {
88-
this.dropdown = this._register(this.instantiationService.createInstance(FeedbackDropdown, this.container, {
68+
private toggleFeedback(): void {
69+
if (!this.dropdown) {
70+
const statusContainr = document.getElementById('status.feedback');
71+
if (statusContainr) {
72+
this.dropdown = this._register(this.instantiationService.createInstance(FeedbackDropdown, statusContainr.getElementsByClassName('octicon').item(0), {
8973
contextViewProvider: this.contextViewService,
9074
feedbackService: this.instantiationService.createInstance(TwitterFeedbackService),
91-
onFeedbackVisibilityChange: (visible: boolean) => {
92-
if (visible) {
93-
addClass(this.container, 'has-beak');
94-
} else {
95-
removeClass(this.container, 'has-beak');
96-
}
97-
}
75+
onFeedbackVisibilityChange: visible => this.entry.update(this.getStatusEntry(visible))
9876
}));
99-
100-
this.updateStyles();
101-
102-
return this.dropdown;
10377
}
10478
}
10579

106-
// Dispose
107-
else {
108-
dispose(this.dropdown);
109-
this.dropdown = undefined;
110-
clearNode(this.container);
80+
if (!this.dropdown.isVisible()) {
81+
this.dropdown.show();
82+
} else {
83+
this.dropdown.hide();
11184
}
112-
113-
return Disposable.None;
11485
}
115-
}
11686

117-
registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
118-
const statusBarItemHoverBackground = theme.getColor(STATUS_BAR_ITEM_HOVER_BACKGROUND);
119-
if (statusBarItemHoverBackground) {
120-
collector.addRule(`.monaco-workbench .part.statusbar > .items-container > .statusbar-item .monaco-dropdown.send-feedback:hover { background-color: ${statusBarItemHoverBackground}; }`);
87+
private getStatusEntry(showBeak?: boolean): IStatusbarEntry {
88+
return {
89+
text: '$(smiley)',
90+
command: '_feedback.open',
91+
showBeak
92+
};
12193
}
122-
});
94+
95+
}

src/vs/workbench/contrib/feedback/browser/media/feedback.css

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,6 @@
113113
background-color: #eaeaea;
114114
}
115115

116-
/* Statusbar */
117-
.monaco-workbench .statusbar > .items-container > .statusbar-item > .monaco-dropdown.send-feedback {
118-
display: inline-block;
119-
padding: 0 5px 0 5px;
120-
}
121-
122-
.monaco-workbench .statusbar > .items-container > .statusbar-item > .monaco-dropdown.send-feedback span.octicon {
123-
text-align: center;
124-
font-size: 14px;
125-
}
126-
127116
/* Theming */
128117
.vs .monaco-workbench .feedback-form .feedback-alias, .vs .monaco-workbench .feedback-form .feedback-description {
129118
font-family: inherit;

0 commit comments

Comments
 (0)