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' ;
87import { FeedbackDropdown , IFeedback , IFeedbackDelegate } from 'vs/workbench/contrib/feedback/browser/feedback' ;
98import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
109import { 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' ;
1510import { 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
1716class 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+ }
0 commit comments