-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add StackingBranchHeader contextMenu and handlers for contextMe…
…nuItems as well as their Modals
- Loading branch information
Showing
2 changed files
with
175 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
apps/desktop/src/lib/branch/StackingBranchHeaderContextMenu.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<script lang="ts"> | ||
import ContextMenu from '$lib/components/contextmenu/ContextMenu.svelte'; | ||
import ContextMenuItem from '$lib/components/contextmenu/ContextMenuItem.svelte'; | ||
import ContextMenuSection from '$lib/components/contextmenu/ContextMenuSection.svelte'; | ||
import TextBox from '$lib/shared/TextBox.svelte'; | ||
import { getContext, getContextStore } from '$lib/utils/context'; | ||
import { BranchController } from '$lib/vbranches/branchController'; | ||
import { VirtualBranch } from '$lib/vbranches/types'; | ||
import Button from '@gitbutler/ui/Button.svelte'; | ||
import Modal from '@gitbutler/ui/Modal.svelte'; | ||
interface Props { | ||
contextMenuEl?: ReturnType<typeof ContextMenu>; | ||
target?: HTMLElement; | ||
addDescription: () => void; | ||
} | ||
let { contextMenuEl = $bindable(), target, addDescription }: Props = $props(); | ||
const branchStore = getContextStore(VirtualBranch); | ||
const branchController = getContext(BranchController); | ||
let deleteSeriesModal: Modal; | ||
let deleteSeriesCommitsModal: Modal; | ||
let renameSeriesModal: Modal; | ||
let newSeriesName = $state(''); | ||
let isDeleting = $state(false); | ||
const branch = $derived($branchStore); | ||
</script> | ||
|
||
<ContextMenu bind:this={contextMenuEl} {target}> | ||
<ContextMenuSection> | ||
<ContextMenuItem | ||
label="Add a description" | ||
on:click={() => { | ||
addDescription(); | ||
contextMenuEl?.close(); | ||
}} | ||
/> | ||
<ContextMenuItem | ||
label="Rename Series" | ||
on:click={async () => { | ||
renameSeriesModal.show(branch); | ||
contextMenuEl?.close(); | ||
}} | ||
/> | ||
<ContextMenuItem | ||
label="Delete Series & Commits" | ||
on:click={() => { | ||
deleteSeriesCommitsModal.show(branch); | ||
contextMenuEl?.close(); | ||
}} | ||
/> | ||
<ContextMenuItem | ||
label="Delete Series Only" | ||
on:click={() => { | ||
deleteSeriesModal.show(branch); | ||
contextMenuEl?.close(); | ||
}} | ||
/> | ||
</ContextMenuSection> | ||
</ContextMenu> | ||
|
||
<Modal | ||
width="small" | ||
bind:this={renameSeriesModal} | ||
onSubmit={(close) => { | ||
branchController.updateBranchRemoteName(branch.id, newSeriesName); | ||
close(); | ||
}} | ||
> | ||
<TextBox label="Series Name" id="newSeriesName" bind:value={newSeriesName} focus /> | ||
|
||
{#snippet controls(close)} | ||
<Button style="ghost" outline type="reset" onclick={close}>Cancel</Button> | ||
<Button style="pop" kind="solid" type="submit">Rename</Button> | ||
{/snippet} | ||
</Modal> | ||
|
||
<Modal | ||
width="small" | ||
title="Delete Series" | ||
bind:this={deleteSeriesModal} | ||
onSubmit={async (close) => { | ||
try { | ||
isDeleting = true; | ||
await branchController.saveAndUnapply(branch.id); | ||
close(); | ||
} finally { | ||
isDeleting = false; | ||
} | ||
}} | ||
> | ||
{#snippet children(branch)} | ||
Are you sure you want to delete <code class="code-string">{branch.name}</code>? | ||
{/snippet} | ||
{#snippet controls(close)} | ||
<Button style="ghost" outline onclick={close}>Cancel</Button> | ||
<Button style="error" kind="solid" type="submit" loading={isDeleting}>Delete</Button> | ||
{/snippet} | ||
</Modal> | ||
|
||
<Modal | ||
width="small" | ||
title="Delete Series & Commits" | ||
bind:this={deleteSeriesCommitsModal} | ||
onSubmit={async (close) => { | ||
try { | ||
isDeleting = true; | ||
await branchController.unapplyWithoutSaving(branch.id); | ||
close(); | ||
} finally { | ||
isDeleting = false; | ||
} | ||
}} | ||
> | ||
{#snippet children(branch)} | ||
Are you sure you want to delete <code class="code-string">{branch.name}</code>? | ||
{/snippet} | ||
{#snippet controls(close)} | ||
<Button style="ghost" outline onclick={close}>Cancel</Button> | ||
<Button style="error" kind="solid" type="submit" loading={isDeleting}>Delete</Button> | ||
{/snippet} | ||
</Modal> |