Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"url": "git+https://github.com/opencor/webapp.git"
},
"type": "module",
"version": "0.20260325.1",
"version": "0.20260325.2",
"engines": {
"bun": ">=1.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"./style.css": "./dist/opencor.css"
},
"version": "0.20260325.1",
"version": "0.20260325.2",
"scripts": {
"build": "vite build && bun scripts/generate.version.js",
"build:lib": "vite build --config vite.lib.config.ts && bunx --bun vue-tsc --project tsconfig.lib.types.json",
Expand Down
12 changes: 11 additions & 1 deletion src/renderer/src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,17 @@ export const fileName = (filePath: string): string => {
// A method to sleep for a number of milliseconds.

export const sleep = (ms: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, ms));
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};

// A method to wait for the next animation frame.

export const waitForNextAnimationFrame = (): Promise<number> => {
return new Promise((resolve: FrameRequestCallback) => {
requestAnimationFrame(resolve);
});
};

// Some constants related to simulation data values.
Expand Down
48 changes: 35 additions & 13 deletions src/renderer/src/components/ContentsComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,44 +113,66 @@ const hasFiles = (): boolean => {
return fileTabs.value.length > 0;
};

const selectFile = (filePath: string): void => {
const waitForTabsUpdate = async (): Promise<void> => {
// Wait a bit to ensure that the file tabs are properly updated.
// Note: although a bit of a hack, this is needed when opening multiple files. Indeed, without this, the file tab may
// not be fully initialised when opening the next file. This means that when we select the file tab, it may try
// to finish initialising itself and, when it comes to our simulation experiment view, this means resizing the
// plots.

await vue.nextTick();

for (let i = 0; i < 3; ++i) {
await common.waitForNextAnimationFrame();
}
};

const selectFile = async (filePath: string, wait: boolean = false): Promise<void> => {
activeFile.value = filePath;

if (wait) {
await waitForTabsUpdate();
}
};

const selectNextFile = (): void => {
const selectNextFile = async (): Promise<void> => {
const fileTabIndex = fileTabs.value.findIndex((fileTab) => fileTab.file.path() === activeFile.value);
const fileTabName = fileTabs.value[(fileTabIndex + 1) % fileTabs.value.length]?.file.path() || '';

if (fileTabName !== '') {
selectFile(fileTabName);
await selectFile(fileTabName);
}
};

const selectPreviousFile = (): void => {
const selectPreviousFile = async (): Promise<void> => {
const fileTabIndex = fileTabs.value.findIndex((fileTab) => fileTab.file.path() === activeFile.value);
const fileTabName =
fileTabs.value[(fileTabIndex - 1 + fileTabs.value.length) % fileTabs.value.length]?.file.path() || '';

if (fileTabName !== '') {
selectFile(fileTabName);
await selectFile(fileTabName);
}
};

const openFile = (file: locApi.File): void => {
const openFile = async (file: locApi.File, wait: boolean = false): Promise<void> => {
const filePath = file.path();
const prevActiveFile = activeFile.value;

selectFile(filePath);
await selectFile(filePath);

fileTabs.value.splice(fileTabs.value.findIndex((fileTab) => fileTab.file.path() === prevActiveFile) + 1, 0, {
file: file,
uiJson: file.uiJson()
});

electronApi?.fileOpened(filePath);

if (wait) {
await waitForTabsUpdate();
}
};

const closeFile = (filePath: string): void => {
const closeFile = async (filePath: string): Promise<void> => {
locApi.fileManager.unmanage(filePath);

const fileTabIndex = fileTabs.value.findIndex((fileTab) => fileTab.file.path() === filePath);
Expand All @@ -161,20 +183,20 @@ const closeFile = (filePath: string): void => {
const nextFileTab = fileTabs.value[Math.min(fileTabIndex, fileTabs.value.length - 1)];

if (nextFileTab) {
selectFile(nextFileTab.file.path());
await selectFile(nextFileTab.file.path());
}
}

electronApi?.fileClosed(filePath);
};

const closeCurrentFile = (): void => {
closeFile(activeFile.value);
const closeCurrentFile = async (): Promise<void> => {
await closeFile(activeFile.value);
};

const closeAllFiles = (): void => {
const closeAllFiles = async (): Promise<void> => {
while (fileTabs.value.length) {
closeCurrentFile();
await closeCurrentFile();
}
};

Expand Down
Loading
Loading