Skip to content
Merged
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
37 changes: 28 additions & 9 deletions projectFile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { dialog } = require('electron');
const { dialog, BrowserWindow } = require('electron');
const fs = require('fs');
const path = require('path');

function openProjectRequest(parent) {
Expand All @@ -14,16 +15,34 @@ function openProjectRequest(parent) {
}

function saveProjectRequest(parent) {
let filename = dialog.showSaveDialogSync(parent, {
properties: ['showOverwriteConfirmation'],
title: 'Save project file...',
filters: [{ name: 'Project file (*.rpe)', extensions: ['rpe'] }],
defaultPath: 'project.rpe',
const folderPath = dialog.showSaveDialogSync(parent, {
title: 'Save project folder...',
defaultPath: 'project',
buttonLabel: 'Save Project Folder',
properties: ['createDirectory'],
});
if (filename !== undefined) {
if (path.extname(filename) !== '.rpe') filename += '.rpe';

if (folderPath) {
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, { recursive: true });
}

const folderName = path.basename(folderPath);
const projectFileName = `${folderName}.rpe`;
const projectFilePath = path.join(folderPath, projectFileName);
fs.writeFileSync(projectFilePath, '');

const currentWindow = BrowserWindow.getFocusedWindow();
if (currentWindow) {
currentWindow.setTitle(`${projectFileName} - Rapid Power Estimator`);
} else {
console.error('No focused window found to set title.');
}

return projectFilePath;
}
return filename === undefined ? '' : filename;

return '';
}

module.exports = {
Expand Down
Loading