Only allow a single model editor per database
This will add checks in the appropriate places to ensure that only a single model editor is opened per database.
This commit is contained in:
@@ -128,6 +128,15 @@ export class ModelEditorModule extends DisposableObject {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const existingViews = this.editorViewTracker.getViews(
|
||||||
|
db.databaseUri.toString(),
|
||||||
|
);
|
||||||
|
if (existingViews.length > 0) {
|
||||||
|
await Promise.all(existingViews.map((view) => view.focusView()));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return withProgress(
|
return withProgress(
|
||||||
async (progress) => {
|
async (progress) => {
|
||||||
const maxStep = 4;
|
const maxStep = 4;
|
||||||
@@ -192,6 +201,17 @@ export class ModelEditorModule extends DisposableObject {
|
|||||||
maxStep,
|
maxStep,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check again just before opening the editor to ensure no model editor has been opened between
|
||||||
|
// our first check and now.
|
||||||
|
const existingViews = this.editorViewTracker.getViews(
|
||||||
|
db.databaseUri.toString(),
|
||||||
|
);
|
||||||
|
if (existingViews.length > 0) {
|
||||||
|
await Promise.all(existingViews.map((view) => view.focusView()));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const view = new ModelEditorView(
|
const view = new ModelEditorView(
|
||||||
this.app,
|
this.app,
|
||||||
this.modelingStore,
|
this.modelingStore,
|
||||||
|
|||||||
@@ -352,6 +352,10 @@ export class ModelEditorView extends AbstractWebview<
|
|||||||
return this.databaseItem.databaseUri.toString();
|
return this.databaseItem.databaseUri.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async focusView(): Promise<void> {
|
||||||
|
this.panel?.reveal();
|
||||||
|
}
|
||||||
|
|
||||||
public async revealMethod(method: Method): Promise<void> {
|
public async revealMethod(method: Method): Promise<void> {
|
||||||
this.panel?.reveal();
|
this.panel?.reveal();
|
||||||
|
|
||||||
@@ -520,6 +524,15 @@ export class ModelEditorView extends AbstractWebview<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let existingViews = this.viewTracker.getViews(
|
||||||
|
addedDatabase.databaseUri.toString(),
|
||||||
|
);
|
||||||
|
if (existingViews.length > 0) {
|
||||||
|
await Promise.all(existingViews.map((view) => view.focusView()));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const modelFile = await pickExtensionPack(
|
const modelFile = await pickExtensionPack(
|
||||||
this.cliServer,
|
this.cliServer,
|
||||||
addedDatabase,
|
addedDatabase,
|
||||||
@@ -532,6 +545,17 @@ export class ModelEditorView extends AbstractWebview<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check again just before opening the editor to ensure no model editor has been opened between
|
||||||
|
// our first check and now.
|
||||||
|
existingViews = this.viewTracker.getViews(
|
||||||
|
addedDatabase.databaseUri.toString(),
|
||||||
|
);
|
||||||
|
if (existingViews.length > 0) {
|
||||||
|
await Promise.all(existingViews.map((view) => view.focusView()));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const view = new ModelEditorView(
|
const view = new ModelEditorView(
|
||||||
this.app,
|
this.app,
|
||||||
this.modelingStore,
|
this.modelingStore,
|
||||||
|
|||||||
Reference in New Issue
Block a user