@@ -304,7 +304,7 @@ function addSession(persistedSession: PersistedSession, hasActivePty: boolean) {
304304 sessions . set ( persistedSession . id , session ) ;
305305
306306 // Add to sidebar
307- addToSidebar ( persistedSession . id , persistedSession . name , hasActivePty ) ;
307+ addToSidebar ( persistedSession . id , persistedSession . name , hasActivePty , persistedSession . config ) ;
308308
309309 // Only add tab if terminal is active
310310 if ( hasActivePty ) {
@@ -351,10 +351,13 @@ function updateSessionState(sessionId: string, isActive: boolean) {
351351 }
352352}
353353
354- function addToSidebar ( sessionId : string , name : string , hasActivePty : boolean ) {
354+ function addToSidebar ( sessionId : string , name : string , hasActivePty : boolean , config : SessionConfig ) {
355355 const list = document . getElementById ( "session-list" ) ;
356356 if ( ! list ) return ;
357357
358+ const isWorktree = config . sessionType === SessionType . WORKTREE ;
359+ const applyMenuItem = isWorktree ? `<button class="session-menu-item apply-to-project-btn" data-id="${ sessionId } ">Apply to project</button>` : '' ;
360+
358361 const item = document . createElement ( "div" ) ;
359362 item . id = `sidebar-${ sessionId } ` ;
360363 item . className = "session-list-item" ;
@@ -368,6 +371,7 @@ function addToSidebar(sessionId: string, name: string, hasActivePty: boolean) {
368371 <button class="session-menu-btn" data-id="${ sessionId } " title="Session options">⋯</button>
369372 <div class="session-menu hidden" data-id="${ sessionId } ">
370373 <button class="session-menu-item rename-session-btn" data-id="${ sessionId } ">Rename</button>
374+ ${ applyMenuItem }
371375 <button class="session-menu-item delete-session-btn" data-id="${ sessionId } ">Delete</button>
372376 </div>
373377 </div>
@@ -430,6 +434,14 @@ function addToSidebar(sessionId: string, name: string, hasActivePty: boolean) {
430434 deleteSession ( sessionId ) ;
431435 } ) ;
432436
437+ // Apply to project button (only for worktree sessions)
438+ const applyBtn = item . querySelector ( ".apply-to-project-btn" ) ;
439+ applyBtn ?. addEventListener ( "click" , ( e ) => {
440+ e . stopPropagation ( ) ;
441+ menu ?. classList . add ( "hidden" ) ;
442+ showApplyToProjectDialog ( sessionId ) ;
443+ } ) ;
444+
433445 list . appendChild ( item ) ;
434446}
435447
@@ -721,6 +733,27 @@ function deleteSession(sessionId: string) {
721733 }
722734}
723735
736+ function showApplyToProjectDialog ( sessionId : string ) {
737+ const session = sessions . get ( sessionId ) ;
738+ if ( ! session ) return ;
739+
740+ const modal = document . getElementById ( "apply-to-project-modal" ) ;
741+ const branchName = document . getElementById ( "apply-branch-name" ) ;
742+ const parentBranch = document . getElementById ( "apply-parent-branch" ) ;
743+
744+ if ( branchName && session . config . branchName ) {
745+ branchName . textContent = session . config . branchName ;
746+ }
747+ if ( parentBranch && session . config . parentBranch ) {
748+ parentBranch . textContent = session . config . parentBranch ;
749+ }
750+
751+ // Store session ID for later use in confirm handler
752+ modal ?. setAttribute ( "data-session-id" , sessionId ) ;
753+
754+ modal ?. classList . remove ( "hidden" ) ;
755+ }
756+
724757// Handle session output
725758ipcRenderer . on ( "session-output" , ( _event , sessionId : string , data : string ) => {
726759 const session = sessions . get ( sessionId ) ;
@@ -1504,6 +1537,45 @@ saveSettingsBtn?.addEventListener("click", async () => {
15041537// Load settings on startup
15051538loadSettings ( ) ;
15061539
1540+ // Apply to Project Modal
1541+ const applyToProjectModal = document . getElementById ( "apply-to-project-modal" ) ;
1542+ const cancelApplyToProjectBtn = document . getElementById ( "cancel-apply-to-project" ) ;
1543+ const confirmApplyToProjectBtn = document . getElementById ( "confirm-apply-to-project" ) ;
1544+
1545+ cancelApplyToProjectBtn ?. addEventListener ( "click" , ( ) => {
1546+ applyToProjectModal ?. classList . add ( "hidden" ) ;
1547+ } ) ;
1548+
1549+ confirmApplyToProjectBtn ?. addEventListener ( "click" , async ( ) => {
1550+ const sessionId = applyToProjectModal ?. getAttribute ( "data-session-id" ) ;
1551+ if ( ! sessionId ) return ;
1552+
1553+ // Disable button during operation
1554+ if ( confirmApplyToProjectBtn ) {
1555+ confirmApplyToProjectBtn . textContent = "Applying..." ;
1556+ confirmApplyToProjectBtn . setAttribute ( "disabled" , "true" ) ;
1557+ }
1558+
1559+ try {
1560+ const result = await ipcRenderer . invoke ( "apply-session-to-project" , sessionId ) ;
1561+
1562+ if ( result . success ) {
1563+ alert ( `Changes applied successfully to project directory.` ) ;
1564+ applyToProjectModal ?. classList . add ( "hidden" ) ;
1565+ } else {
1566+ alert ( `Failed to apply changes: ${ result . error } ` ) ;
1567+ }
1568+ } catch ( error ) {
1569+ alert ( `Error applying changes: ${ error } ` ) ;
1570+ } finally {
1571+ // Re-enable button
1572+ if ( confirmApplyToProjectBtn ) {
1573+ confirmApplyToProjectBtn . textContent = "Apply Changes" ;
1574+ confirmApplyToProjectBtn . removeAttribute ( "disabled" ) ;
1575+ }
1576+ }
1577+ } ) ;
1578+
15071579// Close session menus when clicking outside
15081580document . addEventListener ( "click" , ( e ) => {
15091581 const target = e . target as HTMLElement ;
0 commit comments