1- import React , { useCallback , useEffect } from "react" ;
1+ import React , { useCallback , useEffect , useState } from "react" ;
2+ import { Pencil } from "lucide-react" ;
23import { GitStatusIndicator } from "./GitStatusIndicator" ;
34import { RuntimeBadge } from "./RuntimeBadge" ;
45import { Tooltip , TooltipTrigger , TooltipContent } from "./ui/tooltip" ;
@@ -9,6 +10,7 @@ import { Button } from "@/browser/components/ui/button";
910import type { RuntimeConfig } from "@/common/types/runtime" ;
1011import { useTutorial } from "@/browser/contexts/TutorialContext" ;
1112import { useOpenTerminal } from "@/browser/hooks/useOpenTerminal" ;
13+ import { useOpenInEditor } from "@/browser/hooks/useOpenInEditor" ;
1214
1315interface WorkspaceHeaderProps {
1416 workspaceId : string ;
@@ -26,13 +28,26 @@ export const WorkspaceHeader: React.FC<WorkspaceHeaderProps> = ({
2628 runtimeConfig,
2729} ) => {
2830 const openTerminal = useOpenTerminal ( ) ;
31+ const openInEditor = useOpenInEditor ( ) ;
2932 const gitStatus = useGitStatus ( workspaceId ) ;
3033 const { canInterrupt } = useWorkspaceSidebarState ( workspaceId ) ;
3134 const { startSequence : startTutorial , isSequenceCompleted } = useTutorial ( ) ;
35+ const [ editorError , setEditorError ] = useState < string | null > ( null ) ;
36+
3237 const handleOpenTerminal = useCallback ( ( ) => {
3338 openTerminal ( workspaceId , runtimeConfig ) ;
3439 } , [ workspaceId , openTerminal , runtimeConfig ] ) ;
3540
41+ const handleOpenInEditor = useCallback ( async ( ) => {
42+ setEditorError ( null ) ;
43+ const result = await openInEditor ( workspaceId , runtimeConfig ) ;
44+ if ( ! result . success && result . error ) {
45+ setEditorError ( result . error ) ;
46+ // Clear error after 3 seconds
47+ setTimeout ( ( ) => setEditorError ( null ) , 3000 ) ;
48+ }
49+ } , [ workspaceId , openInEditor , runtimeConfig ] ) ;
50+
3651 // Start workspace tutorial on first entry (only if settings tutorial is done)
3752 useEffect ( ( ) => {
3853 // Don't show workspace tutorial until settings tutorial is completed
@@ -64,24 +79,42 @@ export const WorkspaceHeader: React.FC<WorkspaceHeaderProps> = ({
6479 { namedWorkspacePath }
6580 </ span >
6681 </ div >
67- < Tooltip >
68- < TooltipTrigger asChild >
69- < Button
70- variant = "ghost"
71- size = "icon"
72- onClick = { handleOpenTerminal }
73- className = "text-muted hover:text-foreground ml-2 h-6 w-6 shrink-0 [&_svg]:h-4 [&_svg]:w-4"
74- data-tutorial = "terminal-button"
75- >
76- < svg viewBox = "0 0 16 16" fill = "currentColor" >
77- < path d = "M0 2.75C0 1.784.784 1 1.75 1h12.5c.966 0 1.75.784 1.75 1.75v10.5A1.75 1.75 0 0114.25 15H1.75A1.75 1.75 0 010 13.25V2.75zm1.75-.25a.25.25 0 00-.25.25v10.5c0 .138.112.25.25.25h12.5a.25.25 0 00.25-.25V2.75a.25.25 0 00-.25-.25H1.75zM7.25 8a.75.75 0 01-.22.53l-2.25 2.25a.75.75 0 01-1.06-1.06L5.44 8 3.72 6.28a.75.75 0 111.06-1.06l2.25 2.25c.141.14.22.331.22.53zm1.5 1.5a.75.75 0 000 1.5h3a.75.75 0 000-1.5h-3z" />
78- </ svg >
79- </ Button >
80- </ TooltipTrigger >
81- < TooltipContent side = "bottom" align = "center" >
82- Open terminal window ({ formatKeybind ( KEYBINDS . OPEN_TERMINAL ) } )
83- </ TooltipContent >
84- </ Tooltip >
82+ < div className = "flex items-center" >
83+ { editorError && < span className = "text-danger-soft mr-2 text-xs" > { editorError } </ span > }
84+ < Tooltip >
85+ < TooltipTrigger asChild >
86+ < Button
87+ variant = "ghost"
88+ size = "icon"
89+ onClick = { ( ) => void handleOpenInEditor ( ) }
90+ className = "text-muted hover:text-foreground h-6 w-6 shrink-0"
91+ >
92+ < Pencil className = "h-4 w-4" />
93+ </ Button >
94+ </ TooltipTrigger >
95+ < TooltipContent side = "bottom" align = "center" >
96+ Open in editor ({ formatKeybind ( KEYBINDS . OPEN_IN_EDITOR ) } )
97+ </ TooltipContent >
98+ </ Tooltip >
99+ < Tooltip >
100+ < TooltipTrigger asChild >
101+ < Button
102+ variant = "ghost"
103+ size = "icon"
104+ onClick = { handleOpenTerminal }
105+ className = "text-muted hover:text-foreground ml-1 h-6 w-6 shrink-0 [&_svg]:h-4 [&_svg]:w-4"
106+ data-tutorial = "terminal-button"
107+ >
108+ < svg viewBox = "0 0 16 16" fill = "currentColor" >
109+ < path d = "M0 2.75C0 1.784.784 1 1.75 1h12.5c.966 0 1.75.784 1.75 1.75v10.5A1.75 1.75 0 0114.25 15H1.75A1.75 1.75 0 010 13.25V2.75zm1.75-.25a.25.25 0 00-.25.25v10.5c0 .138.112.25.25.25h12.5a.25.25 0 00.25-.25V2.75a.25.25 0 00-.25-.25H1.75zM7.25 8a.75.75 0 01-.22.53l-2.25 2.25a.75.75 0 01-1.06-1.06L5.44 8 3.72 6.28a.75.75 0 111.06-1.06l2.25 2.25c.141.14.22.331.22.53zm1.5 1.5a.75.75 0 000 1.5h3a.75.75 0 000-1.5h-3z" />
110+ </ svg >
111+ </ Button >
112+ </ TooltipTrigger >
113+ < TooltipContent side = "bottom" align = "center" >
114+ Open terminal window ({ formatKeybind ( KEYBINDS . OPEN_TERMINAL ) } )
115+ </ TooltipContent >
116+ </ Tooltip >
117+ </ div >
85118 </ div >
86119 ) ;
87120} ;
0 commit comments