@@ -30,10 +30,19 @@ define([
3030 PanelFileView . __super__ . initialize . apply ( this , arguments ) ;
3131
3232 var box = codebox . require ( "core/box" ) ;
33+ var files = codebox . require ( "core/files" ) ;
3334
34- // Update tags when file changes
35+ // Remove view when close file
36+ this . listenTo ( files . active , "remove" , this . detachFile ) ;
37+
38+ // Update view when file changes
3539 this . listenTo ( box , "file.active" , this . update ) ;
3640
41+ // Update file view when changes
42+ this . listenTo ( box , "box:watch:change" , function ( e ) {
43+ this . updateFile ( e . data . path ) ;
44+ } ) ;
45+
3746 // Different cached file views
3847 this . fileViews = { } ;
3948 } ,
@@ -63,6 +72,31 @@ define([
6372 this . fileViews [ path ] . $el . appendTo ( this . $el ) ;
6473
6574 return this . ready ( ) ;
75+ } ,
76+
77+ /**
78+ * Detach a file from this file panel
79+ *
80+ * @private
81+ */
82+ detachFile : function ( file ) {
83+ var path = _ . isString ( file ) ? file : file . path ( ) ;
84+ if ( ! this . fileViews [ path ] ) return ;
85+
86+ this . fileViews [ path ] . remove ( ) ;
87+ delete this . fileViews [ path ] ;
88+ } ,
89+
90+ /**
91+ * Update a file
92+ *
93+ * @private
94+ */
95+ updateFile : function ( file ) {
96+ var path = _ . isString ( file ) ? file : file . path ( ) ;
97+ if ( ! this . fileViews [ path ] ) return ;
98+
99+ this . fileViews [ path ] . update ( ) ;
66100 }
67101 } ) ;
68102
0 commit comments