Skip to content

Commit 10c5133

Browse files
committed
Improvements
1 parent 8aff579 commit 10c5133

File tree

8 files changed

+327
-176
lines changed

8 files changed

+327
-176
lines changed

package.json

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7393,6 +7393,46 @@
73937393
"title": "Open Worktrees in New Window",
73947394
"icon": "$(empty-window)"
73957395
},
7396+
{
7397+
"command": "gitlens.home.openPullRequestOnRemote",
7398+
"title": "Open Pull Request on Remote",
7399+
"icon": "$(globe)"
7400+
},
7401+
{
7402+
"command": "gitlens.home.openPullRequestComparison",
7403+
"title": "Open Pull Request Changes",
7404+
"icon": "$(request-changes)"
7405+
},
7406+
{
7407+
"command": "gitlens.home.createPullRequest",
7408+
"title": "Create Pull Request...",
7409+
"icon": "$(git-pull-request-create)"
7410+
},
7411+
{
7412+
"command": "gitlens.home.openWorktree",
7413+
"title": "Open Worktree",
7414+
"icon": "$(browser)"
7415+
},
7416+
{
7417+
"command": "gitlens.home.fetch",
7418+
"title": "Fetch",
7419+
"icon": "$(gl-repo-fetch)"
7420+
},
7421+
{
7422+
"command": "gitlens.home.pull",
7423+
"title": "Pull",
7424+
"icon": "$(gl-repo-pull)"
7425+
},
7426+
{
7427+
"command": "gitlens.home.openInGraph",
7428+
"title": "Open in Commit Graph",
7429+
"icon": "$(gl-graph)"
7430+
},
7431+
{
7432+
"command": "gitlens.home.switchToBranch",
7433+
"title": "Switch to Branch...",
7434+
"icon": "$(gl-switch)"
7435+
},
73967436
{
73977437
"command": "gitlens.graph.openWorktree",
73987438
"title": "Open Worktree",
@@ -11039,6 +11079,38 @@
1103911079
"command": "gitlens.graph.openInWorktree",
1104011080
"when": "false"
1104111081
},
11082+
{
11083+
"command": "gitlens.home.openPullRequestOnRemote",
11084+
"when": "false"
11085+
},
11086+
{
11087+
"command": "gitlens.home.openPullRequestComparison",
11088+
"when": "false"
11089+
},
11090+
{
11091+
"command": "gitlens.home.createPullRequest",
11092+
"when": "false"
11093+
},
11094+
{
11095+
"command": "gitlens.home.openWorktree",
11096+
"when": "false"
11097+
},
11098+
{
11099+
"command": "gitlens.home.switchToBranch",
11100+
"when": "false"
11101+
},
11102+
{
11103+
"command": "gitlens.home.fetch",
11104+
"when": "false"
11105+
},
11106+
{
11107+
"command": "gitlens.home.pull",
11108+
"when": "false"
11109+
},
11110+
{
11111+
"command": "gitlens.home.openInGraph",
11112+
"when": "false"
11113+
},
1104211114
{
1104311115
"command": "gitlens.graph.openWorktree",
1104411116
"when": "false"
@@ -16168,6 +16240,46 @@
1616816240
}
1616916241
],
1617016242
"webview/context": [
16243+
{
16244+
"command": "gitlens.home.openPullRequestComparison",
16245+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestComparison\\b)/",
16246+
"group": "1_gitlens_action@1"
16247+
},
16248+
{
16249+
"command": "gitlens.home.openPullRequestOnRemote",
16250+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openPullRequestOnRemote\\b)/",
16251+
"group": "1_gitlens_action@2"
16252+
},
16253+
{
16254+
"command": "gitlens.home.createPullRequest",
16255+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.createPullRequest\\b)/",
16256+
"group": "1_gitlens_action@3"
16257+
},
16258+
{
16259+
"command": "gitlens.home.openWorktree",
16260+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openWorktree\\b)/",
16261+
"group": "1_gitlens_action@4"
16262+
},
16263+
{
16264+
"command": "gitlens.home.switchToBranch",
16265+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.switchToBranch\\b)/",
16266+
"group": "1_gitlens_action@5"
16267+
},
16268+
{
16269+
"command": "gitlens.home.fetch",
16270+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.fetch\\b)/",
16271+
"group": "1_gitlens_action@6"
16272+
},
16273+
{
16274+
"command": "gitlens.home.pull",
16275+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.pull\\b)/",
16276+
"group": "1_gitlens_action@6"
16277+
},
16278+
{
16279+
"command": "gitlens.home.openInGraph",
16280+
"when": "webviewItem =~ /gitlens:home\\b(?=.*?\\b\\+.*gitlens\\.home\\.openInGraph\\b)/",
16281+
"group": "1_gitlens_action@7"
16282+
},
1617116283
{
1617216284
"command": "gitlens.graph.openWorktree",
1617316285
"when": "!gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?=.*?\\b\\+worktree\\b)/",

src/webviews/apps/plus/home/components/active-work.ts

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ import type { GitTrackingState } from '../../../../../git/models/branch';
88
import { createWebviewCommandLink } from '../../../../../system/webview';
99
import type { GetOverviewBranch, OpenInGraphParams, State } from '../../../../home/protocol';
1010
import { stateContext } from '../../../home/context';
11+
import type { ActionItemProps } from '../../../shared/components/actions/action-list';
1112
import { ipcContext } from '../../../shared/context';
1213
import type { HostIpc } from '../../../shared/ipc';
1314
import { linkStyles } from '../../shared/components/vscode.css';
1415
import { branchCardStyles, createCommandLink } from './branch-section';
1516
import type { Overview, OverviewState } from './overviewState';
1617
import { overviewStateContext } from './overviewState';
1718
import '../../../shared/components/button';
18-
import '../../../shared/components/code-icon';
19-
import '../../../shared/components/skeleton-loader';
2019
import '../../../shared/components/card/card';
20+
import '../../../shared/components/code-icon';
2121
import '../../../shared/components/commit/commit-stats';
2222
import '../../../shared/components/menu/menu-item';
2323
import '../../../shared/components/overlays/popover';
2424
import '../../../shared/components/overlays/tooltip';
2525
import '../../../shared/components/pills/tracking';
2626
import '../../../shared/components/rich/pr-icon';
27+
import '../../../shared/components/skeleton-loader';
2728

2829
export const activeWorkTagName = 'gl-active-work';
2930

@@ -208,41 +209,65 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
208209
`;
209210
}
210211

212+
private prevAttr = JSON.parse(document.body.getAttribute('data-vscode-context') ?? '{}');
213+
211214
private renderActions(branch: GetOverviewBranch, repo: string) {
212215
const branchRefs = {
213216
repoPath: repo,
214217
branchId: branch.id,
215218
};
216-
const actions = [];
219+
const actions: ActionItemProps[] = [];
217220
if (branch.pr) {
218221
actions.push(
219-
html`<action-item
220-
label="Open Pull Request Changes"
221-
icon="request-changes"
222-
href=${createCommandLink('gitlens.home.openPullRequestChanges', branchRefs)}
223-
></action-item>`,
224-
);
225-
actions.push(
226-
html`<action-item
227-
label="Open Pull Request on Remote"
228-
icon="globe"
229-
href=${createCommandLink('gitlens.home.openPullRequestOnRemote', branchRefs)}
230-
></action-item>`,
222+
{
223+
label: 'Open Pull Request Changes',
224+
icon: 'request-changes',
225+
href: createCommandLink('gitlens.home.openPullRequestChanges', branchRefs),
226+
},
227+
{
228+
label: 'Open Pull Request on Remote',
229+
icon: 'globe',
230+
href: createCommandLink('gitlens.home.openPullRequestOnRemote', branchRefs),
231+
},
231232
);
232233
} else if (branch.upstream?.missing === false) {
233-
actions.push(
234-
html`<action-item
235-
label="Create Pull Request..."
236-
icon="git-pull-request-create"
237-
href=${createCommandLink('gitlens.home.createPullRequest', branchRefs)}
238-
></action-item>`,
239-
);
234+
actions.push({
235+
label: 'Create Pull Request...',
236+
icon: 'git-pull-request-create',
237+
href: createCommandLink('gitlens.home.createPullRequest', branchRefs),
238+
});
240239
}
241240

242241
if (!actions.length) {
243242
return nothing;
244243
}
245-
return html`<action-nav class="branch-item__actions">${actions}</action-nav>`;
244+
return html`<action-list
245+
@open-actions-menu=${(e: CustomEvent<{ items: ActionItemProps[] }>) => {
246+
this.prevAttr = JSON.parse(document.body.getAttribute('data-vscode-context') ?? '{}');
247+
let context = 'gitlens:home';
248+
e.detail.items.forEach(x => {
249+
if (x.href) {
250+
context += `+${x.href}`;
251+
}
252+
});
253+
console.log({ context: context });
254+
document.body.setAttribute(
255+
'data-vscode-context',
256+
JSON.stringify({
257+
...this.prevAttr,
258+
webviewItem: context,
259+
...branchRefs,
260+
type: 'branch',
261+
}),
262+
);
263+
}}
264+
@close-actions-menu=${() => {
265+
document.body.setAttribute('data-vscode-context', JSON.stringify(this.prevAttr));
266+
}}
267+
limit=${3}
268+
.items=${actions}
269+
class="branch-item__actions"
270+
></action-list>`;
246271
}
247272

248273
private renderBranchStateActions(

src/webviews/apps/plus/home/components/branch-section.ts

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { customElement, property } from 'lit/decorators.js';
33
import { when } from 'lit/directives/when.js';
44
import type { Commands } from '../../../../../constants.commands';
55
import type { GitTrackingState } from '../../../../../git/models/branch';
6-
import type { GetOverviewBranch, OpenInGraphParams } from '../../../../home/protocol';
6+
import type { BranchRef, GetOverviewBranch, OpenInGraphParams } from '../../../../home/protocol';
77
import type { ActionItemProps } from '../../../shared/components/actions/action-list';
88
import { srOnlyStyles } from '../../../shared/components/styles/lit/a11y.css';
99
import { linkStyles } from '../../shared/components/vscode.css';
@@ -105,27 +105,30 @@ export class GlBranchSection extends LitElement {
105105
this.branches.map(
106106
branch =>
107107
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-
},
108+
@open-actions-menu=${(
109+
e: CustomEvent<{ branchRefs: BranchRef; items: ActionItemProps[] }>,
110+
) => {
111+
const evt = new CustomEvent<{
112+
branchRefs: BranchRef;
113+
items: ActionItemProps[];
114+
}>('branch-context-opened', {
115+
detail: {
116+
branchRefs: e.detail.branchRefs,
117+
items: e.detail.items,
115118
},
116-
);
119+
});
117120
this.dispatchEvent(evt);
118-
console.log('openVContext', { e: e }, branch);
119121
}}
120-
@close-actions-menu=${e => {
121-
const evt = new CustomEvent<{ branch: GetOverviewBranch }>(
122-
'branch-context-closed',
123-
{
124-
detail: {
125-
branch: branch,
126-
},
122+
@close-actions-menu=${(e: CustomEvent<{ items: ActionItemProps[] }>) => {
123+
const evt = new CustomEvent<{
124+
branch: GetOverviewBranch;
125+
// items: ActionItemProps[];
126+
}>('branch-context-closed', {
127+
detail: {
128+
branch: branch,
129+
// items: e.detail.items,
127130
},
128-
);
131+
});
129132
this.dispatchEvent(evt);
130133
console.log('closeVContext', { e: e }, branch);
131134
}}
@@ -245,7 +248,7 @@ export class GlBranchCard extends LitElement {
245248
@property({ type: Object })
246249
branch!: GetOverviewBranch;
247250

248-
get branchRefs() {
251+
get branchRefs(): BranchRef {
249252
return {
250253
repoPath: this.repo,
251254
branchId: this.branch.id,
@@ -394,20 +397,6 @@ export class GlBranchCard extends LitElement {
394397
label: 'Create Pull Request...',
395398
icon: 'git-pull-request-create',
396399
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-
],
411400
});
412401
}
413402
if (this.branch.worktree) {
@@ -430,6 +419,14 @@ export class GlBranchCard extends LitElement {
430419
label: 'Fetch',
431420
icon: 'gl-repo-fetch',
432421
href: this.createCommandLink('gitlens.home.fetch'),
422+
modifiers: [
423+
{
424+
key: 'alt',
425+
label: 'Pull',
426+
icon: 'gl-repo-pull',
427+
href: this.createCommandLink('gitlens.home.pull'),
428+
},
429+
],
433430
},
434431
{
435432
label: 'Open in Commit Graph',
@@ -445,39 +442,20 @@ export class GlBranchCard extends LitElement {
445442
return nothing;
446443
}
447444
return html`<action-list
448-
limit=${2}
445+
limit=${3}
449446
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,
447+
@open-actions-menu=${(e: CustomEvent<{ items: ActionItemProps[] }>) => {
448+
const ev = new CustomEvent<{ items: ActionItemProps[]; branchRefs: BranchRef }>('open-actions-menu', {
449+
detail: { items: e.detail.items, branchRefs: this.branchRefs },
467450
});
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);
451+
this.dispatchEvent(ev);
452+
}}
453+
@close-actions-menu=${() => {
454+
const ev = new CustomEvent<{ items: ActionItemProps[]; branchRefs: BranchRef }>(
455+
'close-actions-menu',
456+
{},
457+
);
458+
this.dispatchEvent(ev);
481459
}}
482460
.items=${actions}
483461
></action-list>`;

0 commit comments

Comments
 (0)