Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions apps/desktop/src/components/FileContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,18 @@
<ContextMenuItem
label="Copy Path"
onclick={async () => {
try {
if (!project) return;
const absPath = await join(project.path, item.files[0].path);
writeClipboard(absPath);
contextMenu.close();
// dismiss();
} catch (err) {
console.error('Failed to copy path', err);
toasts.error('Failed to copy path');
}
if (!project) return;
const absPath = await join(project.path, item.files[0].path);
await writeClipboard(absPath, 'Failed to copy path');
contextMenu.close();
}}
/>
<ContextMenuItem
label="Copy Relative Path"
onclick={() => {
try {
if (!project) return;
writeClipboard(item.files[0].path);
contextMenu.close();
} catch (err) {
console.error('Failed to copy relative path', err);
toasts.error('Failed to copy relative path');
}
onclick={async () => {
if (!project) return;
await writeClipboard(item.files[0].path, 'Failed to copy relative path');
contextMenu.close();
}}
/>
{/if}
Expand Down
28 changes: 9 additions & 19 deletions apps/desktop/src/components/v3/FileContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,19 @@
<ContextMenuItem
label="Copy Path"
onclick={async () => {
try {
if (!project) return;
const absPath = await join(project.path, changes[0]!.path);
writeClipboard(absPath);
contextMenu.close();
// dismiss();
} catch (err) {
console.error('Failed to copy path', err);
toasts.error('Failed to copy path');
}
if (!project) return;
const absPath = await join(project.path, changes[0]!.path);
await writeClipboard(absPath, 'Failed to copy path');
contextMenu.close();
// dismiss();
}}
/>
<ContextMenuItem
label="Copy Relative Path"
onclick={() => {
try {
if (!project) return;
writeClipboard(changes[0]!.path);
contextMenu.close();
} catch (err) {
console.error('Failed to copy relative path', err);
toasts.error('Failed to copy relative path');
}
onclick={async () => {
if (!project) return;
await writeClipboard(changes[0]!.path, 'Failed to copy relative path');
contextMenu.close();
}}
/>
{/if}
Expand Down
20 changes: 18 additions & 2 deletions apps/desktop/src/lib/backend/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import * as toasts from '@gitbutler/ui/toasts';
import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager';

export async function writeClipboard(text: string) {
await writeText(text);
/**
* Copy the provided text into the the system clipboard. Upon completion, a toast will be displayed which contains
* information about the success of this operation.
*
* @param text text to be copied into the system clipboard.
* @param errorMessage optional custom error message which will be displayed if the operation failes. If this is
* not provided, a default generic message will be used.
*/
export async function writeClipboard(text: string, errorMessage = 'Failed to copy') {
await writeText(text)
.then(() => {
toasts.success('Copied to clipboard');
})
.catch((err) => {
toasts.error(errorMessage);
console.error(errorMessage, err);
});
}

export async function readClipboard() {
Expand Down
Loading