@@ -4,6 +4,7 @@ import { when } from 'lit/directives/when.js';
44import type { Commands } from '../../../../../constants.commands' ;
55import type { GitTrackingState } from '../../../../../git/models/branch' ;
66import type { GetOverviewBranch , OpenInGraphParams } from '../../../../home/protocol' ;
7+ import type { ActionItemProps } from '../../../shared/components/actions/action-list' ;
78import { srOnlyStyles } from '../../../shared/components/styles/lit/a11y.css' ;
89import { linkStyles } from '../../shared/components/vscode.css' ;
910import '../../../shared/components/code-icon' ;
@@ -15,6 +16,7 @@ import '../../../shared/components/commit/commit-stats';
1516import '../../../shared/components/formatted-date' ;
1617import '../../../shared/components/pills/tracking' ;
1718import '../../../shared/components/rich/pr-icon' ;
19+ import '../../../shared/components/actions/action-list' ;
1820import '../../../shared/components/actions/action-item' ;
1921import '../../../shared/components/actions/action-nav' ;
2022
@@ -101,7 +103,35 @@ export class GlBranchSection extends LitElement {
101103 this . branches . length > 0 ,
102104 ( ) =>
103105 this . branches . map (
104- branch => html `< gl-branch-card .repo =${ this . repo } .branch =${ branch } > </ gl-branch-card > ` ,
106+ branch =>
107+ html `< gl-branch-card
108+ @open-actions-menu =${ e => {
109+ const evt = new CustomEvent < { branch : GetOverviewBranch } > (
110+ 'branch-context-opened' ,
111+ {
112+ detail : {
113+ branch : branch ,
114+ } ,
115+ } ,
116+ ) ;
117+ this . dispatchEvent ( evt ) ;
118+ console . log ( 'openVContext' , { e : e } , branch ) ;
119+ } }
120+ @close-actions-menu =${ e => {
121+ const evt = new CustomEvent < { branch : GetOverviewBranch } > (
122+ 'branch-context-closed' ,
123+ {
124+ detail : {
125+ branch : branch ,
126+ } ,
127+ } ,
128+ ) ;
129+ this . dispatchEvent ( evt ) ;
130+ console . log ( 'closeVContext' , { e : e } , branch ) ;
131+ } }
132+ .repo=${ this . repo }
133+ .branch=${ branch }
134+ > </ gl-branch-card > ` ,
105135 ) ,
106136 ( ) => html `< p > No ${ this . label } branches</ p > ` ,
107137 ) }
@@ -345,72 +375,112 @@ export class GlBranchCard extends LitElement {
345375 }
346376
347377 private renderActions ( ) {
348- const actions = [ ] ;
378+ const actions : ActionItemProps [ ] = [ ] ;
349379 if ( this . branch . pr ) {
350380 actions . push (
351- html `< action-item
352- label ="Open Pull Request Changes "
353- icon ="request-changes "
354- href =${ this . createCommandLink ( 'gitlens.home.openPullRequestChanges' ) }
355- > </ action-item > ` ,
356- ) ;
357- actions . push (
358- html `< action-item
359- label ="Open Pull Request on Remote "
360- icon ="globe "
361- href =${ this . createCommandLink ( 'gitlens.home.openPullRequestOnRemote' ) }
362- > </ action-item > ` ,
381+ {
382+ label : 'Open Pull Request Changes' ,
383+ icon : 'request-changes' ,
384+ href : this . createCommandLink ( 'gitlens.home.openPullRequestChanges' ) ,
385+ } ,
386+ {
387+ label : 'Open Pull Request on Remote' ,
388+ icon : 'globe' ,
389+ href : this . createCommandLink ( 'gitlens.home.openPullRequestOnRemote' ) ,
390+ } ,
363391 ) ;
364392 } else if ( this . branch . upstream ?. missing === false ) {
365- actions . push (
366- html `< action-item
367- label ="Create Pull Request... "
368- icon ="git-pull-request-create "
369- href =${ this . createCommandLink ( 'gitlens.home.createPullRequest' ) }
370- > </ action-item > ` ,
371- ) ;
393+ actions . push ( {
394+ label : 'Create Pull Request...' ,
395+ icon : 'git-pull-request-create' ,
396+ href : this . createCommandLink ( 'gitlens.home.createPullRequest' ) ,
397+ modifiers : [
398+ {
399+ key : 'alt' ,
400+ label : 'c' ,
401+ icon : 'globe' ,
402+ href : '' ,
403+ } ,
404+ {
405+ key : 'ctrl' ,
406+ label : 'c' ,
407+ icon : 'request-changes' ,
408+ href : '' ,
409+ } ,
410+ ] ,
411+ } ) ;
372412 }
373413 if ( this . branch . worktree ) {
374- actions . push (
375- html `< action-item
376- label ="Open Worktree "
377- icon ="browser "
378- href =${ this . createCommandLink ( 'gitlens.home.openWorktree' ) }
379- > </ action-item > ` ,
380- ) ;
414+ actions . push ( {
415+ label : 'Open Worktree' ,
416+ icon : 'browser' ,
417+ href : this . createCommandLink ( 'gitlens.home.openWorktree' ) ,
418+ } ) ;
381419 } else {
382- actions . push (
383- html `< action-item
384- label ="Switch to Branch... "
385- icon ="gl-switch "
386- href =${ this . createCommandLink ( 'gitlens.home.switchToBranch' ) }
387- > </ action-item > ` ,
388- ) ;
420+ actions . push ( {
421+ label : 'Switch to Branch...' ,
422+ icon : 'gl-switch' ,
423+ href : this . createCommandLink ( 'gitlens.home.switchToBranch' ) ,
424+ } ) ;
389425 }
390426
391427 // branch actions
392428 actions . push (
393- html `< action-item
394- label ="Fetch "
395- icon ="gl-repo-fetch "
396- href =${ this . createCommandLink ( 'gitlens.home.fetch' ) }
397- > </ action-item > ` ,
398- ) ;
399- actions . push (
400- html `< action-item
401- label ="Open in Commit Graph "
402- icon ="gl-graph "
403- href =${ createCommandLink ( 'gitlens.home.openInGraph' , {
429+ {
430+ label : 'Fetch' ,
431+ icon : 'gl-repo-fetch' ,
432+ href : this . createCommandLink ( 'gitlens.home.fetch' ) ,
433+ } ,
434+ {
435+ label : 'Open in Commit Graph' ,
436+ icon : 'gl-graph' ,
437+ href : createCommandLink ( 'gitlens.home.openInGraph' , {
404438 ...this . branchRefs ,
405439 type : 'branch' ,
406- } satisfies OpenInGraphParams ) }
407- > </ action-item > ` ,
440+ } satisfies OpenInGraphParams ) ,
441+ } ,
408442 ) ;
409443
410444 if ( ! actions . length ) {
411445 return nothing ;
412446 }
413- return html `< action-nav class ="branch-item__actions "> ${ actions } </ action-nav > ` ;
447+ return html `< action-list
448+ limit =${ 2 }
449+ class ="branch-item__actions"
450+ @open-actions-menu=${ ( e : CustomEvent ) => {
451+ e . preventDefault ( ) ;
452+
453+ const ev = new CustomEvent ( 'open-actions-menu' ) ;
454+ this . dispatchEvent ( ev ) ;
455+ if ( ev . defaultPrevented ) return ;
456+
457+ const element = e . target as HTMLElement ;
458+ const ev1 = new PointerEvent ( 'contextmenu' , {
459+ bubbles : true ,
460+ cancelable : true ,
461+ composed : true ,
462+ view : window ,
463+ button : 2 ,
464+ buttons : 2 ,
465+ clientX : element . getBoundingClientRect ( ) . right ,
466+ clientY : element . getBoundingClientRect ( ) . bottom ,
467+ } ) ;
468+ element . dispatchEvent ( ev1 ) ;
469+
470+ const _handleClick = ( ) => {
471+ const ev = new CustomEvent ( 'close-actions-menu' ) ;
472+ this . dispatchEvent ( ev ) ;
473+ window . removeEventListener ( 'keyup' , handleClick ) ;
474+ window . removeEventListener ( 'mousedown' , handleClick ) ;
475+ window . removeEventListener ( 'focus' , handleClick ) ;
476+ } ;
477+ const handleClick = _handleClick . bind ( this ) ;
478+ window . addEventListener ( 'keyup' , handleClick ) ;
479+ window . addEventListener ( 'mousedown' , handleClick ) ;
480+ window . addEventListener ( 'focus' , handleClick ) ;
481+ } }
482+ .items=${ actions }
483+ > </ action-list > ` ;
414484 }
415485
416486 private createCommandLink ( command : string ) {
0 commit comments