@@ -123,6 +123,47 @@ export class ReferenceManager {
123123 return res ;
124124 }
125125
126+ /**
127+ * 更新当前项目中的一个Section的引用信息
128+ * @param recentFiles
129+ * @param sectionName
130+ */
131+ public async updateOneSectionReferenceInfo ( recentFiles : RecentFileManager . RecentFile [ ] , sectionName : string ) {
132+ const fileNameList = this . project . references . sections [ sectionName ] ;
133+ const fileNameListNew = [ ] ;
134+ for ( const fileName of fileNameList ) {
135+ const file = recentFiles . find (
136+ ( file ) =>
137+ PathString . getFileNameFromPath ( file . uri . path ) === fileName ||
138+ PathString . getFileNameFromPath ( file . uri . fsPath ) === fileName ,
139+ ) ;
140+ if ( file ) {
141+ // 即使文件存在,也要打开看一看引用块是否在那个文件中。
142+ const thatProject = new Project ( file . uri ) ;
143+ loadAllServicesBeforeInit ( thatProject ) ;
144+ await thatProject . init ( ) ;
145+ if (
146+ this . checkReferenceBlockInProject (
147+ thatProject ,
148+ PathString . getFileNameFromPath ( this . project . uri . path ) ,
149+ sectionName ,
150+ )
151+ ) {
152+ fileNameListNew . push ( fileName ) ;
153+ } else {
154+ toast . warning ( `文件 ${ fileName } 中不再引用 ${ sectionName } ,已从引用列表中移除` ) ;
155+ }
156+ thatProject . dispose ( ) ;
157+ }
158+ }
159+ if ( fileNameListNew . length === 0 ) {
160+ // 直接把这个章节从引用列表中删除
161+ delete this . project . references . sections [ sectionName ] ;
162+ } else {
163+ this . project . references . sections [ sectionName ] = fileNameListNew ;
164+ }
165+ }
166+
126167 /**
127168 * 更新当前项目的引用信息
128169 * (清理无效的引用)
@@ -132,31 +173,7 @@ export class ReferenceManager {
132173
133174 // 遍历当前项目的每一个被引用的Section框
134175 for ( const sectionName in this . project . references . sections ) {
135- const fileNameList = this . project . references . sections [ sectionName ] ;
136- const fileNameListNew = [ ] ;
137- for ( const fileName of fileNameList ) {
138- const file = recentFiles . find (
139- ( file ) =>
140- PathString . getFileNameFromPath ( file . uri . path ) === fileName ||
141- PathString . getFileNameFromPath ( file . uri . fsPath ) === fileName ,
142- ) ;
143- if ( file ) {
144- // 即使文件存在,也要打开看一看引用块是否在那个文件中。
145- const thatProject = new Project ( file . uri ) ;
146- loadAllServicesBeforeInit ( thatProject ) ;
147- await thatProject . init ( ) ;
148- if ( this . checkReferenceBlockInProject ( thatProject , fileName , sectionName ) ) {
149- fileNameListNew . push ( fileName ) ;
150- }
151- thatProject . dispose ( ) ;
152- }
153- }
154- if ( fileNameListNew . length === 0 ) {
155- // 直接把这个章节从引用列表中删除
156- delete this . project . references . sections [ sectionName ] ;
157- } else {
158- this . project . references . sections [ sectionName ] = fileNameListNew ;
159- }
176+ await this . updateOneSectionReferenceInfo ( recentFiles , sectionName ) ;
160177 }
161178
162179 // 遍历每一个直接引用自己整个文件的文件
@@ -306,14 +323,4 @@ export class ReferenceManager {
306323 this . project . renderer . transformWorld2View ( section . rectangle . leftTop ) ,
307324 ) ;
308325 }
309-
310- private findSectionBySectionName ( sectionName : string ) {
311- const section = this . project . stage
312- . filter ( ( object ) => object instanceof Section )
313- . find ( ( section ) => section . text === sectionName ) ;
314- if ( section ) {
315- return section ;
316- }
317- return null ;
318- }
319326}
0 commit comments