refactor: Update code editor paths to use editor from userSettings

This commit is contained in:
Ali Houssain Sareini 2024-10-14 19:43:38 -04:00
parent 0d0652c351
commit 28fa6720b3
5 changed files with 43 additions and 18 deletions

View File

@ -2,15 +2,18 @@
import { listen } from '$lib/backend/ipc';
import { Project } from '$lib/backend/projects';
import { showHistoryView } from '$lib/config/config';
import { editor } from '$lib/editorLink/editorLink';
import { getContextStoreBySymbol } from '@gitbutler/shared/context';
import { SETTINGS, type Settings } from '$lib/settings/userSettings';
import * as events from '$lib/utils/events';
import { unsubscribe } from '$lib/utils/unsubscribe';
import { openExternalUrl } from '$lib/utils/url';
import { getContext } from '@gitbutler/shared/context';
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import type { Writable } from 'svelte/store';
const project = getContext(Project);
const userSettings = getContextStoreBySymbol<Settings, Writable<Settings>>(SETTINGS);
onMount(() => {
const unsubscribeSettings = listen<string>('menu://project/settings/clicked', () => {
@ -20,7 +23,7 @@
const unsubscribeOpenInVSCode = listen<string>(
'menu://project/open-in-vscode/clicked',
async () => {
const path = `${$editor}://file${project.vscodePath}?windowId=_blank`;
const path = `${$userSettings.defaultCodeEditor}://file${project.vscodePath}?windowId=_blank`;
openExternalUrl(path);
}
);

View File

@ -2,21 +2,29 @@
import zenSvg from '$lib/assets/dzen-pc.svg?raw';
import { Project } from '$lib/backend/projects';
import { BaseBranch } from '$lib/baseBranch/baseBranch';
import { editor } from '$lib/editorLink/editorLink';
import { SETTINGS, type Settings } from '$lib/settings/userSettings';
import { getGitHost } from '$lib/gitHost/interface/gitHost';
import { openExternalUrl } from '$lib/utils/url';
import { BranchController } from '$lib/vbranches/branchController';
import { getContext, getContextStore } from '@gitbutler/shared/context';
import {
getContext,
getContextStore,
getContextStoreBySymbol
} from '@gitbutler/shared/context';
import Icon from '@gitbutler/ui/Icon.svelte';
import type { Writable } from 'svelte/store';
const gitHost = getGitHost();
const baseBranch = getContextStore(BaseBranch);
const branchController = getContext(BranchController);
const userSettings = getContextStoreBySymbol<Settings, Writable<Settings>>(SETTINGS);
const project = getContext(Project);
async function openInVSCode() {
openExternalUrl(`${$editor}://file${project.vscodePath}/?windowId=_blank`);
openExternalUrl(
`${$userSettings.defaultCodeEditor}://file${project.vscodePath}/?windowId=_blank`
);
}
</script>
@ -50,7 +58,8 @@
</div>
<button
class="empty-board__suggestions__link"
on:click={async () => await openExternalUrl('https://docs.gitbutler.com')}
on:click={async () =>
await openExternalUrl('https://docs.gitbutler.com')}
>
<div class="empty-board__suggestions__link__icon">
<Icon name="docs" />
@ -66,7 +75,7 @@
<div class="empty-board__suggestions__link__icon">
<Icon name="vscode" />
</div>
<span class="text-12">Open in VSCode</span>
<span class="text-12">Open in Editor</span>
</button>
</div>
</div>

View File

@ -2,7 +2,9 @@
import { Project } from '$lib/backend/projects';
import { CommitService } from '$lib/commits/service';
import { conflictEntryHint, type ConflictEntryPresence } from '$lib/conflictEntryPresence';
import { editor } from '$lib/editorLink/editorLink';
import { SETTINGS, type Settings } from '$lib/settings/userSettings';
import { getContextStoreBySymbol } from '@gitbutler/shared/context';
import FileContextMenu from '$lib/file/FileContextMenu.svelte';
import { ModeService, type EditModeMetadata } from '$lib/modes/service';
import ScrollableContainer from '$lib/scroll/ScrollableContainer.svelte';
@ -17,6 +19,7 @@
import FileListItem from '@gitbutler/ui/file/FileListItem.svelte';
import { join } from '@tauri-apps/api/path';
import type { FileStatus } from '@gitbutler/ui/file/types';
import type { Writable } from 'svelte/store';
interface Props {
editModeMetadata: EditModeMetadata;
@ -28,6 +31,7 @@
const remoteCommitService = getContext(CommitService);
const uncommitedFileWatcher = getContext(UncommitedFilesWatcher);
const modeService = getContext(ModeService);
const userSettings = getContextStoreBySymbol<Settings, Writable<Settings>>(SETTINGS);
const uncommitedFiles = uncommitedFileWatcher.uncommitedFiles;
@ -162,7 +166,7 @@
async function openAllConflictedFiles() {
for (const file of conflictedFiles) {
const absPath = await join(project.vscodePath, file.path);
openExternalUrl(`${$editor}://file${absPath}`);
openExternalUrl(`${$userSettings.defaultCodeEditor}://file${absPath}`);
}
}
</script>
@ -173,8 +177,8 @@
{editModeMetadata.commitOid.slice(0, 7)}
</span>
<InfoButton title="Edit Mode">
Edit Mode lets you modify an existing commit in isolation or resolve conflicts. Any changes
made, including new files, will be added to the selected commit.
Edit Mode lets you modify an existing commit in isolation or resolve conflicts. Any
changes made, including new files, will be added to the selected commit.
</InfoButton>
</h2>

View File

@ -3,7 +3,9 @@
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 { editor } from '$lib/editorLink/editorLink';
import { getContextStoreBySymbol } from '@gitbutler/shared/context';
import { SETTINGS, type Settings } from '$lib/settings/userSettings';
import { computeFileStatus } from '$lib/utils/fileStatus';
import * as toasts from '$lib/utils/toasts';
import { openExternalUrl } from '$lib/utils/url';
@ -13,6 +15,7 @@
import Button from '@gitbutler/ui/Button.svelte';
import Modal from '@gitbutler/ui/Modal.svelte';
import { join } from '@tauri-apps/api/path';
import type { Writable } from 'svelte/store';
export let branchId: string | undefined;
export let target: HTMLElement | undefined;
@ -20,6 +23,7 @@
const branchController = getContext(BranchController);
const project = getContext(Project);
const userSettings = getContextStoreBySymbol<Settings, Writable<Settings>>(SETTINGS);
let confirmationModal: Modal;
let contextMenu: ReturnType<typeof ContextMenu>;
@ -90,12 +94,12 @@
if (!project) return;
for (let file of item.files) {
const absPath = await join(project.vscodePath, file.path);
openExternalUrl(`${$editor}://file${absPath}`);
openExternalUrl(`${$userSettings.defaultCodeEditor}://file${absPath}`);
}
contextMenu.close();
} catch {
console.error('Failed to open in VSCode');
toasts.error('Failed to open in VSCode');
console.error('Failed to open in editor');
toasts.error('Failed to open in editor');
}
}}
/>

View File

@ -2,10 +2,12 @@
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 { editor } from '$lib/editorLink/editorLink';
import { SETTINGS, type Settings } from '$lib/settings/userSettings';
import { getContextStoreBySymbol } from '@gitbutler/shared/context';
import { openExternalUrl } from '$lib/utils/url';
import { BranchController } from '$lib/vbranches/branchController';
import { getContext } from '@gitbutler/shared/context';
import type { Writable } from 'svelte/store';
interface Props {
target: HTMLElement | undefined;
@ -17,6 +19,7 @@
let { target, filePath, projectPath, readonly }: Props = $props();
const branchController = getContext(BranchController);
const userSettings = getContextStoreBySymbol<Settings, Writable<Settings>>(SETTINGS);
let contextMenu: ReturnType<typeof ContextMenu>;
@ -43,10 +46,12 @@
{/if}
{#if item.lineNumber}
<ContextMenuItem
label="Open in VSCode"
label="Open in Editor"
on:click={() => {
projectPath &&
openExternalUrl(`${$editor}://file${projectPath}/${filePath}:${item.lineNumber}`);
openExternalUrl(
`${$userSettings.defaultCodeEditor}://file${projectPath}/${filePath}:${item.lineNumber}`
);
contextMenu.close();
}}
/>