@@ -144,14 +144,34 @@ export enum PatchSuggestionState {
144144 ERROR = 'error' ,
145145}
146146
147+ enum SelectedProjectType {
148+ /**
149+ * No project selected
150+ */
151+ NONE = 'none' ,
152+ /**
153+ * The selected project is not an automatic workspace project
154+ */
155+ REGULAR = 'regular' ,
156+ /**
157+ * The selected project is a disconnected automatic workspace project
158+ */
159+ AUTOMATIC_DISCONNECTED = 'automaticDisconncted' ,
160+ /**
161+ * The selected project is a connected automatic workspace project
162+ */
163+ AUTOMATIC_CONNECTED = 'automaticConnected' ,
164+ }
165+
147166export interface ViewInput {
148167 workspaceDiff : WorkspaceDiff . WorkspaceDiff . WorkspaceDiffImpl ;
149168 patchSuggestionState : PatchSuggestionState ;
150169 changeSummary ?: string ;
151170 sources ?: string ;
152- projectName ?: string ;
153- savedToDisk ?: boolean ;
171+ projectName : string ;
154172 projectPath : Platform . DevToolsPath . RawPathString ;
173+ projectType : SelectedProjectType ;
174+ savedToDisk ?: boolean ;
155175 applyToWorkspaceTooltipText : Platform . UIString . LocalizedString ;
156176 onLearnMoreTooltipClick : ( ) => void ;
157177 onApplyToWorkspace : ( ) => void ;
@@ -318,12 +338,13 @@ export class PatchWidget extends UI.Widget.Widget {
318338 ` ;
319339 }
320340
341+ const iconName = input . projectType === SelectedProjectType . AUTOMATIC_DISCONNECTED ? 'folder-off' : input . projectType === SelectedProjectType . AUTOMATIC_CONNECTED ? 'folder-asterisk' : 'folder' ;
321342 return html `
322343 < div class ="footer ">
323344 ${ input . projectName ? html `
324345 < div class ="change-workspace ">
325346 < div class ="selected-folder ">
326- < devtools-icon .name =${ 'folder' } > </ devtools-icon > < span class ="folder-name " title =${ input . projectPath } > ${ input . projectName } </ span >
347+ < devtools-icon .name =${ iconName } > </ devtools-icon > < span class ="folder-name " title =${ input . projectPath } > ${ input . projectName } </ span >
327348 </ div >
328349 ${ input . onChangeWorkspaceClick ? html `
329350 < devtools-button
@@ -346,7 +367,7 @@ export class PatchWidget extends UI.Widget.Widget {
346367 </ span >
347368 </ div >
348369 ` : html `
349- < devtools-button
370+ < devtools-button
350371 @click =${ input . onApplyToWorkspace }
351372 .jslogContext =${ 'stage-to-workspace' }
352373 .variant=${ Buttons . Button . Variant . OUTLINED } >
@@ -412,22 +433,48 @@ export class PatchWidget extends UI.Widget.Widget {
412433 void UI . ViewManager . ViewManager . instance ( ) . showView ( 'chrome-ai' ) ;
413434 }
414435
415- override performUpdate ( ) : void {
416- const projectName = this . #project ? Common . ParsedURL . ParsedURL . encodedPathToRawPathString (
417- this . #project. displayName ( ) as Platform . DevToolsPath . EncodedPathString ) :
418- undefined ;
419- const projectPath = this . #project ?
420- Common . ParsedURL . ParsedURL . urlToRawPathString (
421- this . #project. id ( ) as Platform . DevToolsPath . UrlString , Host . Platform . isWin ( ) ) :
422- Platform . DevToolsPath . EmptyRawPathString ;
436+ #getDisplayedProject( ) : { projectName : string , projectPath : Platform . DevToolsPath . RawPathString } {
437+ if ( this . #project) {
438+ return {
439+ projectName : Common . ParsedURL . ParsedURL . encodedPathToRawPathString (
440+ this . #project. displayName ( ) as Platform . DevToolsPath . EncodedPathString ) ,
441+ projectPath : Common . ParsedURL . ParsedURL . urlToRawPathString (
442+ this . #project. id ( ) as Platform . DevToolsPath . UrlString , Host . Platform . isWin ( ) ) ,
443+ } ;
444+ }
445+ if ( this . #automaticFileSystem) {
446+ return {
447+ projectName : Common . ParsedURL . ParsedURL . extractName ( this . #automaticFileSystem. root ) ,
448+ projectPath : this . #automaticFileSystem. root ,
449+ } ;
450+ }
451+ return {
452+ projectName : '' ,
453+ projectPath : Platform . DevToolsPath . EmptyRawPathString ,
454+ } ;
455+ }
456+
457+ #shouldShowChangeButton( ) : boolean {
423458 const automaticFileSystemProject =
424459 this . #automaticFileSystem ? this . #workspace. projectForFileSystemRoot ( this . #automaticFileSystem. root ) : null ;
425- const projects = this . #workspace. projectsForType ( Workspace . Workspace . projectTypes . FileSystem )
426- . filter (
427- project => project instanceof Persistence . FileSystemWorkspaceBinding . FileSystem &&
428- project . fileSystem ( ) . type ( ) ===
429- Persistence . PlatformFileSystem . PlatformFileSystemType . WORKSPACE_PROJECT ) ;
430- const showChangeButton = projects . length > 1 || this . #project !== automaticFileSystemProject ;
460+ const regularProjects = this . #workspace. projectsForType ( Workspace . Workspace . projectTypes . FileSystem )
461+ . filter (
462+ project => project instanceof Persistence . FileSystemWorkspaceBinding . FileSystem &&
463+ project . fileSystem ( ) . type ( ) ===
464+ Persistence . PlatformFileSystem . PlatformFileSystemType . WORKSPACE_PROJECT )
465+ . filter ( project => project !== automaticFileSystemProject ) ;
466+ return regularProjects . length > 0 ;
467+ }
468+
469+ #getSelectedProjectType( projectPath : Platform . DevToolsPath . RawPathString ) : SelectedProjectType {
470+ if ( this . #automaticFileSystem && this . #automaticFileSystem. root === projectPath ) {
471+ return this . #project ? SelectedProjectType . AUTOMATIC_CONNECTED : SelectedProjectType . AUTOMATIC_DISCONNECTED ;
472+ }
473+ return this . #project ? SelectedProjectType . NONE : SelectedProjectType . REGULAR ;
474+ }
475+
476+ override performUpdate ( ) : void {
477+ const { projectName, projectPath} = this . #getDisplayedProject( ) ;
431478
432479 this . #view(
433480 {
@@ -437,6 +484,7 @@ export class PatchWidget extends UI.Widget.Widget {
437484 sources : this . #patchSources,
438485 projectName,
439486 projectPath,
487+ projectType : this . #getSelectedProjectType( projectPath ) ,
440488 savedToDisk : this . #savedToDisk,
441489 applyToWorkspaceTooltipText : this . #noLogging ?
442490 lockedString ( UIStringsNotTranslate . applyToWorkspaceTooltipNoLogging ) :
@@ -448,8 +496,9 @@ export class PatchWidget extends UI.Widget.Widget {
448496 } ,
449497 onDiscard : this . #onDiscard. bind ( this ) ,
450498 onSaveAll : this . #onSaveAll. bind ( this ) ,
451- onChangeWorkspaceClick : showChangeButton ? this . #showSelectWorkspaceDialog. bind ( this , { applyPatch : false } ) :
452- undefined ,
499+ onChangeWorkspaceClick : this . #shouldShowChangeButton( ) ?
500+ this . #showSelectWorkspaceDialog. bind ( this , { applyPatch : false } ) :
501+ undefined ,
453502 } ,
454503 this . #viewOutput, this . contentElement ) ;
455504 }
@@ -459,6 +508,7 @@ export class PatchWidget extends UI.Widget.Widget {
459508 this . #selectDefaultProject( ) ;
460509
461510 if ( isAiAssistancePatchingEnabled ( ) ) {
511+ this . #workspace. addEventListener ( Workspace . Workspace . Events . ProjectAdded , this . #onProjectAdded, this ) ;
462512 this . #workspace. addEventListener ( Workspace . Workspace . Events . ProjectRemoved , this . #onProjectRemoved, this ) ;
463513
464514 // @ts -expect-error temporary global function for local testing.
@@ -470,6 +520,7 @@ export class PatchWidget extends UI.Widget.Widget {
470520
471521 override willHide ( ) : void {
472522 if ( isAiAssistancePatchingEnabled ( ) ) {
523+ this . #workspace. removeEventListener ( Workspace . Workspace . Events . ProjectAdded , this . #onProjectAdded, this ) ;
473524 this . #workspace. removeEventListener ( Workspace . Workspace . Events . ProjectRemoved , this . #onProjectRemoved, this ) ;
474525 }
475526 }
@@ -531,6 +582,12 @@ export class PatchWidget extends UI.Widget.Widget {
531582 this . requestUpdate ( ) ;
532583 }
533584
585+ #onProjectAdded( ) : void {
586+ if ( this . #project === undefined ) {
587+ this . #selectDefaultProject( ) ;
588+ }
589+ }
590+
534591 #onProjectRemoved( ) : void {
535592 if ( this . #project && ! this . #workspace. project ( this . #project. id ( ) ) ) {
536593 this . #projectIdSetting. set ( '' ) ;
0 commit comments