Skip to content

Commit 2822507

Browse files
authored
Implement Project Save Feature with Directory Creation Based on User Input (#238)
1 parent 6e48c6b commit 2822507

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

projectFile.js

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const { dialog } = require('electron');
1+
const { dialog, BrowserWindow } = require('electron');
2+
const fs = require('fs');
23
const path = require('path');
34

45
function openProjectRequest(parent) {
@@ -14,16 +15,34 @@ function openProjectRequest(parent) {
1415
}
1516

1617
function saveProjectRequest(parent) {
17-
let filename = dialog.showSaveDialogSync(parent, {
18-
properties: ['showOverwriteConfirmation'],
19-
title: 'Save project file...',
20-
filters: [{ name: 'Project file (*.rpe)', extensions: ['rpe'] }],
21-
defaultPath: 'project.rpe',
18+
const folderPath = dialog.showSaveDialogSync(parent, {
19+
title: 'Save project folder...',
20+
defaultPath: 'project',
21+
buttonLabel: 'Save Project Folder',
22+
properties: ['createDirectory'],
2223
});
23-
if (filename !== undefined) {
24-
if (path.extname(filename) !== '.rpe') filename += '.rpe';
24+
25+
if (folderPath) {
26+
if (!fs.existsSync(folderPath)) {
27+
fs.mkdirSync(folderPath, { recursive: true });
28+
}
29+
30+
const folderName = path.basename(folderPath);
31+
const projectFileName = `${folderName}.rpe`;
32+
const projectFilePath = path.join(folderPath, projectFileName);
33+
fs.writeFileSync(projectFilePath, '');
34+
35+
const currentWindow = BrowserWindow.getFocusedWindow();
36+
if (currentWindow) {
37+
currentWindow.setTitle(`${projectFileName} - Rapid Power Estimator`);
38+
} else {
39+
console.error('No focused window found to set title.');
40+
}
41+
42+
return projectFilePath;
2543
}
26-
return filename === undefined ? '' : filename;
44+
45+
return '';
2746
}
2847

2948
module.exports = {

0 commit comments

Comments
 (0)