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:
Koen Vlaswinkel
2023-10-11 11:51:05 +02:00
parent 2b47d3d192
commit 76db520ce7
2 changed files with 44 additions and 0 deletions

View File

@@ -128,6 +128,15 @@ export class ModelEditorModule extends DisposableObject {
return;
}
const existingViews = this.editorViewTracker.getViews(
db.databaseUri.toString(),
);
if (existingViews.length > 0) {
await Promise.all(existingViews.map((view) => view.focusView()));
return;
}
return withProgress(
async (progress) => {
const maxStep = 4;
@@ -192,6 +201,17 @@ export class ModelEditorModule extends DisposableObject {
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(
this.app,
this.modelingStore,

View File

@@ -352,6 +352,10 @@ export class ModelEditorView extends AbstractWebview<
return this.databaseItem.databaseUri.toString();
}
public async focusView(): Promise<void> {
this.panel?.reveal();
}
public async revealMethod(method: Method): Promise<void> {
this.panel?.reveal();
@@ -520,6 +524,15 @@ export class ModelEditorView extends AbstractWebview<
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(
this.cliServer,
addedDatabase,
@@ -532,6 +545,17 @@ export class ModelEditorView extends AbstractWebview<
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(
this.app,
this.modelingStore,