Skip to content

Commit

Permalink
#52 Copy branch and tag names to the clipboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutchie committed Apr 23, 2019
1 parent f7c7331 commit 2917ad6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/gitGraphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ export class GitGraphView {
commitDetails: await this.dataSource.commitDetails(msg.repo, msg.commitHash)
});
break;
case 'copyCommitHashToClipboard':
case 'copyToClipboard':
this.sendMessage({
command: 'copyCommitHashToClipboard',
success: await copyToClipboard(msg.commitHash)
command: 'copyToClipboard',
type: msg.type,
success: await copyToClipboard(msg.data)
});
break;
case 'createBranch':
Expand Down
19 changes: 10 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,14 @@ export interface ResponseCommitDetails {
commitDetails: GitCommitDetails | null;
}

export interface RequestCopyCommitHashToClipboard {
command: 'copyCommitHashToClipboard';
repo: string;
commitHash: string;
}
export interface ResponseCopyCommitHashToClipboard {
command: 'copyCommitHashToClipboard';
export interface RequestCopyToClipboard {
command: 'copyToClipboard';
type: string;
data: string;
}
export interface ResponseCopyToClipboard {
command: 'copyToClipboard';
type: string;
success: boolean;
}

Expand Down Expand Up @@ -331,7 +332,7 @@ export type RequestMessage =
| RequestCheckoutCommit
| RequestCherrypickCommit
| RequestCommitDetails
| RequestCopyCommitHashToClipboard
| RequestCopyToClipboard
| RequestCreateBranch
| RequestDeleteBranch
| RequestDeleteTag
Expand All @@ -354,7 +355,7 @@ export type ResponseMessage =
| ResponseCheckoutCommit
| ResponseCherrypickCommit
| ResponseCommitDetails
| ResponseCopyCommitHashToClipboard
| ResponseCopyToClipboard
| ResponseCreateBranch
| ResponseDeleteBranch
| ResponseDeleteTag
Expand Down
16 changes: 12 additions & 4 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
{
title: 'Copy Commit Hash to Clipboard',
onClick: () => {
sendMessage({ command: 'copyCommitHashToClipboard', repo: this.currentRepo!, commitHash: hash });
sendMessage({ command: 'copyToClipboard', type: 'Commit Hash', data: hash });
}
}
], sourceElem);
Expand All @@ -452,7 +452,7 @@
addListenerToClass('gitRef', 'contextmenu', (e: Event) => {
e.stopPropagation();
let sourceElem = <HTMLElement>(<Element>e.target).closest('.gitRef')!;
let refName = unescapeHtml(sourceElem.dataset.name!), menu;
let refName = unescapeHtml(sourceElem.dataset.name!), menu: ContextMenuElement[], copyType: string;
if (sourceElem.classList.contains('tag')) {
menu = [{
title: 'Delete Tag' + ELLIPSIS,
Expand All @@ -470,6 +470,7 @@
}, null);
}
}];
copyType = 'Tag Name';
} else {
if (sourceElem.classList.contains('head')) {
menu = [{
Expand Down Expand Up @@ -506,7 +507,14 @@
onClick: () => this.checkoutBranchAction(sourceElem, refName)
}];
}
copyType = 'Branch Name';
}
menu.push(null, {
title: 'Copy ' + copyType + ' to Clipboard',
onClick: () => {
sendMessage({ command: 'copyToClipboard', type: copyType, data: refName });
}
});
showContextMenu(<MouseEvent>e, menu, sourceElem);
});
addListenerToClass('gitRef', 'click', (e: Event) => e.stopPropagation());
Expand Down Expand Up @@ -758,8 +766,8 @@
gitGraph.showCommitDetails(msg.commitDetails, generateGitFileTree(msg.commitDetails.fileChanges));
}
break;
case 'copyCommitHashToClipboard':
if (msg.success === false) showErrorDialog('Unable to Copy Commit Hash to Clipboard', null, null);
case 'copyToClipboard':
if (msg.success === false) showErrorDialog('Unable to Copy ' + msg.type + ' to Clipboard', null, null);
break;
case 'createBranch':
refreshGraphOrDisplayError(msg.status, 'Unable to Create Branch');
Expand Down

0 comments on commit 2917ad6

Please sign in to comment.