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;
|
||||
}
|
||||
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user