1- import { Event , EventEmitter , Memento , window } from 'vscode'
1+ import { Event , EventEmitter , Memento } from 'vscode'
2+ import { setContextForEditorTitleIcons } from './context'
23import { ExperimentsModel } from './model'
34import { pickExperiments } from './model/quickPicks'
45import { pickAndModifyParams } from './model/modify/quickPick'
@@ -25,8 +26,6 @@ import { FileSystemData } from '../fileSystem/data'
2526import { Response } from '../vscode/response'
2627import { Title } from '../vscode/title'
2728import { createTypedAccumulator } from '../util/object'
28- import { setContextValue } from '../vscode/context'
29- import { standardizePath } from '../fileSystem/path'
3029import { pickPaths } from '../path/selection/quickPick'
3130import { Toast } from '../vscode/toast'
3231
@@ -122,7 +121,7 @@ export class Experiments extends BaseRepository<TableData> {
122121
123122 this . webviewMessages = this . createWebviewMessageHandler ( )
124123 this . setupInitialData ( )
125- this . setActiveEditorContext ( )
124+ this . watchActiveEditor ( )
126125 }
127126
128127 public update ( ) {
@@ -498,43 +497,13 @@ export class Experiments extends BaseRepository<TableData> {
498497 return experiment ?. id
499498 }
500499
501- private setActiveEditorContext ( ) {
502- const setActiveEditorContext = ( active : boolean ) => {
503- setContextValue ( 'dvc.params.fileActive' , active )
504- const activeDvcRoot = active ? this . dvcRoot : undefined
505- this . paramsFileFocused . fire ( activeDvcRoot )
506- }
507-
508- this . dispose . track (
509- this . onDidChangeColumns ( ( ) => {
510- const path = standardizePath ( window . activeTextEditor ?. document . fileName )
511- if ( ! path ) {
512- return
513- }
514-
515- if ( ! this . columns . getParamsFiles ( ) . has ( path ) ) {
516- return
517- }
518- setActiveEditorContext ( true )
519- } )
520- )
521-
522- this . dispose . track (
523- window . onDidChangeActiveTextEditor ( event => {
524- const path = standardizePath ( event ?. document . fileName )
525- if ( ! path ) {
526- setActiveEditorContext ( false )
527- return
528- }
529-
530- if ( path . includes ( this . dvcRoot ) ) {
531- if ( this . columns . getParamsFiles ( ) . has ( path ) ) {
532- setActiveEditorContext ( true )
533- return
534- }
535- setActiveEditorContext ( false )
536- }
537- } )
500+ private watchActiveEditor ( ) {
501+ setContextForEditorTitleIcons (
502+ this . dvcRoot ,
503+ this . dispose ,
504+ ( ) => this . columns . getParamsFiles ( ) ,
505+ this . paramsFileFocused ,
506+ this . onDidChangeColumns
538507 )
539508 }
540509}
0 commit comments