5
5
6
6
import 'vs/css!./media/feedback' ;
7
7
import * as nls from 'vs/nls' ;
8
- import { IDisposable , DisposableStore } from 'vs/base/common/lifecycle' ;
9
- import { Dropdown } from 'vs/base/browser/ui/dropdown/dropdown' ;
8
+ import { IDisposable , DisposableStore , Disposable } from 'vs/base/common/lifecycle' ;
10
9
import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
11
10
import * as dom from 'vs/base/browser/dom' ;
12
11
import { ICommandService } from 'vs/platform/commands/common/commands' ;
@@ -24,6 +23,8 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
24
23
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent' ;
25
24
import { KeyCode } from 'vs/base/common/keyCodes' ;
26
25
import { Codicon } from 'vs/base/common/codicons' ;
26
+ import { Emitter } from 'vs/base/common/event' ;
27
+ import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService' ;
27
28
28
29
export interface IFeedback {
29
30
feedback : string ;
@@ -36,17 +37,18 @@ export interface IFeedbackDelegate {
36
37
}
37
38
38
39
export interface IFeedbackWidgetOptions {
39
- contextViewProvider : IContextViewService ;
40
40
feedbackService : IFeedbackDelegate ;
41
- onFeedbackVisibilityChange ?: ( visible : boolean ) => void ;
42
41
}
43
42
44
- export class FeedbackWidget extends Dropdown {
43
+ export class FeedbackWidget extends Disposable {
44
+ private visible : boolean | undefined ;
45
+ private _onDidChangeVisibility = new Emitter < boolean > ( ) ;
46
+ readonly onDidChangeVisibility = this . _onDidChangeVisibility . event ;
47
+
45
48
private maxFeedbackCharacters : number ;
46
49
47
50
private feedback : string = '' ;
48
51
private sentiment : number = 1 ;
49
- private autoHideTimeout ?: number ;
50
52
51
53
private readonly feedbackDelegate : IFeedbackDelegate ;
52
54
@@ -63,8 +65,9 @@ export class FeedbackWidget extends Dropdown {
63
65
private isPure : boolean = true ;
64
66
65
67
constructor (
66
- container : HTMLElement ,
67
- private options : IFeedbackWidgetOptions ,
68
+ options : IFeedbackWidgetOptions ,
69
+ @IContextViewService private readonly contextViewService : IContextViewService ,
70
+ @IWorkbenchLayoutService private readonly layoutService : IWorkbenchLayoutService ,
68
71
@ICommandService private readonly commandService : ICommandService ,
69
72
@ITelemetryService private readonly telemetryService : ITelemetryService ,
70
73
@IIntegrityService private readonly integrityService : IIntegrityService ,
@@ -73,7 +76,7 @@ export class FeedbackWidget extends Dropdown {
73
76
@IProductService productService : IProductService ,
74
77
@IOpenerService private readonly openerService : IOpenerService
75
78
) {
76
- super ( container , options ) ;
79
+ super ( ) ;
77
80
78
81
this . feedbackDelegate = options . feedbackService ;
79
82
this . maxFeedbackCharacters = this . feedbackDelegate . getCharacterLimit ( this . sentiment ) ;
@@ -88,22 +91,24 @@ export class FeedbackWidget extends Dropdown {
88
91
}
89
92
} ) ;
90
93
91
- this . element . classList . add ( 'send-feedback' ) ;
92
- this . element . title = nls . localize ( 'sendFeedback' , "Tweet Feedback" ) ;
94
+ // Hide feedback widget whenever notifications appear
95
+ this . _register ( this . layoutService . onDidChangeNotificationsVisibility ( visible => {
96
+ if ( visible ) {
97
+ this . hide ( ) ;
98
+ }
99
+ } ) ) ;
93
100
}
94
101
95
- protected override getAnchor ( ) : HTMLElement | IAnchor {
96
- const position = dom . getDomNodePagePosition ( this . element ) ;
102
+ private getAnchor ( ) : HTMLElement | IAnchor {
103
+ const dimension = this . layoutService . dimension ;
97
104
98
105
return {
99
- x : position . left + position . width , // center above the container
100
- y : position . top - 26 , // above status bar and beak
101
- width : position . width ,
102
- height : position . height
106
+ x : dimension . width - 8 ,
107
+ y : dimension . height - 31
103
108
} ;
104
109
}
105
110
106
- protected override renderContents ( container : HTMLElement ) : IDisposable {
111
+ private renderContents ( container : HTMLElement ) : IDisposable {
107
112
const disposables = new DisposableStore ( ) ;
108
113
109
114
container . classList . add ( 'monaco-menu-container' ) ;
@@ -379,40 +384,53 @@ export class FeedbackWidget extends Dropdown {
379
384
return element ;
380
385
}
381
386
382
- override show ( ) : void {
383
- super . show ( ) ;
384
-
385
- if ( this . options . onFeedbackVisibilityChange ) {
386
- this . options . onFeedbackVisibilityChange ( true ) ;
387
+ show ( ) : void {
388
+ if ( this . visible ) {
389
+ return ;
387
390
}
388
391
392
+ this . visible = true ;
393
+ this . contextViewService . showContextView ( {
394
+ getAnchor : ( ) => this . getAnchor ( ) ,
395
+
396
+ render : ( container ) => {
397
+ return this . renderContents ( container ) ;
398
+ } ,
399
+
400
+ onDOMEvent : ( e , activeElement ) => {
401
+ this . onEvent ( e , activeElement ) ;
402
+ } ,
403
+
404
+ onHide : ( ) => this . _onDidChangeVisibility . fire ( false )
405
+ } ) ;
406
+
407
+ this . _onDidChangeVisibility . fire ( true ) ;
408
+
389
409
this . updateCharCountText ( ) ;
390
410
}
391
411
392
- protected override onHide ( ) : void {
393
- if ( this . options . onFeedbackVisibilityChange ) {
394
- this . options . onFeedbackVisibilityChange ( false ) ;
412
+ hide ( ) : void {
413
+ if ( ! this . visible ) {
414
+ return ;
395
415
}
396
- }
397
416
398
- override hide ( ) : void {
399
417
if ( this . feedbackDescriptionInput ) {
400
418
this . feedback = this . feedbackDescriptionInput . value ;
401
419
}
402
420
403
- if ( this . autoHideTimeout ) {
404
- clearTimeout ( this . autoHideTimeout ) ;
405
- this . autoHideTimeout = undefined ;
406
- }
407
-
408
421
if ( this . hideButton && ! this . hideButton . checked ) {
409
422
this . statusbarService . updateEntryVisibility ( 'status.feedback' , false ) ;
410
423
}
411
424
412
- super . hide ( ) ;
425
+ this . visible = false ;
426
+ this . contextViewService . hideContextView ( ) ;
427
+ }
428
+
429
+ isVisible ( ) : boolean {
430
+ return ! ! this . visible ;
413
431
}
414
432
415
- override onEvent ( e : Event , activeElement : HTMLElement ) : void {
433
+ private onEvent ( e : Event , activeElement : HTMLElement ) : void {
416
434
if ( e instanceof KeyboardEvent ) {
417
435
const keyboardEvent = < KeyboardEvent > e ;
418
436
if ( keyboardEvent . keyCode === 27 ) { // Escape
0 commit comments