@@ -33,7 +33,7 @@ import 'vs/css!./media/views';
33
33
import { VSDataTransfer } from 'vs/base/common/dataTransfer' ;
34
34
import { localize } from 'vs/nls' ;
35
35
import { createActionViewItem , createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
36
- import { Action2 , IMenu , IMenuService , MenuId , MenuRegistry , registerAction2 } from 'vs/platform/actions/common/actions' ;
36
+ import { Action2 , IMenuService , MenuId , MenuRegistry , registerAction2 } from 'vs/platform/actions/common/actions' ;
37
37
import { CommandsRegistry , ICommandService } from 'vs/platform/commands/common/commands' ;
38
38
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
39
39
import { ContextKeyExpr , IContextKey , IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
@@ -800,7 +800,9 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
800
800
event . stopPropagation ( ) ;
801
801
802
802
this . tree ! . setFocus ( [ node ] ) ;
803
- const actions = treeMenus . getResourceContextActions ( node ) ;
803
+ const selected = this . canSelectMany ? this . getSelection ( ) : [ ] ;
804
+ selected . unshift ( node ) ;
805
+ const actions = treeMenus . getResourceContextActions ( selected ) ;
804
806
if ( ! actions . length ) {
805
807
return ;
806
808
}
@@ -1311,7 +1313,7 @@ class TreeRenderer extends Disposable implements ITreeRenderer<ITreeItem, FuzzyS
1311
1313
1312
1314
templateData . actionBar . context = < TreeViewItemHandleArg > { $treeViewId : this . treeViewId , $treeItemHandle : node . handle } ;
1313
1315
1314
- const menuActions = this . menus . getResourceActions ( node , templateData . elementDisposable ) ;
1316
+ const menuActions = this . menus . getResourceActions ( [ node ] , templateData . elementDisposable ) ;
1315
1317
templateData . actionBar . push ( menuActions . actions , { icon : true , label : false } ) ;
1316
1318
1317
1319
if ( this . _actionRunner ) {
@@ -1581,41 +1583,68 @@ class TreeMenus implements IDisposable {
1581
1583
@IMenuService private readonly menuService : IMenuService
1582
1584
) { }
1583
1585
1584
- getResourceActions ( element : ITreeItem , disposableStore : DisposableStore ) : { menu ?: IMenu ; actions : IAction [ ] } {
1585
- const actions = this . getActions ( MenuId . ViewItemContext , element , disposableStore ) ;
1586
- return { menu : actions . menu , actions : actions . primary } ;
1586
+ getResourceActions ( elements : ITreeItem [ ] , disposableStore : DisposableStore ) : { actions : IAction [ ] } {
1587
+ const actions = this . getActions ( MenuId . ViewItemContext , elements , disposableStore ) ;
1588
+ return { actions : actions . primary } ;
1587
1589
}
1588
1590
1589
- getResourceContextActions ( element : ITreeItem ) : IAction [ ] {
1590
- return this . getActions ( MenuId . ViewItemContext , element ) . secondary ;
1591
+ getResourceContextActions ( elements : ITreeItem [ ] ) : IAction [ ] {
1592
+ return this . getActions ( MenuId . ViewItemContext , elements ) . secondary ;
1591
1593
}
1592
1594
1593
1595
public setContextKeyService ( service : IContextKeyService ) {
1594
1596
this . contextKeyService = service ;
1595
1597
}
1596
1598
1597
- private getActions ( menuId : MenuId , element : ITreeItem , listen ?: DisposableStore ) : { menu ?: IMenu ; primary : IAction [ ] ; secondary : IAction [ ] } {
1599
+ private getActions ( menuId : MenuId , elements : ITreeItem [ ] , listen ?: DisposableStore ) : { primary : IAction [ ] ; secondary : IAction [ ] } {
1598
1600
if ( ! this . contextKeyService ) {
1599
1601
return { primary : [ ] , secondary : [ ] } ;
1600
1602
}
1601
1603
1602
- const contextKeyService = this . contextKeyService . createOverlay ( [
1603
- [ 'view' , this . id ] ,
1604
- [ 'viewItem' , element . contextValue ]
1605
- ] ) ;
1606
-
1607
- const menu = this . menuService . createMenu ( menuId , contextKeyService ) ;
1608
- const primary : IAction [ ] = [ ] ;
1609
- const secondary : IAction [ ] = [ ] ;
1610
- const result = { primary, secondary, menu } ;
1611
- createAndFillInContextMenuActions ( menu , { shouldForwardArgs : true } , result , 'inline' ) ;
1612
- if ( listen ) {
1613
- listen . add ( menu . onDidChange ( ( ) => this . _onDidChange . fire ( element ) ) ) ;
1614
- listen . add ( menu ) ;
1615
- } else {
1616
- menu . dispose ( ) ;
1604
+ const allowedPrimary = new Map < string , IAction > ( ) ;
1605
+ const allowedSecondary = new Map < string , IAction > ( ) ;
1606
+ for ( let i = 0 ; i < elements . length ; i ++ ) {
1607
+ const element = elements [ i ] ;
1608
+ const contextKeyService = this . contextKeyService . createOverlay ( [
1609
+ [ 'view' , this . id ] ,
1610
+ [ 'viewItem' , element . contextValue ]
1611
+ ] ) ;
1612
+
1613
+ const menu = this . menuService . createMenu ( menuId , contextKeyService ) ;
1614
+ const primary : IAction [ ] = [ ] ;
1615
+ const secondary : IAction [ ] = [ ] ;
1616
+ const result = { primary, secondary, menu } ;
1617
+ createAndFillInContextMenuActions ( menu , { shouldForwardArgs : true } , result , 'inline' ) ;
1618
+ if ( i === 0 ) {
1619
+ for ( const action of result . primary ) {
1620
+ allowedPrimary . set ( action . id , action ) ;
1621
+ }
1622
+ for ( const action of result . secondary ) {
1623
+ allowedSecondary . set ( action . id , action ) ;
1624
+ }
1625
+ } else {
1626
+ const primaryKeys = allowedPrimary . keys ( ) ;
1627
+ for ( const key of primaryKeys ) {
1628
+ if ( ! result . primary . some ( action => action . id === key ) ) {
1629
+ allowedPrimary . delete ( key ) ;
1630
+ }
1631
+ }
1632
+ const secondaryKeys = allowedSecondary . keys ( ) ;
1633
+ for ( const key of secondaryKeys ) {
1634
+ if ( ! result . secondary . some ( action => action . id === key ) ) {
1635
+ allowedSecondary . delete ( key ) ;
1636
+ }
1637
+ }
1638
+ }
1639
+ if ( listen && elements . length === 1 ) {
1640
+ listen . add ( menu . onDidChange ( ( ) => this . _onDidChange . fire ( element ) ) ) ;
1641
+ listen . add ( menu ) ;
1642
+ } else {
1643
+ menu . dispose ( ) ;
1644
+ }
1617
1645
}
1618
- return result ;
1646
+
1647
+ return { primary : Array . from ( allowedPrimary . values ( ) ) , secondary : Array . from ( allowedSecondary . values ( ) ) } ;
1619
1648
}
1620
1649
1621
1650
dispose ( ) {
0 commit comments