@@ -50,6 +50,8 @@ export interface IWorkspace extends Omit<IPublicApiWorkspace<
5050 onChangeActiveEditorView ( fn : ( ) => void ) : IPublicTypeDisposable ;
5151
5252 emitChangeActiveEditorView ( ) : void ;
53+
54+ openEditorWindowByResource ( resource : IResource , sleep : boolean ) : Promise < void > ;
5355}
5456
5557export class Workspace implements IWorkspace {
@@ -91,12 +93,12 @@ export class Workspace implements IWorkspace {
9193
9294 @obx . ref window : IEditorWindow ;
9395
94- windowQueue : {
96+ windowQueue : ( {
9597 name : string ;
9698 title : string ;
9799 options : Object ;
98100 viewName ?: string ;
99- } [ ] = [ ] ;
101+ } | IResource ) [ ] = [ ] ;
100102
101103 constructor (
102104 readonly registryInnerPlugin : ( designer : IDesigner , editor : IEditor , plugins : IPublicApiPlugins ) => Promise < IPublicTypeDisposable > ,
@@ -192,7 +194,7 @@ export class Workspace implements IWorkspace {
192194 this . remove ( index ) ;
193195 }
194196
195- private remove ( index : number ) {
197+ private async remove ( index : number ) {
196198 if ( index < 0 ) {
197199 return ;
198200 }
@@ -202,16 +204,16 @@ export class Workspace implements IWorkspace {
202204 if ( this . window === window ) {
203205 this . window = this . windows [ index ] || this . windows [ index + 1 ] || this . windows [ index - 1 ] ;
204206 if ( this . window ?. sleep ) {
205- this . window . init ( ) ;
207+ await this . window . init ( ) ;
206208 }
207209 this . emitChangeActiveWindow ( ) ;
208210 }
209211 this . emitChangeWindow ( ) ;
210212 this . window ?. updateState ( WINDOW_STATE . active ) ;
211213 }
212214
213- removeEditorWindow ( resourceName : string , title : string ) {
214- const index = this . windows . findIndex ( d => ( d . resource ?. name === resourceName && d . title === title ) ) ;
215+ removeEditorWindow ( resourceName : string , id : string ) {
216+ const index = this . windows . findIndex ( d => ( d . resource ?. name === resourceName && d . title === id ) ) ;
215217 this . remove ( index ) ;
216218 }
217219
@@ -228,6 +230,47 @@ export class Workspace implements IWorkspace {
228230 this . window ?. updateState ( WINDOW_STATE . active ) ;
229231 }
230232
233+ async openEditorWindowByResource ( resource : IResource , sleep : boolean = false ) : Promise < void > {
234+ if ( this . window && ! this . window ?. initReady && ! sleep ) {
235+ this . windowQueue . push ( resource ) ;
236+ return ;
237+ }
238+
239+ this . window ?. updateState ( WINDOW_STATE . inactive ) ;
240+
241+ const filterWindows = this . windows . filter ( d => ( d . resource ?. id === resource . id ) ) ;
242+ if ( filterWindows && filterWindows . length ) {
243+ this . window = filterWindows [ 0 ] ;
244+ if ( ! sleep && this . window . sleep ) {
245+ await this . window . init ( ) ;
246+ } else {
247+ this . checkWindowQueue ( ) ;
248+ }
249+ this . emitChangeActiveWindow ( ) ;
250+ this . window ?. updateState ( WINDOW_STATE . active ) ;
251+ return ;
252+ }
253+
254+ const window = new EditorWindow ( resource , this , {
255+ title : resource . title ,
256+ options : resource . options ,
257+ viewName : resource . viewName ,
258+ sleep,
259+ } ) ;
260+
261+ this . windows = [ ...this . windows , window ] ;
262+ this . editorWindowMap . set ( window . id , window ) ;
263+ if ( sleep ) {
264+ this . emitChangeWindow ( ) ;
265+ return ;
266+ }
267+ this . window = window ;
268+ await this . window . init ( ) ;
269+ this . emitChangeWindow ( ) ;
270+ this . emitChangeActiveWindow ( ) ;
271+ this . window ?. updateState ( WINDOW_STATE . active ) ;
272+ }
273+
231274 async openEditorWindow ( name : string , title : string , options : Object , viewName ?: string , sleep ?: boolean ) {
232275 if ( this . window && ! this . window ?. initReady && ! sleep ) {
233276 this . windowQueue . push ( {
0 commit comments