From 28fa6720b3b2e85e4adb188b76318390ec092d42 Mon Sep 17 00:00:00 2001 From: Ali Houssain Sareini Date: Mon, 14 Oct 2024 19:43:38 -0400 Subject: [PATCH] refactor: Update code editor paths to use editor from userSettings --- .../ProjectSettingsMenuAction.svelte | 7 +++++-- .../src/lib/components/BoardEmptyState.svelte | 19 ++++++++++++++----- .../src/lib/components/EditMode.svelte | 12 ++++++++---- .../src/lib/file/FileContextMenu.svelte | 12 ++++++++---- .../src/lib/hunk/HunkContextMenu.svelte | 11 ++++++++--- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/apps/desktop/src/lib/barmenuActions/ProjectSettingsMenuAction.svelte b/apps/desktop/src/lib/barmenuActions/ProjectSettingsMenuAction.svelte index 9945bf06c..115f2e6fa 100644 --- a/apps/desktop/src/lib/barmenuActions/ProjectSettingsMenuAction.svelte +++ b/apps/desktop/src/lib/barmenuActions/ProjectSettingsMenuAction.svelte @@ -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); onMount(() => { const unsubscribeSettings = listen('menu://project/settings/clicked', () => { @@ -20,7 +23,7 @@ const unsubscribeOpenInVSCode = listen( '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); } ); diff --git a/apps/desktop/src/lib/components/BoardEmptyState.svelte b/apps/desktop/src/lib/components/BoardEmptyState.svelte index dcdca436f..201edfebd 100644 --- a/apps/desktop/src/lib/components/BoardEmptyState.svelte +++ b/apps/desktop/src/lib/components/BoardEmptyState.svelte @@ -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); const project = getContext(Project); async function openInVSCode() { - openExternalUrl(`${$editor}://file${project.vscodePath}/?windowId=_blank`); + openExternalUrl( + `${$userSettings.defaultCodeEditor}://file${project.vscodePath}/?windowId=_blank` + ); } @@ -50,7 +58,8 @@ diff --git a/apps/desktop/src/lib/components/EditMode.svelte b/apps/desktop/src/lib/components/EditMode.svelte index 33321b77d..d7cec7235 100644 --- a/apps/desktop/src/lib/components/EditMode.svelte +++ b/apps/desktop/src/lib/components/EditMode.svelte @@ -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); 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}`); } } @@ -173,8 +177,8 @@ {editModeMetadata.commitOid.slice(0, 7)} - 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. diff --git a/apps/desktop/src/lib/file/FileContextMenu.svelte b/apps/desktop/src/lib/file/FileContextMenu.svelte index 633304600..17735013b 100644 --- a/apps/desktop/src/lib/file/FileContextMenu.svelte +++ b/apps/desktop/src/lib/file/FileContextMenu.svelte @@ -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); let confirmationModal: Modal; let contextMenu: ReturnType; @@ -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'); } }} /> diff --git a/apps/desktop/src/lib/hunk/HunkContextMenu.svelte b/apps/desktop/src/lib/hunk/HunkContextMenu.svelte index 95616a2e2..1469e49bd 100644 --- a/apps/desktop/src/lib/hunk/HunkContextMenu.svelte +++ b/apps/desktop/src/lib/hunk/HunkContextMenu.svelte @@ -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); let contextMenu: ReturnType; @@ -43,10 +46,12 @@ {/if} {#if item.lineNumber} { projectPath && - openExternalUrl(`${$editor}://file${projectPath}/${filePath}:${item.lineNumber}`); + openExternalUrl( + `${$userSettings.defaultCodeEditor}://file${projectPath}/${filePath}:${item.lineNumber}` + ); contextMenu.close(); }} />