Add and change context menus

- delete virtual branch from left tray
- unapply branch from swimlane menu
This commit is contained in:
Mattias Granlund 2023-07-03 11:39:34 +01:00
parent 9cfa03c642
commit a1960673ae
3 changed files with 32 additions and 6 deletions

View File

@ -1,10 +1,12 @@
<script lang="ts"> <script lang="ts">
export let disabled = false; export let disabled = false;
export let title = '';
</script> </script>
<button <button
on:click|preventDefault on:click|preventDefault
{disabled} {disabled}
{title}
class="w-full px-4 py-2 text-sm no-underline enabled:hover:bg-light-100 disabled:text-light-600 enabled:dark:hover:bg-dark-600" class="w-full px-4 py-2 text-sm no-underline enabled:hover:bg-light-100 disabled:text-light-600 enabled:dark:hover:bg-dark-600"
> >
<slot /> <slot />

View File

@ -176,8 +176,8 @@
</button> </button>
</div> </div>
<PopupMenu bind:this={popupMenu} let:item={branchId}> <PopupMenu bind:this={popupMenu} let:item={branchId}>
<PopupMenuItem on:click={() => branchId && virtualBranches.deleteBranch(branchId)}> <PopupMenuItem on:click={() => branchId && virtualBranches.unapplyBranch(branchId)}>
Delete Unapply
</PopupMenuItem> </PopupMenuItem>
</PopupMenu> </PopupMenu>

View File

@ -20,7 +20,8 @@
let yourBranchesOpen = true; let yourBranchesOpen = true;
let remoteBranchesOpen = true; let remoteBranchesOpen = true;
let popupMenu: PopupMenu; let yourBranchContextMenu: PopupMenu;
let remoteBranchContextMenu: PopupMenu;
$: behindMessage = target.behind > 0 ? `behind ${target.behind}` : 'up-to-date'; $: behindMessage = target.behind > 0 ? `behind ${target.behind}` : 'up-to-date';
@ -65,6 +66,7 @@
use:rememberWidth use:rememberWidth
class="w-80 shrink-0 resize-x overflow-y-auto bg-white text-light-800 dark:bg-dark-900 dark:text-dark-100" class="w-80 shrink-0 resize-x overflow-y-auto bg-white text-light-800 dark:bg-dark-900 dark:text-dark-100"
> >
<!-- Target branch -->
<div class="pl-2 pr-4 pt-2 text-light-700 dark:bg-dark-700 dark:text-dark-200">Target branch</div> <div class="pl-2 pr-4 pt-2 text-light-700 dark:bg-dark-700 dark:text-dark-200">Target branch</div>
<div <div
class="flex w-full flex-row items-center gap-x-4 border-b border-light-400 pl-2 pr-4 text-light-900 dark:border-dark-500 dark:bg-dark-700 dark:text-dark-100" class="flex w-full flex-row items-center gap-x-4 border-b border-light-400 pl-2 pr-4 text-light-900 dark:border-dark-500 dark:bg-dark-700 dark:text-dark-100"
@ -82,6 +84,8 @@
</button> </button>
</div> </div>
</div> </div>
<!-- Your branches -->
<div <div
class="flex items-center justify-between border-b border-light-400 bg-light-100 py-2 pl-2 pr-4 dark:border-dark-600 dark:bg-dark-800" class="flex items-center justify-between border-b border-light-400 bg-light-100 py-2 pl-2 pr-4 dark:border-dark-600 dark:bg-dark-800"
> >
@ -99,7 +103,11 @@
<div class="flex flex-col dark:bg-dark-900" use:accordion={yourBranchesOpen}> <div class="flex flex-col dark:bg-dark-900" use:accordion={yourBranchesOpen}>
{#each branches as branch (branch.id)} {#each branches as branch (branch.id)}
{@const latestModifiedAt = branch.files.at(0)?.hunks.at(0)?.modifiedAt} {@const latestModifiedAt = branch.files.at(0)?.hunks.at(0)?.modifiedAt}
<div class="border-b border-light-400 p-2 pl-2 pr-4 dark:border-dark-600" title={branch.name}> <div
on:contextmenu|preventDefault={(e) => yourBranchContextMenu.openByMouse(e, branch)}
class="border-b border-light-400 p-2 pl-2 pr-4 dark:border-dark-600"
title={branch.name}
>
<div class="flex flex-row justify-between"> <div class="flex flex-row justify-between">
<div> <div>
<Checkbox <Checkbox
@ -120,6 +128,8 @@
</div> </div>
{/each} {/each}
</div> </div>
<!-- Remote branches -->
{#if remoteBranches} {#if remoteBranches}
<div <div
class="flex items-center justify-between border-b border-light-400 bg-light-100 py-2 pl-2 pr-4 dark:border-dark-600 dark:bg-dark-800" class="flex items-center justify-between border-b border-light-400 bg-light-100 py-2 pl-2 pr-4 dark:border-dark-600 dark:bg-dark-800"
@ -139,7 +149,7 @@
<div class="dark:bg-dark-900" use:accordion={remoteBranchesOpen}> <div class="dark:bg-dark-900" use:accordion={remoteBranchesOpen}>
{#each remoteBranches as branch} {#each remoteBranches as branch}
<div <div
on:contextmenu|preventDefault={(e) => popupMenu.openByMouse(e, branch)} on:contextmenu|preventDefault={(e) => remoteBranchContextMenu.openByMouse(e, branch)}
class="flex flex-col justify-between border-b border-light-400 p-2 pl-2 pr-4 dark:border-dark-600" class="flex flex-col justify-between border-b border-light-400 p-2 pl-2 pr-4 dark:border-dark-600"
> >
<div class="flex flex-row items-center gap-x-2"> <div class="flex flex-row items-center gap-x-2">
@ -177,7 +187,21 @@
{/each} {/each}
</div> </div>
{/if} {/if}
<PopupMenu bind:this={popupMenu} let:item>
<!-- Your branches context menu -->
<PopupMenu bind:this={yourBranchContextMenu} let:item>
{@const disabled = branches.some((b) => b.id == item.id && b.active)}
<PopupMenuItem
{disabled}
title={disabled ? 'Unapply before delete' : 'Delete branch'}
on:click={() => item && virtualBranches.deleteBranch(item.id)}
>
Delete
</PopupMenuItem>
</PopupMenu>
<!-- Remote branches context menu -->
<PopupMenu bind:this={remoteBranchContextMenu} let:item>
{@const disabled = !remoteBranches.some((b) => b.sha == item.sha && b.mergeable)} {@const disabled = !remoteBranches.some((b) => b.sha == item.sha && b.mergeable)}
<PopupMenuItem {disabled} on:click={() => item && makeBranch(item.name)}>Apply</PopupMenuItem> <PopupMenuItem {disabled} on:click={() => item && makeBranch(item.name)}>Apply</PopupMenuItem>
</PopupMenu> </PopupMenu>