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 ;
@@ -35,13 +36,16 @@ export interface IFeedbackDelegate {
35
36
getCharacterLimit ( sentiment : number ) : number ;
36
37
}
37
38
38
- export interface IFeedbackDropdownOptions {
39
- contextViewProvider : IContextViewService ;
39
+ export interface IFeedbackWidgetOptions {
40
40
feedbackService : IFeedbackDelegate ;
41
41
onFeedbackVisibilityChange ?: ( visible : boolean ) => void ;
42
42
}
43
43
44
- export class FeedbackDropdown extends Dropdown {
44
+ export class FeedbackWidget extends Disposable {
45
+ private visible : boolean | undefined ;
46
+ private _onDidChangeVisibility = new Emitter < boolean > ( ) ;
47
+ readonly onDidChangeVisibility = this . _onDidChangeVisibility . event ;
48
+
45
49
private maxFeedbackCharacters : number ;
46
50
47
51
private feedback : string = '' ;
@@ -63,8 +67,9 @@ export class FeedbackDropdown extends Dropdown {
63
67
private isPure : boolean = true ;
64
68
65
69
constructor (
66
- container : HTMLElement ,
67
- private options : IFeedbackDropdownOptions ,
70
+ private options : IFeedbackWidgetOptions ,
71
+ @IContextViewService private readonly contextViewService : IContextViewService ,
72
+ @IWorkbenchLayoutService private readonly layoutService : IWorkbenchLayoutService ,
68
73
@ICommandService private readonly commandService : ICommandService ,
69
74
@ITelemetryService private readonly telemetryService : ITelemetryService ,
70
75
@IIntegrityService private readonly integrityService : IIntegrityService ,
@@ -73,7 +78,7 @@ export class FeedbackDropdown extends Dropdown {
73
78
@IProductService productService : IProductService ,
74
79
@IOpenerService private readonly openerService : IOpenerService
75
80
) {
76
- super ( container , options ) ;
81
+ super ( ) ;
77
82
78
83
this . feedbackDelegate = options . feedbackService ;
79
84
this . maxFeedbackCharacters = this . feedbackDelegate . getCharacterLimit ( this . sentiment ) ;
@@ -87,23 +92,18 @@ export class FeedbackDropdown extends Dropdown {
87
92
this . isPure = false ;
88
93
}
89
94
} ) ;
90
-
91
- dom . addClass ( this . element , 'send-feedback' ) ;
92
- this . element . title = nls . localize ( 'sendFeedback' , "Tweet Feedback" ) ;
93
95
}
94
96
95
- protected getAnchor ( ) : HTMLElement | IAnchor {
96
- const position = dom . getDomNodePagePosition ( this . element ) ;
97
+ private getAnchor ( ) : HTMLElement | IAnchor {
98
+ const dimension = this . layoutService . dimension ;
97
99
98
100
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
101
+ x : dimension . width - 8 ,
102
+ y : dimension . height - 31
103
103
} ;
104
104
}
105
105
106
- protected renderContents ( container : HTMLElement ) : IDisposable {
106
+ private renderContents ( container : HTMLElement ) : IDisposable {
107
107
const disposables = new DisposableStore ( ) ;
108
108
109
109
dom . addClass ( container , 'monaco-menu-container' ) ;
@@ -380,7 +380,26 @@ export class FeedbackDropdown extends Dropdown {
380
380
}
381
381
382
382
show ( ) : void {
383
- super . show ( ) ;
383
+ if ( this . visible ) {
384
+ return ;
385
+ }
386
+
387
+ this . visible = true ;
388
+ this . _onDidChangeVisibility . fire ( true ) ;
389
+
390
+ this . contextViewService . showContextView ( {
391
+ getAnchor : ( ) => this . getAnchor ( ) ,
392
+
393
+ render : ( container ) => {
394
+ return this . renderContents ( container ) ;
395
+ } ,
396
+
397
+ onDOMEvent : ( e , activeElement ) => {
398
+ this . onEvent ( e , activeElement ) ;
399
+ } ,
400
+
401
+ onHide : ( ) => this . onHide ( )
402
+ } ) ;
384
403
385
404
if ( this . options . onFeedbackVisibilityChange ) {
386
405
this . options . onFeedbackVisibilityChange ( true ) ;
@@ -389,13 +408,17 @@ export class FeedbackDropdown extends Dropdown {
389
408
this . updateCharCountText ( ) ;
390
409
}
391
410
392
- protected onHide ( ) : void {
411
+ private onHide ( ) : void {
393
412
if ( this . options . onFeedbackVisibilityChange ) {
394
413
this . options . onFeedbackVisibilityChange ( false ) ;
395
414
}
396
415
}
397
416
398
417
hide ( ) : void {
418
+ if ( ! this . visible ) {
419
+ return ;
420
+ }
421
+
399
422
if ( this . feedbackDescriptionInput ) {
400
423
this . feedback = this . feedbackDescriptionInput . value ;
401
424
}
@@ -409,10 +432,17 @@ export class FeedbackDropdown extends Dropdown {
409
432
this . statusbarService . updateEntryVisibility ( 'status.feedback' , false ) ;
410
433
}
411
434
412
- super . hide ( ) ;
435
+ this . visible = false ;
436
+ this . _onDidChangeVisibility . fire ( false ) ;
437
+
438
+ this . contextViewService . hideContextView ( ) ;
439
+ }
440
+
441
+ isVisible ( ) : boolean {
442
+ return ! ! this . visible ;
413
443
}
414
444
415
- onEvent ( e : Event , activeElement : HTMLElement ) : void {
445
+ private onEvent ( e : Event , activeElement : HTMLElement ) : void {
416
446
if ( e instanceof KeyboardEvent ) {
417
447
const keyboardEvent = < KeyboardEvent > e ;
418
448
if ( keyboardEvent . keyCode === 27 ) { // Escape
0 commit comments