77
88import 'vs/css!./toolbar' ;
99import nls = require( 'vs/nls' ) ;
10+ import { Promise } from 'vs/base/common/winjs.base' ;
1011import { IDisposable } from 'vs/base/common/lifecycle' ;
1112import { Builder , $ } from 'vs/base/browser/builder' ;
1213import types = require( 'vs/base/common/types' ) ;
@@ -15,7 +16,7 @@ import {ActionBar, ActionsOrientation, IActionItemProvider, BaseActionItem} from
1516import { IContextMenuProvider , DropdownMenu , IActionProvider , ILabelRenderer , IDropdownMenuOptions } from 'vs/base/browser/ui/dropdown/dropdown' ;
1617import { ListenerUnbind } from 'vs/base/common/eventEmitter' ;
1718
18- export var CONTEXT = 'context.toolbar' ;
19+ export const CONTEXT = 'context.toolbar' ;
1920
2021export interface IToolBarOptions {
2122 orientation ?: ActionsOrientation ;
@@ -34,9 +35,9 @@ export class ToolBar {
3435
3536 constructor ( container : HTMLElement , contextMenuProvider : IContextMenuProvider , options : IToolBarOptions = { orientation : ActionsOrientation . HORIZONTAL } ) {
3637 this . options = options ;
37- this . toggleMenuAction = new ToggleMenuAction ( ) ;
38+ this . toggleMenuAction = new ToggleMenuAction ( ( ) => this . toggleMenuActionItem && this . toggleMenuActionItem . show ( ) ) ;
3839
39- var element = document . createElement ( 'div' ) ;
40+ let element = document . createElement ( 'div' ) ;
4041 element . className = 'monaco-toolbar' ;
4142 container . appendChild ( element ) ;
4243
@@ -58,7 +59,6 @@ export class ToolBar {
5859 ( < ToggleMenuAction > action ) . menuActions ,
5960 contextMenuProvider ,
6061 this . options . actionItemProvider ,
61- this . options . orientation === ActionsOrientation . HORIZONTAL ,
6262 this . actionRunner ,
6363 'toolbar-toggle-more'
6464 ) ;
@@ -85,7 +85,7 @@ export class ToolBar {
8585
8686 public setActions ( primaryActions : IAction [ ] , secondaryActions ?: IAction [ ] ) : ( ) => void {
8787 return ( ) => {
88- var primaryActionsToSet = primaryActions ? primaryActions . slice ( 0 ) : [ ] ;
88+ let primaryActionsToSet = primaryActions ? primaryActions . slice ( 0 ) : [ ] ;
8989
9090 // Inject additional action to open secondary actions if present
9191 this . hasSecondaryActions = secondaryActions && secondaryActions . length > 0 ;
@@ -104,7 +104,7 @@ export class ToolBar {
104104
105105 // Add after the "..." action if we have secondary actions
106106 if ( this . hasSecondaryActions ) {
107- var itemCount = this . actionBar . length ( ) ;
107+ let itemCount = this . actionBar . length ( ) ;
108108 this . actionBar . push ( primaryActions , { icon : true , label : false , index : itemCount } ) ;
109109 }
110110
@@ -130,9 +130,18 @@ class ToggleMenuAction extends Action {
130130 public static ID = 'toolbar.toggle.more' ;
131131
132132 private _menuActions : IAction [ ] ;
133+ private toggleDropdownMenu : ( ) => void ;
133134
134- constructor ( ) {
135+ constructor ( toggleDropdownMenu : ( ) => void ) {
135136 super ( ToggleMenuAction . ID , nls . localize ( 'more' , "More" ) , null , true ) ;
137+
138+ this . toggleDropdownMenu = toggleDropdownMenu ;
139+ }
140+
141+ public run ( ) : Promise {
142+ this . toggleDropdownMenu ( ) ;
143+
144+ return Promise . as ( true ) ;
136145 }
137146
138147 public get menuActions ( ) {
@@ -145,59 +154,40 @@ class ToggleMenuAction extends Action {
145154}
146155
147156export class DropdownMenuActionItem extends BaseActionItem {
148-
149157 private menuActionsOrProvider : any ;
150- private animateClick : boolean ;
151158 private dropdownMenu : DropdownMenu ;
152159 private toUnbind : ListenerUnbind ;
153160 private contextMenuProvider : IContextMenuProvider ;
154161 private actionItemProvider : IActionItemProvider ;
155162 private clazz : string ;
156163
157- constructor ( action : IAction , menuActions : IAction [ ] , contextMenuProvider : IContextMenuProvider , actionItemProvider : IActionItemProvider , animateClick : boolean , actionRunner : IActionRunner , clazz : string ) ;
158- constructor ( action : IAction , actionProvider : IActionProvider , contextMenuProvider : IContextMenuProvider , actionItemProvider : IActionItemProvider , animateClick : boolean , actionRunner : IActionRunner , clazz : string ) ;
159- constructor ( action : IAction , menuActionsOrProvider : any , contextMenuProvider : IContextMenuProvider , actionItemProvider : IActionItemProvider , animateClick : boolean , actionRunner : IActionRunner , clazz : string ) {
164+ constructor ( action : IAction , menuActions : IAction [ ] , contextMenuProvider : IContextMenuProvider , actionItemProvider : IActionItemProvider , actionRunner : IActionRunner , clazz : string ) ;
165+ constructor ( action : IAction , actionProvider : IActionProvider , contextMenuProvider : IContextMenuProvider , actionItemProvider : IActionItemProvider , actionRunner : IActionRunner , clazz : string ) ;
166+ constructor ( action : IAction , menuActionsOrProvider : any , contextMenuProvider : IContextMenuProvider , actionItemProvider : IActionItemProvider , actionRunner : IActionRunner , clazz : string ) {
160167 super ( null , action ) ;
161168
162169 this . menuActionsOrProvider = menuActionsOrProvider ;
163170 this . contextMenuProvider = contextMenuProvider ;
164171 this . actionItemProvider = actionItemProvider ;
165- this . animateClick = animateClick ;
166172 this . actionRunner = actionRunner ;
167173 this . clazz = clazz ;
168174 }
169175
170176 public render ( container : HTMLElement ) : void {
171- super . render ( container ) ;
172-
173- var labelRenderer : ILabelRenderer = ( el : HTMLElement ) : IDisposable => {
174- var e = $ ( 'a.action-label' ) . attr ( {
177+ let labelRenderer : ILabelRenderer = ( el : HTMLElement ) : IDisposable => {
178+ this . builder = $ ( 'a.action-label' ) . attr ( {
175179 tabIndex : '0' ,
176180 role : 'menuitem' ,
177181 title : this . _action . label || '' ,
178182 class : this . clazz
179- } ) . appendTo ( el ) ;
183+ } ) ;
180184
181- $ ( 'span.label' ) . text ( this . getAction ( ) . label ) . appendTo ( e ) ;
182-
183- if ( this . animateClick ) {
184- $ ( el ) . on ( 'mousedown' , ( e : MouseEvent ) => {
185- if ( e . button === 0 ) {
186- $ ( el ) . addClass ( 'active' ) ;
187- }
188- } ) ;
189-
190- $ ( el ) . on ( [ 'mouseup' , 'mouseout' ] , ( e : MouseEvent ) => {
191- if ( e . button === 0 ) {
192- $ ( el ) . removeClass ( 'active' ) ;
193- }
194- } ) ;
195- }
185+ this . builder . appendTo ( el ) ;
196186
197187 return null ;
198188 } ;
199189
200- var options : IDropdownMenuOptions = {
190+ let options : IDropdownMenuOptions = {
201191 contextMenuProvider : this . contextMenuProvider ,
202192 labelRenderer : labelRenderer
203193 } ;
@@ -220,6 +210,10 @@ export class DropdownMenuActionItem extends BaseActionItem {
220210 this . toUnbind = this . addEmitter ( this . dropdownMenu ) ;
221211 }
222212
213+ public show ( ) : void {
214+ this . dropdownMenu && this . dropdownMenu . show ( ) ;
215+ }
216+
223217 public dispose ( ) : void {
224218 this . toUnbind ( ) ;
225219 this . dropdownMenu . dispose ( ) ;
0 commit comments