@@ -21,6 +21,7 @@ import copy from 'copy-to-clipboard';
2121import {
2222 addTransformToStack ,
2323 addCollapseResourceTransformToStack ,
24+ addCollapseSourceTransformToStack ,
2425 expandAllCallNodeDescendants ,
2526 updateBottomBoxContentsAndMaybeOpen ,
2627 setContextMenuVisibility ,
@@ -80,6 +81,7 @@ type StateProps = {
8081type DispatchProps = {
8182 readonly addTransformToStack : typeof addTransformToStack ;
8283 readonly addCollapseResourceTransformToStack : typeof addCollapseResourceTransformToStack ;
84+ readonly addCollapseSourceTransformToStack : typeof addCollapseSourceTransformToStack ;
8385 readonly expandAllCallNodeDescendants : typeof expandAllCallNodeDescendants ;
8486 readonly updateBottomBoxContentsAndMaybeOpen : typeof updateBottomBoxContentsAndMaybeOpen ;
8587 readonly setContextMenuVisibility : typeof setContextMenuVisibility ;
@@ -326,6 +328,7 @@ class CallNodeContextMenuImpl extends React.PureComponent<Props> {
326328 const {
327329 addTransformToStack,
328330 addCollapseResourceTransformToStack,
331+ addCollapseSourceTransformToStack,
329332 implementation,
330333 inverted,
331334 } = this . props ;
@@ -393,6 +396,21 @@ class CallNodeContextMenuImpl extends React.PureComponent<Props> {
393396 ) ;
394397 break ;
395398 }
399+ case 'collapse-source' : {
400+ const { funcTable } = thread ;
401+ const sourceIndex = funcTable . source [ selectedFunc ] ;
402+ if ( sourceIndex === null ) {
403+ throw new Error (
404+ 'collapse-source was triggered on a function without a source'
405+ ) ;
406+ }
407+ addCollapseSourceTransformToStack (
408+ threadsKey ,
409+ sourceIndex ,
410+ implementation
411+ ) ;
412+ break ;
413+ }
396414 case 'collapse-direct-recursion' : {
397415 addTransformToStack ( threadsKey , {
398416 type : 'collapse-direct-recursion' ,
@@ -539,6 +557,36 @@ class CallNodeContextMenuImpl extends React.PureComponent<Props> {
539557 return stringTable . getString ( resNameStringIndex ) ;
540558 }
541559
560+ getNameForSelectedSource ( ) : string | null {
561+ const rightClickedCallNodeInfo = this . getRightClickedCallNodeInfo ( ) ;
562+
563+ if ( rightClickedCallNodeInfo === null ) {
564+ throw new Error (
565+ "The context menu assumes there is a selected call node and there wasn't one."
566+ ) ;
567+ }
568+
569+ const {
570+ callNodeInfo,
571+ callNodeIndex,
572+ thread : { funcTable, stringTable, sources } ,
573+ } = rightClickedCallNodeInfo ;
574+
575+ const funcIndex = callNodeInfo . funcForNode ( callNodeIndex ) ;
576+ if ( funcIndex === undefined ) {
577+ return null ;
578+ }
579+ if ( ! funcTable . isJS [ funcIndex ] ) {
580+ return null ;
581+ }
582+ const sourceIndex = funcTable . source [ funcIndex ] ;
583+ if ( sourceIndex === null ) {
584+ return null ;
585+ }
586+ const fileNameIndex = sources . filename [ sourceIndex ] ;
587+ return stringTable . getString ( fileNameIndex ) ;
588+ }
589+
542590 getRightClickedCallNodeInfo ( ) : null | {
543591 readonly thread : Thread ;
544592 readonly threadsKey : ThreadsKey ;
@@ -602,6 +650,7 @@ class CallNodeContextMenuImpl extends React.PureComponent<Props> {
602650 const hasCategory = categoryIndex !== - 1 ;
603651 // This could be the C++ library, or the JS filename.
604652 const nameForResource = this . getNameForSelectedResource ( ) ;
653+ const nameForSource = this . getNameForSelectedSource ( ) ;
605654 const categoryName : string = hasCategory
606655 ? categories [ categoryIndex ] . name
607656 : '' ;
@@ -740,6 +789,22 @@ class CallNodeContextMenuImpl extends React.PureComponent<Props> {
740789 } )
741790 : null }
742791
792+ { nameForSource
793+ ? this . renderTransformMenuItem ( {
794+ l10nId : 'CallNodeContextMenu--transform-collapse-source' ,
795+ l10nProps : {
796+ vars : { nameForSource : nameForSource } ,
797+ elems : { strong : < strong /> } ,
798+ } ,
799+ shortcut : 'X' ,
800+ icon : 'Collapse' ,
801+ onClick : this . _handleClick ,
802+ transform : 'collapse-source' ,
803+ title : '' ,
804+ content : `Collapse source <strong>${ nameForSource } </strong>` ,
805+ } )
806+ : null }
807+
743808 { funcHasRecursiveCall ( callNodeTable , funcIndex )
744809 ? this . renderTransformMenuItem ( {
745810 l10nId : 'CallNodeContextMenu--transform-collapse-recursion' ,
@@ -951,6 +1016,7 @@ export const CallNodeContextMenu = explicitConnect<
9511016 mapDispatchToProps : {
9521017 addTransformToStack,
9531018 addCollapseResourceTransformToStack,
1019+ addCollapseSourceTransformToStack,
9541020 expandAllCallNodeDescendants,
9551021 updateBottomBoxContentsAndMaybeOpen,
9561022 setContextMenuVisibility,
0 commit comments